-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the ability to change states form Dashboard
This enable users to change states through the Machinery Dashboard while still passing through the machinery internals, including guard and callback functions.
- Loading branch information
1 parent
18e75d3
commit b043e48
Showing
19 changed files
with
243 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const alertTemplate = require('./templates/alert_template'); | ||
|
||
module.exports = class SortableList { | ||
constructor(holder) { | ||
let listElm = $(holder).find('ul.list-group')[0] | ||
let sortable = new Sortable(listElm, { | ||
group: { name: 'lists', pull: true, put: true}, | ||
onAdd: this.changeState.bind(this) | ||
}); | ||
} | ||
|
||
changeState(event) { | ||
let mountedPath = $("body")[0].dataset.mountedPath | ||
let itemEl = event.item; | ||
let resourceId = itemEl.dataset.id; | ||
let to_state = $(event.to).parents('.holder')[0].dataset.state; | ||
let url = `${mountedPath}/api/resources/${resourceId}` | ||
let data = {state: to_state} | ||
|
||
$.post(url, data, function(response) { | ||
if(response[0] == "error") { | ||
this.rollbackTransition(response[1], event); | ||
} | ||
}.bind(this)).fail(function() { | ||
let message = "Error on the request, check logs and try again." | ||
this.rollbackTransition(message, event); | ||
}.bind(this)); | ||
} | ||
|
||
rollbackTransition(message, event) { | ||
let error_message = `${message} Item moved back to it's original state.` | ||
let template = alertTemplate.render(error_message); | ||
$('main').prepend(template); | ||
this.moveItemBack(event.item, event.from, event.oldIndex); | ||
} | ||
|
||
moveItemBack(item, state, index) { | ||
let _index = (index == 0) ? 0 : index - 1 | ||
let _item = $(state).find("li.resource-item").eq(_index) | ||
|
||
if(index == 0){ | ||
$(item).insertBefore(_item); | ||
} | ||
else { | ||
$(item).insertAfter(_item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let renderAlert = function(message) { | ||
return ` | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
${message} | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
` | ||
|
||
} | ||
|
||
module.exports = { | ||
render: renderAlert | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.