fix effector params bug, and better handling of effector timeout/errors
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/77d8a0ec Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/77d8a0ec Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/77d8a0ec Branch: refs/heads/0.5.0 Commit: 77d8a0ec7a6477f546cd391e2ffa3339b29da95b Parents: dd22cea Author: Alex Heneveld <[email protected]> Authored: Fri Nov 16 23:29:06 2012 +0000 Committer: Alex Heneveld <[email protected]> Committed: Fri Nov 16 23:36:53 2012 +0000 ---------------------------------------------------------------------- .../webapp/assets/js/view/application-tree.js | 3 ++ .../src/main/webapp/assets/js/view/effector.js | 33 +++++++++++++++----- .../webapp/assets/tpl/apps/effector-modal.html | 2 +- .../test/javascript/specs/view/effector-spec.js | 2 +- 4 files changed, 31 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/77d8a0ec/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js b/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js index 533346e..b9fd28e 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js @@ -96,6 +96,9 @@ define([ if (appName === undefined) appName = $("span.entity_tree_node#"+id).data("parent-app") + if (appName === undefined) + // no such app + return var app = new Application.Model() app.url = "/v1/applications/" + appName http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/77d8a0ec/usage/jsgui/src/main/webapp/assets/js/view/effector.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/effector.js b/usage/jsgui/src/main/webapp/assets/js/view/effector.js index 1bab0b9..e19ffca 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/effector.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/effector.js @@ -11,7 +11,8 @@ define([ effectorParam:_.template(ParamHtml), effectorParamList:_.template(ParamListHtml), events:{ - "click .trigger-effector":"triggerEffector" + "click .invoke-effector":"invokeEffector", + "shown":"unfade" }, render:function () { var that = this, params = this.model.get("parameters") @@ -36,32 +37,50 @@ define([ this.$(".modal-body").find('*[rel="tooltip"]').tooltip() return this }, + unfade: function() { + this.$el.fadeTo(500,1); + }, extractParamsFromTable:function () { var parameters = {} // iterate over the rows this.$(".effector-param").each(function (index) { var key = $(this).find(".param-name").text(), - value = $(this).find(".param-value").text() + value = $(this).find(".param-value").val() // we need to create an object out of the input so it will send as the server expects: java Map parameters[key] = $.parseJSON(value) }) return parameters }, - triggerEffector:function () { + invokeEffector:function () { var that = this var url = this.model.getLinkByName("self") var parameters = this.extractParamsFromTable() - // trigger the event by ajax with attached parameters + this.$el.fadeTo(500,0.5); $.ajax({ type:"POST", - url:url, + url:url+"?timeout=0", data:JSON.stringify(parameters), contentType:"application/json", success:function (data) { - // hide the modal that.$el.modal("hide") + that.$el.fadeTo(500,1); + // data.id contains the task, if we wanted to switch to showing it + // NB we now timeout immediately, so always run in background + // ideally we might have a timeout of 300ms + // switch to task if it is still running + // otherwise show the answer + // ... or simpler, just switch to task, so response can be shown + }, + error: function(data) { + that.$el.fadeTo(100,1).delay(200).fadeTo(200,0.2).delay(200).fadeTo(200,1); + // TODO render the error better than poor-man's flashing + // (would just be connection error -- with timeout=0 we get a task even for invalid input) + + // console.log might throw error but that's okay... + console.log("ERROR invoking effector") + console.log(data) }}) - // un-delegate trigger events + // un-delegate events this.undelegateEvents() } }) http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/77d8a0ec/usage/jsgui/src/main/webapp/assets/tpl/apps/effector-modal.html ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/tpl/apps/effector-modal.html b/usage/jsgui/src/main/webapp/assets/tpl/apps/effector-modal.html index a951675..757f240 100644 --- a/usage/jsgui/src/main/webapp/assets/tpl/apps/effector-modal.html +++ b/usage/jsgui/src/main/webapp/assets/tpl/apps/effector-modal.html @@ -13,5 +13,5 @@ <div class="modal-footer"> <button type="button" class="btn btn-info btn-mini" data-dismiss="modal">Cancel</button> - <button type="button" class="btn btn-danger btn-mini trigger-effector">Invoke</button> + <button type="button" class="btn btn-danger btn-mini invoke-effector">Invoke</button> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/77d8a0ec/usage/jsgui/src/test/javascript/specs/view/effector-spec.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/test/javascript/specs/view/effector-spec.js b/usage/jsgui/src/test/javascript/specs/view/effector-spec.js index 9da5865..5e3c636 100644 --- a/usage/jsgui/src/test/javascript/specs/view/effector-spec.js +++ b/usage/jsgui/src/test/javascript/specs/view/effector-spec.js @@ -39,7 +39,7 @@ define([ }) it("must have two buttons in the footer", function () { expect(modalView.$(".modal-footer button").length).toBe(2) - expect(modalView.$(".modal-footer button.trigger-effector").length).toBe(1) + expect(modalView.$(".modal-footer button.invoke-effector").length).toBe(1) }) it("must properly extract parameters from table", function () {
