brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreatu...@apache.org
Subject [4/6] git commit: make js for displaying gui more consistent, using JSON.stringify rather than FormatJSON since the latter doesn't do quotes right, and stringifying activity tags
Date Wed, 17 Sep 2014 13:28:20 GMT
make js for displaying gui more consistent, using JSON.stringify rather than FormatJSON since
the latter doesn't do quotes right, and stringifying activity tags


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

Branch: refs/heads/master
Commit: e9d412f0c65a2596ec5ed144ca489945c1b3e9a0
Parents: 8a8879d
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Sep 12 22:45:46 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Sat Sep 13 02:50:53 2014 +0100

----------------------------------------------------------------------
 .../main/webapp/assets/js/libs/brooklyn-utils.js | 19 +++++++++++--------
 .../main/webapp/assets/js/libs/json-formatter.js |  2 ++
 .../webapp/assets/js/view/activity-details.js    | 11 ++++++-----
 .../assets/js/view/application-add-wizard.js     |  6 +++---
 .../src/main/webapp/assets/js/view/catalog.js    |  4 ++--
 .../webapp/assets/js/view/entity-activities.js   |  2 +-
 .../webapp/assets/js/view/entity-advanced.js     | 10 +++++-----
 .../main/webapp/assets/js/view/entity-summary.js |  8 ++------
 8 files changed, 32 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js b/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
