summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2013-09-14 11:23:18 +0000
committerAlex Rudyy <orudyy@apache.org>2013-09-14 11:23:18 +0000
commit883d7bd6a52f219984ffeb3c7fd5f7fd0bc7b1f9 (patch)
treeb9da138e63219f363a34f8b9684d7a56ad9e5de4 /qpid/java
parent36d57ef5c4efd18def268c45989a23c1df1439c1 (diff)
downloadqpid-python-883d7bd6a52f219984ffeb3c7fd5f7fd0bc7b1f9.tar.gz
Introduce UpdatableGrid widget
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1523216 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js10
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js166
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js56
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js121
4 files changed, 210 insertions, 143 deletions
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
index c882447f5d..9c0baf3111 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
@@ -161,6 +161,11 @@ define([
this.inherited(arguments);
try
{
+ if (this.filterDefDialog)
+ {
+ this.filterDefDialog.destroy();
+ this.filterDefDialog = null;
+ }
if (this.grid)
{
this.grid.unwrap("filter");
@@ -186,11 +191,6 @@ define([
this.filterStatusTip.destroy();
this.filterStatusTip = null;
}
- if (this.filterDefDialog)
- {
- this.filterDefDialog.destroy();
- this.filterDefDialog = null;
- }
this.args = null;
}catch(e){
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
index bb1e32bc31..7016e4eb5b 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
@@ -28,40 +28,31 @@ define(["dojo/_base/xhr",
"qpid/common/updater",
"qpid/common/UpdatableStore",
"qpid/common/util",
- "dojox/grid/EnhancedGrid",
+ "dojo/store/Memory",
+ "dojo/data/ObjectStore",
"qpid/common/grid/EnhancedFilter",
"dojox/grid/enhanced/plugins/NestedSorting",
"dojo/domReady!"],
- function (xhr, parser, array, lang, properties, updater, UpdatableStore, util, EnhancedGrid, EnhancedFilter, NestedSorting) {
-
- /*
- * Construct GridUpdater from the following arguments:
- * serviceUrl - service URL to fetch data for the grid. Optional, if data is specified
- * data - array containing data for the grid. Optional, if serviceUrl is specified
- * node - dom node or dom node id to
- * structure,
- * funct,
- * gridProperties,
- * gridConstructor
- */
- function GridUpdater(args) {
+ function (xhr, parser, array, lang, properties, updater, UpdatableStore, util, Memory, ObjectStore) {
- var self = this;
-
- // GridUpdater fields
+ function GridUpdater(args, store) {
this.updatable = args.hasOwnProperty("updatable") ? args.updatable : true ;
this.serviceUrl = args.serviceUrl;
- this.updatableStore = null;
- this.grid = null;
+
this.onUpdate = args.onUpdate;
- this._args = args;
+
this.appendData = args.append;
this.appendLimit = args.appendLimit;
+ this.initialData = args.data;
+ this.initializeStore(store);
+ };
+
+ GridUpdater.prototype.buildUpdatableGridArguments = function(args)
+ {
+ var filterPluginFound = args && args.hasOwnProperty("plugins") && args.plugins.filter ? true: false;
- // default grid properties
var gridProperties = {
autoHeight: true,
- updateDelay: 0, // no delay updates when receiving notifications from a datastore
plugins: {
pagination: {
defaultPageSize: 25,
@@ -73,30 +64,23 @@ define(["dojo/_base/xhr",
maxPageStep: 4,
position: "bottom"
},
- enhancedFilter: {}
+ enhancedFilter: {
+ disableFiltering: filterPluginFound
+ }
}
};
- var filterPluginFound = false;
-
- // merge args grid properties with default grid properties
- if(args && args.gridProperties)
+ if(args)
{
- var argProperties = args.gridProperties;
- for(var argProperty in argProperties)
+ for(var argProperty in args)
{
- if(argProperties.hasOwnProperty(argProperty))
+ if(args.hasOwnProperty(argProperty))
{
if (argProperty == "plugins")
{
- var argPlugins = argProperties[ argProperty ];
+ var argPlugins = args[ argProperty ];
for(var argPlugin in argPlugins)
{
- if (argPlugin == "filter")
- {
- // we need to switch off filtering in EnhancedFilter
- filterPluginFound = true;
- }
if(argPlugins.hasOwnProperty(argPlugin))
{
var argPluginProperties = argPlugins[ argPlugin ];
@@ -120,65 +104,95 @@ define(["dojo/_base/xhr",
}
else
{
- gridProperties[ argProperty ] = argProperties[ argProperty ];
+ gridProperties[ argProperty ] = args[ argProperty ];
}
}
}
}
- if (filterPluginFound)
- {
- gridProperties.plugins.enhancedFilter.disableFiltering = true;
- }
+ gridProperties.updater = this;
+ gridProperties.store = this.dataStore;
- var updatableStoreFactory = function(data)
+ return gridProperties;
+ };
+
+ GridUpdater.prototype.initializeStore = function(store)
+ {
+ var self = this;
+
+ function processData(data)
{
- try
- {
- self.updatableStore = new UpdatableStore(data, self._args.node, self._args.structure,
- self._args.funct, gridProperties, self._args.GridConstructor || EnhancedGrid, self.appendData);
- }
- catch(e)
- {
- console.error(e);
- throw e;
- }
- self.grid = self.updatableStore.grid;
- self.grid.updater = self;
- if (self.onUpdate)
- {
- self.onUpdate(data);
- }
- if (self.serviceUrl)
- {
- updater.add(self);
- }
+ var dataSet = false;
+ if (!store)
+ {
+ store = new ObjectStore({objectStore: new Memory({data: data, idProperty: "id"})});
+ dataSet = true;
+ }
+ self.dataStore = store
+ self.store = store;
+ if (store instanceof ObjectStore)
+ {
+ if( store.objectStore instanceof Memory)
+ {
+ self.memoryStore = store.objectStore;
+ }
+ self.store = store.objectStore
+ }
+
+ if (data)
+ {
+ try
+ {
+ if ((dataSet || self.updateOrAppend(data)) && self.onUpdate)
+ {
+ self.onUpdate(data);
+ }
+ }
+ catch(e)
+ {
+ console.error(e);
+ }
+ }
};
- if (args && args.serviceUrl)
+ if (this.serviceUrl)
{
var requestUrl = lang.isFunction(this.serviceUrl) ? this.serviceUrl() : this.serviceUrl;
- xhr.get({url: requestUrl, sync: properties.useSyncGet, handleAs: "json"}).then(updatableStoreFactory, util.errorHandler);
+ xhr.get({url: requestUrl, sync: true, handleAs: "json"}).then(processData, util.errorHandler);
}
- else if (args && args.data)
+ else
{
- updatableStoreFactory(args.data);
+ processData(this.initialData);
}
- }
+ };
+
+ GridUpdater.prototype.start = function(grid)
+ {
+ this.grid = grid;
+ if (this.serviceUrl)
+ {
+ updater.add(this);
+ }
+ };
GridUpdater.prototype.destroy = function()
{
updater.remove(this);
- if (this.updatableStore)
+ if (this.dataStore)
{
- this.updatableStore.close();
- this.updatableStore = null;
- }
- if (this.grid)
- {
- this.grid.destroy();
- this.grid = null;
+ this.dataStore.close();
+ this.dataStore = null;
}
+ this.store = null;
+ this.memoryStore = null;
+ this.grid = null;
+ };
+
+ GridUpdater.prototype.updateOrAppend = function(data)
+ {
+ return this.appendData ?
+ UpdatableStore.prototype.append.call(this, data, this.appendLimit):
+ UpdatableStore.prototype.update.call(this, data);
};
GridUpdater.prototype.refresh = function(data)
@@ -186,7 +200,7 @@ define(["dojo/_base/xhr",
this.updating = true;
try
{
- if (this.appendData ? this.updatableStore.append(data, this.appendLimit): this.updatableStore.update(data))
+ if (this.updateOrAppend(data))
{
// EnhancedGrid with Filter plugin has "filter" layer.
// The filter expression needs to be re-applied after the data update
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js
new file mode 100644
index 0000000000..04041388bd
--- /dev/null
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js
@@ -0,0 +1,56 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+define([
+ "dojo/_base/declare",
+ "dojox/grid/EnhancedGrid",
+ "dojo/domReady!"], function(declare, EnhancedGrid){
+
+ return declare("qpid.common.grid.UpdatableGrid", [EnhancedGrid], {
+
+ updater: null,
+
+ postCreate: function(){
+ this.inherited(arguments);
+ if (this.updater)
+ {
+ this.updater.start(this);
+ }
+ },
+
+ destroy: function(){
+ if (this.updater)
+ {
+ try
+ {
+ this.updater.destroy();
+ }
+ catch(e)
+ {
+ console.error(e)
+ }
+ this.updater = null;
+ }
+ this.inherited(arguments);
+ }
+ });
+
+});
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js
index 4bec7440ab..56b37d0167 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js
@@ -24,10 +24,11 @@ define(["dojo/_base/xhr",
"dojo/date/locale",
"dijit/registry",
"qpid/common/grid/GridUpdater",
+ "qpid/common/grid/UpdatableGrid",
"qpid/management/logs/LogFileDownloadDialog",
"dojo/text!../../../logs/showLogViewer.html",
"dojo/domReady!"],
- function (xhr, parser, query, locale, registry, GridUpdater, LogFileDownloadDialog, markup) {
+ function (xhr, parser, query, locale, registry, GridUpdater, UpdatableGrid, LogFileDownloadDialog, markup) {
var defaulGridRowLimit = 4096;
@@ -58,6 +59,11 @@ define(["dojo/_base/xhr",
this.downloadLogsButton.on("click", function(evt){
self.downloadLogDialog.showDialog();
});
+ this._buildGrid();
+ };
+
+ LogViewer.prototype._buildGrid = function() {
+ var self = this;
var gridStructure = [
{
@@ -97,44 +103,39 @@ define(["dojo/_base/xhr",
{ name: "Log Message", field: "message", width: "auto", datatype: "string"}
];
- this._buildGrid(gridStructure);
- };
-
- LogViewer.prototype._buildGrid = function(gridStructure) {
- var self = this;
var gridNode = query("#broker-logfile", this.contentPane.containerNode)[0];
try
{
- this.updater = new GridUpdater({
- updatable: false,
- serviceUrl: function()
- {
- return "rest/logrecords?lastLogId=" + self.lastLogId;
- },
- onUpdate: function(items)
- {
- if (items)
+ var updater = new GridUpdater({
+ updatable: false,
+ serviceUrl: function()
+ {
+ return "rest/logrecords?lastLogId=" + self.lastLogId;
+ },
+ onUpdate: function(items)
{
- var maxId = -1;
- for(var i in items)
+ if (items)
{
- var item = items[i];
- if (item.id > maxId)
+ var maxId = -1;
+ for(var i in items)
{
- maxId = item.id
+ var item = items[i];
+ if (item.id > maxId)
+ {
+ maxId = item.id
+ }
+ }
+ if (maxId != -1)
+ {
+ self.lastLogId = maxId
}
}
- if (maxId != -1)
- {
- self.lastLogId = maxId
- }
- }
- },
- append: true,
- appendLimit: defaulGridRowLimit,
- node: gridNode,
- structure: gridStructure,
- gridProperties: {
+ },
+ append: true,
+ appendLimit: defaulGridRowLimit
+ });
+ this.grid = new UpdatableGrid(updater.buildUpdatableGridArguments({
+ structure: gridStructure,
selectable: true,
selectionMode: "none",
sortInfo: -1,
@@ -144,35 +145,31 @@ define(["dojo/_base/xhr",
enhancedFilter:{defaulGridRowLimit: defaulGridRowLimit},
indirectSelection: false
}
- },
- funct: function (obj)
- {
- var onStyleRow = function(row)
- {
- var item = obj.grid.getItem(row.index);
- if(item){
- var level = obj.dataStore.getValue(item, "level", null);
- var changed = false;
- if(level == "ERROR"){
- row.customClasses += " redBackground";
- changed = true;
- } else if(level == "WARN"){
- row.customClasses += " yellowBackground";
- changed = true;
- } else if(level == "DEBUG"){
- row.customClasses += " grayBackground";
- changed = true;
- }
- if (changed)
- {
- obj.grid.focus.styleRow(row);
- }
- }
- };
- obj.grid.on("styleRow", onStyleRow);
- obj.grid.startup();
+ }), gridNode);
+ var onStyleRow = function(row)
+ {
+ var item = self.grid.getItem(row.index);
+ if(item){
+ var level = self.grid.store.getValue(item, "level", null);
+ var changed = false;
+ if(level == "ERROR"){
+ row.customClasses += " redBackground";
+ changed = true;
+ } else if(level == "WARN"){
+ row.customClasses += " yellowBackground";
+ changed = true;
+ } else if(level == "DEBUG"){
+ row.customClasses += " grayBackground";
+ changed = true;
+ }
+ if (changed)
+ {
+ self.grid.focus.styleRow(row);
+ }
}
- });
+ };
+ this.grid.on("styleRow", onStyleRow);
+ this.grid.startup();
}
catch(err)
{
@@ -181,10 +178,10 @@ define(["dojo/_base/xhr",
};
LogViewer.prototype.close = function() {
- if (this.updater)
+ if (this.grid)
{
- this.updater.destroy();
- this.updater = null;
+ this.grid.destroy();
+ this.grid = null;
}
if (this.downloadLogDialog)
{