Update standard to 5.2 and fix coding style.
This commit is contained in:
@@ -20,12 +20,12 @@ var PRODUCTION = process.argv.indexOf('--production') !== -1
|
||||
// ===================================================================
|
||||
|
||||
function src (patterns) {
|
||||
return PRODUCTION ?
|
||||
gulp.src(patterns, {
|
||||
return PRODUCTION
|
||||
? gulp.src(patterns, {
|
||||
base: SRC_DIR,
|
||||
cwd: SRC_DIR
|
||||
}) :
|
||||
watch(patterns, {
|
||||
})
|
||||
: watch(patterns, {
|
||||
base: SRC_DIR,
|
||||
cwd: SRC_DIR,
|
||||
ignoreInitial: false,
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
"must": "^0.12.0",
|
||||
"node-inspector": "^0.12.2",
|
||||
"sinon": "^1.14.1",
|
||||
"standard": "^5.1.0"
|
||||
"standard": "^5.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp build --production",
|
||||
|
||||
@@ -53,9 +53,9 @@ signOut.permission = ''
|
||||
export async function getUser () {
|
||||
const userId = this.session.get('user_id')
|
||||
|
||||
return userId === undefined ?
|
||||
null :
|
||||
this.getUserPublicProperties(await this.getUser(userId))
|
||||
return userId === undefined
|
||||
? null
|
||||
: this.getUserPublicProperties(await this.getUser(userId))
|
||||
}
|
||||
|
||||
getUser.description = 'return the currently connected user'
|
||||
|
||||
@@ -39,7 +39,6 @@ export default class Collection extends EventEmitter {
|
||||
const array = isArray(models)
|
||||
if (!array) {
|
||||
models = [models]
|
||||
|
||||
}
|
||||
|
||||
const {Model} = this
|
||||
@@ -60,16 +59,16 @@ export default class Collection extends EventEmitter {
|
||||
models = await this._add(models, opts)
|
||||
this.emit('add', models)
|
||||
|
||||
return array ?
|
||||
models :
|
||||
new this.Model(models[0])
|
||||
return array
|
||||
? models
|
||||
: new this.Model(models[0])
|
||||
}
|
||||
|
||||
async first (properties) {
|
||||
if (!isObject(properties)) {
|
||||
properties = (properties !== undefined) ?
|
||||
{ id: properties } :
|
||||
{}
|
||||
properties = (properties !== undefined)
|
||||
? { id: properties }
|
||||
: {}
|
||||
}
|
||||
|
||||
const model = await this._first(properties)
|
||||
@@ -78,9 +77,9 @@ export default class Collection extends EventEmitter {
|
||||
|
||||
async get (properties) {
|
||||
if (!isObject(properties)) {
|
||||
properties = (properties !== undefined) ?
|
||||
{ id: properties } :
|
||||
{}
|
||||
properties = (properties !== undefined)
|
||||
? { id: properties }
|
||||
: {}
|
||||
}
|
||||
|
||||
return await this._get(properties)
|
||||
@@ -131,9 +130,9 @@ export default class Collection extends EventEmitter {
|
||||
models = await this._update(models)
|
||||
this.emit('update', models)
|
||||
|
||||
return array ?
|
||||
models :
|
||||
new this.Model(models[0])
|
||||
return array
|
||||
? models
|
||||
: new this.Model(models[0])
|
||||
}
|
||||
|
||||
// Methods to override in implementations.
|
||||
@@ -168,8 +167,8 @@ export default class Collection extends EventEmitter {
|
||||
async _first (properties) {
|
||||
const models = await this.get(properties)
|
||||
|
||||
return models.length ?
|
||||
models[0] :
|
||||
null
|
||||
return models.length
|
||||
? models[0]
|
||||
: null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,10 +123,9 @@ export default class Redis extends Collection {
|
||||
if (id !== undefined) {
|
||||
delete properties.id
|
||||
return this._extract([id]).then(models => {
|
||||
return (models.length && !isEmpty(properties)) ?
|
||||
filter(models) :
|
||||
models
|
||||
|
||||
return (models.length && !isEmpty(properties))
|
||||
? filter(models)
|
||||
: models
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -402,7 +402,6 @@ const setUpApi = (webSocketServer, xo) => {
|
||||
socket.send(data, onSend)
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
return api
|
||||
|
||||
@@ -30,7 +30,9 @@ export class Remotes extends Collection {
|
||||
|
||||
async get (properties) {
|
||||
const remotes = await super.get(properties)
|
||||
forEach(remotes, remote => {remote.enabled = (remote.enabled === 'true')})
|
||||
forEach(remotes, remote => {
|
||||
remote.enabled = (remote.enabled === 'true')
|
||||
})
|
||||
return remotes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ export class Schedules extends Collection {
|
||||
|
||||
async get (properties) {
|
||||
const schedules = await super.get(properties)
|
||||
forEach(schedules, schedule => {schedule.enabled = (schedule.enabled === 'true')})
|
||||
forEach(schedules, schedule => {
|
||||
schedule.enabled = (schedule.enabled === 'true')
|
||||
})
|
||||
return schedules
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,9 +155,9 @@ export function vm (obj) {
|
||||
CPUs: {
|
||||
max: +obj.VCPUs_max,
|
||||
number: (
|
||||
isRunning && metrics ?
|
||||
+metrics.VCPUs_number :
|
||||
+obj.VCPUs_at_startup
|
||||
isRunning && metrics
|
||||
? +metrics.VCPUs_number
|
||||
: +obj.VCPUs_at_startup
|
||||
)
|
||||
},
|
||||
current_operations: obj.current_operations,
|
||||
@@ -228,9 +228,9 @@ export function vm (obj) {
|
||||
VIFs: link(obj, 'VIFs'),
|
||||
|
||||
$container: (
|
||||
isRunning ?
|
||||
link(obj, 'resident_on') :
|
||||
link(obj, 'pool') // TODO: handle local VMs (`VM.get_possible_hosts()`).
|
||||
isRunning
|
||||
? link(obj, 'resident_on')
|
||||
: link(obj, 'pool') // TODO: handle local VMs (`VM.get_possible_hosts()`).
|
||||
),
|
||||
$VBDs: link(obj, 'VBDs'),
|
||||
|
||||
@@ -294,9 +294,9 @@ export function sr (obj) {
|
||||
VDIs: link(obj, 'VDIs'),
|
||||
|
||||
$container: (
|
||||
obj.shared ?
|
||||
link(obj, 'pool') :
|
||||
obj.$PBDs[0] && link(obj.$PBDs[0], 'host')
|
||||
obj.shared
|
||||
? link(obj, 'pool')
|
||||
: obj.$PBDs[0] && link(obj.$PBDs[0], 'host')
|
||||
),
|
||||
$PBDs: link(obj, 'PBDs')
|
||||
}
|
||||
|
||||
13
src/xapi.js
13
src/xapi.js
@@ -416,7 +416,6 @@ export default class Xapi extends XapiBase {
|
||||
|
||||
async _cloneVm (vm, nameLabel = vm.name_label) {
|
||||
return await this.call('VM.clone', vm.$ref, nameLabel)
|
||||
|
||||
}
|
||||
|
||||
async _snapshotVm (vm, nameLabel = vm.name_label) {
|
||||
@@ -436,9 +435,9 @@ export default class Xapi extends XapiBase {
|
||||
|
||||
async copyVm (vmId, srId = null, nameLabel = undefined) {
|
||||
const vm = this.getObject(vmId)
|
||||
const srRef = (srId == null) ?
|
||||
'' :
|
||||
this.getObject(srId).$ref
|
||||
const srRef = (srId == null)
|
||||
? ''
|
||||
: this.getObject(srId).$ref
|
||||
|
||||
return await this._getOrWaitObject(
|
||||
await this.call('VM.copy', vm.$ref, nameLabel || vm.nameLabel, srRef)
|
||||
@@ -681,9 +680,9 @@ export default class Xapi extends XapiBase {
|
||||
|
||||
if (type === 'CD') {
|
||||
// Choose position 3 if allowed.
|
||||
position = includes(allowed, '3') ?
|
||||
'3' :
|
||||
allowed[0]
|
||||
position = includes(allowed, '3')
|
||||
? '3'
|
||||
: allowed[0]
|
||||
} else {
|
||||
position = allowed[0]
|
||||
|
||||
|
||||
22
src/xo.js
22
src/xo.js
@@ -634,7 +634,9 @@ export default class Xo extends EventEmitter {
|
||||
|
||||
async syncAllRemotes () {
|
||||
const remotes = await this.getAllRemotes()
|
||||
forEach(remotes, remote => {this.updateRemote(remote.id, {})})
|
||||
forEach(remotes, remote => {
|
||||
this.updateRemote(remote.id, {})
|
||||
})
|
||||
}
|
||||
|
||||
async disableAllRemotes () {
|
||||
@@ -968,9 +970,9 @@ export default class Xo extends EventEmitter {
|
||||
return generateToken().then(token => {
|
||||
const url = `/api/${token}`
|
||||
|
||||
return url in watchers ?
|
||||
generateUniqueUrl() :
|
||||
url
|
||||
return url in watchers
|
||||
? generateUniqueUrl()
|
||||
: url
|
||||
})
|
||||
})()
|
||||
|
||||
@@ -1048,13 +1050,13 @@ export default class Xo extends EventEmitter {
|
||||
if (isString(opts)) {
|
||||
opts = parseUrl(opts)
|
||||
} else {
|
||||
opts.method = opts.method != null ?
|
||||
opts.method.toUpperCase() :
|
||||
'GET'
|
||||
opts.method = opts.method != null
|
||||
? opts.method.toUpperCase()
|
||||
: 'GET'
|
||||
|
||||
opts.proxyMethod = opts.proxyMethod != null ?
|
||||
opts.proxyMethod.toUpperCase() :
|
||||
opts.method
|
||||
opts.proxyMethod = opts.proxyMethod != null
|
||||
? opts.proxyMethod.toUpperCase()
|
||||
: opts.method
|
||||
}
|
||||
|
||||
opts.createdAt = Date.now()
|
||||
|
||||
Reference in New Issue
Block a user