Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Logger.js URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Logger.js?rev=1741609&r1=1741608&r2=1741609&view=diff ============================================================================== --- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Logger.js (original) +++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Logger.js Fri Apr 29 11:04:40 2016 @@ -19,253 +19,284 @@ * */ define(["dojo/parser", - "dojo/query", - "dojo/_base/connect", - "dijit/registry", - "dojox/html/entities", - "qpid/common/properties", - "qpid/common/updater", - "qpid/common/util", - "qpid/common/formatter", - "qpid/common/UpdatableStore", - "dojox/grid/EnhancedGrid", - "dojo/text!showLogger.html", - "qpid/management/addLogger", - "qpid/management/addLogInclusionRule", - "dojo/domReady!"], - function (parser, query, connect, registry, entities, properties, updater, util, formatter, UpdatableStore, EnhancedGrid, template, addLogger, addLogInclusionRule) - { - - function Logger(name, parent, controller) - { - this.name = name; - this.controller = controller; - this.management = controller.management; - var isBrokerParent = parent.type == "broker"; - this.category = isBrokerParent ? "BrokerLogger" : "VirtualHostLogger"; - this.logInclusionRuleCategory = isBrokerParent? "BrokerLogInclusionRule" : "VirtualHostLogInclusionRule"; - this.modelObj = {type: this.category.toLowerCase(), name: name, parent: parent}; - this.userFriendlyName = (isBrokerParent ? "Broker Logger" : "Virtual Host Logger"); - } - - Logger.prototype.getTitle = function () - { - return this.userFriendlyName + ": " + this.name; - }; - - Logger.prototype.open = function (contentPane) - { - var that = this; - this.contentPane = contentPane; - contentPane.containerNode.innerHTML = template; - parser.parse(contentPane.containerNode).then(function (instances) - { - that.onOpen(contentPane.containerNode) - }); - - }; - - Logger.prototype.onOpen = function (containerNode) - { - var that = this; - this.editLoggerButton = registry.byNode(query(".editLoggerButton", containerNode)[0]); - this.deleteLoggerButton = registry.byNode(query(".deleteLoggerButton", containerNode)[0]); - this.deleteLoggerButton.on("click", - function (e) - { - if (confirm("Are you sure you want to delete logger '" + entities.encode(String(that.name)) + "'?")) - { - that.management.remove(that.modelObj).then( - function (x) - { - that.destroy(); - }, util.xhrErrorHandler); - } - } - ); - this.editLoggerButton.on("click", - function (event) - { - that.management.load(that.modelObj, {actuals: true, depth: 0}).then( - function(data) - { - addLogger.show(that.management, that.modelObj, that.category, data[0]); - } - ); - } - ); - - var gridProperties = { - selectionMode: "extended", - plugins: { - indirectSelection: true - } - }; - - this.logInclusionRuleGrid = new UpdatableStore([], query(".logInclusionRuleGrid", containerNode)[0], - [ - {name: "Rule Name", field: "name", width: "20%"}, - {name: "Type", field: "type", width: "20%"}, - {name: "Logger Name", field: "loggerName", width: "30%"}, - {name: "Level", field: "level", width: "20%"}, - {name: "Durable", field: "durable", width: "10%", formatter: util.buildCheckboxMarkup} - ], function (obj) - { - connect.connect(obj.grid, "onRowDblClick", obj.grid, - function (evt) - { - var idx = evt.rowIndex; - var theItem = this.getItem(idx); - that.showLogInclusionRule(theItem); - }); - }, gridProperties, EnhancedGrid); - - this.addLogInclusionRuleButton = registry.byNode(query(".addLogInclusionRuleButton", containerNode)[0]); - this.deleteLogInclusionRuleButton = registry.byNode(query(".deleteLogInclusionRuleButton", containerNode)[0]); - - this.deleteLogInclusionRuleButton.on("click", - function (e) - { - util.deleteSelectedObjects( - that.logInclusionRuleGrid.grid, - "Are you sure you want to delete log inclusion rule", - that.management, - {type: that.logInclusionRuleCategory.toLowerCase(), parent: that.modelObj}, - that.loggerUpdater); - } - ); - - this.addLogInclusionRuleButton.on("click", - function(e) - { - addLogInclusionRule.show(that.management, that.modelObj, that.logInclusionRuleCategory); - } - ); - - this.loggerUpdater = new Updater(this); - this.loggerUpdater.update(function (x) - { - updater.add(that.loggerUpdater); - }); - }; - - Logger.prototype.showLogInclusionRule = function (item) - { - var ruleModelObj = {name: item.name, type: this.logInclusionRuleCategory.toLowerCase(), parent: this.modelObj}; - var that = this; - this.management.load(ruleModelObj, {actuals: true}).then( - function(data) - { - addLogInclusionRule.show(that.management, ruleModelObj, that.logInclusionRuleCategory, data[0]); - }); - }; - - Logger.prototype.close = function () - { - updater.remove(this.loggerUpdater); - }; - - Logger.prototype.destroy = function () - { - this.close(); - this.contentPane.onClose(); - this.controller.tabContainer.removeChild(this.contentPane); - this.contentPane.destroyRecursive(); - }; - - function Updater(logger) - { - var domNode = logger.contentPane.containerNode; - this.tabObject = logger; - this.modelObj = logger.modelObj; - var that = this; - - function findNode(name) - { - return query("." + name, domNode)[0]; - } - - function storeNodes(names) - { - for (var i = 0; i < names.length; i++) - { - that[names[i]] = findNode(names[i]); - } - } - - storeNodes(["name", "state", "type", "loggerAttributes", "loggerTypeSpecificDetails", "logInclusionRuleWarning", "durable", "errorCount", "warnCount"]); - } - - Updater.prototype.update = function (callback) - { - var that = this; - that.tabObject.management.load(this.modelObj).then( - function (data) - { - that.loggerData = data[0] || {}; - that.updateUI(that.loggerData); - - if (callback) - { - callback(); - } - }, - function (error) - { - util.tabErrorHandler(error, { - updater: that, - contentPane: that.tabObject.contentPane, - tabContainer: that.tabObject.controller.tabContainer, - name: that.modelObj.name, - category: that.tabObject.userFriendlyName - }); - }); - }; - - Updater.prototype.updateUI = function (data) - { - this.name.innerHTML = entities.encode(String(data["name"])); - this.state.innerHTML = entities.encode(String(data["state"])); - this.type.innerHTML = entities.encode(String(data["type"])); - this.durable.innerHTML = util.buildCheckboxMarkup(data["durable"]); - this.errorCount.innerHTML = String(data["statistics"]["errorCount"]); - this.warnCount.innerHTML = String(data["statistics"]["warnCount"]); - - if (!this.details) - { - var that = this; - require(["qpid/management/logger/" + this.tabObject.modelObj.type + "/show"], - function (Details) - { - that.details = new Details({ - containerNode: that.loggerAttributes, - typeSpecificDetailsNode: that.loggerTypeSpecificDetails, - metadata: that.tabObject.management.metadata, - data: data, - management: that.tabObject.management, - modelObj: that.tabObject.modelObj - }); - } - ); - } - else - { - this.details.update(data); - } - - var ruleFieldName = this.tabObject.logInclusionRuleCategory.toLowerCase() + "s"; // add plural "s" - if (data[ruleFieldName]) - { - this.tabObject.logInclusionRuleGrid.grid.domNode.style.display = "block"; - this.logInclusionRuleWarning.style.display = "none"; - } - else - { - this.tabObject.logInclusionRuleGrid.grid.domNode.style.display = "none"; - this.logInclusionRuleWarning.style.display = "block"; - } - util.updateUpdatableStore(this.tabObject.logInclusionRuleGrid, data[ruleFieldName]); - }; + "dojo/query", + "dojo/_base/connect", + "dijit/registry", + "dojox/html/entities", + "qpid/common/properties", + "qpid/common/updater", + "qpid/common/util", + "qpid/common/formatter", + "qpid/common/UpdatableStore", + "dojox/grid/EnhancedGrid", + "dojo/text!showLogger.html", + "qpid/management/addLogger", + "qpid/management/addLogInclusionRule", + "dojo/domReady!"], + function (parser, query, connect, registry, entities, properties, updater, util, formatter, UpdatableStore, EnhancedGrid, template, addLogger, addLogInclusionRule) + { + + function Logger(name, parent, controller) + { + this.name = name; + this.controller = controller; + this.management = controller.management; + var isBrokerParent = parent.type == "broker"; + this.category = isBrokerParent ? "BrokerLogger" : "VirtualHostLogger"; + this.logInclusionRuleCategory = + isBrokerParent ? "BrokerLogInclusionRule" : "VirtualHostLogInclusionRule"; + this.modelObj = { + type: this.category.toLowerCase(), + name: name, + parent: parent + }; + this.userFriendlyName = (isBrokerParent ? "Broker Logger" : "Virtual Host Logger"); + } + + Logger.prototype.getTitle = function () + { + return this.userFriendlyName + ": " + this.name; + }; + + Logger.prototype.open = function (contentPane) + { + var that = this; + this.contentPane = contentPane; + contentPane.containerNode.innerHTML = template; + parser.parse(contentPane.containerNode).then(function (instances) + { + that.onOpen(contentPane.containerNode) + }); + + }; + + Logger.prototype.onOpen = function (containerNode) + { + var that = this; + this.editLoggerButton = registry.byNode(query(".editLoggerButton", containerNode)[0]); + this.deleteLoggerButton = registry.byNode(query(".deleteLoggerButton", containerNode)[0]); + this.deleteLoggerButton.on("click", function (e) + { + if (confirm("Are you sure you want to delete logger '" + entities.encode(String(that.name)) + "'?")) + { + that.management.remove(that.modelObj).then(function (x) + { + that.destroy(); + }, util.xhrErrorHandler); + } + }); + this.editLoggerButton.on("click", function (event) + { + that.management.load(that.modelObj, + { + actuals: true, + depth: 0 + }).then(function (data) + { + addLogger.show(that.management, + that.modelObj, + that.category, + data[0]); + }); + }); + + var gridProperties = { + selectionMode: "extended", + plugins: { + indirectSelection: true + } + }; + + this.logInclusionRuleGrid = new UpdatableStore([], query(".logInclusionRuleGrid", containerNode)[0], [{ + name: "Rule Name", + field: "name", + width: "20%" + }, + { + name: "Type", + field: "type", + width: "20%" + }, + { + name: "Logger Name", + field: "loggerName", + width: "30%" + }, + { + name: "Level", + field: "level", + width: "20%" + }, + { + name: "Durable", + field: "durable", + width: "10%", + formatter: util.buildCheckboxMarkup + }], function (obj) + { + connect.connect(obj.grid, "onRowDblClick", obj.grid, function (evt) + { + var idx = evt.rowIndex; + var theItem = this.getItem(idx); + that.showLogInclusionRule(theItem); + }); + }, gridProperties, EnhancedGrid); + + this.addLogInclusionRuleButton = registry.byNode(query(".addLogInclusionRuleButton", containerNode)[0]); + this.deleteLogInclusionRuleButton = + registry.byNode(query(".deleteLogInclusionRuleButton", containerNode)[0]); + + this.deleteLogInclusionRuleButton.on("click", function (e) + { + util.deleteSelectedObjects(that.logInclusionRuleGrid.grid, + "Are you sure you want to delete log inclusion rule", + that.management, + { + type: that.logInclusionRuleCategory.toLowerCase(), + parent: that.modelObj + }, + that.loggerUpdater); + }); + + this.addLogInclusionRuleButton.on("click", function (e) + { + addLogInclusionRule.show(that.management, that.modelObj, that.logInclusionRuleCategory); + }); + + this.loggerUpdater = new Updater(this); + this.loggerUpdater.update(function (x) + { + updater.add(that.loggerUpdater); + }); + }; + + Logger.prototype.showLogInclusionRule = function (item) + { + var ruleModelObj = { + name: item.name, + type: this.logInclusionRuleCategory.toLowerCase(), + parent: this.modelObj + }; + var that = this; + this.management.load(ruleModelObj, {actuals: true}).then(function (data) + { + addLogInclusionRule.show(that.management, + ruleModelObj, + that.logInclusionRuleCategory, + data[0]); + }); + }; + + Logger.prototype.close = function () + { + updater.remove(this.loggerUpdater); + }; + + Logger.prototype.destroy = function () + { + this.close(); + this.contentPane.onClose(); + this.controller.tabContainer.removeChild(this.contentPane); + this.contentPane.destroyRecursive(); + }; + + function Updater(logger) + { + var domNode = logger.contentPane.containerNode; + this.tabObject = logger; + this.modelObj = logger.modelObj; + var that = this; + + function findNode(name) + { + return query("." + name, domNode)[0]; + } + + function storeNodes(names) + { + for (var i = 0; i < names.length; i++) + { + that[names[i]] = findNode(names[i]); + } + } + + storeNodes(["name", + "state", + "type", + "loggerAttributes", + "loggerTypeSpecificDetails", + "logInclusionRuleWarning", + "durable", + "errorCount", + "warnCount"]); + } + + Updater.prototype.update = function (callback) + { + var that = this; + that.tabObject.management.load(this.modelObj).then(function (data) + { + that.loggerData = data[0] || {}; + that.updateUI(that.loggerData); + + if (callback) + { + callback(); + } + }, function (error) + { + util.tabErrorHandler(error, { + updater: that, + contentPane: that.tabObject.contentPane, + tabContainer: that.tabObject.controller.tabContainer, + name: that.modelObj.name, + category: that.tabObject.userFriendlyName + }); + }); + }; + + Updater.prototype.updateUI = function (data) + { + this.name.innerHTML = entities.encode(String(data["name"])); + this.state.innerHTML = entities.encode(String(data["state"])); + this.type.innerHTML = entities.encode(String(data["type"])); + this.durable.innerHTML = util.buildCheckboxMarkup(data["durable"]); + this.errorCount.innerHTML = String(data["statistics"]["errorCount"]); + this.warnCount.innerHTML = String(data["statistics"]["warnCount"]); + + if (!this.details) + { + var that = this; + require(["qpid/management/logger/" + this.tabObject.modelObj.type + "/show"], function (Details) + { + that.details = new Details({ + containerNode: that.loggerAttributes, + typeSpecificDetailsNode: that.loggerTypeSpecificDetails, + metadata: that.tabObject.management.metadata, + data: data, + management: that.tabObject.management, + modelObj: that.tabObject.modelObj + }); + }); + } + else + { + this.details.update(data); + } + + var ruleFieldName = this.tabObject.logInclusionRuleCategory.toLowerCase() + "s"; // add plural "s" + if (data[ruleFieldName]) + { + this.tabObject.logInclusionRuleGrid.grid.domNode.style.display = "block"; + this.logInclusionRuleWarning.style.display = "none"; + } + else + { + this.tabObject.logInclusionRuleGrid.grid.domNode.style.display = "none"; + this.logInclusionRuleWarning.style.display = "block"; + } + util.updateUpdatableStore(this.tabObject.logInclusionRuleGrid, data[ruleFieldName]); + }; - return Logger; - }); + return Logger; + });
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js?rev=1741609&r1=1741608&r2=1741609&view=diff ============================================================================== --- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js (original) +++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js Fri Apr 29 11:04:40 2016 @@ -29,546 +29,592 @@ define(["dojo/_base/lang", "qpid/common/metadata", "qpid/common/timezone", "qpid/management/UserPreferences"], - function (lang, array, xhr, ioQuery, json, Promise, Deferred, sasl, Metadata, Timezone, UserPreferences) - { + function (lang, array, xhr, ioQuery, json, Promise, Deferred, sasl, Metadata, Timezone, UserPreferences) + { - function shallowCopy(source, target, excludes) - { - if (source) - { - for(var fieldName in source) - { - if(source.hasOwnProperty(fieldName)) - { - if (excludes && array.indexOf(excludes,fieldName) != -1) - { - continue; - } - - target[fieldName] = source[fieldName]; - } - } - } - return target; - } - - function merge(data1, data2) - { - var result = {}; - shallowCopy(data1, result); - shallowCopy(data2, result); - return result; - } - - // summary: - // This is a facade for sending management requests to broker at given brokerURL specifying schema, host and port. - // Optional errorHandler method can be set and invoked on error responses. - function Management(brokerURL, errorHandler) - { - this.brokerURL = brokerURL; - this.errorHandler = errorHandler || function(error){console.error(error);}; - } - - // summary: - // Submits HTTP request to broker using dojo.request.xhr - // request: Object? - // request object can have the same fields as dojo.request.xhr options and additional 'url' field: - // data: String|Object|FormData? - // Data to transfer. This is ignored for GET and DELETE requests. - // headers: Object? - // Headers to use for the request. - // user: String? - // Username to use during the request. - // password: String? - // Password to use during the request. - // withCredentials: Boolean? - // For cross-site requests, whether to send credentials or not. - // query: Object? - // the query parameters to add to the request url - // handleAs: String - // Indicates how the response will be handled. - // url: String? - // relative URL to broker REST API - // - // returns: promise of type dojo.promise.Promise - // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. - Management.prototype.submit = function(request) - { - var requestOptions = { - sync: false, - handleAs: "json", - withCredentials: true, - headers: { "Content-Type": "application/json"} - }; - - if (request) - { - shallowCopy(request, requestOptions, ["url"]); - if (requestOptions.data && requestOptions.headers && requestOptions.headers["Content-Type"] - && requestOptions.headers["Content-Type"] == "application/json" - && typeof requestOptions.data != "string") - { - requestOptions.data = json.stringify(request.data ); - } - } - - if (!requestOptions.method) - { - requestOptions.method = "GET"; - } - - var url = this.getFullUrl(request.url); - var promise = xhr(url, requestOptions); - var errorHandler = this.errorHandler; - - // decorate promise in order to use a default error handler when 'then' method is invoked without providing error handler - return lang.mixin(new Promise(), - { - then: function(callback, errback, progback) { return promise.then(callback, errback||errorHandler, progback ); }, - cancel: function(reason, strict) { return promise.cancel(reason, strict); }, - isResolved: function(){return promise.isResolved();}, - isRejected: function(){return promise.isRejected();}, - isFulfilled: function(){return promise.isFulfilled();}, - isCanceled: function(){return promise.isCanceled();}, - always: function(callbackOrErrback){return promise.always(callbackOrErrback);}, - otherwise: function(errback){return promise.otherwise(errback);}, - trace: function(){ return promise.trace();}, - traceRejected: function(){return promise.traceRejected();}, - toString: function(){return promise.toString();}, - response: promise.response + function shallowCopy(source, target, excludes) + { + if (source) + { + for (var fieldName in source) + { + if (source.hasOwnProperty(fieldName)) + { + if (excludes && array.indexOf(excludes, fieldName) != -1) + { + continue; + } + + target[fieldName] = source[fieldName]; + } + } + } + return target; + } + + function merge(data1, data2) + { + var result = {}; + shallowCopy(data1, result); + shallowCopy(data2, result); + return result; + } + + // summary: + // This is a facade for sending management requests to broker at given brokerURL specifying schema, host and port. + // Optional errorHandler method can be set and invoked on error responses. + function Management(brokerURL, errorHandler) + { + this.brokerURL = brokerURL; + this.errorHandler = errorHandler || function (error) + { + console.error(error); + }; + } + + // summary: + // Submits HTTP request to broker using dojo.request.xhr + // request: Object? + // request object can have the same fields as dojo.request.xhr options and additional 'url' field: + // data: String|Object|FormData? + // Data to transfer. This is ignored for GET and DELETE requests. + // headers: Object? + // Headers to use for the request. + // user: String? + // Username to use during the request. + // password: String? + // Password to use during the request. + // withCredentials: Boolean? + // For cross-site requests, whether to send credentials or not. + // query: Object? + // the query parameters to add to the request url + // handleAs: String + // Indicates how the response will be handled. + // url: String? + // relative URL to broker REST API + // + // returns: promise of type dojo.promise.Promise + // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. + Management.prototype.submit = function (request) + { + var requestOptions = { + sync: false, + handleAs: "json", + withCredentials: true, + headers: {"Content-Type": "application/json"} + }; + + if (request) + { + shallowCopy(request, requestOptions, ["url"]); + if (requestOptions.data && requestOptions.headers && requestOptions.headers["Content-Type"] + && requestOptions.headers["Content-Type"] == "application/json" && typeof requestOptions.data + != "string") + { + requestOptions.data = json.stringify(request.data); + } + } + + if (!requestOptions.method) + { + requestOptions.method = "GET"; + } + + var url = this.getFullUrl(request.url); + var promise = xhr(url, requestOptions); + var errorHandler = this.errorHandler; + + // decorate promise in order to use a default error handler when 'then' method is invoked without providing error handler + return lang.mixin(new Promise(), { + then: function (callback, errback, progback) + { + return promise.then(callback, errback || errorHandler, progback); + }, + cancel: function (reason, strict) + { + return promise.cancel(reason, strict); + }, + isResolved: function () + { + return promise.isResolved(); + }, + isRejected: function () + { + return promise.isRejected(); + }, + isFulfilled: function () + { + return promise.isFulfilled(); + }, + isCanceled: function () + { + return promise.isCanceled(); + }, + always: function (callbackOrErrback) + { + return promise.always(callbackOrErrback); + }, + otherwise: function (errback) + { + return promise.otherwise(errback); + }, + trace: function () + { + return promise.trace(); + }, + traceRejected: function () + { + return promise.traceRejected(); + }, + toString: function () + { + return promise.toString(); + }, + response: promise.response }); - }; + }; + + Management.prototype.get = function (request) + { + var requestOptions = merge(request, {method: "GET"}); + return this.submit(requestOptions); + }; + + Management.prototype.post = function (request, data) + { + var requestOptions = merge(request, + { + method: "POST", + data: data + }); + return this.submit(requestOptions); + }; + + Management.prototype.del = function (request) + { + var requestOptions = merge(request, {method: "DELETE"}); + return this.submit(requestOptions); + }; + + // summary: + // Loads object data specified as modelObj argument + // modelObj: Object? + // is a JSON object specifying the hierarchy + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // + // parameters: Object? + // is optional JSON to pass additional request parameters which will be added into query of REST url + // + // returns: promise of type dojo.promise.Promise + // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. + Management.prototype.load = function (modelObj, parameters, requestOptions) + { + var url = this.objectToURL(modelObj); + var request = {url: url}; - Management.prototype.get = function(request) - { - var requestOptions = merge(request, {method: "GET"}); - return this.submit(requestOptions); - }; - - Management.prototype.post = function(request, data) - { - var requestOptions = merge(request, {method: "POST", data: data}); - return this.submit(requestOptions); - }; - - Management.prototype.del = function(request) - { - var requestOptions = merge(request, {method: "DELETE"}); - return this.submit(requestOptions); - }; - - // summary: - // Loads object data specified as modelObj argument - // modelObj: Object? - // is a JSON object specifying the hierarchy - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // - // parameters: Object? - // is optional JSON to pass additional request parameters which will be added into query of REST url - // - // returns: promise of type dojo.promise.Promise - // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. - Management.prototype.load = function(modelObj, parameters, requestOptions) - { - var url = this.objectToURL(modelObj); - var request = {url: url}; - - if (requestOptions) - { - lang.mixin(request,requestOptions); - } - - if (parameters) - { - request.query = parameters; - } - return this.get(request); - }; - - // summary: - // Creates object as specified in data parameter with given category and with given parent parentModelObject - // category: String? - // Object category - // - // parentModelObject: Object? - // Parent object hierarchy - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // data; Object? - // Object structure - // - // returns: promise of type dojo.promise.Promise - // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. - Management.prototype.create = function(category, parentModelObject, data) - { - var newObjectModel ={type: category.toLowerCase(), parent: parentModelObject}; - var url = this.objectToURL(newObjectModel); - var request = {url: url}; - return this.post(request, data); - }; - - // summary: - // Updates object (which can be located using modelObj parameter) attributes to the values set in data parameter - // - // modelObj: Object? - // Object specifying hierarchy - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // data; Object? - // New attributes - // - // returns: promise of type dojo.promise.Promise - // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. - Management.prototype.update = function(modelObj, data) - { - var url = this.objectToURL(modelObj); - var request = {url: url}; - return this.post(request, data); - }; - - // summary: - // Removes object specified as modelObj argument - // modelObj: Object? - // hierarchy object - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // parameters: Object? - // is optional JSON object to pass additional request parameters which will be added into query of REST url - // - // returns: promise of type dojo.promise.Promise - // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. - Management.prototype.remove = function(modelObj, parameters) - { - var url = this.objectToURL(modelObj); - var request = {url: url}; - if (parameters) - { - request.query = parameters; - } - return this.del(request); - }; - - // summary: - // Downloads current JSON for object specified as modelObj argument - // - // modelObj: Object? - // hierarchy object - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // parameters: Object? - // is optional JSON object to pass additional request parameters which will be added into query of REST url - // - Management.prototype.download = function(modelObj, parameters) - { - var url = this.buildObjectURL(modelObj, parameters); - setTimeout(function() {window.location = url;}, 100); - } - - // summary: - // Downloads current JSON for object specified as modelObj argument into iframe - Management.prototype.downloadIntoFrame = function(modelObj, parameters) - { - var url = this.buildObjectURL(modelObj, parameters); - var iframe = document.createElement('iframe'); - iframe.id = "downloader_" + modelObj.name; - document.body.appendChild(iframe); - iframe.src = url; - // It seems there is no way to remove this iframe in a manner that is cross browser compatible. - } - - // summary: - // Builds relative REST url (excluding schema, host and port) for the object representing CO hierarchy - // modelObj: Object? - // hierarchy object - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // parameters: Object? - // is optional JSON object to pass additional request parameters which will be added into query of REST url - // - // returns: relative REST url for the hierarchy object - // - Management.prototype.objectToURL = function(modelObj) - { - var url = null; - if (modelObj.type == "broker") - { - url = "broker" - } - else - { - url = encodeURIComponent(modelObj.type); - var parentPath = this.objectToPath(modelObj); - if (parentPath) - { - url = url + "/" + parentPath; - } - - if (modelObj.name) - { - if (url.substring(url.length - 1) != "/") - { - url = url + "/"; - } - // Double encode the object name in case it contains slashes - url = url + encodeURIComponent(encodeURIComponent(modelObj.name)) - } - } - return "api/latest/" + url; - }; - - // summary: - // Builds a servlet path of REST url for the object representing CO hierarchy - // modelObj: Object? - // hierarchy object - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // parameters: Object? - // is optional JSON object to pass additional request parameters which will be added into query of REST url - // - // returns: relative REST servlet path for the hierarchy object - // - Management.prototype.objectToPath = function(modelObj) - { - var path = ""; - var parent = modelObj.parent; - while (parent && parent.type != "broker") - { - if (path) - { - path = encodeURIComponent(encodeURIComponent(parent.name)) + "/" + path; - } - else - { - path = encodeURIComponent(encodeURIComponent(parent.name)); - } - parent = parent.parent; - } - return path; - }; - - // summary: - // Builds full REST url for the object representing CO hierarchy - // modelObj: Object? - // hierarchy object - // It can have the following fields: - // name: String? - // name of the object - // type: String? - // category of the object - // parent: Object? - // parent of the object in the same format, having fields name, type, parent - // parameters: Object? - // is optional JSON object to pass additional request parameters which will be added into query of REST url - // - // returns: full REST url for the hierarchy object - // - Management.prototype.buildObjectURL = function(modelObj, parameters) - { - var url = this.objectToURL(modelObj); - if (parameters) - { - url = url + "?" + ioQuery.objectToQuery(parameters); - } - return this.getFullUrl(url); - } - - // summary: - // Returns full REST url for the relative REST url - // - // returns: full urk for the given relative URL - // - Management.prototype.getFullUrl = function(url) - { - var baseUrl = this.brokerURL || ""; - if (baseUrl != "") - { - baseUrl = baseUrl + "/"; - } - return baseUrl + url; - } - - // summary: - // Loads meta data, time zones, user preferences and invokes callback functions after loading user preferences - // - Management.prototype.init = function(callback) - { - var that = this; - this.loadMetadata(function() + if (requestOptions) + { + lang.mixin(request, requestOptions); + } + + if (parameters) + { + request.query = parameters; + } + return this.get(request); + }; + + // summary: + // Creates object as specified in data parameter with given category and with given parent parentModelObject + // category: String? + // Object category + // + // parentModelObject: Object? + // Parent object hierarchy + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // data; Object? + // Object structure + // + // returns: promise of type dojo.promise.Promise + // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. + Management.prototype.create = function (category, parentModelObject, data) + { + var newObjectModel = { + type: category.toLowerCase(), + parent: parentModelObject + }; + var url = this.objectToURL(newObjectModel); + var request = {url: url}; + return this.post(request, data); + }; + + // summary: + // Updates object (which can be located using modelObj parameter) attributes to the values set in data parameter + // + // modelObj: Object? + // Object specifying hierarchy + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // data; Object? + // New attributes + // + // returns: promise of type dojo.promise.Promise + // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. + Management.prototype.update = function (modelObj, data) + { + var url = this.objectToURL(modelObj); + var request = {url: url}; + return this.post(request, data); + }; + + // summary: + // Removes object specified as modelObj argument + // modelObj: Object? + // hierarchy object + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // parameters: Object? + // is optional JSON object to pass additional request parameters which will be added into query of REST url + // + // returns: promise of type dojo.promise.Promise + // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. + Management.prototype.remove = function (modelObj, parameters) + { + var url = this.objectToURL(modelObj); + var request = {url: url}; + if (parameters) + { + request.query = parameters; + } + return this.del(request); + }; + + // summary: + // Downloads current JSON for object specified as modelObj argument + // + // modelObj: Object? + // hierarchy object + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // parameters: Object? + // is optional JSON object to pass additional request parameters which will be added into query of REST url + // + Management.prototype.download = function (modelObj, parameters) + { + var url = this.buildObjectURL(modelObj, parameters); + setTimeout(function () { - that.loadTimezones(function() - { - that.loadUserPreferences(callback) - }); - }); - }; - - // summary: - // Loads meta data and store it under 'metadata' field as object of type qpid.common.metadata object. - // When meta data are loaded successfully a callback function is executed, otherwise default error handler is invoked - // - Management.prototype.loadMetadata = function(callback) - { - var that = this; - this.get({url: "service/metadata"}).then( - function(data) - { - that.metadata = new Metadata(data); - if (callback) - { - callback(); - } - }); - }; - - // summary: - // Loads timezones and store them under 'timezone' field as object of type qpid.common.timezone object - // When timezones are loaded successfully a callback function is executed, otherwise default error handler is invoked - // - Management.prototype.loadTimezones = function(callback) - { - var that = this; - that.get({url: "service/timezones"}).then( - function(timezones) - { - that.timezone = new Timezone(timezones); - if (callback) - { - callback(); - } - }); - }; - - // summary: - // Loads user preferences and store them under 'userPreferences' field as object of type qpid.management.UserPreferences - // Callback is invoked on both successful and unsuccessful preferences request - // - Management.prototype.loadUserPreferences = function(callback) - { - this.userPreferences = new UserPreferences(this); - this.userPreferences.load(callback, callback); - }; - - var saslServiceUrl = "service/sasl"; - - Management.prototype.getSaslStatus = function() - { - return this.get({url: saslServiceUrl}); - } - - Management.prototype.sendSaslResponse = function(response) - { - return this.submit({ - url: saslServiceUrl, - data: response, - headers: {}, - method: "POST" - }); - }; - - Management.prototype.authenticate = function(forceAuthentication) - { - var that = this; - var deferred = new Deferred(); - var successCallback = function(data) - { - that.getSaslStatus().then(function(saslData) - { - if (saslData.user) - { - deferred.resolve(saslData); - } - else + window.location = url; + }, 100); + } + + // summary: + // Downloads current JSON for object specified as modelObj argument into iframe + Management.prototype.downloadIntoFrame = function (modelObj, parameters) + { + var url = this.buildObjectURL(modelObj, parameters); + var iframe = document.createElement('iframe'); + iframe.id = "downloader_" + modelObj.name; + document.body.appendChild(iframe); + iframe.src = url; + // It seems there is no way to remove this iframe in a manner that is cross browser compatible. + } + + // summary: + // Builds relative REST url (excluding schema, host and port) for the object representing CO hierarchy + // modelObj: Object? + // hierarchy object + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // parameters: Object? + // is optional JSON object to pass additional request parameters which will be added into query of REST url + // + // returns: relative REST url for the hierarchy object + // + Management.prototype.objectToURL = function (modelObj) + { + var url = null; + if (modelObj.type == "broker") + { + url = "broker" + } + else + { + url = encodeURIComponent(modelObj.type); + var parentPath = this.objectToPath(modelObj); + if (parentPath) + { + url = url + "/" + parentPath; + } + + if (modelObj.name) + { + if (url.substring(url.length - 1) != "/") + { + url = url + "/"; + } + // Double encode the object name in case it contains slashes + url = url + encodeURIComponent(encodeURIComponent(modelObj.name)) + } + } + return "api/latest/" + url; + }; + + // summary: + // Builds a servlet path of REST url for the object representing CO hierarchy + // modelObj: Object? + // hierarchy object + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // parameters: Object? + // is optional JSON object to pass additional request parameters which will be added into query of REST url + // + // returns: relative REST servlet path for the hierarchy object + // + Management.prototype.objectToPath = function (modelObj) + { + var path = ""; + var parent = modelObj.parent; + while (parent && parent.type != "broker") + { + if (path) + { + path = encodeURIComponent(encodeURIComponent(parent.name)) + "/" + path; + } + else + { + path = encodeURIComponent(encodeURIComponent(parent.name)); + } + parent = parent.parent; + } + return path; + }; + + // summary: + // Builds full REST url for the object representing CO hierarchy + // modelObj: Object? + // hierarchy object + // It can have the following fields: + // name: String? + // name of the object + // type: String? + // category of the object + // parent: Object? + // parent of the object in the same format, having fields name, type, parent + // parameters: Object? + // is optional JSON object to pass additional request parameters which will be added into query of REST url + // + // returns: full REST url for the hierarchy object + // + Management.prototype.buildObjectURL = function (modelObj, parameters) + { + var url = this.objectToURL(modelObj); + if (parameters) + { + url = url + "?" + ioQuery.objectToQuery(parameters); + } + return this.getFullUrl(url); + } + + // summary: + // Returns full REST url for the relative REST url + // + // returns: full urk for the given relative URL + // + Management.prototype.getFullUrl = function (url) + { + var baseUrl = this.brokerURL || ""; + if (baseUrl != "") + { + baseUrl = baseUrl + "/"; + } + return baseUrl + url; + } + + // summary: + // Loads meta data, time zones, user preferences and invokes callback functions after loading user preferences + // + Management.prototype.init = function (callback) + { + var that = this; + this.loadMetadata(function () + { + that.loadTimezones(function () + { + that.loadUserPreferences(callback) + }); + }); + }; + + // summary: + // Loads meta data and store it under 'metadata' field as object of type qpid.common.metadata object. + // When meta data are loaded successfully a callback function is executed, otherwise default error handler is invoked + // + Management.prototype.loadMetadata = function (callback) + { + var that = this; + this.get({url: "service/metadata"}).then(function (data) + { + that.metadata = new Metadata(data); + if (callback) { - deferred.reject({message: "User identifier is not found!" - + " Authentication failed!"}); + callback(); } - }, - failureCallback); - }; - var failureCallback = function(data) - { - deferred.reject(data); - }; - this.getSaslStatus().then(function(data) + }); + }; + + // summary: + // Loads timezones and store them under 'timezone' field as object of type qpid.common.timezone object + // When timezones are loaded successfully a callback function is executed, otherwise default error handler is invoked + // + Management.prototype.loadTimezones = function (callback) + { + var that = this; + that.get({url: "service/timezones"}).then(function (timezones) + { + that.timezone = new Timezone(timezones); + if (callback) + { + callback(); + } + }); + }; + + // summary: + // Loads user preferences and store them under 'userPreferences' field as object of type qpid.management.UserPreferences + // Callback is invoked on both successful and unsuccessful preferences request + // + Management.prototype.loadUserPreferences = function (callback) + { + this.userPreferences = new UserPreferences(this); + this.userPreferences.load(callback, callback); + }; + + var saslServiceUrl = "service/sasl"; + + Management.prototype.getSaslStatus = function () + { + return this.get({url: saslServiceUrl}); + } + + Management.prototype.sendSaslResponse = function (response) + { + return this.submit({ + url: saslServiceUrl, + data: response, + headers: {}, + method: "POST" + }); + }; + + Management.prototype.authenticate = function (forceAuthentication) + { + var that = this; + var deferred = new Deferred(); + var successCallback = function (data) + { + that.getSaslStatus().then(function (saslData) + { + if (saslData.user) + { + deferred.resolve(saslData); + } + else + { + deferred.reject({ + message: "User identifier is not found!" + + " Authentication failed!" + }); + } + }, failureCallback); + }; + var failureCallback = function (data) + { + deferred.reject(data); + }; + this.getSaslStatus().then(function (data) + { + if (data.user && !forceAuthentication) + { + deferred.resolve(data); + } + else { - if (data.user && !forceAuthentication) - { - deferred.resolve(data); - } - else - { - sasl.authenticate(data.mechanisms, that).then(successCallback, - failureCallback); - } - }, - failureCallback); - return deferred.promise; - }; - - // summary: - // Sends query request - // query: query Object? - // is a JSON object specifying the hierarchy - // It can have the following fields: - // where: String? - // sql like expression containing 'where' conditions - // select: String? - // coma separated list of fields to select - // category: String? - // category of the object - // parent: Object? - // hierarchy object defining query scope, - // if not set queries will be executed against broker. - // Virtual host query scope can be defined by setting parent - // into corresponding object representing a virtual host hierarchy - // - // returns: promise of type dojo.promise.Promise - // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. - Management.prototype.query = function(query) - { - var url = "api/latest/" + (query.parent && query.parent.type === "virtualhost" ? - "queryvhost/" + this.objectToPath({parent: query.parent}) : - "querybroker") + (query.category ? "/" + query.category : ""); - var request = {url: this.getFullUrl(url), query: {}}; - shallowCopy(query, request.query, ["parent", "category"]); - return this.get(request); - }; + sasl.authenticate(data.mechanisms, that) + .then(successCallback, failureCallback); + } + }, failureCallback); + return deferred.promise; + }; + + // summary: + // Sends query request + // query: query Object? + // is a JSON object specifying the hierarchy + // It can have the following fields: + // where: String? + // sql like expression containing 'where' conditions + // select: String? + // coma separated list of fields to select + // category: String? + // category of the object + // parent: Object? + // hierarchy object defining query scope, + // if not set queries will be executed against broker. + // Virtual host query scope can be defined by setting parent + // into corresponding object representing a virtual host hierarchy + // + // returns: promise of type dojo.promise.Promise + // Promise returned by dojo.request.xhr with modified then method allowing to use default error handler if none is specified. + Management.prototype.query = function (query) + { + var url = "api/latest/" + (query.parent && query.parent.type === "virtualhost" ? "queryvhost/" + + this.objectToPath({parent: query.parent}) : "querybroker") + (query.category ? "/" + + query.category : ""); + var request = { + url: this.getFullUrl(url), + query: {} + }; + shallowCopy(query, request.query, ["parent", "category"]); + return this.get(request); + }; - return Management; - }); + return Management; + }); Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js?rev=1741609&r1=1741608&r2=1741609&view=diff ============================================================================== --- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js (original) +++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js Fri Apr 29 11:04:40 2016 @@ -29,31 +29,41 @@ define(["dojo/parser", "dojox/html/entities", "dojo/text!showPlugin.html", "dojo/domReady!"], - function (parser, query, connect, properties, updater, util, registry, event, entities, template) { + function (parser, query, connect, properties, updater, util, registry, event, entities, template) + { - function Plugin(name, parent, controller) { + function Plugin(name, parent, controller) + { this.name = name; this.controller = controller; this.management = controller.management; - this.modelObj = { type: "plugin", name: name, parent: parent }; + this.modelObj = { + type: "plugin", + name: name, + parent: parent + }; } - Plugin.prototype.getTitle = function() { - return "Plugin: " + this.name ; + Plugin.prototype.getTitle = function () + { + return "Plugin: " + this.name; }; - Plugin.prototype.open = function(contentPane) { + Plugin.prototype.open = function (contentPane) + { var that = this; this.contentPane = contentPane; - contentPane.containerNode.innerHTML = template; - parser.parse(contentPane.containerNode).then(function(instances) - { - that.pluginUpdater = new PluginUpdater(contentPane, that.modelObj, that.controller); - }); + contentPane.containerNode.innerHTML = template; + parser.parse(contentPane.containerNode).then(function (instances) + { + that.pluginUpdater = + new PluginUpdater(contentPane, that.modelObj, that.controller); + }); }; - Plugin.prototype.close = function() { - updater.remove( this.pluginUpdater ); + Plugin.prototype.close = function () + { + updater.remove(this.pluginUpdater); }; function PluginUpdater(contentPane, pluginObject, controller) @@ -68,25 +78,27 @@ define(["dojo/parser", var that = this; this.management.load(that.modelObj) - .then(function(data) + .then(function (data) { that.pluginData = data[0]; that.updateHeader(); - require(["qpid/management/plugin/"+ that.pluginData.type.toLowerCase().replace('-','')], - function(SpecificPlugin) { - that.details = new SpecificPlugin(query(".pluginDetails", node)[0], pluginObject, controller, contentPane); - }); + require(["qpid/management/plugin/" + that.pluginData.type.toLowerCase().replace('-', '')], + function (SpecificPlugin) + { + that.details = new SpecificPlugin(query(".pluginDetails", + node)[0], pluginObject, controller, contentPane); + }); }, util.xhrErrorHandler); } - PluginUpdater.prototype.updateHeader = function() + PluginUpdater.prototype.updateHeader = function () { - this.name.innerHTML = entities.encode(String(this.pluginData[ "name" ])); - this.type.innerHTML = entities.encode(String(this.pluginData[ "type" ])); + this.name.innerHTML = entities.encode(String(this.pluginData["name"])); + this.type.innerHTML = entities.encode(String(this.pluginData["type"])); }; return Plugin; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
