You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2016/04/13 14:58:42 UTC
svn commit: r1738933 [1/2] - in
/qpid/java/trunk/broker-plugins/management-http: ./
src/main/java/org/apache/qpid/server/management/plugin/
src/main/java/resources/ src/main/java/resources/css/
src/main/java/resources/js/qpid/management/ src/main/java/...
Author: orudyy
Date: Wed Apr 13 12:58:41 2016
New Revision: 1738933
URL: http://svn.apache.org/viewvc?rev=1738933&view=rev
Log:
QPID-6983: Add query building UI
Added:
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/QueryTab.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/CriteriaPane.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/DropDownSelect.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/QueryBuilder.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/WhereCriteria.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/WhereExpression.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/query/
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/query/CriteriaPane.html
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/query/OptionsPanel.html
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/query/QueryBuilder.html
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/query/WhereCriteria.html
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/showQueryTab.html
Modified:
qpid/java/trunk/broker-plugins/management-http/pom.xml
qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/DojoHelper.java
qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/css/common.css
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/index.html
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/showVirtualHost.html
qpid/java/trunk/broker-plugins/management-http/src/main/resources-maven/dojoconfig.properties
Modified: qpid/java/trunk/broker-plugins/management-http/pom.xml
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/pom.xml?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/pom.xml (original)
+++ qpid/java/trunk/broker-plugins/management-http/pom.xml Wed Apr 13 12:58:41 2016
@@ -31,6 +31,8 @@
<properties>
<dojo-version>1.10.3</dojo-version>
+ <dstore-version>1.1.1</dstore-version>
+ <dgrid-version>1.0.0</dgrid-version>
</properties>
<dependencies>
@@ -92,6 +94,30 @@
<type>zip</type>
</dependency>
+ <dependency>
+ <groupId>org.webjars.bower</groupId>
+ <artifactId>dstore</artifactId>
+ <version>${dstore-version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>dojo</artifactId>
+ <groupId>org.webjars.bower</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.webjars.bower</groupId>
+ <artifactId>dgrid</artifactId>
+ <version>${dgrid-version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>dojo</artifactId>
+ <groupId>org.webjars.bower</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
<!-- test dependencies -->
<dependency>
<groupId>org.apache.qpid</groupId>
@@ -99,6 +125,7 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+
</dependencies>
<build>
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/DojoHelper.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/DojoHelper.java?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/DojoHelper.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/DojoHelper.java Wed Apr 13 12:58:41 2016
@@ -37,11 +37,14 @@ public class DojoHelper
public static final String DOJO_PATH_PROPERTY = "dojo-path";
public static final String DIJIT_PATH_PROPERTY = "dijit-path";
public static final String DOJOX_PATH_PROPERTY = "dojox-path";
-
+ public static final String DGRID_PATH_PROPERTY = "dgrid-path";
+ public static final String DSTORE_PATH_PROPERTY = "dstore-path";
private static String _version = "undefined";
private static String _dojoPath = "/dojo-undefined/dojo";
private static String _dijitPath = "/dojo-undefined/dijit";
private static String _dojoxPath = "/dojo-undefined/dojox";
+ private static String _dgridPath = "/META-INF/resources/webjars/dgrid/dgrid-undefined";
+ private static String _dstorePath = "/META-INF/resources/webjars/dstore/dstore-undefined";
// Loads the value from the properties file.
static
@@ -88,6 +91,8 @@ public class DojoHelper
_dojoPath = props.getProperty(DOJO_PATH_PROPERTY, _dojoPath);
_dijitPath = props.getProperty(DIJIT_PATH_PROPERTY, _dijitPath);
_dojoxPath = props.getProperty(DOJOX_PATH_PROPERTY, _dojoxPath);
+ _dgridPath = props.getProperty(DGRID_PATH_PROPERTY, _dgridPath);
+ _dstorePath = props.getProperty(DSTORE_PATH_PROPERTY, _dstorePath);
}
}
catch (IOException e)
@@ -116,4 +121,15 @@ public class DojoHelper
{
return _dojoxPath;
}
+
+ public static String getDstorePath()
+ {
+ return _dstorePath;
+ }
+
+ public static String getDgridPath()
+ {
+ return _dgridPath;
+ }
+
}
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java Wed Apr 13 12:58:41 2016
@@ -300,6 +300,8 @@ public class HttpManagement extends Abst
root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDojoPath(), true)), "/dojo/dojo/*");
root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDijitPath(), true)), "/dojo/dijit/*");
root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDojoxPath(), true)), "/dojo/dojox/*");
+ root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDgridPath(), true)), "/dojo/dgrid/*");
+ root.addServlet(new ServletHolder(new FileServlet(DojoHelper.getDstorePath(), true)), "/dojo/dstore/*");
for(String pattern : STATIC_FILE_TYPES)
{
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/css/common.css
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/css/common.css?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/css/common.css (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/css/common.css Wed Apr 13 12:58:41 2016
@@ -18,9 +18,6 @@
* under the License.
*
*/
-* {
- outline: none !important;
-}
html, body {
height: 100%;
@@ -246,12 +243,12 @@ div .messages {
}
.alignLeft {
- float: left;
+ float: left !important;
display: inline-block;
}
.alignRight {
- float: right;
+ float: right !important;
display: inline-block;
}
@@ -364,4 +361,69 @@ div .messages {
background-size: 1em;
width:100%;
height:100%;
+}
+
+.queryDefaultField
+{
+ width: 7em;
+}
+
+.querySearchField
+{
+ width: 20%;
+}
+
+.dgrid-column-selected
+{
+ width: 2em;
+}
+
+.dgrid-column-attributeName
+{
+ width: auto;
+}
+
+
+.selectGrid
+{
+ height:20em;
+}
+
+.criteriaPanelTitle
+{
+ padding:0px !important;
+}
+
+.criteriaPanelTitleText
+{
+ vertical-align: middle !important;
+}
+
+.criteriaPanelTitleButton
+{
+ margin: 0px !important;
+}
+
+.criteriaControl
+{
+ margin-bottom: 5px !important;
+}
+
+.criteriaControl.dijitTextBoxReadOnly
+{
+ width:100%;
+}
+
+.criteriaControl.dijitTextBoxReadOnly,
+.claro .criteriaControl.dijitTextBoxReadOnly,
+.claro .criteriaControl.dijitTextBoxReadOnlyFocused .dijitInputContainer
+{
+ background-color: #efefef !important;
+ background-image: none !important;
+}
+
+textarea.querySearchField
+{
+ height: 1.2em;
+ margin-bottom: 2px;
}
\ No newline at end of file
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/index.html
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/index.html?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/index.html (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/index.html Wed Apr 13 12:58:41 2016
@@ -27,6 +27,9 @@
<link rel="stylesheet" href="dojo/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css">
<link rel="stylesheet" href="dojo/dojox/form/resources/CheckedMultiSelect.css">
<link rel="stylesheet" href="dojo/dojox/form/resources/FileInput.css" />
+ <link rel="stylesheet" href="dojo/dijit/themes/claro/document.css">
+ <link rel="stylesheet" href="dojo/dgrid/css/dgrid.css">
+ <link rel="stylesheet" href="dojo/dgrid/css/skins/claro.css">
<link rel="stylesheet" href="css/common.css" media="screen">
<script>
function getContextPath()
@@ -50,7 +53,9 @@
{ name:"dojo", location:"dojo/dojo" },
{ name:"dijit", location:"dojo/dijit" },
{ name:"dojox", location:"dojo/dojox" },
- { name:"qpid", location:"js/qpid" }
+ { name:"qpid", location:"js/qpid" },
+ { name:"dgrid", location:"dojo/dgrid" },
+ { name:"dstore", location:"dojo/dstore" }
]
};
@@ -83,6 +88,7 @@
], function(parser, query, ConsoleHelper, Management, util, treeView, controller, updater, entities, registry, dom){
parser.parse();
qpidManagementHelper = ConsoleHelper;
+ qpidManagementHelper.controller = controller;
management = new Management("",util.xhrErrorHandler);
management.authenticate().then(function(data)
{
@@ -130,6 +136,8 @@
<div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick: function(){qpidManagementHelper.showAPI();}">REST API</div>
<div data-dojo-type="dijit.MenuItem"
data-dojo-props="iconClass: 'helpIcon', onClick: function(){qpidManagementHelper.showHelp();}">Help</div>
+ <div data-dojo-type="dijit.MenuItem"
+ data-dojo-props="iconClass: 'dijitIconApplication', onClick: function(){qpidManagementHelper.controller.show('queryTab');}">Query</div>
</div>
</div>
</div>
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=1738933&r1=1738932&r2=1738933&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 Wed Apr 13 12:58:41 2016
@@ -541,5 +541,101 @@ define(["dojo/_base/lang",
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
+ // virtualhost: String?
+ // virtualhost name
+ //
+ // requestOptions: Object?
+ // is optional request settings
+ //
+ // 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, requestOptions)
+ {
+ var url = "api/latest/" + (query.parent && query.parent.type === "virtualhost" ?
+ "queryvhost/" + this.objectToPath({parent: query.parent}) :
+ "querybroker") + (query.category ? "/" + query.category : "");
+ url = this.getFullUrl(url);
+ var request = {url: url};
+
+ if (requestOptions)
+ {
+ lang.mixin(request,requestOptions);
+ }
+
+ // id should be selected always
+ var select = "id";
+ if (query.select)
+ {
+ select = select + "," + query.select;
+ }
+ var parameters = {select: select};
+ if (query.where)
+ {
+ parameters.where=query.where
+ }
+ request.query = parameters;
+ var promise = this.get(request);
+ if (query.select && query.transformIntoObjects)
+ {
+ var deferred = new Deferred();
+ promise.then( function(data)
+ {
+ if (data)
+ {
+ var transformed = [];
+ try
+ {
+ if (data.results)
+ {
+ var headers = select.split(",");
+ for (var i in headers)
+ {
+ headers[i] = headers[i].replace(/^\s+|\s+$/gm,'');
+ }
+ for (var r in data.results)
+ {
+ var results = data.results[r];
+ var object = {};
+ for (var i in headers)
+ {
+ var headerName = headers[i];
+ var headerValue = results[i];
+ object[headerName] = headerValue;
+ }
+ transformed.push(object);
+ }
+ }
+ }
+ finally
+ {
+ deferred.resolve(transformed);
+ }
+ }
+ else
+ {
+ deferred.reject({message: "User identifier is not found!"
+ + " Authentication failed!"});
+ }
+ },
+ function(error)
+ {
+ deferred.reject(error);
+ });
+ return deferred.promise;
+ }
+ return promise;
+ };
+
return Management;
});
Added: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/QueryTab.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/QueryTab.js?rev=1738933&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/QueryTab.js (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/QueryTab.js Wed Apr 13 12:58:41 2016
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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/parser",
+ "dojo/query",
+ "dijit/registry",
+ "dojox/html/entities",
+ "qpid/common/properties",
+ "qpid/common/util",
+ "qpid/common/formatter",
+ "dojo/text!showQueryTab.html",
+ "qpid/management/query/QueryBuilder",
+ "dojo/dom-construct",
+ "dojo/domReady!"],
+ function (parser, query, registry, entities, properties, util, formatter, template, QueryBuilder, domConstruct)
+ {
+
+ function QueryTab(name, parent, controller)
+ {
+ this.name = name;
+ this.controller = controller;
+ this.management = controller.management;
+ this.parent = parent;
+ }
+
+ QueryTab.prototype.getTitle = function ()
+ {
+ return "Query";
+ };
+
+ QueryTab.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)
+ },
+ function(e)
+ {
+ console.error("Unexpected error on parsing query tab template", e);
+ });
+ };
+
+ QueryTab.prototype.onOpen = function (containerNode)
+ {
+ this.queryEditorNode = query(".queryEditorNode", containerNode)[0];
+ this.queryBuilder = new QueryBuilder({management: this.management,
+ parentModelObj: this.parent,
+ controller: this.controller},
+ this.queryEditorNode);
+ };
+
+ QueryTab.prototype.close = function ()
+ {
+
+ };
+
+ QueryTab.prototype.destroy = function ()
+ {
+ this.close();
+ this.contentPane.onClose();
+ this.controller.tabContainer.removeChild(this.contentPane);
+ this.contentPane.destroyRecursive();
+ };
+
+ return QueryTab;
+ });
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js Wed Apr 13 12:58:41 2016
@@ -163,6 +163,15 @@ define(["dojo/parser",
editVirtualHost.show(that.management, that.modelObj);
});
+ that.addQueryButton = registry.byNode(query(".addQuery", containerNode)[0]);
+ that.addQueryButton.on("click",
+ function(e)
+ {
+ that.controller.show('queryTab', '', that.modelObj);
+ }
+ );
+
+
that.vhostUpdater.update(function(){updater.add( that.vhostUpdater );});
});
};
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js?rev=1738933&r1=1738932&r2=1738933&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js Wed Apr 13 12:58:41 2016
@@ -39,10 +39,12 @@ define(["dojo/dom",
"qpid/management/PreferencesProvider",
"qpid/management/VirtualHostNode",
"qpid/management/Logger",
+ "qpid/management/QueryTab",
"dojo/ready",
+ "dojox/uuid/generateRandomUuid",
"dojo/domReady!"],
function (dom, registry, ContentPane, CheckBox, entities, Broker, VirtualHost, Exchange, Queue, Connection, AuthProvider,
- GroupProvider, Group, KeyStore, TrustStore, AccessControlProvider, Port, Plugin, PreferencesProvider, VirtualHostNode, Logger, ready) {
+ GroupProvider, Group, KeyStore, TrustStore, AccessControlProvider, Port, Plugin, PreferencesProvider, VirtualHostNode, Logger, QueryTab, ready) {
var controller = {};
var constructors = { broker: Broker, virtualhost: VirtualHost, exchange: Exchange,
@@ -51,7 +53,8 @@ define(["dojo/dom",
group: Group, keystore: KeyStore, truststore: TrustStore,
accesscontrolprovider: AccessControlProvider, port: Port,
plugin: Plugin, preferencesprovider: PreferencesProvider,
- virtualhostnode: VirtualHostNode, brokerlogger: Logger, virtualhostlogger: Logger};
+ virtualhostnode: VirtualHostNode, brokerlogger: Logger, virtualhostlogger: Logger,
+ queryTab: QueryTab};
var tabDiv = dom.byId("managedViews");
@@ -78,7 +81,7 @@ define(["dojo/dom",
}
var that = this;
- var objId = (parent ? generateName(parent) + "/" : "") + objType + ":" + name;
+ var objId = (parent ? generateName(parent) + "/" : "") + objType + ":" + (name ? name : "-" + dojox.uuid.generateRandomUuid());
var obj = this.viewedObjects[ objId ];
if(obj) {
@@ -104,7 +107,7 @@ define(["dojo/dom",
});
this.tabContainer.addChild( contentPane );
var userPreferences = this.management.userPreferences;
- if (objType != "broker")
+ if (objType != "broker" && name)
{
var preferencesCheckBox = new dijit.form.CheckBox({
checked: userPreferences.isTabStored(obj.tabData),
Added: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/CriteriaPane.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/CriteriaPane.js?rev=1738933&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/CriteriaPane.js (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/CriteriaPane.js Wed Apr 13 12:58:41 2016
@@ -0,0 +1,354 @@
+/*
+ *
+ * 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",
+ "dojo/_base/array",
+ "dojo/_base/lang",
+ "dojo/string",
+ "dojo/dom-construct",
+ "dojo/dom-style",
+ "dojo/text!query/CriteriaPane.html",
+ "dojox/html/entities",
+ "dojo/Evented",
+ "dijit/_WidgetBase",
+ "dijit/_TemplatedMixin",
+ "dijit/_WidgetsInTemplateMixin",
+ "dijit/layout/ContentPane",
+ "dijit/TitlePane",
+ "dijit/form/Button",
+ "dijit/form/ValidationTextBox",
+ "dijit/form/TextBox",
+ "dijit/form/NumberTextBox",
+ "dijit/form/Select",
+ "dojo/domReady!"
+],
+function(declare, array, lang, string, domConstruct, domStyle, template, entities, Evented)
+{
+ var ANY = "any";
+ var IS_NULL = "is null";
+ var IS_NOT_NULL = "is not null";
+ var CONTAINS = "contains";
+ var NOT_CONTAINS = "not contains";
+ var STARTS_WITH = "starts with";
+ var ENDS_WIDTH = "ends with";
+ var NOT_STARTS_WITH = "not starts with";
+ var NOT_ENDS_WIDTH = "not ends with";
+ var NOT = "not";
+ var EQUAL = "=";
+ var NOT_EQUAL = "<>";
+ var LESS_THAN = "<";
+ var LESS_EQUAL_THAN = "<=";
+ var GREATER_THAN = ">";
+ var GREATER_EQUAL_THAN = ">=";
+
+ var CONDITIONS_NOT_NEEDING_WIDGET = [ANY,IS_NULL,IS_NOT_NULL];
+ var BOOLEAN_CONDITIONS = [ANY,IS_NULL,IS_NOT_NULL,EQUAL,NOT_EQUAL];
+ var STRING_CONDITIONS = [ANY,IS_NULL,IS_NOT_NULL,EQUAL,NOT_EQUAL,CONTAINS,NOT_CONTAINS,STARTS_WITH,ENDS_WIDTH,
+ NOT_STARTS_WITH,NOT_ENDS_WIDTH];
+ var NUMERIC_CONDITIONS = [ANY,IS_NULL,IS_NOT_NULL,EQUAL,NOT_EQUAL,LESS_THAN,LESS_EQUAL_THAN,GREATER_THAN,
+ GREATER_EQUAL_THAN];
+ var ENUM_CONDITIONS = [ANY,IS_NULL,IS_NOT_NULL,EQUAL,NOT_EQUAL];
+
+ var sqlEscape = function(value)
+ {
+ return value.replace("'", "'''");
+ }
+
+ var sqlLikeEscape = function(value)
+ {
+ return sqlEscape(value).replace("%", "\\%").replace("_", "\\_");
+ }
+
+ var sqlValue = function(value, type)
+ {
+ return (isNumericType(type) || type === "Boolean") ? value : "'" + sqlEscape(value) + "'"
+ }
+
+ var isNumericType = function(type)
+ {
+ return (type === "Long"
+ || type == "Integer"
+ || type == "Double"
+ || type == "Float"
+ || type == "Short"
+ || type == "Number"
+ );
+ }
+
+ var buildExpression = function(name, condition, value, type)
+ {
+ if (condition === ANY)
+ {
+ return undefined;
+ }
+ else if (condition === IS_NULL)
+ {
+ return name + " " + IS_NULL;
+ }
+ else if (condition === IS_NOT_NULL)
+ {
+ return name + " " + IS_NOT_NULL;
+ }
+ else if (condition === CONTAINS || condition === NOT_CONTAINS)
+ {
+ var exp = (condition === NOT_CONTAINS ? " " + NOT : "");
+ return name + exp + " like '%" + sqlLikeEscape(value) + "%' escape '\\'";
+ }
+ else if (condition === STARTS_WITH || condition === NOT_STARTS_WITH)
+ {
+ var exp = (condition === NOT_STARTS_WITH ? " " + NOT : "");
+ return name + exp + " like '" + sqlLikeEscape(value) + "%' escape '\\'";
+ }
+ else if (condition === ENDS_WIDTH || condition === NOT_ENDS_WIDTH)
+ {
+ var exp = (condition === NOT_ENDS_WIDTH ? " " + NOT : "");
+ return name + exp + " like '%" + sqlLikeEscape(value) + "' escape '\\'";
+ }
+ else
+ {
+ return name + " " + condition + " " + sqlValue(value, type);
+ }
+ }
+
+ var getTypeConditions = function(type, validValues)
+ {
+ if (type === "Boolean")
+ {
+ return BOOLEAN_CONDITIONS;
+ }
+ else if (isNumericType(type))
+ {
+ return NUMERIC_CONDITIONS;
+ }
+ else
+ {
+ if (validValues && validValues.length)
+ {
+ return ENUM_CONDITIONS;
+ }
+ return STRING_CONDITIONS;
+ }
+ }
+ var arrayToOptions = function(conditions, defaultValue)
+ {
+ var options = [];
+ for (var i=0;i<conditions.length;i++)
+ {
+ var selected = conditions[i] == defaultValue;
+ options.push({label: conditions[i], value: conditions[i], selected: selected});
+ }
+ return options;
+ }
+ var conditionHasWidget = function(condition)
+ {
+ return array.indexOf(CONDITIONS_NOT_NEEDING_WIDGET,condition) == -1;
+ }
+
+
+ return declare( "qpid.management.query.CriteriaPane",
+ [dijit._WidgetBase, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin, Evented],
+ {
+ //Strip out the apache comment header from the template html as comments unsupported.
+ templateString: template.replace(/<!--[\s\S]*?-->/g, ""),
+
+ /**
+ * fields from template
+ */
+ conditionExpression: null,
+ criteriaCondition: null,
+ criteriaValueInputContainer: null,
+ removeButton: null,
+ contentPane: null,
+ titleNode: null,
+
+ /**
+ * mandatory constructor arguments
+ */
+ criteriaName: null,
+ typeName: null,
+ typeValidValues: null,
+
+ /**
+ * auxiliary fields
+ */
+ _removed: false,
+ _stored: false,
+ _lastCondition: undefined,
+ _savedValue: undefined,
+ _savedCondition: undefined,
+
+ postCreate: function()
+ {
+ this.inherited(arguments);
+ this._postCreate();
+ },
+ _postCreate: function()
+ {
+ var conditions = getTypeConditions(this.typeName, this.typeValidValues);
+ this.criteriaCondition.set("options", arrayToOptions(conditions, ANY));
+ this.criteriaCondition.on("change", lang.hitch(this, this._conditionChanged));
+
+
+ if (this.typeName === "Boolean")
+ {
+ this.typeValidValues = ['true', 'false'];
+ }
+
+ var domNode = domConstruct.create("div", {}, this.criteriaValueInputContainer);
+ if (this.typeValidValues && this.typeValidValues.length)
+ {
+ var options = arrayToOptions(this.typeValidValues, this.typeValidValues[0]);
+ this.valueEditor = new dijit.form.Select({options: options,
+ disabled: true},
+ domNode);
+ }
+ else
+ {
+ this.valueEditor = isNumericType(this.typeName)
+ ? new dijit.form.NumberTextBox({
+ value: 0,
+ disabled: true,
+ required:true,
+ intermediateChanges: true,
+ invalidMessage:'Please enter a numeric value.'},
+ domNode)
+ : new dijit.form.ValidationTextBox({value: '',
+ disabled: true,
+ required:true,
+ intermediateChanges: true},
+ domNode);
+ }
+ this.valueEditor.startup();
+ this.valueEditor.on("change", lang.hitch(this, this._conditionValueChanged));
+ this.removeCriteria.on("click", lang.hitch(this, this._removalRequested));
+ this._conditionChanged(ANY);
+ this._saveState()
+ },
+ _saveState: function()
+ {
+ this._savedValue = this.valueEditor.value;
+ this._savedCondition = this.criteriaCondition.value;
+ },
+ _conditionChanged: function(newValue)
+ {
+ if (this.criteriaCondition.value != this._lastCondition)
+ {
+ var editable = conditionHasWidget(newValue);
+ this.valueEditor.set("disabled", !editable);
+ this._lastCondition = newValue;
+ this._conditionValueChanged();
+ }
+ },
+ _conditionValueChanged: function(newValue)
+ {
+ var expression = buildExpression(this.criteriaName,
+ this.criteriaCondition.value,
+ this._getConditionValue(),
+ this.typeName);
+ if (!expression)
+ {
+ expression = this.criteriaName + ":" + ANY;
+ }
+ this.conditionExpression.innerHTML = entities.encode(String(expression));
+
+ // notify listeners that criteria is changed
+ this.emit("change", this);
+ },
+ getExpression : function()
+ {
+ if (this._removed)
+ {
+ return undefined;
+ }
+ return buildExpression(this.criteriaName,
+ this.criteriaCondition.value,
+ this._getConditionValue(),
+ this.typeName);
+ },
+ _getConditionValue: function()
+ {
+ return this.valueEditor.value;
+ },
+ _removalRequested: function()
+ {
+ if (this._stored)
+ {
+ // do not destroy already stored criteria
+ // in order to restore it on cancellation
+
+ this._removed = true;
+ domStyle.set(this.domNode, "display", "none");
+
+ // notify listeners that criteria is changed
+ this.emit("change", this);
+ }
+ else
+ {
+ this.destroyRecursive(false);
+ }
+ },
+ cancelled: function()
+ {
+ if (this._removed)
+ {
+ domStyle.set(this.domNode, "display", "");
+ this._removed = false;
+ }
+
+ if (!this._stored)
+ {
+ this.destroyRecursive(false);
+ }
+ else
+ {
+ this.valueEditor.set("value", this._savedValue);
+ this.criteriaCondition.set("value", this._savedCondition);
+ }
+ },
+ submitted: function()
+ {
+ if (this._removed)
+ {
+ this.destroyRecursive(false);
+ }
+ else
+ {
+ this._saveState();
+ this._stored = true;
+ }
+ },
+ setRemovable: function(removable)
+ {
+ this.removeCriteria.set("disabled", !removable);
+ },
+ validate: function()
+ {
+ if (!this.valueEditor.get("disabled"))
+ {
+ return this.valueEditor.isValid();
+ }
+ return true;
+ }
+
+ });
+
+});
\ No newline at end of file
Added: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/DropDownSelect.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/DropDownSelect.js?rev=1738933&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/DropDownSelect.js (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/DropDownSelect.js Wed Apr 13 12:58:41 2016
@@ -0,0 +1,389 @@
+/*
+ *
+ * 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",
+ "dojo/_base/lang",
+ "dojo/_base/array",
+ "dojo/json",
+ "dojo/dom-construct",
+ "dojo/text!query/OptionsPanel.html",
+ "dgrid/OnDemandGrid",
+ "dgrid/Keyboard",
+ "dgrid/Selection",
+ "dgrid/Selector",
+ "dgrid/extensions/DijitRegistry",
+ "dgrid/extensions/Pagination",
+ "dstore/Memory",
+ "dijit/popup",
+ "dojo/Evented",
+ "dijit/TooltipDialog",
+ "dijit/layout/ContentPane",
+ "dijit/form/Button",
+ "dijit/form/ValidationTextBox",
+ "dijit/form/CheckBox",
+ "dijit/_WidgetBase",
+ "dijit/_TemplatedMixin",
+ "dijit/_WidgetsInTemplateMixin",
+ "dojo/domReady!"
+],
+function(declare, lang, array, json, domConstruct, template, Grid, Keyboard, Selection,
+ Selector, DijitRegistry, Pagination, Memory, popup, Evented)
+{
+
+ var Summary = declare(null,
+ {
+ showFooter: true,
+ buildRendering: function ()
+ {
+ this.inherited(arguments);
+ this.summaryAreaNode = domConstruct.create('div',
+ {
+ className: 'dgrid-status',
+ role: 'row',
+ style: { overflow: 'hidden',
+ display: 'none' }
+ },
+ this.footerNode);
+ this.totalLabelNode = domConstruct.create('span',
+ {
+ innerHTML: "Total: "
+ },
+ this.summaryAreaNode);
+ this.totalValueNode = domConstruct.create('span',
+ {
+ innerHTML: "0"
+ },
+ this.summaryAreaNode);
+ },
+ setTotal: function (total)
+ {
+ if (total>0)
+ {
+ this.totalValueNode.innerHTML = total;
+ this.summaryAreaNode.style.display = "block";
+ }
+ else
+ {
+ this.summaryAreaNode.style.display = "none";
+ }
+ }
+ });
+
+ OptionsPanel = declare("qpid.management.query.OptionsPanel",
+ [dijit._WidgetBase, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin],
+ {
+ /**
+ * dijit._TemplatedMixin enforced fields
+ */
+ //Strip out the apache comment header from the template html as comments unsupported.
+ templateString: template.replace(/<!--[\s\S]*?-->/g, ""),
+
+ /**
+ * template attach points
+ */
+ search: null,
+ clearButton: null,
+ selectOptions: null,
+ doneButton: null,
+ cancelButton: null,
+
+ /**
+ * widget fields which can be set via constructor arguments or #set("data",{...})
+ */
+ idProperty: "id",
+ nameProperty: "name",
+ store: null,
+ items: null,
+
+ /**
+ * widget inner fields
+ */
+ _optionsGrid: null,
+
+ postCreate: function()
+ {
+ this.inherited(arguments);
+ this._postCreate();
+ },
+ startup: function()
+ {
+ this.inherited(arguments);
+ this._optionsGrid.startup();
+ },
+ _postCreate: function()
+ {
+ this.clearButton.on("click", lang.hitch(this, this._onClear));
+ this.search.on("change", lang.hitch(this, this._searchChanged));
+ this.search.on("keyUp", lang.hitch(this, function(evt)
+ {
+ if (evt.keyCode == dojo.keys.ENTER && this.search.value)
+ {
+ this._applyFilter();
+ }
+ }));
+ this._toggleClearButtons();
+ this._buildOptionsGrid();
+ this._selectionChanged();
+ },
+ _buildOptionsGrid: function()
+ {
+ var CustomGrid = declare([ Grid, Keyboard, Selector, Summary ]);
+ if (!this.store)
+ {
+ this.store = new Memory({data: this.items || [], idProperty: this.idProperty});
+ }
+ var grid = new CustomGrid({
+ columns: this._getOptionColumns(),
+ collection: this.store,
+ selectionMode: 'multiple',
+ cellNavigation: true,
+ sort: this.nameProperty,
+ allowSelectAll: true,
+ minRowsPerPage : this.items ? this.items.length : 100,
+ deselectOnRefresh: false
+ },
+ this.optionsGrid);
+ grid.on('dgrid-select', lang.hitch(this, this._selectionChanged));
+ grid.on('dgrid-deselect', lang.hitch(this, this._selectionChanged));
+ grid.setTotal(this.items ? this.items.length : 0);
+ this._optionsGrid = grid;
+ },
+ _setDataAttr:function(data)
+ {
+ if (data.idProperty)
+ {
+ this.idProperty = data.idProperty;
+ }
+
+ if (data.nameProperty)
+ {
+ this.nameProperty = data.nameProperty;
+ }
+
+ var store;
+ if (data.store)
+ {
+ store = data.store;
+ }
+ else if (data.items)
+ {
+ store = new Memory({data: data.items, idProperty: this.idProperty});
+ this.items = data.items;
+ }
+
+ if (store)
+ {
+ this.store = store;
+ this._optionsGrid.set("columns", this._getOptionColumns());
+ this._optionsGrid.set("minRowsPerPage", data.items?data.items.length:100);
+ this._applyFilter();
+ this._optionsGrid.setTotal(this.items ? this.items.length : 0);
+ }
+
+ if (data.selected)
+ {
+ this._selectGrid(data.selected);
+ }
+ },
+ _selectGrid: function(selected)
+ {
+ var selectedRowIds = lang.clone(this._optionsGrid.selection || {});
+ if (selected && selected.length && this.store)
+ {
+ for(var i=0;i<selected.length;i++)
+ {
+ var id = selected[i] && selected[i].hasOwnProperty(this.idProperty) ? selected[i][this.idProperty] : selected[i];
+ if (id in selectedRowIds)
+ {
+ delete selectedRowIds[id];
+ }
+ else
+ {
+ this._optionsGrid.select(id, null, true);
+ }
+ }
+ }
+
+ for (var id in selectedRowIds)
+ {
+ if (this._optionsGrid.selection[id])
+ {
+ this._optionsGrid.select(id, null, false);
+ }
+ }
+ },
+ _onClear: function()
+ {
+ this.search.set("value", "");
+ },
+ _applyFilter:function()
+ {
+ if (this.search.value)
+ {
+ var searchRegExp = new RegExp(".*" + this.search.value + ".*", "i");
+ var filter = {};
+ filter[this.nameProperty] = searchRegExp;
+ this._optionsGrid.set("collection", this.store.filter(filter));
+ }
+ else
+ {
+ this._optionsGrid.set("collection", this.store);
+ }
+ },
+ _toggleClearButtons:function()
+ {
+ this.clearButton.set("disabled", !this.search.value);
+ },
+ _searchChanged: function()
+ {
+ this._toggleClearButtons();
+ this.defer(this._applyFilter);
+ },
+ _selectionChanged: function(event)
+ {
+ this.doneButton.set("disabled", !this._isSelected());
+ },
+ _getOptionColumns: function()
+ {
+ var columns = {selected: { label: 'All', selector: 'checkbox' }};
+ columns[this.nameProperty] = { label:"Name", sortable: true }
+ return columns;
+ },
+ _isSelected: function()
+ {
+ var selectionFound = false;
+ for (var id in this._optionsGrid.selection)
+ {
+ if (this._optionsGrid.selection[id])
+ {
+ selectionFound = true;
+ break;
+ }
+ }
+ return selectionFound;
+ },
+ _getSelectedItemsAttr: function()
+ {
+ var selected = [];
+ if (this.store && this._optionsGrid.selection)
+ {
+ for (var id in this._optionsGrid.selection)
+ {
+ if (this._optionsGrid.selection[id])
+ {
+ selected.push(id);
+ }
+ }
+ }
+ var filter = new this.store.Filter().in(this.idProperty, selected);
+ var promise = this.store.filter(filter).fetch();
+ return promise;
+ },
+ _reset: function(items)
+ {
+ this._onClear();
+
+ items = items || [];
+ this._selectGrid(items);
+ }
+ });
+
+ return declare("qpid.management.query.DropDownSelect",
+ [dijit._WidgetBase, Evented],
+ {
+ _selectButton: null,
+ _optionsDialog: null,
+ _optionsPanel: null,
+ _selectedItems: null,
+
+ postCreate: function()
+ {
+ this.inherited(arguments);
+ this._postCreate();
+ },
+ _postCreate: function()
+ {
+ this._optionsPanel = new OptionsPanel({},this._createDomNode());
+ this._optionsDialog = new dijit.TooltipDialog({content:this._optionsPanel}, this._createDomNode());
+ this._selectButton = new dijit.form.DropDownButton({label: this.label || "Select",
+ dropDown: this._optionsDialog},
+ this._createDomNode());
+ this._optionsPanel.doneButton.on("click", lang.hitch(this, this._onSelectionDone));
+ this._optionsPanel.cancelButton.on("click", lang.hitch(this, this._hideAndResetSearch));
+ this._optionsDialog.on("hide", lang.hitch(this, this._resetSearch));
+ this._optionsDialog.on("show", lang.hitch(this, this._onShow));
+ this._selectButton.startup();
+ this._optionsPanel.startup();
+ this._optionsDialog.startup();
+ },
+ _createDomNode: function()
+ {
+ return domConstruct.create("span", null, this.domNode);
+ },
+ _setDataAttr:function(data)
+ {
+ this._optionsPanel.set("data", data);
+ var promise = this._optionsPanel.get("selectedItems");
+ dojo.when(promise,
+ lang.hitch(this,
+ function(selectedItems)
+ {
+ this._selectedItems = selectedItems;
+ }));
+ },
+ _getSelectedItemsAttr: function()
+ {
+ return this._optionsPanel.get("selectedItems");
+ },
+ _onSelectionDone: function()
+ {
+ var promise = this._optionsPanel.get("selectedItems");
+ dojo.when(promise, lang.hitch(this, function(selectedItems)
+ {
+ this._selectedItems = selectedItems;
+ this._hideAndResetSearch(selectedItems);
+ this.emit("change", selectedItems);
+ }));
+ },
+ _hideAndResetSearch: function()
+ {
+ popup.close(this._optionsDialog);
+ this._resetSearch();
+ },
+ _resetSearch:function()
+ {
+ this._optionsPanel._reset(this._selectedItems);
+ },
+ _setDisabled:function(value)
+ {
+ this._selectButton.set("disabled", value);
+ },
+ _getDisabled:function()
+ {
+ return this._selectButton.get("disabled")
+ },
+ _onShow: function()
+ {
+ this._optionsPanel._optionsGrid.resize();
+ }
+ });
+});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org