Author: orudyy
Date: Fri Mar 25 17:55:39 2016
New Revision: 1736622
URL: http://svn.apache.org/viewvc?rev=1736622&view=rev
Log:
QPID-6983: WIP - Add query 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/ColumnsSelector.js
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/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/query/
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/query/ColumnsSelector.html
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/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/common/FormWidgetMixin.js
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
qpid/java/trunk/client/example/src/main/java/org/apache/qpid/example/Hello.java
qpid/java/trunk/systests/pom.xml
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=1736622&r1=1736621&r2=1736622&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/pom.xml (original)
+++ qpid/java/trunk/broker-plugins/management-http/pom.xml Fri Mar 25 17:55:39
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=1736622&r1=1736621&r2=1736622&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
Fri Mar 25 17:55:39 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=1736622&r1=1736621&r2=1736622&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
Fri Mar 25 17:55:39 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=1736622&r1=1736621&r2=1736622&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
Fri Mar 25 17:55:39 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;
}
@@ -359,4 +356,59 @@ div .messages {
background-size: 1em;
width:100%;
height:100%;
-}
\ No newline at end of file
+}
+
+.queryDefaultField
+{
+ width: 7em;
+}
+
+.querySearchField
+{
+ width: 20%;
+}
+
+.dgrid-column-selected
+{
+ width: 2em;
+}
+
+.dgrid-column-attributeName
+{
+ width: auto;
+}
+
+.compactGrid
+{
+ 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;
+}
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=1736622&r1=1736621&r2=1736622&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
Fri Mar 25 17:55:39 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/common/FormWidgetMixin.js
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/FormWidgetMixin.js?rev=1736622&r1=1736621&r2=1736622&view=diff
==============================================================================
---
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/FormWidgetMixin.js
(original)
+++
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/common/FormWidgetMixin.js
Fri Mar 25 17:55:39 2016
@@ -97,6 +97,7 @@ define(["dojo/_base/declare"], function(
{
this._hasBeenBlurred = false;
this._setValueAttr(this._resetValue, true);
- }
+ },
+ focus: function() {}
});
});
\ No newline at end of file
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=1736622&r1=1736621&r2=1736622&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 Mar 25 17:55:39 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=1736622&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
Fri Mar 25 17:55:39 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=1736622&r1=1736621&r2=1736622&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
Fri Mar 25 17:55:39 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=1736622&r1=1736621&r2=1736622&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
Fri Mar 25 17:55:39 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/ColumnsSelector.js
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/ColumnsSelector.js?rev=1736622&view=auto
==============================================================================
---
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/ColumnsSelector.js
(added)
+++
qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/query/ColumnsSelector.js
Fri Mar 25 17:55:39 2016
@@ -0,0 +1,282 @@
+/*
+ *
+ * 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/string",
+ "dojo/text!query/ColumnsSelector.html",
+ "dgrid/Grid",
+ "dgrid/Keyboard",
+ "dgrid/Selection",
+ "dgrid/Selector",
+ "dgrid/extensions/DijitRegistry",
+ "dgrid/extensions/Pagination",
+ "dstore/Memory",
+ "dijit/popup",
+ "dijit/TooltipDialog",
+ "dijit/layout/ContentPane",
+ "dijit/form/Button",
+ "dijit/form/ValidationTextBox",
+ "dijit/form/CheckBox",
+ "dijit/_Widget",
+ "dijit/_TemplatedMixin",
+ "dijit/_WidgetsInTemplateMixin",
+ "dojo/domReady!"
+],
+function(declare, lang, array, string, template, Grid, Keyboard, Selection,
+ Selector, DijitRegistry, Pagination, Memory, popup)
+{
+ return declare("qpid.management.query.ColumnsSelector",
+ [dijit._Widget, 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,
+ columnSelectorContainer: null,
+ doneButton: null,
+ cancelButton: null,
+
+ /**
+ * widget fields
+ */
+ onDone: null,
+ onCancel: null,
+ _columnsGrid: null,
+
+ postCreate: function()
+ {
+ this.inherited(arguments);
+ this._initWidgets();
+ },
+ _setDataAttr:function(data)
+ {
+ this._store = new Memory({data: data,
idProperty: 'id'});
+ this._columnsGrid.set("rowsPerPage",
data.length);
+ this._applyFilter();
+ },
+ _setSelectedAttr:function(selected)
+ {
+ var grid = this._columnsGrid;
+ var data = this._store.data;
+ var selection = this._getSelection();
+ for(var i = 0; i< selection.length; i++)
+ {
+ grid.select(selection[i], null, false);
+ }
+ if (selected && selected.length &&
selected.length>0)
+ {
+ array.forEach(data,
+ function (item)
+ {
+ for(var
i=0;i<selected.length;i++)
+ {
+ if (item.id ===
selected[i])
+ {
+ grid.select(item,
null, true);
+ }
+ }
+ });
+ }
+ },
+ updateData: function(data, selected, onDone, onCancel)
+ {
+ if (onDone)
+ {
+ this.onDone = onDone;
+ }
+ if (onCancel)
+ {
+ this.onCancel = onCancel;
+ }
+ this._setDataAttr(data);
+ this._setSelectedAttr(selected);
+ },
+ _initWidgets:function()
+ {
+ var that = this;
+ this.doneButton.on("click",
lang.hitch(this, this._onSelectionDone));
+ this.cancelButton.on("click",
lang.hitch(this, this._onCancellation));
+ this.clearButton.on("click",
lang.hitch(this, function(){this.search.set("value", "");}));
+ this.search.on("change",
lang.hitch(this, this._searchChanged));
+ this.search.on("keyUp", lang.hitch(this,
function(evt)
+
{
+
var key = evt.keyCode;
+
if (key == dojo.keys.ENTER && this.search.value)
+
{
+
this._applyFilter();
+
}
+
}));
+ this._buildColumnsGrid();
+ this._toggleButtons();
+ this._selectionChanged();
+ },
+ _applyFilter:function()
+ {
+ if (this.search.value)
+ {
+ var searchRegExp = new RegExp(".*" +
this.search.value + ".*", "i");
+ this._columnsGrid.set("collection",
this._store.filter({attributeName: searchRegExp }));
+ }
+ else
+ {
+ this._columnsGrid.set("collection",
this._store);
+ }
+ },
+
+ _onSelectionDone: function()
+ {
+ var selection = this._getSelection();
+ if (selection && selection.length >0)
+ {
+ this.search.set("value", "");
+ var onDone = this.onDone;
+ if (onDone)
+ {
+ window.setTimeout(function()
+ {
+
onDone(selection);
+ },
+ 50);
+ }
+ }
+ },
+ _onCancellation: function()
+ {
+ var onCancel = this.onCancel;
+ if (onCancel)
+ {
+ window.setTimeout(function()
+ {
+ onCancel();
+ },
+ 50);
+ }
+ },
+ _toggleButtons:function()
+ {
+ this.clearButton.set("disabled",
!this.search.value);
+ },
+ _searchChanged: function()
+ {
+ this._toggleButtons();
+
+ var that = this;
+ if (this._searchTimeout)
+ {
+ clearTimeout(this._searchTimeout);
+ this._searchTimeout = null;
+ };
+ this._searchTimeout =
setTimeout(function()
+ {
+
that._applyFilter();
+ }, 100);
+ },
+ _buildColumnsGrid: function()
+ {
+ var that = this;
+ var CustomGrid = declare([ Grid,
Pagination, Keyboard, Selector ]);
+ var grid = new CustomGrid({
+ columns:
this._getGridColumns(),
+
collection: new Memory({data: [], idProperty: 'id'}),
+
selectionMode: 'multiple',
+
cellNavigation: false,
+ sort:
"attributeName",
+
allowSelectAll: true,
+
rowsPerPage : 100,
+
deselectOnRefresh: false
+ },
+
this.columnSelectorContainer
+ );
+ grid.on('dgrid-select', lang.hitch(this,
this._selectionChanged));
+ grid.on('dgrid-deselect',
lang.hitch(this, this._selectionChanged));
+ this._columnsGrid = grid;
+ grid.startup();
+
+ },
+ _selectionChanged: function(event)
+ {
+ this.doneButton.set("disabled",
!this._isSelected());
+ },
+ _getGridColumns: function()
+ {
+ var columns = {
+ selected: { label:
'All', selector: 'checkbox' },
+ attributeName: {
label:"Name", sortable: true }
+ };
+ return columns;
+ },
+ _refreshGrid:function() // <---- DEAD
+ {
+ var that = this;
+ var selection = this._getSelection();
+ this._columnsGrid.refresh();
+ array.forEach(selection,
+ function (item)
+ {
+
that._columnsGrid.select(item, null, true);
+ });
+
+ },
+ _isSelected: function()
+ {
+ var selectionFound = false;
+ for (var id in
this._columnsGrid.selection)
+ {
+ if (this._columnsGrid.selection[id])
+ {
+ selectionFound = true;
+ break;
+ }
+ }
+ return selectionFound;
+ },
+ _getSelection: function()
+ {
+ var selected = [];
+ if (this._store &&
this._columnsGrid.selection)
+ {
+ for (var id in
this._columnsGrid.selection)
+ {
+ if
(this._columnsGrid.selection[id])
+ {
+ this._store.forEach(function
(object)
+ {
+ if (object.id == id)
+ {
+ selected.push(object);
+ }
+ });
+ }
+ }
+ }
+ return selected;
+ }
+ });
+});
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=1736622&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
Fri Mar 25 17:55:39 2016
@@ -0,0 +1,363 @@
+/*
+ *
+ * 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",
+ "qpid/common/FormWidgetMixin",
+ "dijit/_Widget",
+ "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)
+{
+ 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,NOT,EQUAL,NOT_EQUAL];
+ var STRING_CONDITIONS = [ANY,IS_NULL,IS_NOT_NULL,NOT,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,NOT,EQUAL,NOT_EQUAL,
LESS_THAN, LESS_EQUAL_THAN, GREATER_THAN, GREATER_EQUAL_THAN];
+ var ENUM_CONDITIONS = [ANY,IS_NULL,IS_NOT_NULL,NOT,EQUAL,NOT_EQUAL];
+
+ var sqlEscape = function(value)
+ {
+ return new
String(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 if (condition === NOT)
+ {
+ return " " + NOT + " " + name +
" = " + sqlValue(value, type);
+ }
+ 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;
+ var value = conditions[i];
+ if (value != null &&
lang.isObject(value))
+ {
+ value = new String(value) ;
+ }
+ options.push({label: value, value:
value, selected: selected});
+ }
+ return options;
+ }
+ var conditionHasWidget = function(condition)
+ {
+ return
array.indexOf(CONDITIONS_NOT_NEEDING_WIDGET,condition) == -1;
+ }
+
+
+ return declare( "qpid.management.query.CriteriaPane",
+ [dijit._Widget, dijit._TemplatedMixin,
dijit._WidgetsInTemplateMixin, qpid.common.FormWidgetMixin],
+ {
+ //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._buildExpression();
+ }
+ },
+ _conditionValueChanged: function(newValue)
+ {
+ this._buildExpression();
+ },
+ _buildExpression: function()
+ {
+ 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));
+ this.set("value", expression);
+ },
+ 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");
+
+ // signal to listener that
criteria is removed
+ this.set("value", undefined);
+ }
+ 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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]