guvnor
Version:
A node process manager that isn't spanners all the way down
56 lines (51 loc) • 1.5 kB
JavaScript
var View = require('ampersand-view')
var templates = require('../templates')
var notify = require('../helpers/notification')
module.exports = View.extend({
template: templates.buttons.restart,
bindings: {
'model.isRestarting': [{
type: 'booleanClass',
no: 'fa-refresh',
selector: '[data-hook=restartbutton] i'
}, {
type: 'booleanClass',
name: 'fa-circle-o-notch',
selector: '[data-hook=restartbutton] i'
}, {
type: 'booleanClass',
name: 'fa-spin',
selector: '[data-hook=restartbutton] i'
}, {
type: 'booleanAttribute',
name: 'disabled',
selector: '[data-hook=restartbutton]'
}]
},
events: {
'click [data-hook=restartbutton]': 'restartProcess'
},
restartProcess: function (event) {
event.target.blur()
this.model.isRestarting = true
window.app.socket.emit('process:restart', {
host: this.model.collection.parent.name,
process: this.model.id
}, function (error) {
this.model.isRestarting = false
if (error) {
notify({
header: 'Restart error',
message: ['%s on %s failed to restart - %s', this.model.name, this.model.collection.parent.name, error.message],
type: 'danger'
})
} else {
notify({
header: 'Restart complete',
message: ['%s on %s restarted', this.model.name, this.model.collection.parent.name],
type: 'success'
})
}
}.bind(this))
}
})