index e85913f..6d5a864 100644
--- a/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
+++ b/usage/jsgui/src/main/webapp/assets/js/libs/brooklyn-utils.js
@@ -35,14 +35,17 @@ define([
     };
 
     Util.toDisplayString = function(data) {
-        var escaped = Util.roundIfNumberToNumDecimalPlaces(data, 4);
-        if (escaped != null) {
-            if (typeof escaped === 'string')
-                escaped = Util.escape(escaped);
-            else
-                escaped = JSON.stringify(escaped);
-        }
-        return escaped;
+        data = Util.roundIfNumberToNumDecimalPlaces(data, 4);
+        if (typeof data !== 'string')
+            data = JSON.stringify(data);
+        return Util.escape(data);
+    };
+
+    Util.toTextAreaString = function(data) {
+        data = Util.roundIfNumberToNumDecimalPlaces(data, 8);
+        if (typeof data !== 'string')
+            data = JSON.stringify(data, null, 2);
+        return data;
     };
 
     if (!String.prototype.trim) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/libs/json-formatter.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/libs/json-formatter.js b/usage/jsgui/src/main/webapp/assets/js/libs/json-formatter.js
index 8d68a7c..d0cd399 100644
--- a/usage/jsgui/src/main/webapp/assets/js/libs/json-formatter.js
+++ b/usage/jsgui/src/main/webapp/assets/js/libs/json-formatter.js
@@ -1,5 +1,7 @@
 /**
  * Code from: http://joncom.be/
+ * 
+ * TODO remove? JSON.stringify seems to do this and more, including correctly handling double
quotes and indentation
  */
 define([
     "jquery"

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/view/activity-details.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/activity-details.js b/usage/jsgui/src/main/webapp/assets/js/view/activity-details.js
index df98a77..e1c6259 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/activity-details.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/activity-details.js
@@ -20,12 +20,12 @@
  * Displays details on an activity/task
  */
 define([
-    "underscore", "jquery", "backbone", "brooklyn-utils", "view/viewutils", "formatJson",
"moment",
+    "underscore", "jquery", "backbone", "brooklyn-utils", "view/viewutils", "moment",
     "model/task-summary",
     "text!tpl/apps/activity-details.html", "text!tpl/apps/activity-table.html", 
 
     "bootstrap", "jquery-datatables", "datatables-extensions"
-], function (_, $, Backbone, Util, ViewUtils, FormatJSON, moment,
+], function (_, $, Backbone, Util, ViewUtils, moment,
     TaskSummary,
     ActivityDetailsHtml, ActivityTableHtml) {
 
@@ -158,8 +158,9 @@ define([
                  })
             this.updateFieldWith('tags', function(tags) {
                 var tagBody = "";
-                for (var tag in tags)
-                    tagBody += "<div class='activity-tag-giftlabel'>"+_.escape(tags[tag])+"</div>";
+                for (var tag in tags) {
+                    tagBody += "<div class='activity-tag-giftlabel'>"+Util.toDisplayString(tags[tag])+"</div>";
+                }
                 return tagBody;
             })
             
@@ -171,7 +172,7 @@ define([
                 function(v) { return v <= 0 ? "-" : moment(v).format('D MMM YYYY H:mm:ss.SSS')+"
&nbsp; <i>"+moment(v).from(startTimeUtc, true)+" later</i>" })
 
             ViewUtils.updateTextareaWithData(this.$(".task-json .for-textarea"), 
-                FormatJSON(this.task.toJSON()), false, false, 150, 400)
+                Util.toTextAreaString(this.task), false, false, 150, 400)
 
             ViewUtils.updateTextareaWithData(this.$(".task-detail .for-textarea"), 
                 this.task.get('detailedStatus'), false, false, 30, 250)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js b/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
index 6cd1284..51724d3 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
@@ -21,7 +21,7 @@
  * Also creates an empty Application model.
  */
 define([
-    "underscore", "jquery", "backbone", "formatJson",
+    "underscore", "jquery", "backbone", "brooklyn-utils",
     "model/entity", "model/application", "model/location",
     "text!tpl/app-add-wizard/modal-wizard.html",
     "text!tpl/app-add-wizard/create.html",
@@ -35,7 +35,7 @@ define([
     "text!tpl/app-add-wizard/preview.html",
     "bootstrap"
     
-], function (_, $, Backbone, FormatJSON, Entity, Application, Location,
+], function (_, $, Backbone, Util, Entity, Application, Location,
              ModalHtml, CreateHtml, CreateStepTemplateEntryHtml, CreateEntityEntryHtml,
              RequiredConfigEntryHtml, EditConfigEntryHtml, DeployHtml,
              DeployLocationRowHtml, DeployLocationOptionHtml, PreviewHtml
@@ -701,7 +701,7 @@ define([
             if (!this.model.spec.get("config") || _.keys(this.model.spec.get("config")).length==0)
{
                 delete this.model.spec.attributes["config"]
             }
-            this.$('#app-summary').val(FormatJSON(this.model.spec.toJSON()))
+            this.$('#app-summary').val(Util.toTextAreaString(this.model.spec))
         },
         render:function () {
             this.delegateEvents()

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
index 24389d9..9875f73 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
@@ -17,7 +17,7 @@
  * under the License.
 */
 define([
-    "underscore", "jquery", "backbone", "formatJson", "brooklyn",
+    "underscore", "jquery", "backbone", "brooklyn",
     "model/location", "model/entity",
     "text!tpl/catalog/page.html",
     "text!tpl/catalog/details-entity.html",
@@ -29,7 +29,7 @@ define([
     "text!tpl/catalog/nav-entry.html",
 
     "bootstrap", "jquery-form"
-], function(_, $, Backbone, FormatJSON, Brooklyn,
+], function(_, $, Backbone, Brooklyn,
         Location, Entity,
         CatalogPageHtml, DetailsEntityHtml, DetailsGenericHtml, LocationDetailsHtml,
         AddCatalogEntryHtml, AddEntityHtml, AddLocationHtml, EntryHtml) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
index 1545cf1..07dc948 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
@@ -25,7 +25,7 @@ define([
     "text!tpl/apps/activities.html", "text!tpl/apps/activity-table.html", 
     "text!tpl/apps/activity-row-details.html", "text!tpl/apps/activity-row-details-main.html",
     "text!tpl/apps/activity-full-details.html", 
-    "bootstrap", "formatJson", "jquery-datatables", "datatables-extensions", "moment"
+    "bootstrap", "jquery-datatables", "datatables-extensions", "moment"
 ], function (_, $, Backbone, Util, ViewUtils, ActivityDetailsView, 
     ActivitiesHtml, ActivityTableHtml, ActivityRowDetailsHtml, ActivityRowDetailsMainHtml,
ActivityFullDetailsHtml) {
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/view/entity-advanced.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-advanced.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-advanced.js
index 362cadb..34966ae 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-advanced.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-advanced.js
@@ -21,9 +21,9 @@
  *
  * @type {*}
  */
-define(["underscore", "jquery", "backbone", "brooklyn", "brooklyn-utils", "view/viewutils",
"formatJson",
+define(["underscore", "jquery", "backbone", "brooklyn", "brooklyn-utils", "view/viewutils",
     "text!tpl/apps/advanced.html", "view/entity-config", "view/change-name-invoke", "view/add-child-invoke",
"view/policy-new"
-], function(_, $, Backbone, Brooklyn, Util, ViewUtils, FormatJSON,
+], function(_, $, Backbone, Brooklyn, Util, ViewUtils,
         AdvancedHtml, EntityConfigView, ChangeNameInvokeView, AddChildInvokeView, NewPolicyView)
{
     var EntityAdvancedView = Backbone.View.extend({
         events: {
@@ -56,15 +56,15 @@ define(["underscore", "jquery", "backbone", "brooklyn", "brooklyn-utils",
"view/
         },
         modelChange: function() {
             this.$('#entity-name').html(Util.toDisplayString(this.model.get("name")));
-            ViewUtils.updateTextareaWithData($("#advanced-entity-json", this.$el), FormatJSON(this.model.toJSON()),
true, false, 250, 600);
+            ViewUtils.updateTextareaWithData($("#advanced-entity-json", this.$el), Util.toTextAreaString(this.model),
true, false, 250, 600);
         },
         renderLocationData: function(data) {
-            ViewUtils.updateTextareaWithData($("#advanced-locations", this.$el), FormatJSON(data),
true, false, 250, 600);
+            ViewUtils.updateTextareaWithData($("#advanced-locations", this.$el), Util.toTextAreaString(data),
true, false, 250, 600);
         },
         renderTags: function(data) {
             var list = "";
             for (tag in data)
-                list += "<div class='activity-tag-giftlabel'>"+_.escape(JSON.stringify(data[tag]))+"</div>";
+                list += "<div class='activity-tag-giftlabel'>"+Util.toDisplayString(data[tag])+"</div>";
             if (!list) list = "No tags";
             this.$('#advanced-entity-tags').html(list);
         },

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9d412f0/usage/jsgui/src/main/webapp/assets/js/view/entity-summary.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-summary.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-summary.js
index 7984fac..b2b52aa 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-summary.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-summary.js
@@ -22,8 +22,8 @@
  */
 define([
     "underscore", "jquery", "backbone", "view/viewutils",
-    "text!tpl/apps/summary.html", "formatJson"
-], function (_, $, Backbone, ViewUtils, SummaryHtml, FormatJSON) {
+    "text!tpl/apps/summary.html"
+], function (_, $, Backbone, ViewUtils, SummaryHtml) {
 
     var EntitySummaryView = Backbone.View.extend({
         events:{
@@ -33,14 +33,10 @@ define([
         initialize: function() {
             _.bindAll(this)
             var that = this
-            var ej = FormatJSON(this.model.toJSON());
             this.$el.html(this.template({
                 entity:this.model,
                 application:this.options.application,
-                entityJson:ej,
-                applicationJson:FormatJSON(this.options.application.toJSON())
             }))
-            ViewUtils.updateTextareaWithData($(".for-textarea", this.$el), ej, true, false,
150, 400)
             ViewUtils.attachToggler(this.$el)
 
             // TODO we should have a backbone object exported from the sensors view which
we can listen to here


Mime
View raw message