brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] incubator-brooklyn git commit: Boolean effector parameters are rendered as checkboxes.
Date Fri, 24 Jul 2015 05:08:54 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master bfcb8c35e -> 371009293


Boolean effector parameters are rendered as checkboxes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/56305914
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/56305914
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/56305914

Branch: refs/heads/master
Commit: 56305914443affe6bec8c021e2b0bfe6288faa0f
Parents: 3e36892
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Thu Jul 16 14:38:00 2015 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Thu Jul 16 14:38:00 2015 +0100

----------------------------------------------------------------------
 .../webapp/assets/js/view/effector-invoke.js    | 22 +++++---
 .../src/main/webapp/assets/tpl/apps/param.html  |  8 +++
 .../javascript/specs/model/effector-spec.js     | 54 ++++++++++++--------
 .../specs/view/effector-invoke-spec.js          | 35 +++++++------
 .../fixtures/effector-summary-list.json         |  8 ++-
 5 files changed, 83 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56305914/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
index 8d8f714..7c9e0bd 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/effector-invoke.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/effector-invoke.js
@@ -71,6 +71,9 @@ define([
                 // select the body of the table we just rendered and append params
                 var $tbody = this.$("tbody")
                 _(params).each(function (param) {
+                    // TODO: this should be another view whose implementation is specific
to
+                    // the type of the parameter (i.e. text, dates, checkboxes etc. can all
+                    // be handled separately).
                     $tbody.append(that.effectorParam({
                         name:param.name,
                         type:param.type,
@@ -112,19 +115,26 @@ define([
         },
 
         extractParamsFromTable:function () {
-            var parameters = {}
-            
+            var parameters = {};
+
             // iterate over the rows
+            // TODO: this should be generic alongside the rendering of parameters.
             this.$(".effector-param").each(function (index) {
                 var key = $(this).find(".param-name").text();
-                var value = $(this).find(".param-value").attr('id') == 'selector-container'
? 
-                        $(this).find(".param-value option:selected").attr("value") : 
-                        $(this).find(".param-value").val();
+                var valElement = $(this).find(".param-value");
+                var value;
+                if (valElement.attr('id') == 'selector-container') {
+                    value = $(this).find(".param-value option:selected").attr("value")
+                } else if (valElement.is(":checkbox")) {
+                    value = ("checked" == valElement.attr("checked")) ? "true" : "false";
+                } else {
+                    value = valElement.val();
+                }
                 //treat empty field as null value
                 if (value !== '') {
                     parameters[key] = value;
                 }
-            })
+            });
             return parameters
         },
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56305914/usage/jsgui/src/main/webapp/assets/tpl/apps/param.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/tpl/apps/param.html b/usage/jsgui/src/main/webapp/assets/tpl/apps/param.html
index 8bd5904..b292012 100644
--- a/usage/jsgui/src/main/webapp/assets/tpl/apps/param.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/apps/param.html
@@ -26,6 +26,14 @@ under the License.
     server-side mechanism for populating options in some situations. -->
     <% if (name == 'locations' || name == 'location') { %>
     <td><div id="selector-container" class="input-medium param-value"></div></td>
+    <% } else if (type == 'java.lang.Boolean') { %>
+    <td>
+        <% if (defaultValue) { %>
+        <input type="checkbox" class="param-value" checked>
+        <% } else { %>
+        <input type="checkbox" class="param-value">
+        <% } %>
+    </td>
     <% } else { %>
     <td><!--  use 1 line textarea so it can be resized -->
       <textarea class="input-medium param-value"><%- defaultValue %></textarea>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56305914/usage/jsgui/src/test/javascript/specs/model/effector-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/model/effector-spec.js b/usage/jsgui/src/test/javascript/specs/model/effector-spec.js
index d525ee4..5ffdebd 100644
--- a/usage/jsgui/src/test/javascript/specs/model/effector-spec.js
+++ b/usage/jsgui/src/test/javascript/specs/model/effector-spec.js
@@ -19,30 +19,42 @@
 define([
     "model/effector-summary", "model/effector-param"
 ], function (EffectorSummary, EffectorParam) {
-    $.ajaxSetup({ async:false });
-    
+
+    $.ajaxSetup({async: false});
+
     describe("effector-spec: EffectorSummary model", function () {
-        var effectorCollection = new EffectorSummary.Collection
-        effectorCollection.url = "fixtures/effector-summary-list.json"
-        effectorCollection.fetch()
+        var effectorCollection = new EffectorSummary.Collection;
+        effectorCollection.url = "fixtures/effector-summary-list.json";
+        effectorCollection.fetch();
 
-        it("must have 3 objects", function () {
-            expect(effectorCollection.length).toBe(3)
-        })
+        it("must have start, stop and restart effectors", function () {
+            var actual = effectorCollection.pluck("name").sort();
+            var expected = ["restart", "start", "stop"].sort();
+            expect(actual).toEqual(expected);
+        });
 
-        it("has a first object 'name'", function () {
-            var effector1 = effectorCollection.at(0)
-            expect(effector1.get("name")).toBe("start")
-            expect(effector1.get("returnType")).toBe("void")
-            expect(effector1.get("parameters").length).toBe(1)
-        })
+        describe("the start effector", function () {
+            var startEffector = effectorCollection.at(0);
+            it("has void return type and two parameters", function () {
+                expect(startEffector.get("name")).toBe("start");
+                expect(startEffector.get("returnType")).toBe("void");
+                expect(startEffector.get("parameters").length).toBe(2);
+            });
+
+            it("has a parameter named 'locations'", function () {
+                var parameter = new EffectorParam.Model(startEffector.getParameterByName("locations"));
+                expect(parameter.get("name")).toBe("locations");
+                expect(parameter.get("type")).toBe("java.util.Collection");
+                expect(parameter.get("description")).toBe("A list of locations");
+            });
 
-        it(" effector1 has a first parameter named 'locations'", function () {
-            var effector1 = effectorCollection.at(0)
-            var param1 = new EffectorParam.Model(effector1.getParameterByName("locations"))
-            expect(param1.get("name")).toBe("locations")
-            expect(param1.get("type")).toBe("java.util.Collection")
-            expect(param1.get("description")).toBe("")
+            it("has a parameter named 'booleanValue'", function () {
+                var parameter = new EffectorParam.Model(startEffector.getParameterByName("booleanValue"));
+                expect(parameter.get("name")).toBe("booleanValue");
+                expect(parameter.get("type")).toBe("java.lang.Boolean");
+                expect(parameter.get("description")).toBe("True or false");
+                expect(parameter.get("defaultValue")).toBe(true);
+            });
         })
     })
-})
+});

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56305914/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
index dbd7c8e..a2685bc 100644
--- a/usage/jsgui/src/test/javascript/specs/view/effector-invoke-spec.js
+++ b/usage/jsgui/src/test/javascript/specs/view/effector-invoke-spec.js
@@ -32,10 +32,12 @@ define([
     locationsFixture.url = 'fixtures/location-list.json'
     locationsFixture.fetch()
 
+    const effector = collection.at(0);
+
     var modalView = new EffectorInvokeView({
         tagName:"div",
         className:"modal",
-        model:collection.at(0),
+        model: effector,
         entity:entityFixture.at(0),
         locations: locationsFixture
     })
@@ -44,10 +46,6 @@ define([
         // render and keep the reference to the view
         modalView.render()
 
-        // Select the third item in the option list rather than the "None" and
-        // horizontal bar placeholders.
-        modalView.$(".select-location option:eq(2)").attr("selected", "selected");
-
         it("must render a bootstrap modal", function () {
             expect(modalView.$(".modal-header").length).toBe(1)
             expect(modalView.$(".modal-body").length).toBe(1)
@@ -61,19 +59,24 @@ define([
         })
 
         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)
-        })
+            expect(modalView.$(".modal-body table").length).toBe(1);
+            // +1 because one <tr> from table head
+            expect(modalView.$(".modal-body tr").length).toBe(effector.get("parameters").length
+ 1)
+        });
 
         it("must properly extract parameters from table", function () {
-            var params = modalView.extractParamsFromTable()
+            // Select the third item in the option list rather than the "None" and
+            // horizontal bar placeholders.
+            window.m = modalView;
+            modalView.$(".select-location option:eq(2)").attr("selected", "selected");
+
+            var params = modalView.extractParamsFromTable();
+            console.log(params);
             expect(params["locations"]).toBe("123")
-            expect(params).toEqual({"locations": "123"})
-        })
+            expect(params).toEqual({
+                "locations": "123",
+                "booleanValue": "true"
+            });
+        });
     })
 })
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56305914/usage/rest-api/src/test/resources/fixtures/effector-summary-list.json
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/test/resources/fixtures/effector-summary-list.json b/usage/rest-api/src/test/resources/fixtures/effector-summary-list.json
index dd7aaaa..fe2828c 100644
--- a/usage/rest-api/src/test/resources/fixtures/effector-summary-list.json
+++ b/usage/rest-api/src/test/resources/fixtures/effector-summary-list.json
@@ -7,7 +7,13 @@
             {
                 "name":"locations",
                 "type":"java.util.Collection",
-                "description":null
+                "description":"A list of locations"
+            },
+            {
+                "name":"booleanValue",
+                "type":"java.lang.Boolean",
+                "description":"True or false",
+                "defaultValue": true
             }
         ],
         "links":{


Mime
View raw message