You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ea...@apache.org on 2018/06/25 21:26:49 UTC
[3/8] qpid-dispatch git commit: DISPATCH-1049 Add console tests
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrOverview.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrOverview.js b/console/stand-alone/plugin/js/qdrOverview.js
index 2f784e7..536d93a 100644
--- a/console/stand-alone/plugin/js/qdrOverview.js
+++ b/console/stand-alone/plugin/js/qdrOverview.js
@@ -16,21 +16,15 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-'use strict';
/* global angular d3 */
+import { QDRFolder, QDRLeaf, QDRCore, QDRLogger, QDRTemplatePath, QDRRedirectWhenConnected } from './qdrGlobals.js';
-/**
- * @module QDR
- */
-var QDR = (function (QDR) {
+export class OverviewController {
+ constructor(QDRService, $scope, $log, $location, $timeout, $uibModal) {
+ this.controllerName = 'QDR.OverviewController';
- /**
- *
- * Controller that handles the QDR overview page
- */
- QDR.module.controller('QDR.OverviewController', ['$scope', 'QDRService', '$location', '$timeout', '$uibModal', 'uiGridConstants', function($scope, QDRService, $location, $timeout, $uibModal) {
-
- QDR.log.debug('QDR.OverviewControll started with location of ' + $location.path() + ' and connection of ' + QDRService.management.connection.is_connected());
+ let QDRLog = new QDRLogger($log, 'OverviewController');
+ QDRLog.debug('QDR.OverviewControll started with location of ' + $location.path() + ' and connection of ' + QDRService.management.connection.is_connected());
let updateIntervalHandle = undefined;
const updateInterval = 5000;
@@ -46,14 +40,14 @@ var QDR = (function (QDR) {
content: '<i class="icon-list"></i> Attributes',
title: 'View the attribute values on your selection',
isValid: function () { return true; },
- href: function () { return '#/' + QDR.pluginName + '/attributes'; },
+ href: function () { return '#/attributes'; },
index: 0
},
{
content: '<i class="icon-leaf"></i> Operations',
title: 'Execute operations on your selection',
isValid: function () { return true; },
- href: function () { return '#/' + QDR.pluginName + '/operations'; },
+ href: function () { return '#/operations'; },
index: 1
}];
$scope.activeTab = $scope.subLevelTabs[0];
@@ -72,7 +66,7 @@ var QDR = (function (QDR) {
{title: 'Overview', name: 'Overview', right: false}
];
- $scope.tmplOverviewTree = QDR.templatePath + 'tmplOverviewTree.html';
+ $scope.tmplOverviewTree = QDRTemplatePath + 'tmplOverviewTree.html';
$scope.templates = [
{ name: 'Charts', url: 'overviewCharts.html'},
{ name: 'Routers', url: 'routers.html'},
@@ -188,7 +182,7 @@ var QDR = (function (QDR) {
if (nodes[node]['connection'].results[i][0] === 'inter-router')
++connections;
}
- let routerRow = {connections: connections, nodeId: node, id: QDRService.management.topology.nameFromId(node)};
+ let routerRow = {connections: connections, nodeId: node, id: QDRService.utilities.nameFromId(node)};
nodes[node]['router'].attributeNames.forEach( function (routerAttr, i) {
if (routerAttr !== 'routerId' && routerAttr !== 'id')
routerRow[routerAttr] = nodes[node]['router'].results[0][i];
@@ -441,7 +435,7 @@ var QDR = (function (QDR) {
}
return include;
});
- QDR.log.info('setting linkFields in updateLinkGrid');
+ QDRLog.info('setting linkFields in updateLinkGrid');
$scope.linkFields = filteredLinks;
expandGridToContent('Links', $scope.linkFields.length);
getLinkPagedData($scope.linkPagingOptions.pageSize, $scope.linkPagingOptions.currentPage);
@@ -594,7 +588,7 @@ var QDR = (function (QDR) {
var getAllLinkFields = function (completionCallbacks, selectionCallback) {
if (!$scope.linkFields) {
- QDR.log.debug('$scope.linkFields was not defined!');
+ QDRLog.debug('$scope.linkFields was not defined!');
return;
}
let nodeIds = QDRService.management.topology.nodeIdList();
@@ -611,10 +605,10 @@ var QDR = (function (QDR) {
if (elapsed < 0)
return 0;
let delivered = QDRService.utilities.valFor(response.attributeNames, result, 'deliveryCount') - oldname[0].rawDeliveryCount;
- //QDR.log.debug("elapsed " + elapsed + " delivered " + delivered)
+ //QDRLog.debug("elapsed " + elapsed + " delivered " + delivered)
return elapsed > 0 ? parseFloat(Math.round((delivered/elapsed) * 100) / 100).toFixed(2) : 0;
} else {
- //QDR.log.debug("unable to find old linkName")
+ //QDRLog.debug("unable to find old linkName")
return 0;
}
};
@@ -637,7 +631,7 @@ var QDR = (function (QDR) {
return QDRService.utilities.pretty(und + uns);
};
var getLinkName = function () {
- let namestr = QDRService.management.topology.nameFromId(nodeName);
+ let namestr = QDRService.utilities.nameFromId(nodeName);
return namestr + ':' + QDRService.utilities.valFor(response.attributeNames, result, 'identity');
};
var fixAddress = function () {
@@ -1050,8 +1044,8 @@ var QDR = (function (QDR) {
.then( function (results, context) {
let statusCode = context.message.application_properties.statusCode;
if (statusCode < 200 || statusCode >= 300) {
- QDR.Core.notification('error', context.message.statusDescription);
- QDR.log.error('Error ' + context.message.statusDescription);
+ QDRCore.notification('error', context.message.statusDescription);
+ QDRLog.error('Error ' + context.message.statusDescription);
}
});
};
@@ -1220,9 +1214,9 @@ var QDR = (function (QDR) {
}
});
d.result.then(function () {
- QDR.log.debug('d.open().then');
+ QDRLog.debug('d.open().then');
}, function () {
- QDR.log.debug('Modal dismissed at: ' + new Date());
+ QDRLog.debug('Modal dismissed at: ' + new Date());
});
}
@@ -1365,7 +1359,7 @@ var QDR = (function (QDR) {
let entry = allLogEntries[n];
entry.forEach( function (module) {
if (module.name === node.key) {
- module.nodeName = QDRService.management.topology.nameFromId(n);
+ module.nodeName = QDRService.utilities.nameFromId(n);
module.nodeId = n;
module.enable = logInfo.enable;
$scope.logModuleData.push(module);
@@ -1441,7 +1435,7 @@ var QDR = (function (QDR) {
};
if (!QDRService.management.connection.is_connected()) {
- QDR.redirectWhenConnected($location, 'overview');
+ QDRRedirectWhenConnected($location, 'overview');
return;
}
$scope.template = $scope.templates[0];
@@ -1530,7 +1524,7 @@ var QDR = (function (QDR) {
var showCharts = function () {
};
- let charts = new QDR.Folder('Charts');
+ let charts = new QDRFolder('Charts');
charts.info = {fn: showCharts};
charts.type = 'Charts'; // for the charts template
charts.key = 'Charts';
@@ -1538,7 +1532,7 @@ var QDR = (function (QDR) {
topLevelChildren.push(charts);
// create a routers tree branch
- let routers = new QDR.Folder('Routers');
+ let routers = new QDRFolder('Routers');
routers.type = 'Routers';
routers.info = {fn: allRouterInfo};
routers.expanded = (expandedNodeList.indexOf('Routers') > -1);
@@ -1549,8 +1543,8 @@ var QDR = (function (QDR) {
// called when the list of routers changes
var updateRouterTree = function (nodes) {
var worker = function (node) {
- let name = QDRService.management.topology.nameFromId(node);
- let router = new QDR.Leaf(name);
+ let name = QDRService.utilities.nameFromId(node);
+ let router = new QDRLeaf(name);
router.type = 'Router';
router.info = {fn: routerInfo};
router.nodeId = node;
@@ -1563,7 +1557,7 @@ var QDR = (function (QDR) {
};
// create an addresses tree branch
- let addresses = new QDR.Folder('Addresses');
+ let addresses = new QDRFolder('Addresses');
addresses.type = 'Addresses';
addresses.info = {fn: allAddressInfo};
addresses.expanded = (expandedNodeList.indexOf('Addresses') > -1);
@@ -1573,7 +1567,7 @@ var QDR = (function (QDR) {
topLevelChildren.push(addresses);
var updateAddressTree = function (addressFields) {
var worker = function (address) {
- let a = new QDR.Leaf(address.title);
+ let a = new QDRLeaf(address.title);
a.info = {fn: addressInfo};
a.key = address.uid;
a.fields = address;
@@ -1601,7 +1595,7 @@ var QDR = (function (QDR) {
};
$scope.filter = angular.fromJson(localStorage[FILTERKEY]) || {endpointsOnly: 'true', hideConsoles: true};
- let links = new QDR.Folder('Links');
+ let links = new QDRFolder('Links');
links.type = 'Links';
links.info = {fn: allLinkInfo};
links.expanded = (expandedNodeList.indexOf('Links') > -1);
@@ -1613,7 +1607,7 @@ var QDR = (function (QDR) {
// called both before the tree is created and whenever a background update is done
var updateLinkTree = function (linkFields) {
var worker = function (link) {
- let l = new QDR.Leaf(link.title);
+ let l = new QDRLeaf(link.title);
let isConsole = QDRService.utilities.isConsole(QDRService.management.topology.getConnForLink(link));
l.info = {fn: linkInfo};
l.key = link.uid;
@@ -1630,7 +1624,7 @@ var QDR = (function (QDR) {
updateLeaves(linkFields, 'Links', worker);
};
- let connections = new QDR.Folder('Connections');
+ let connections = new QDRFolder('Connections');
connections.type = 'Connections';
connections.info = {fn: allConnectionInfo};
connections.expanded = (expandedNodeList.indexOf('Connections') > -1);
@@ -1645,7 +1639,7 @@ var QDR = (function (QDR) {
if (connection.name === 'connection/' && connection.role === 'inter-router' && connection.host === '')
host = connection.container + ':' + connection.identity;
- let c = new QDR.Leaf(host);
+ let c = new QDRLeaf(host);
let isConsole = QDRService.utilities.isAConsole (connection.properties, connection.identity, connection.role, connection.routerId);
c.type = 'Connection';
c.info = {fn: connectionInfo};
@@ -1664,7 +1658,7 @@ var QDR = (function (QDR) {
var updateLogTree = function (logFields) {
var worker = function (log) {
- let l = new QDR.Leaf(log.name);
+ let l = new QDRLeaf(log.name);
l.type = 'Log';
l.info = {fn: logInfo};
l.key = log.name;
@@ -1678,7 +1672,7 @@ var QDR = (function (QDR) {
let htmlReady = false;
let dataReady = false;
$scope.largeNetwork = QDRService.management.topology.isLargeNetwork();
- let logs = new QDR.Folder('Logs');
+ let logs = new QDRFolder('Logs');
logs.type = 'Logs';
logs.info = {fn: allLogInfo};
logs.expanded = (expandedNodeList.indexOf('Logs') > -1);
@@ -1723,13 +1717,13 @@ var QDR = (function (QDR) {
// add placeholders for the top level tree nodes
let topLevelTreeNodes = [routers, addresses, links, connections, logs];
topLevelTreeNodes.forEach( function (parent) {
- let placeHolder = new QDR.Leaf('loading...');
+ let placeHolder = new QDRLeaf('loading...');
placeHolder.extraClasses = 'loading';
parent.children = [placeHolder];
});
var updateExpanded = function () {
- QDR.log.debug('updateExpandedEntities');
+ QDRLog.debug('updateExpandedEntities');
clearTimeout(updateIntervalHandle);
let tree = $('#overtree').fancytree('getTree');
@@ -1742,7 +1736,7 @@ var QDR = (function (QDR) {
});
q.await( function (error) {
if (error)
- QDR.log.error(error.message);
+ QDRLog.error(error.message);
// if there are no active nodes, activate the saved one
let tree = $('#overtree').fancytree('getTree');
@@ -1771,8 +1765,7 @@ var QDR = (function (QDR) {
clearTimeout(updateIntervalHandle);
$(window).off('resize', resizer);
});
- }]);
-
- return QDR;
-}(QDR || {}));
+ }
+}
+OverviewController.$inject = ['QDRService', '$scope', '$log', '$location', '$timeout', '$uibModal'];
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrOverviewChartsController.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrOverviewChartsController.js b/console/stand-alone/plugin/js/qdrOverviewChartsController.js
index e47e597..a65d74c 100644
--- a/console/stand-alone/plugin/js/qdrOverviewChartsController.js
+++ b/console/stand-alone/plugin/js/qdrOverviewChartsController.js
@@ -16,14 +16,11 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-'use strict';
/* global angular */
-/**
- * @module QDR
- */
-var QDR = (function(QDR) {
- QDR.module.controller('QDR.OverviewChartsController', function ($scope, QDRService, QDRChartService, $timeout) {
+export class OverviewChartsController {
+ constructor(QDRService, QDRChartService, $scope, $timeout) {
+ this.controllerName = 'QDR.OverviewChartsController';
$scope.overviewCharts = [];
let updateTimer;
@@ -90,7 +87,7 @@ var QDR = (function(QDR) {
];
$scope.overviewCharts = charts.map( function (chart) {
let c = QDRChartService.registerChart(chart);
- return new QDRChartService.pfAreaChart(c, c.id(), true);
+ return QDRChartService.pfAreaChart(c, c.id(), true);
});
@@ -128,7 +125,6 @@ var QDR = (function(QDR) {
QDRChartService.unRegisterChart(svg.chart);
});
});
- });
- return QDR;
-
-} (QDR || {}));
+ }
+}
+OverviewChartsController.$inject = ['QDRService', 'QDRChartService', '$scope', '$timeout'];
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrOverviewLogsController.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrOverviewLogsController.js b/console/stand-alone/plugin/js/qdrOverviewLogsController.js
index 1e541a5..316605e 100644
--- a/console/stand-alone/plugin/js/qdrOverviewLogsController.js
+++ b/console/stand-alone/plugin/js/qdrOverviewLogsController.js
@@ -16,19 +16,19 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-'use strict';
-/**
- * @module QDR
- */
-var QDR = (function(QDR) {
- QDR.module.controller('QDR.OverviewLogsController', function ($scope, $uibModalInstance, QDRService, $timeout, nodeName, nodeId, module, level) {
+import { QDRCore, QDRLogger } from './qdrGlobals.js';
+export class OverviewLogsController {
+ constructor(QDRService, $scope, $log, $uibModalInstance, $timeout, nodeName, nodeId, module, level) {
+ this.controllerName = 'QDR.OverviewLogsController';
+
+ let QDRLog = new QDRLogger($log, 'OverviewLogsController');
var gotLogInfo = function (nodeId, response, context) {
let statusCode = context.message.application_properties.statusCode;
if (statusCode < 200 || statusCode >= 300) {
- QDR.Core.notification('error', context.message.statusDescription);
- QDR.log.info('Error ' + context.message.statusDescription);
+ QDRCore.notification('error', context.message.statusDescription);
+ QDRLog.info('Error ' + context.message.statusDescription);
} else {
let levelLogs = response.filter( function (result) {
if (result[1] == null)
@@ -37,7 +37,7 @@ var QDR = (function(QDR) {
});
let logFields = levelLogs.map( function (result) {
return {
- nodeId: QDRService.management.topology.nameFromId(nodeId),
+ nodeId: QDRService.utilities.nameFromId(nodeId),
name: result[0],
type: result[1],
message: result[2],
@@ -64,7 +64,6 @@ var QDR = (function(QDR) {
$uibModalInstance.close(true);
};
- });
- return QDR;
-
-} (QDR || {}));
+ }
+}
+OverviewLogsController.$inject = ['QDRService', '$scope', '$log', '$uibModalInstance', '$timeout', 'nodeName', 'nodeId', 'module', 'level'];
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrSchema.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrSchema.js b/console/stand-alone/plugin/js/qdrSchema.js
index 69569ea..4421636 100644
--- a/console/stand-alone/plugin/js/qdrSchema.js
+++ b/console/stand-alone/plugin/js/qdrSchema.js
@@ -16,19 +16,18 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-'use strict';
-/**
- * @module QDR
- */
-var QDR = (function (QDR) {
+import { QDRRedirectWhenConnected} from './qdrGlobals.js';
+
+export class SchemaController {
+ constructor(QDRService, $scope, $location, $timeout) {
+ this.controllerName = 'QDR.SchemaController';
- QDR.module.controller('QDR.SchemaController', ['$scope', '$location', '$timeout', 'QDRService', function($scope, $location, $timeout, QDRService) {
if (!QDRService.management.connection.is_connected()) {
- QDR.redirectWhenConnected($location, 'schema');
+ QDRRedirectWhenConnected($location, 'schema');
return;
}
var onDisconnect = function () {
- $timeout( function () {QDR.redirectWhenConnected('schema');});
+ $timeout( function () {QDRRedirectWhenConnected('schema');});
};
// we are currently connected. setup a handler to get notified if we are ever disconnected
QDRService.management.connection.addDisconnectAction( onDisconnect );
@@ -77,7 +76,6 @@ var QDR = (function (QDR) {
QDRService.management.connection.delDisconnectAction( onDisconnect );
});
- }]);
-
- return QDR;
-}(QDR || {}));
+ }
+}
+SchemaController.$inject = ['QDRService', '$scope', '$location', '$timeout'];
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrService.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrService.js b/console/stand-alone/plugin/js/qdrService.js
index f4effdd..8f13192 100644
--- a/console/stand-alone/plugin/js/qdrService.js
+++ b/console/stand-alone/plugin/js/qdrService.js
@@ -16,254 +16,95 @@ Licensed to the Apache Software Foundation (ASF) under one
specific language governing permissions and limitations
under the License.
*/
-'use strict';
/* global Promise */
-/**
- * @module QDR
- */
-var QDR = (function(QDR) {
-
- // The QDR service handles the connection to the router
- QDR.module.factory('QDRService', ['$timeout', '$location', function($timeout, $location) {
- let dm = require('dispatch-management');
- let self = {
- management: new dm.Management($location.protocol()),
- utilities: dm.Utilities,
-
- onReconnect: function () {
- self.management.connection.on('disconnected', self.onDisconnect);
- let org = localStorage[QDR.LAST_LOCATION] || '/overview';
- $timeout ( function () {
- $location.path(org);
- $location.search('org', null);
- $location.replace();
- });
- },
- onDisconnect: function () {
- self.management.connection.on('connected', self.onReconnect);
- $timeout( function () {
- $location.path('/connect');
- let curPath = $location.path();
- let parts = curPath.split('/');
- let org = parts[parts.length-1];
- if (org && org.length > 0 && org !== 'connect') {
- $location.search('org', org);
- } else {
- $location.search('org', null);
- }
- $location.replace();
- });
- },
-
- connect: function (connectOptions) {
- return new Promise ( function (resolve, reject) {
- self.management.connection.connect(connectOptions)
- .then( function (r) {
- // if we are ever disconnected, show the connect page and wait for a reconnect
- self.management.connection.on('disconnected', self.onDisconnect);
-
- self.management.getSchema()
+import { Management as dm } from '../../modules/management.js';
+import { utils } from '../../modules/utilities.js';
+
+import { QDR_LAST_LOCATION, QDRLogger} from './qdrGlobals.js';
+
+export class QDRService {
+ constructor($log, $timeout, $location) {
+ this.$timeout = $timeout;
+ this.$location = $location;
+ this.management = new dm($location.protocol());
+ this.utilities = utils;
+ this.QDRLog = new QDRLogger($log, 'QDRService');
+ }
+
+ // Example service function
+ onReconnect () {
+ this.management.connection.on('disconnected', this.onDisconnect);
+ let org = localStorage[QDR_LAST_LOCATION] || '/overview';
+ this.$timeout ( function () {
+ this.$location.path(org);
+ this.$location.search('org', null);
+ this.$location.replace();
+ });
+ }
+ onDisconnect () {
+ this.management.connection.on('connected', this.onReconnect);
+ this.$timeout( function () {
+ this.$location.path('/connect');
+ let curPath = this.$location.path();
+ let parts = curPath.split('/');
+ let org = parts[parts.length-1];
+ if (org && org.length > 0 && org !== 'connect') {
+ this.$location.search('org', org);
+ } else {
+ this.$location.search('org', null);
+ }
+ this.$location.replace();
+ });
+ }
+ connect (connectOptions) {
+ let self = this;
+ return new Promise ( function (resolve, reject) {
+ self.management.connection.connect(connectOptions)
+ .then( function (r) {
+ // if we are ever disconnected, show the connect page and wait for a reconnect
+ self.management.connection.on('disconnected', self.onDisconnect);
+
+ self.management.getSchema()
+ .then( function () {
+ self.QDRLog.info('got schema after connection');
+ self.management.topology.setUpdateEntities([]);
+ self.QDRLog.info('requesting a topology');
+ self.management.topology.get() // gets the list of routers
.then( function () {
- QDR.log.info('got schema after connection');
- self.management.topology.setUpdateEntities([]);
- QDR.log.info('requesting a topology');
- self.management.topology.get() // gets the list of routers
- .then( function () {
- QDR.log.info('got initial topology');
- let curPath = $location.path();
- let parts = curPath.split('/');
- let org = parts[parts.length-1];
- if (org === '' || org === 'connect') {
- org = localStorage[QDR.LAST_LOCATION] || QDR.pluginRoot + '/overview';
- }
- $timeout ( function () {
- $location.path(org);
- $location.search('org', null);
- $location.replace();
- });
- });
+ self.QDRLog.info('got initial topology');
+ let curPath = self.$location.path();
+ let parts = curPath.split('/');
+ let org = parts[parts.length-1];
+ if (org === '' || org === 'connect') {
+ org = localStorage[QDR_LAST_LOCATION] || '/overview';
+ }
+ self.$timeout ( function () {
+ self.$location.path(org);
+ self.$location.search('org', null);
+ self.$location.replace();
+ });
});
- resolve(r);
- }, function (e) {
- reject(e);
});
+ resolve(r);
+ }, function (e) {
+ reject(e);
});
- },
- disconnect: function () {
- self.management.connection.disconnect();
- delete self.management;
- self.management = new dm.Management($location.protocol());
- }
-
-
- };
-
- return self;
- }]);
-
- return QDR;
+ });
+ }
+ disconnect () {
+ this.management.connection.disconnect();
+ delete this.management;
+ this.management = new dm(this.$location.protocol());
+ }
+}
-}(QDR || {}));
+QDRService.$inject = ['$log', '$timeout', '$location'];
(function() {
console.dump = function(o) {
if (window.JSON && window.JSON.stringify)
- QDR.log.info(JSON.stringify(o, undefined, 2));
+ console.log(JSON.stringify(o, undefined, 2));
else
console.log(o);
};
-})();
-
-if (!String.prototype.startsWith) {
- String.prototype.startsWith = function (searchString, position) {
- return this.substr(position || 0, searchString.length) === searchString;
- };
-}
-
-if (!String.prototype.endsWith) {
- String.prototype.endsWith = function(searchString, position) {
- let subjectString = this.toString();
- if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
- position = subjectString.length;
- }
- position -= searchString.length;
- let lastIndex = subjectString.lastIndexOf(searchString, position);
- return lastIndex !== -1 && lastIndex === position;
- };
-}
-
-// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
-if (!Array.prototype.findIndex) {
- Object.defineProperty(Array.prototype, 'findIndex', {
- value: function(predicate) {
- // 1. Let O be ? ToObject(this value).
- if (this == null) {
- throw new TypeError('"this" is null or not defined');
- }
-
- let o = Object(this);
-
- // 2. Let len be ? ToLength(? Get(O, "length")).
- let len = o.length >>> 0;
-
- // 3. If IsCallable(predicate) is false, throw a TypeError exception.
- if (typeof predicate !== 'function') {
- throw new TypeError('predicate must be a function');
- }
-
- // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
- let thisArg = arguments[1];
-
- // 5. Let k be 0.
- let k = 0;
-
- // 6. Repeat, while k < len
- while (k < len) {
- // a. Let Pk be ! ToString(k).
- // b. Let kValue be ? Get(O, Pk).
- // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
- // d. If testResult is true, return k.
- let kValue = o[k];
- if (predicate.call(thisArg, kValue, k, o)) {
- return k;
- }
- // e. Increase k by 1.
- k++;
- }
-
- // 7. Return -1.
- return -1;
- }
- });
-}
-
-// https://tc39.github.io/ecma262/#sec-array.prototype.find
-if (!Array.prototype.find) {
- Object.defineProperty(Array.prototype, 'find', {
- value: function(predicate) {
- // 1. Let O be ? ToObject(this value).
- if (this == null) {
- throw new TypeError('"this" is null or not defined');
- }
-
- let o = Object(this);
-
- // 2. Let len be ? ToLength(? Get(O, "length")).
- let len = o.length >>> 0;
-
- // 3. If IsCallable(predicate) is false, throw a TypeError exception.
- if (typeof predicate !== 'function') {
- throw new TypeError('predicate must be a function');
- }
-
- // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
- let thisArg = arguments[1];
-
- // 5. Let k be 0.
- let k = 0;
-
- // 6. Repeat, while k < len
- while (k < len) {
- // a. Let Pk be ! ToString(k).
- // b. Let kValue be ? Get(O, Pk).
- // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
- // d. If testResult is true, return kValue.
- let kValue = o[k];
- if (predicate.call(thisArg, kValue, k, o)) {
- return kValue;
- }
- // e. Increase k by 1.
- k++;
- }
-
- // 7. Return undefined.
- return undefined;
- }
- });
-}
-
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
-if (!Array.prototype.fill) {
- Object.defineProperty(Array.prototype, 'fill', {
- value: function(value) {
-
- // Steps 1-2.
- if (this == null) {
- throw new TypeError('this is null or not defined');
- }
-
- var O = Object(this);
-
- // Steps 3-5.
- var len = O.length >>> 0;
-
- // Steps 6-7.
- var start = arguments[1];
- var relativeStart = start >> 0;
-
- // Step 8.
- var k = relativeStart < 0 ?
- Math.max(len + relativeStart, 0) :
- Math.min(relativeStart, len);
-
- // Steps 9-10.
- var end = arguments[2];
- var relativeEnd = end === undefined ?
- len : end >> 0;
-
- // Step 11.
- var final = relativeEnd < 0 ?
- Math.max(len + relativeEnd, 0) :
- Math.min(relativeEnd, len);
-
- // Step 12.
- while (k < final) {
- O[k] = value;
- k++;
- }
-
- // Step 13.
- return O;
- }
- });
-}
\ No newline at end of file
+})();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrSettings.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrSettings.js b/console/stand-alone/plugin/js/qdrSettings.js
index e73d13b..2d0e01b 100644
--- a/console/stand-alone/plugin/js/qdrSettings.js
+++ b/console/stand-alone/plugin/js/qdrSettings.js
@@ -16,29 +16,20 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-'use strict';
/* global angular */
-/**
- * @module QDR
- */
-var QDR = (function(QDR) {
+import { QDR_SETTINGS_KEY, QDRLogger} from './qdrGlobals.js';
- /**
- * @method SettingsController
- * @param $scope
- * @param QDRServer
- *
- * Controller that handles the QDR settings page
- */
-
- QDR.module.controller('QDR.SettingsController', ['$scope', 'QDRService', 'QDRChartService', '$timeout', function($scope, QDRService, QDRChartService, $timeout) {
+export class SettingsController {
+ constructor(QDRService, QDRChartService, $scope, $log, $timeout) {
+ this.controllerName = 'QDR.SettingsController';
+ let QDRLog = new QDRLogger($log, 'SettingsController');
$scope.connecting = false;
$scope.connectionError = false;
$scope.connectionErrorText = undefined;
$scope.forms = {};
- $scope.formEntity = angular.fromJson(localStorage[QDR.SETTINGS_KEY]) || {
+ $scope.formEntity = angular.fromJson(localStorage[QDR_SETTINGS_KEY]) || {
address: '',
port: '',
username: '',
@@ -51,7 +42,7 @@ var QDR = (function(QDR) {
if (newValue !== oldValue) {
let pass = newValue.password;
newValue.password = '';
- localStorage[QDR.SETTINGS_KEY] = angular.toJson(newValue);
+ localStorage[QDR_SETTINGS_KEY] = angular.toJson(newValue);
newValue.password = pass;
}
}, true);
@@ -84,7 +75,7 @@ var QDR = (function(QDR) {
};
var doConnect = function() {
- QDR.log.info('doConnect called on connect page');
+ QDRLog.info('doConnect called on connect page');
if (!$scope.formEntity.address)
$scope.formEntity.address = 'localhost';
if (!$scope.formEntity.port)
@@ -116,65 +107,7 @@ var QDR = (function(QDR) {
failed(e);
});
};
- }]);
-
-
- QDR.module.directive('posint', function() {
- return {
- require: 'ngModel',
-
- link: function(scope, elem, attr, ctrl) {
- // input type number allows + and - but we don't want them so filter them out
- elem.bind('keypress', function(event) {
- let nkey = !event.charCode ? event.which : event.charCode;
- let skey = String.fromCharCode(nkey);
- let nono = '-+.,';
- if (nono.indexOf(skey) >= 0) {
- event.preventDefault();
- return false;
- }
- // firefox doesn't filter out non-numeric input. it just sets the ctrl to invalid
- if (/[!@#$%^&*()]/.test(skey) && event.shiftKey || // prevent shift numbers
- !( // prevent all but the following
- nkey <= 0 || // arrows
- nkey == 8 || // delete|backspace
- nkey == 13 || // enter
- (nkey >= 37 && nkey <= 40) || // arrows
- event.ctrlKey || event.altKey || // ctrl-v, etc.
- /[0-9]/.test(skey)) // numbers
- ) {
- event.preventDefault();
- return false;
- }
- });
- // check the current value of input
- var _isPortInvalid = function(value) {
- let port = value + '';
- let isErrRange = false;
- // empty string is valid
- if (port.length !== 0) {
- let n = ~~Number(port);
- if (n < 1 || n > 65535) {
- isErrRange = true;
- }
- }
- ctrl.$setValidity('range', !isErrRange);
- return isErrRange;
- };
-
- //For DOM -> model validation
- ctrl.$parsers.unshift(function(value) {
- return _isPortInvalid(value) ? undefined : value;
- });
-
- //For model -> DOM validation
- ctrl.$formatters.unshift(function(value) {
- _isPortInvalid(value);
- return value;
- });
- }
- };
- });
+ }
+}
+SettingsController.$inject = ['QDRService', 'QDRChartService', '$scope', '$log', '$timeout'];
- return QDR;
-}(QDR || {}));
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/qdrTopAddressesController.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrTopAddressesController.js b/console/stand-alone/plugin/js/qdrTopAddressesController.js
index 2c3d3a3..2c27dbc 100644
--- a/console/stand-alone/plugin/js/qdrTopAddressesController.js
+++ b/console/stand-alone/plugin/js/qdrTopAddressesController.js
@@ -16,14 +16,11 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-'use strict';
/* global angular */
-/**
- * @module QDR
- */
-var QDR = (function(QDR) {
- QDR.module.controller('QDR.TopAddressesController', function ($scope, QDRService, $timeout) {
+export class TopAddressesController {
+ constructor(QDRService, $scope, $timeout) {
+ this.controllerName = 'QDR.TopAddressesController';
$scope.addressesData = [];
$scope.topAddressesGrid = {
@@ -214,7 +211,6 @@ var QDR = (function(QDR) {
clearInterval(timer);
});
- });
- return QDR;
-
-} (QDR || {}));
+ }
+}
+TopAddressesController.$inject = ['QDRService', '$scope', '$timeout'];
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/topology/links.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/topology/links.js b/console/stand-alone/plugin/js/topology/links.js
new file mode 100644
index 0000000..d7f4110
--- /dev/null
+++ b/console/stand-alone/plugin/js/topology/links.js
@@ -0,0 +1,216 @@
+/*
+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.
+*/
+
+class Link {
+ constructor(source, target, dir, cls, uid) {
+ this.source = source;
+ this.target = target;
+ this.left = dir != 'out';
+ this.right = (dir == 'out' || dir == 'both');
+ this.cls = cls;
+ this.uid = uid;
+ }
+}
+
+export class Links {
+ constructor(QDRService, logger) {
+ this.links = [];
+ this.QDRService = QDRService;
+ this.logger = logger;
+ }
+ getLinkSource (nodesIndex) {
+ for (let i=0; i<this.links.length; ++i) {
+ if (this.links[i].target === nodesIndex)
+ return i;
+ }
+ return -1;
+ }
+ getLink(_source, _target, dir, cls, uid) {
+ for (let i = 0; i < this.links.length; i++) {
+ let s = this.links[i].source,
+ t = this.links[i].target;
+ if (typeof this.links[i].source == 'object') {
+ s = s.id;
+ t = t.id;
+ }
+ if (s == _source && t == _target) {
+ return i;
+ }
+ // same link, just reversed
+ if (s == _target && t == _source) {
+ return -i;
+ }
+ }
+ //this.logger.debug("creating new link (" + (links.length) + ") between " + nodes[_source].name + " and " + nodes[_target].name);
+ if (this.links.some( function (l) { return l.uid === uid;}))
+ uid = uid + '.' + this.links.length;
+ return this.links.push(new Link(_source, _target, dir, cls, uid)) - 1;
+ }
+ linkFor (source, target) {
+ for (let i = 0; i < this.links.length; ++i) {
+ if ((this.links[i].source == source) && (this.links[i].target == target))
+ return this.links[i];
+ if ((this.links[i].source == target) && (this.links[i].target == source))
+ return this.links[i];
+ }
+ // the selected node was a client/broker
+ return null;
+ }
+
+
+ initializeLinks (nodeInfo, nodes, unknowns, localStorage, height) {
+ let animate = false;
+ let source = 0;
+ let client = 1.0;
+ for (let id in nodeInfo) {
+ let onode = nodeInfo[id];
+ if (!onode['connection'])
+ continue;
+ let conns = onode['connection'].results;
+ let attrs = onode['connection'].attributeNames;
+ //QDRLog.debug("external client parent is " + parent);
+ let normalsParent = {}; // 1st normal node for this parent
+
+ for (let j = 0; j < conns.length; j++) {
+ let connection = this.QDRService.utilities.flatten(attrs, conns[j]);
+ let role = connection.role;
+ let properties = connection.properties || {};
+ let dir = connection.dir;
+ if (role == 'inter-router') {
+ let connId = connection.container;
+ let target = getContainerIndex(connId, nodeInfo, this.QDRService);
+ if (target >= 0) {
+ this.getLink(source, target, dir, '', source + '-' + target);
+ }
+ } /* else if (role == "normal" || role == "on-demand" || role === "route-container")*/ {
+ // not an connection between routers, but an external connection
+ let name = this.QDRService.utilities.nameFromId(id) + '.' + connection.identity;
+
+ // if we have any new clients, animate the force graph to position them
+ let position = localStorage[name] ? JSON.parse(localStorage[name]) : undefined;
+ if ((typeof position == 'undefined')) {
+ animate = true;
+ position = {
+ x: Math.round(nodes.get(source).x + 40 * Math.sin(client / (Math.PI * 2.0))),
+ y: Math.round(nodes.get(source).y + 40 * Math.cos(client / (Math.PI * 2.0))),
+ fixed: false
+ };
+ //QDRLog.debug("new client pos (" + position.x + ", " + position.y + ")")
+ }// else QDRLog.debug("using previous location")
+ if (position.y > height) {
+ position.y = Math.round(nodes.get(source).y + 40 + Math.cos(client / (Math.PI * 2.0)));
+ }
+ let existingNodeIndex = nodes.nodeExists(connection.container);
+ let normalInfo = nodes.normalExists(connection.container);
+ let node = nodes.getOrCreateNode(id, name, role, nodeInfo, nodes.getLength(), position.x, position.y, connection.container, j, position.fixed, properties);
+ let nodeType = this.QDRService.utilities.isAConsole(properties, connection.identity, role, node.key) ? 'console' : 'client';
+ let cdir = getLinkDir(id, connection, onode, this.QDRService);
+ if (existingNodeIndex >= 0) {
+ // make a link between the current router (source) and the existing node
+ this.getLink(source, existingNodeIndex, dir, 'small', connection.name);
+ } else if (normalInfo.nodesIndex) {
+ // get node index of node that contained this connection in its normals array
+ let normalSource = this.getLinkSource(normalInfo.nodesIndex);
+ if (normalSource >= 0) {
+ if (cdir === 'unknown')
+ cdir = dir;
+ node.cdir = cdir;
+ nodes.add(node);
+ // create link from original node to the new node
+ this.getLink(this.links[normalSource].source, nodes.getLength()-1, cdir, 'small', connection.name);
+ // create link from this router to the new node
+ this.getLink(source, nodes.getLength()-1, cdir, 'small', connection.name);
+ // remove the old node from the normals list
+ nodes.get(normalInfo.nodesIndex).normals.splice(normalInfo.normalsIndex, 1);
+ }
+ } else if (role === 'normal') {
+ // normal nodes can be collapsed into a single node if they are all the same dir
+ if (cdir !== 'unknown') {
+ node.user = connection.user;
+ node.isEncrypted = connection.isEncrypted;
+ node.host = connection.host;
+ node.connectionId = connection.identity;
+ node.cdir = cdir;
+ // determine arrow direction by using the link directions
+ if (!normalsParent[nodeType+cdir]) {
+ normalsParent[nodeType+cdir] = node;
+ nodes.add(node);
+ node.normals = [node];
+ // now add a link
+ this.getLink(source, nodes.getLength() - 1, cdir, 'small', connection.name);
+ client++;
+ } else {
+ normalsParent[nodeType+cdir].normals.push(node);
+ }
+ } else {
+ node.id = nodes.getLength() - 1 + unknowns.length;
+ unknowns.push(node);
+ }
+ } else {
+ nodes.add(node);
+ // now add a link
+ this.getLink(source, nodes.getLength() - 1, dir, 'small', connection.name);
+ client++;
+ }
+ }
+ }
+ source++;
+ }
+ return animate;
+ }
+ clearHighlighted () {
+ for (let i = 0; i < this.links.length; ++i) {
+ this.links[i].highlighted = false;
+ }
+ }
+}
+
+var getContainerIndex = function (_id, nodeInfo, QDRService) {
+ let nodeIndex = 0;
+ for (let id in nodeInfo) {
+ if (QDRService.utilities.nameFromId(id) === _id)
+ return nodeIndex;
+ ++nodeIndex;
+ }
+ return -1;
+};
+
+var getLinkDir = function (id, connection, onode, QDRService) {
+ let links = onode['router.link'];
+ if (!links) {
+ return 'unknown';
+ }
+ let inCount = 0, outCount = 0;
+ links.results.forEach( function (linkResult) {
+ let link = QDRService.utilities.flatten(links.attributeNames, linkResult);
+ if (link.linkType === 'endpoint' && link.connectionId === connection.identity)
+ if (link.linkDir === 'in')
+ ++inCount;
+ else
+ ++outCount;
+ });
+ if (inCount > 0 && outCount > 0)
+ return 'both';
+ if (inCount > 0)
+ return 'in';
+ if (outCount > 0)
+ return 'out';
+ return 'unknown';
+};
+
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/b5deb035/console/stand-alone/plugin/js/topology/nodes.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/topology/nodes.js b/console/stand-alone/plugin/js/topology/nodes.js
new file mode 100644
index 0000000..45ef23f
--- /dev/null
+++ b/console/stand-alone/plugin/js/topology/nodes.js
@@ -0,0 +1,162 @@
+/*
+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.
+*/
+
+export class Node {
+ constructor(id, name, nodeType, properties, routerId, x, y, nodeIndex, resultIndex, fixed, connectionContainer) {
+ this.key = id;
+ this.name = name;
+ this.nodeType = nodeType;
+ this.properties = properties;
+ this.routerId = routerId;
+ this.x = x;
+ this.y = y;
+ this.id = nodeIndex;
+ this.resultIndex = resultIndex;
+ this.fixed = !!+fixed;
+ this.cls = '';
+ this.container = connectionContainer;
+ }
+}
+
+export class Nodes {
+ constructor(QDRService, logger) {
+ this.nodes = [];
+ this.QDRService = QDRService;
+ this.logger = logger;
+ }
+ getLength () {
+ return this.nodes.length;
+ }
+ get (index) {
+ if (index < this.getLength()) {
+ return this.nodes[index];
+ }
+ this.logger.error(`Attempted to get node[${index}] but there were only ${this.getLength()} nodes`);
+ return undefined;
+ }
+ setNodesFixed (name, b) {
+ this.nodes.some(function (n) {
+ if (n.name === name) {
+ n.fixed = b;
+ return true;
+ }
+ });
+ }
+ nodeFor (name) {
+ for (let i = 0; i < this.nodes.length; ++i) {
+ if (this.nodes[i].name == name)
+ return this.nodes[i];
+ }
+ return null;
+ }
+ nodeExists (connectionContainer) {
+ return this.nodes.findIndex( function (node) {
+ return node.container === connectionContainer;
+ });
+ }
+ normalExists (connectionContainer) {
+ let normalInfo = {};
+ for (let i=0; i<this.nodes.length; ++i) {
+ if (this.nodes[i].normals) {
+ if (this.nodes[i].normals.some(function (normal, j) {
+ if (normal.container === connectionContainer && i !== j) {
+ normalInfo = {nodesIndex: i, normalsIndex: j};
+ return true;
+ }
+ return false;
+ }))
+ break;
+ }
+ }
+ return normalInfo;
+ }
+ savePositions () {
+ this.nodes.forEach( function (d) {
+ localStorage[d.name] = JSON.stringify({
+ x: Math.round(d.x),
+ y: Math.round(d.y),
+ fixed: (d.fixed & 1) ? 1 : 0,
+ });
+ });
+ }
+ find (connectionContainer, properties, name) {
+ properties = properties || {};
+ for (let i=0; i<this.nodes.length; ++i) {
+ if (this.nodes[i].name === name || this.nodes[i].container === connectionContainer) {
+ if (properties.product)
+ this.nodes[i].properties = properties;
+ return this.nodes[i];
+ }
+ }
+ return undefined;
+ }
+ getOrCreateNode (id, name, nodeType, nodeInfo, nodeIndex, x, y,
+ connectionContainer, resultIndex, fixed, properties) {
+ properties = properties || {};
+ let gotNode = this.find(connectionContainer, properties, name);
+ if (gotNode) {
+ return gotNode;
+ }
+ let routerId = this.QDRService.utilities.nameFromId(id);
+ return new Node(id, name, nodeType, properties, routerId, x, y,
+ nodeIndex, resultIndex, fixed, connectionContainer);
+ }
+ add (obj) {
+ this.nodes.push(obj);
+ return obj;
+ }
+ addUsing (id, name, nodeType, nodeInfo, nodeIndex, x, y,
+ connectContainer, resultIndex, fixed, properties) {
+ let obj = this.getOrCreateNode(id, name, nodeType, nodeInfo, nodeIndex, x, y,
+ connectContainer, resultIndex, fixed, properties);
+ this.nodes.push(obj);
+ return obj;
+ }
+ clearHighlighted () {
+ for (let i = 0; i<this.nodes.length; ++i) {
+ this.nodes[i].highlighted = false;
+ }
+ }
+ initialize (nodeInfo, localStorage, width, height) {
+ let nodeCount = Object.keys(nodeInfo).length;
+ let yInit = 50;
+ let animate = false;
+ for (let id in nodeInfo) {
+ let name = this.QDRService.utilities.nameFromId(id);
+ // if we have any new nodes, animate the force graph to position them
+ let position = localStorage[name] ? JSON.parse(localStorage[name]) : undefined;
+ if (!position) {
+ animate = true;
+ position = {
+ x: Math.round(width / 4 + ((width / 2) / nodeCount) * this.nodes.length),
+ y: Math.round(height / 2 + Math.sin(this.nodes.length / (Math.PI*2.0)) * height / 4),
+ fixed: false,
+ };
+ }
+ if (position.y > height) {
+ position.y = 200 - yInit;
+ yInit *= -1;
+ }
+ this.addUsing(id, name, 'inter-router', nodeInfo, this.nodes.length, position.x, position.y, name, undefined, position.fixed, {});
+ }
+ return animate;
+ }
+
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org