You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:51:42 UTC
[09/50] [abbrv] brooklyn-ui git commit: renamed view/effector.js to
effector-invoke
renamed view/effector.js to effector-invoke
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/73881a0e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/73881a0e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/73881a0e
Branch: refs/heads/0.5.0
Commit: 73881a0e95bae8447ebaa52652351cd36a6a96f5
Parents: bb4a303
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Nov 19 11:37:54 2012 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Nov 27 15:46:47 2012 -0800
----------------------------------------------------------------------
.../webapp/assets/js/view/effector-invoke.js | 88 ++++++++++++++++++++
.../src/main/webapp/assets/js/view/effector.js | 88 --------------------
.../webapp/assets/js/view/entity-effectors.js | 6 +-
.../specs/view/effector-invoke-spec.js | 51 ++++++++++++
.../test/javascript/specs/view/effector-spec.js | 51 ------------
5 files changed, 142 insertions(+), 142 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/73881a0e/usage/jsgui/src/main/webapp/assets/js/view/effector-invoke.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/effector-invoke.js b/usage/jsgui/src/main/webapp/assets/js/view/effector-invoke.js
new file mode 100644
index 0000000..211e703
--- /dev/null
+++ b/usage/jsgui/src/main/webapp/assets/js/view/effector-invoke.js
@@ -0,0 +1,88 @@
+/**
+ * Render an entity effector as a modal.
+ */
+define([
+ "underscore", "jquery", "backbone", "text!tpl/apps/effector-modal.html", "text!tpl/apps/param.html",
+ "text!tpl/apps/param-list.html"
+], function (_, $, Backbone, EffectorModalHtml, ParamHtml, ParamListHtml) {
+
+ var EffectorInvokeView = Backbone.View.extend({
+ template:_.template(EffectorModalHtml),
+ effectorParam:_.template(ParamHtml),
+ effectorParamList:_.template(ParamListHtml),
+ events:{
+ "click .invoke-effector":"invokeEffector",
+ "shown":"unfade"
+ },
+ render:function () {
+ var that = this, params = this.model.get("parameters")
+ this.$el.html(this.template({
+ name:this.model.get("name"),
+ entityName:this.options.entity.get("name"),
+ description:this.model.get("description")?this.model.get("description"):""
+ }))
+ // do we have parameters to render?
+ if (params.length !== 0) {
+ this.$(".modal-body").html(this.effectorParamList({}))
+ // select the body of the table we just rendered and append params
+ var $tbody = this.$("tbody")
+ _(params).each(function (param) {
+ $tbody.append(that.effectorParam({
+ name:param.name,
+ type:param.type,
+ description:param.description?param.description:""
+ }))
+ })
+ }
+ 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").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
+ },
+ invokeEffector:function () {
+ var that = this
+ var url = this.model.getLinkByName("self")
+ var parameters = this.extractParamsFromTable()
+ this.$el.fadeTo(500,0.5);
+ $.ajax({
+ type:"POST",
+ url:url+"?timeout=0",
+ data:JSON.stringify(parameters),
+ contentType:"application/json",
+ success:function (data) {
+ 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 events
+ this.undelegateEvents()
+ }
+ })
+ return EffectorInvokeView
+})
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/73881a0e/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
deleted file mode 100644
index e19ffca..0000000
--- a/usage/jsgui/src/main/webapp/assets/js/view/effector.js
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * Render an entity effector as a modal.
- */
-define([
- "underscore", "jquery", "backbone", "text!tpl/apps/effector-modal.html", "text!tpl/apps/param.html",
- "text!tpl/apps/param-list.html"
-], function (_, $, Backbone, EffectorModalHtml, ParamHtml, ParamListHtml) {
-
- var EffectorView = Backbone.View.extend({
- template:_.template(EffectorModalHtml),
- effectorParam:_.template(ParamHtml),
- effectorParamList:_.template(ParamListHtml),
- events:{
- "click .invoke-effector":"invokeEffector",
- "shown":"unfade"
- },
- render:function () {
- var that = this, params = this.model.get("parameters")
- this.$el.html(this.template({
- name:this.model.get("name"),
- entityName:this.options.entity.get("name"),
- description:this.model.get("description")?this.model.get("description"):""
- }))
- // do we have parameters to render?
- if (params.length !== 0) {
- this.$(".modal-body").html(this.effectorParamList({}))
- // select the body of the table we just rendered and append params
- var $tbody = this.$("tbody")
- _(params).each(function (param) {
- $tbody.append(that.effectorParam({
- name:param.name,
- type:param.type,
- description:param.description?param.description:""
- }))
- })
- }
- 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").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
- },
- invokeEffector:function () {
- var that = this
- var url = this.model.getLinkByName("self")
- var parameters = this.extractParamsFromTable()
- this.$el.fadeTo(500,0.5);
- $.ajax({
- type:"POST",
- url:url+"?timeout=0",
- data:JSON.stringify(parameters),
- contentType:"application/json",
- success:function (data) {
- 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 events
- this.undelegateEvents()
- }
- })
- return EffectorView
-})
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/73881a0e/usage/jsgui/src/main/webapp/assets/js/view/entity-effectors.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-effectors.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-effectors.js
index dcca91d..a86dc71 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-effectors.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-effectors.js
@@ -6,8 +6,8 @@
*/
define([
"underscore", "jquery", "backbone", "model/effector-summary",
- "view/effector", "text!tpl/apps/effector.html", "text!tpl/apps/effector-row.html", "bootstrap"
-], function (_, $, Backbone, EffectorSummary, EffectorView, EffectorHtml, EffectorRowHtml) {
+ "view/effector-invoke", "text!tpl/apps/effector.html", "text!tpl/apps/effector-row.html", "bootstrap"
+], function (_, $, Backbone, EffectorSummary, EffectorInvokeView, EffectorHtml, EffectorRowHtml) {
var EntityEffectorsView = Backbone.View.extend({
template:_.template(EffectorHtml),
@@ -45,7 +45,7 @@ define([
showEffectorModal:function (eventName) {
// get the model that we need to show, create its view and show it
var cid = $(eventName.currentTarget).attr("id")
- this._modal = new EffectorView({
+ this._modal = new EffectorInvokeView({
el:"#effector-modal",
model:this._effectors.getByCid(cid),
entity:this.model
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/73881a0e/usage/jsgui/src/test/javascript/specs/view/effector-invoke-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/view/effector-invoke-spec.js b/usage/jsgui/src/test/javascript/specs/view/effector-invoke-spec.js
new file mode 100644
index 0000000..f434bf9
--- /dev/null
+++ b/usage/jsgui/src/test/javascript/specs/view/effector-invoke-spec.js
@@ -0,0 +1,51 @@
+define([
+ "underscore", "view/effector-invoke", "model/effector-summary", "model/entity"
+], function (_, EffectorInvokeView, EffectorSummary, Entity) {
+
+ var modalView, collection = new EffectorSummary.Collection()
+ collection.url = "fixtures/effector-summary-list.json"
+ collection.fetch()
+
+ var entityFixture = new Entity.Collection
+ entityFixture.url = 'fixtures/entity.json'
+ entityFixture.fetch({async:true})
+
+ modalView = new EffectorInvokeView({
+ tagName:"div",
+ className:"modal",
+ model:collection.at(0),
+ entity:entityFixture.at(0)
+ })
+
+ describe("view/effector-invoke", function () {
+ // render and keep the reference to the view
+ modalView.render()
+ it("must render a bootstrap modal", function () {
+ expect(modalView.$(".modal-header").length).toBe(1)
+ expect(modalView.$(".modal-body").length).toBe(1)
+ expect(modalView.$(".modal-footer").length).toBe(1)
+ })
+
+ it("must have effector name, entity name, and effector description in header", function () {
+ expect(modalView.$(".modal-header h3").html()).toContain("start")
+ expect(modalView.$(".modal-header h3").html()).toContain("Vanilla")
+ expect(modalView.$(".modal-header p").html()).toBe("Start the process/service represented by an entity")
+ })
+
+ it("must have the list of parameters in body", function () {
+ expect(modalView.$(".modal-body table").length).toBe(1)
+ expect(modalView.$(".modal-body tr").length).toBe(2) // one tr from the head
+ expect(modalView.$(".modal-body .param-name").html()).toBe("locations")
+ })
+ it("must have two buttons in the footer", function () {
+ expect(modalView.$(".modal-footer button").length).toBe(2)
+ expect(modalView.$(".modal-footer button.invoke-effector").length).toBe(1)
+ })
+
+ it("must properly extract parameters from table", function () {
+ var params = modalView.extractParamsFromTable()
+ expect(params["locations"]).toBe(null)
+ expect(params).toEqual({"locations":null})
+ })
+ })
+})
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/73881a0e/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
deleted file mode 100644
index 5e3c636..0000000
--- a/usage/jsgui/src/test/javascript/specs/view/effector-spec.js
+++ /dev/null
@@ -1,51 +0,0 @@
-define([
- "underscore", "view/effector", "model/effector-summary", "model/entity"
-], function (_, EffectorView, EffectorSummary, Entity) {
-
- var modalView, collection = new EffectorSummary.Collection()
- collection.url = "fixtures/effector-summary-list.json"
- collection.fetch()
-
- var entityFixture = new Entity.Collection
- entityFixture.url = 'fixtures/entity.json'
- entityFixture.fetch({async:true})
-
- modalView = new EffectorView({
- tagName:"div",
- className:"modal",
- model:collection.at(0),
- entity:entityFixture.at(0)
- })
-
- describe("view/effector", function () {
- // render and keep the reference to the view
- modalView.render()
- it("must render a bootstrap modal", function () {
- expect(modalView.$(".modal-header").length).toBe(1)
- expect(modalView.$(".modal-body").length).toBe(1)
- expect(modalView.$(".modal-footer").length).toBe(1)
- })
-
- it("must have effector name, entity name, and effector description in header", function () {
- expect(modalView.$(".modal-header h3").html()).toContain("start")
- expect(modalView.$(".modal-header h3").html()).toContain("Vanilla")
- expect(modalView.$(".modal-header p").html()).toBe("Start the process/service represented by an entity")
- })
-
- it("must have the list of parameters in body", function () {
- expect(modalView.$(".modal-body table").length).toBe(1)
- expect(modalView.$(".modal-body tr").length).toBe(2) // one tr from the head
- expect(modalView.$(".modal-body .param-name").html()).toBe("locations")
- })
- it("must have two buttons in the footer", function () {
- expect(modalView.$(".modal-footer button").length).toBe(2)
- expect(modalView.$(".modal-footer button.invoke-effector").length).toBe(1)
- })
-
- it("must properly extract parameters from table", function () {
- var params = modalView.extractParamsFromTable()
- expect(params["locations"]).toBe(null)
- expect(params).toEqual({"locations":null})
- })
- })
-})
\ No newline at end of file