qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject svn commit: r1753269 - in /qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid: common/ConsoleHelper.js common/Structure.js management/query/QueryCreateDialogForm.js management/query/QueryWidget.js
Date Mon, 18 Jul 2016 16:59:03 GMT
Author: orudyy
Date: Mon Jul 18 16:59:02 2016
New Revision: 1753269

URL: http://svn.apache.org/viewvc?rev=1753269&view=rev
Log:
QPID-7238: Use structure data to populate scope controls in QueryCreateDialogForm and QueryCloneDialogForm

Modified:
    qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
    qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/Structure.js
    qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryCreateDialogForm.js
    qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryWidget.js

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js?rev=1753269&r1=1753268&r2=1753269&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
Mon Jul 18 16:59:02 2016
@@ -118,7 +118,8 @@ define(["dojo/query",
                     {
                         ready(function ()
                         {
-                            queryCreateDialogForm = new QueryCreateDialogForm({management:
management});
+                            queryCreateDialogForm =
+                                new QueryCreateDialogForm({management: management, structure:
controller.structure});
                             queryCreateDialogForm.on("create", function (e)
                             {
                                 queryCreateDialog.hide();
@@ -129,19 +130,14 @@ define(["dojo/query",
                                 queryCreateDialog.hide();
                             });
                             queryCreateDialog = new Dialog({title: "Create query", content:
queryCreateDialogForm});
-                            queryCreateDialogForm.loadScope(function ()
-                            {
-                                queryCreateDialog.show();
-                            });
+                            queryCreateDialog.show();
                         });
                     });
             }
             else
             {
-                queryCreateDialogForm.loadScope(function ()
-                {
-                    queryCreateDialog.show();
-                });
+                queryCreateDialogForm.initScope();
+                queryCreateDialog.show();
             }
         },
         showQueryBrowser: function (e)

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/Structure.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/Structure.js?rev=1753269&r1=1753268&r2=1753269&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/Structure.js
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/Structure.js
Mon Jul 18 16:59:02 2016
@@ -21,55 +21,96 @@
 define(["dojo/_base/lang"],
     function (lang)
     {
-        function Structure()
+        var traverseStructure = function traverseTree(structure, parent, visit)
         {
-            this.structure = null;
+            var result = visit(parent);
+            if (result)
+            {
+                return result;
+            }
+            for (var fieldName in structure)
+            {
+                var fieldValue = structure[fieldName];
+                if (lang.isArray(fieldValue))
+                {
+                    var fieldType = fieldName.substring(0, fieldName.length - 1);
+                    for (var i = 0; i < fieldValue.length; i++)
+                    {
+                        var object = fieldValue[i];
+                        var item = {
+                            id: object.id,
+                            name: object.name,
+                            type: fieldType,
+                            parent: parent
+                        };
+                        result = traverseStructure(object, item, visit);
+                        if (result)
+                        {
+                            return result;
+                        }
+                    }
+                }
+            }
+            return false;
         };
 
-        Structure.prototype.update = function (structure)
+        var findObjectById = function findObjectById(structureRoot, id)
         {
-            this.structure = structure;
+            return traverseStructure(
+                structureRoot,
+                {
+                    id: structureRoot.id,
+                    name: structureRoot.name,
+                    type: "broker"
+                },
+                function (item)
+                {
+                    if (item.id === id)
+                    {
+                        return item;
+                    }
+                });
         };
 
-        Structure.prototype.findById = function (id)
+        var findObjectsByType = function findObjectsByType(structureRoot, type)
         {
-            var findObject = function findObject(structure, parent, type)
-            {
-                var item = {
-                    id: structure.id,
-                    name: structure.name,
-                    type: type,
-                    parent: parent
-                };
-                if (item.id == id)
+            var items = [];
+            traverseStructure(
+                structureRoot,
                 {
-                    return item;
-                }
-                else
+                    id: structureRoot.id,
+                    name: structureRoot.name,
+                    type: "broker"
+                },
+                function (item)
                 {
-                    for (var fieldName in structure)
+                    if (item.type === type)
                     {
-                        var fieldValue = structure[fieldName];
-                        if (lang.isArray(fieldValue))
-                        {
-                            var fieldType = fieldName.substring(0, fieldName.length - 1);
-                            for (var i = 0; i < fieldValue.length; i++)
-                            {
-                                var object = fieldValue[i];
-                                var result = findObject(object, item, fieldType);
-                                if (result != null)
-                                {
-                                    return result;
-                                }
-                            }
-                        }
+                        items.push(item);
                     }
-                    return null;
-                }
-            };
+                    return false;
+                });
+            return items;
+        };
+
+        function Structure()
+        {
+            this.structure = null;
+        }
 
-            return findObject(this.structure, null, "broker");
+        Structure.prototype.update = function (structure)
+        {
+            this.structure = structure;
+        };
 
+        Structure.prototype.findById = function (id)
+        {
+            return findObjectById(this.structure, id);
+        };
+
+        Structure.prototype.findByType = function (type)
+        {
+            return findObjectsByType(this.structure, type);
         };
 
         return Structure;

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryCreateDialogForm.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryCreateDialogForm.js?rev=1753269&r1=1753268&r2=1753269&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryCreateDialogForm.js
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryCreateDialogForm.js
Mon Jul 18 16:59:02 2016
@@ -58,6 +58,7 @@ define(["dojo/_base/declare",
             //Strip out the apache comment header from the template html as comments unsupported.
             templateString: template.replace(/<!--[\s\S]*?-->/g, ""),
 
+            structure: null,
             management: null,
 
             /**
@@ -74,47 +75,32 @@ define(["dojo/_base/declare",
                 this.inherited(arguments);
                 this._postCreate();
             },
-            // TODO eliminate duplication and avoid knowledge of management.
-            loadScope: function (scopeCallback)
+            initScope: function ()
             {
-                var result = this.management.query({
-                    select: "id, $parent.name as parentName, name",
-                    category: "virtualhost"
-                });
-                var that = this;
-                result.then(function (data)
-                    {
-                        that._scopeDataLoaded(data.results, scopeCallback);
-                    },
-                    function (error)
-                    {
-                        that._scopeDataLoaded([], scopeCallback);
-                    });
-            },
-            _scopeDataLoaded: function (data, scopeCallback)
-            {
-                var brokerItem = {id: "broker", name: "Broker"};
-                var defaultValue = undefined;
-                var items = [brokerItem];
+                var brokers = this.structure.findByType("broker");
+                var virtualHosts = this.structure.findByType("virtualhost");
+                var objects = brokers.concat(virtualHosts);
+
+                var items = [];
+                var brokerId = null;
                 this._scopeModelObjects = {};
-                this._scopeModelObjects[brokerItem.id] = {type: "broker"};
-                for (var i = 0; i < data.length; i++)
+                for (var i = 0; i < objects.length; i++)
                 {
-                    var name = data[i][2];
-                    var parentName = data[i][1];
+                    if (objects[i].type === "broker")
+                    {
+                        name = objects[i].name;
+                        brokerId = objects[i].id;
+                    }
+                    else
+                    {
+                        name = "VH:" + objects[i].parent.name + "/" + objects[i].name;
+                    }
+                    var id = objects[i].id;
                     items.push({
-                        id: data[i][0],
-                        name: "VH:" + parentName + "/" + name
+                        id: id,
+                        name: name
                     });
-                    this._scopeModelObjects[data[i][0]] = {
-                        name: name,
-                        type: "virtualhost",
-                        parent: {
-                            name: parentName,
-                            type: "virtualhostnode",
-                            parent: {type: "broker"}
-                        }
-                    };
+                    this._scopeModelObjects[id] = objects[i];
                 }
 
                 var scopeStore = new Memory({
@@ -122,23 +108,12 @@ define(["dojo/_base/declare",
                     idProperty: 'id'
                 });
                 this.scope.set("store", scopeStore);
-                if (defaultValue)
-                {
-                    this.scope.set("value", defaultValue.id);
-                    this.scope.set("disabled", true);
-                }
-                else
-                {
-                    this.scope.set("value", brokerItem.id);
-                }
+                this.scope.set("value", brokerId);
                 this._onChange();
-                if (scopeCallback)
-                {
-                    scopeCallback();
-                }
             },
             _postCreate: function ()
             {
+                this.initScope()
                 this.cancelButton.on("click", lang.hitch(this, this._onCancel));
                 this.okButton.on("click", lang.hitch(this, this._onFormSubmit));
                 this.scope.on("change", lang.hitch(this, this._onChange));

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryWidget.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryWidget.js?rev=1753269&r1=1753268&r2=1753269&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryWidget.js
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryWidget.js
Mon Jul 18 16:59:02 2016
@@ -181,6 +181,9 @@ define(["dojo/_base/declare",
                 okButton: null,
                 cancelButton: null,
 
+                // internal fields
+                _scopeModelObjects: {},
+
                 postCreate: function ()
                 {
                     this.inherited(arguments);
@@ -198,9 +201,16 @@ define(["dojo/_base/declare",
                     var options = [];
                     for (var i = 0; i < items.length; i++)
                     {
-                        var id = items[i].type === "broker" ? "broker" : items[i].id;
-                        var name = items[i].type === "broker" ? "Broker" : "VH:" + items[i].parent.name
+ "/"
-                                                                           + items[i].name;
+                        var name = null, id = items[i].id;
+                        if (items[i].type === "broker")
+                        {
+                            name = items[i].name;
+                        }
+                        else
+                        {
+                            name = "VH:" + items[i].parent.name + "/" + items[i].name;
+                        }
+
                         this._scopeModelObjects[id] = items[i];
                         options.push({id: id, name: name});
                     }
@@ -213,8 +223,19 @@ define(["dojo/_base/declare",
                 },
                 _setDefaultScopeItemAttr: function (defaultValue)
                 {
-                    this.scope.set("value",
-                        !defaultValue || defaultValue.type === "broker" ? "broker" : defaultValue.id);
+                    if (defaultValue)
+                    {
+                        for (var filed in this._scopeModelObjects)
+                        {
+                            var item = this._scopeModelObjects[filed];
+                            if (item.id === defaultValue.id || (item.type === "broker" &&
defaultValue.type
+                                                                                        
 === "broker"))
+                            {
+                                this.scope.set("value", item.id);
+                                break;
+                            }
+                        }
+                    }
                 },
 
                 _onCancel: function (data)
@@ -1002,45 +1023,10 @@ define(["dojo/_base/declare",
                 },
                 _cloneQuery: function ()
                 {
-                    var result = this.management.query({
-                        select: "id, $parent.name as parentName, name",
-                        category: "virtualhost"
-                    });
-                    var that = this;
-                    result.then(function (data)
-                        {
-                            that._scopeDataLoaded(data.results);
-                        },
-                        function (error)
-                        {
-                            that._scopeDataLoaded([]);
-                        });
-
-                },
-                // TODO eliminate duplication and avoid knowledge of management.
-                _scopeDataLoaded: function (data)
-                {
-                    var brokerItem = {type: "broker"};
-                    var items = [brokerItem];
-                    for (var i = 0; i < data.length; i++)
-                    {
-                        var id = data[i][0];
-                        var parentName = data[i][1];
-                        var name = data[i][2];
-                        var item = {
-                            id: id,
-                            name: name,
-                            type: "virtualhost",
-                            parent: {
-                                name: parentName,
-                                type: "virtualhostnode",
-                                parent: {type: "broker"}
-                            }
-                        };
-                        items.push(item);
-                    }
-
-                    this._queryCloneDialogForm.set("scopeItems", items);
+                    var brokers = this.controller.structure.findByType("broker");
+                    var virtualHosts = this.controller.structure.findByType("virtualhost");
+                    var objects = brokers.concat(virtualHosts);
+                    this._queryCloneDialogForm.set("scopeItems", objects);
                     this._queryCloneDialogForm.set("defaultScopeItem", this.parentObject);
                     this._queryCloneDialog.show();
                 },



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message