http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/3c9a22b4/console/app/app-small.js ---------------------------------------------------------------------- diff --git a/console/app/app-small.js b/console/app/app-small.js new file mode 100644 index 0000000..01cda95 --- /dev/null +++ b/console/app/app-small.js @@ -0,0 +1,13089 @@ +var StringHelpers; +(function (StringHelpers) { + var dateRegex = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:/i; + function isDate(str) { + if (!angular.isString(str)) { + return false; + } + return dateRegex.test(str); + } + StringHelpers.isDate = isDate; + function obfusicate(str) { + if (!angular.isString(str)) { + return null; + } + return str.chars().map(function (c) { + return '*'; + }).join(''); + } + StringHelpers.obfusicate = obfusicate; + function toString(obj) { + if (!obj) { + return '{ null }'; + } + var answer = []; + angular.forEach(obj, function (value, key) { + var val = value; + if (('' + key).toLowerCase() === 'password') { + val = StringHelpers.obfusicate(value); + } + else if (angular.isObject(val)) { + val = toString(val); + } + answer.push(key + ': ' + val); + }); + return '{ ' + answer.join(', ') + ' }'; + } + StringHelpers.toString = toString; +})(StringHelpers || (StringHelpers = {})); +var Core; +(function (Core) { + function createConnectToServerOptions(options) { + var defaults = { + scheme: 'http', + host: null, + port: null, + path: null, + useProxy: true, + jolokiaUrl: null, + userName: null, + password: null, + view: null, + name: null + }; + var opts = options || {}; + return angular.extend(defaults, opts); + } + Core.createConnectToServerOptions = createConnectToServerOptions; + function createConnectOptions(options) { + return createConnectToServerOptions(options); + } + Core.createConnectOptions = createConnectOptions; +})(Core || (Core = {})); +var UrlHelpers; +(function (UrlHelpers) { + var log = Logger.get("UrlHelpers"); + function noHash(url) { + if (url.startsWith('#')) { + return url.last(url.length - 1); + } + else { + return url; + } + } + UrlHelpers.noHash = noHash; + function extractPath(url) { + if (url.has('?')) { + return url.split('?')[0]; + } + else { + return url; + } + } + UrlHelpers.extractPath = extractPath; + function contextActive(url, thingICareAbout) { + var cleanUrl = extractPath(url); + if (thingICareAbout.endsWith('/') && thingICareAbout.startsWith("/")) { + return cleanUrl.has(thingICareAbout); + } + if (thingICareAbout.startsWith("/")) { + return noHash(cleanUrl).startsWith(thingICareAbout); + } + return cleanUrl.endsWith(thingICareAbout); + } + UrlHelpers.contextActive = contextActive; + function join() { + var paths = []; + for (var _i = 0; _i < arguments.length; _i++) { + paths[_i - 0] = arguments[_i]; + } + var tmp = []; + var length = paths.length - 1; + paths.forEach(function (path, index) { + if (Core.isBlank(path)) { + return; + } + if (index !== 0 && path.first(1) === '/') { + path = path.slice(1); + } + if (index !== length && path.last(1) === '/') { + path = path.slice(0, path.length - 1); + } + if (!Core.isBlank(path)) { + tmp.push(path); + } + }); + var rc = tmp.join('/'); + return rc; + } + UrlHelpers.join = join; + UrlHelpers.parseQueryString = hawtioPluginLoader.parseQueryString; + function maybeProxy(jolokiaUrl, url) { + if (jolokiaUrl && jolokiaUrl.startsWith('proxy/')) { + log.debug("Jolokia URL is proxied, applying proxy to: ", url); + return join('proxy', url); + } + var origin = window.location['origin']; + if (url && (url.startsWith('http') && !url.startsWith(origin))) { + log.debug("Url doesn't match page origin: ", origin, " applying proxy to: ", url); + return join('proxy', url); + } + log.debug("No need to proxy: ", url); + return url; + } + UrlHelpers.maybeProxy = maybeProxy; + function escapeColons(url) { + var answer = url; + if (url.startsWith('proxy')) { + answer = url.replace(/:/g, '\\:'); + } + else { + answer = url.replace(/:([^\/])/, '\\:$1'); + } + return answer; + } + UrlHelpers.escapeColons = escapeColons; +})(UrlHelpers || (UrlHelpers = {})); +var Core; +(function (Core) { + Core.injector = null; + var _urlPrefix = null; + Core.connectionSettingsKey = "jvmConnect"; + function _resetUrlPrefix() { + _urlPrefix = null; + } + Core._resetUrlPrefix = _resetUrlPrefix; + function url(path) { + if (path) { + if (path.startsWith && path.startsWith("/")) { + if (!_urlPrefix) { + _urlPrefix = $('base').attr('href') || ""; + if (_urlPrefix.endsWith && _urlPrefix.endsWith('/')) { + _urlPrefix = _urlPrefix.substring(0, _urlPrefix.length - 1); + } + } + if (_urlPrefix) { + return _urlPrefix + path; + } + } + } + return path; + } + Core.url = url; + function windowLocation() { + return window.location; + } + Core.windowLocation = windowLocation; + String.prototype.unescapeHTML = function () { + var txt = document.createElement("textarea"); + txt.innerHTML = this; + return txt.value; + }; + if (!Object.keys) { + console.debug("Creating hawt.io version of Object.keys()"); + Object.keys = function (obj) { + var keys = [], k; + for (k in obj) { + if (Object.prototype.hasOwnProperty.call(obj, k)) { + keys.push(k); + } + } + return keys; + }; + } + function _resetJolokiaUrls() { + jolokiaUrls = [ + Core.url("jolokia"), + "/jolokia" + ]; + return jolokiaUrls; + } + Core._resetJolokiaUrls = _resetJolokiaUrls; + var jolokiaUrls = Core._resetJolokiaUrls(); + function trimLeading(text, prefix) { + if (text && prefix) { + if (text.startsWith(prefix)) { + return text.substring(prefix.length); + } + } + return text; + } + Core.trimLeading = trimLeading; + function trimTrailing(text, postfix) { + if (text && postfix) { + if (text.endsWith(postfix)) { + return text.substring(0, text.length - postfix.length); + } + } + return text; + } + Core.trimTrailing = trimTrailing; + function loadConnectionMap() { + var localStorage = Core.getLocalStorage(); + try { + var answer = angular.fromJson(localStorage[Core.connectionSettingsKey]); + if (!answer) { + return {}; + } + else { + return answer; + } + } + catch (e) { + delete localStorage[Core.connectionSettingsKey]; + return {}; + } + } + Core.loadConnectionMap = loadConnectionMap; + function saveConnectionMap(map) { + Logger.get("Core").debug("Saving connection map: ", StringHelpers.toString(map)); + localStorage[Core.connectionSettingsKey] = angular.toJson(map); + } + Core.saveConnectionMap = saveConnectionMap; + function getConnectOptions(name, localStorage) { + if (localStorage === void 0) { localStorage = Core.getLocalStorage(); } + if (!name) { + return null; + } + return Core.loadConnectionMap()[name]; + } + Core.getConnectOptions = getConnectOptions; + Core.ConnectionName = null; + function getConnectionNameParameter(search) { + if (Core.ConnectionName) { + return Core.ConnectionName; + } + var connectionName = undefined; + if ('con' in window) { + connectionName = window['con']; + Logger.get("Core").debug("Found connection name from window: ", connectionName); + } + else { + connectionName = search["con"]; + if (angular.isArray(connectionName)) { + connectionName = connectionName[0]; + } + if (connectionName) { + connectionName = connectionName.unescapeURL(); + Logger.get("Core").debug("Found connection name from URL: ", connectionName); + } + else { + Logger.get("Core").debug("No connection name found, using direct connection to JVM"); + } + } + Core.ConnectionName = connectionName; + return connectionName; + } + Core.getConnectionNameParameter = getConnectionNameParameter; + function createServerConnectionUrl(options) { + Logger.get("Core").debug("Connect to server, options: ", StringHelpers.toString(options)); + var answer = null; + if (options.jolokiaUrl) { + answer = options.jolokiaUrl; + } + if (answer === null) { + answer = options.scheme || 'http'; + answer += '://' + (options.host || 'localhost'); + if (options.port) { + answer += ':' + options.port; + } + if (options.path) { + answer = UrlHelpers.join(answer, options.path); + } + } + if (options.useProxy) { + answer = UrlHelpers.join('proxy', answer); + } + Logger.get("Core").debug("Using URL: ", answer); + return answer; + } + Core.createServerConnectionUrl = createServerConnectionUrl; + function getJolokiaUrl() { + var query = hawtioPluginLoader.parseQueryString(); + var localMode = query['localMode']; + if (localMode) { + Logger.get("Core").debug("local mode so not using jolokia URL"); + jolokiaUrls = []; + return null; + } + var uri = null; + var connectionName = Core.getConnectionNameParameter(query); + if (connectionName) { + var connectOptions = Core.getConnectOptions(connectionName); + if (connectOptions) { + uri = createServerConnectionUrl(connectOptions); + Logger.get("Core").debug("Using jolokia URI: ", uri, " from local storage"); + } + else { + Logger.get("Core").debug("Connection parameter found but no stored connections under name: ", connectionName); + } + } + if (!uri) { + var fakeCredentials = { + username: 'public', + password: 'biscuit' + }; + var localStorage = getLocalStorage(); + if ('userDetails' in window) { + fakeCredentials = window['userDetails']; + } + else if ('userDetails' in localStorage) { + fakeCredentials = angular.fromJson(localStorage['userDetails']); + } + uri = jolokiaUrls.find(function (url) { + var jqxhr = $.ajax(url, { + async: false, + username: fakeCredentials.username, + password: fakeCredentials.password + }); + return jqxhr.status === 200 || jqxhr.status === 401 || jqxhr.status === 403; + }); + Logger.get("Core").debug("Using jolokia URI: ", uri, " via discovery"); + } + return uri; + } + Core.getJolokiaUrl = getJolokiaUrl; + function adjustHeight() { + var windowHeight = $(window).height(); + var headerHeight = $("#main-nav").height(); + var containerHeight = windowHeight - headerHeight; + $("#main").css("min-height", "" + containerHeight + "px"); + } + Core.adjustHeight = adjustHeight; + function isChromeApp() { + var answer = false; + try { + answer = (chrome && chrome.app && chrome.extension) ? true : false; + } + catch (e) { + answer = false; + } + return answer; + } + Core.isChromeApp = isChromeApp; + function addCSS(path) { + if ('createStyleSheet' in document) { + document.createStyleSheet(path); + } + else { + var link = $("<link>"); + $("head").append(link); + link.attr({ + rel: 'stylesheet', + type: 'text/css', + href: path + }); + } + } + Core.addCSS = addCSS; + var dummyStorage = {}; + function getLocalStorage() { + var storage = window.localStorage || (function () { + return dummyStorage; + })(); + return storage; + } + Core.getLocalStorage = getLocalStorage; + function asArray(value) { + return angular.isArray(value) ? value : [value]; + } + Core.asArray = asArray; + function parseBooleanValue(value, defaultValue) { + if (defaultValue === void 0) { defaultValue = false; } + if (!angular.isDefined(value) || !value) { + return defaultValue; + } + if (value.constructor === Boolean) { + return value; + } + if (angular.isString(value)) { + switch (value.toLowerCase()) { + case "true": + case "1": + case "yes": + return true; + default: + return false; + } + } + if (angular.isNumber(value)) { + return value !== 0; + } + throw new Error("Can't convert value " + value + " to boolean"); + } + Core.parseBooleanValue = parseBooleanValue; + function toString(value) { + if (angular.isNumber(value)) { + return numberToString(value); + } + else { + return angular.toJson(value, true); + } + } + Core.toString = toString; + function booleanToString(value) { + return "" + value; + } + Core.booleanToString = booleanToString; + function parseIntValue(value, description) { + if (description === void 0) { description = "integer"; } + if (angular.isString(value)) { + try { + return parseInt(value); + } + catch (e) { + console.log("Failed to parse " + description + " with text '" + value + "'"); + } + } + else if (angular.isNumber(value)) { + return value; + } + return null; + } + Core.parseIntValue = parseIntValue; + function numberToString(value) { + return "" + value; + } + Core.numberToString = numberToString; + function parseFloatValue(value, description) { + if (description === void 0) { description = "float"; } + if (angular.isString(value)) { + try { + return parseFloat(value); + } + catch (e) { + console.log("Failed to parse " + description + " with text '" + value + "'"); + } + } + else if (angular.isNumber(value)) { + return value; + } + return null; + } + Core.parseFloatValue = parseFloatValue; + function pathGet(object, paths) { + var pathArray = (angular.isArray(paths)) ? paths : (paths || "").split("."); + var value = object; + angular.forEach(pathArray, function (name) { + if (value) { + try { + value = value[name]; + } + catch (e) { + return null; + } + } + else { + return null; + } + }); + return value; + } + Core.pathGet = pathGet; + function pathSet(object, paths, newValue) { + var pathArray = (angular.isArray(paths)) ? paths : (paths || "").split("."); + var value = object; + var lastIndex = pathArray.length - 1; + angular.forEach(pathArray, function (name, idx) { + var next = value[name]; + if (idx >= lastIndex || !angular.isObject(next)) { + next = (idx < lastIndex) ? {} : newValue; + value[name] = next; + } + value = next; + }); + return value; + } + Core.pathSet = pathSet; + function $applyNowOrLater($scope) { + if ($scope.$$phase || $scope.$root.$$phase) { + setTimeout(function () { + Core.$apply($scope); + }, 50); + } + else { + $scope.$apply(); + } + } + Core.$applyNowOrLater = $applyNowOrLater; + function $applyLater($scope, timeout) { + if (timeout === void 0) { timeout = 50; } + setTimeout(function () { + Core.$apply($scope); + }, timeout); + } + Core.$applyLater = $applyLater; + function $apply($scope) { + var phase = $scope.$$phase || $scope.$root.$$phase; + if (!phase) { + $scope.$apply(); + } + } + Core.$apply = $apply; + function $digest($scope) { + var phase = $scope.$$phase || $scope.$root.$$phase; + if (!phase) { + $scope.$digest(); + } + } + Core.$digest = $digest; + function getOrCreateElements(domElement, arrayOfElementNames) { + var element = domElement; + angular.forEach(arrayOfElementNames, function (name) { + if (element) { + var children = $(element).children(name); + if (!children || !children.length) { + $("<" + name + "></" + name + ">").appendTo(element); + children = $(element).children(name); + } + element = children; + } + }); + return element; + } + Core.getOrCreateElements = getOrCreateElements; + var _escapeHtmlChars = { + "#": "#", + "'": "'", + "<": "<", + ">": ">", + "\"": """ + }; + function unescapeHtml(str) { + angular.forEach(_escapeHtmlChars, function (value, key) { + var regex = new RegExp(value, "g"); + str = str.replace(regex, key); + }); + str = str.replace(/>/g, ">"); + return str; + } + Core.unescapeHtml = unescapeHtml; + function escapeHtml(str) { + if (angular.isString(str)) { + var newStr = ""; + for (var i = 0; i < str.length; i++) { + var ch = str.charAt(i); + var ch = _escapeHtmlChars[ch] || ch; + newStr += ch; + } + return newStr; + } + else { + return str; + } + } + Core.escapeHtml = escapeHtml; + function isBlank(str) { + if (str === undefined || str === null) { + return true; + } + if (angular.isString(str)) { + return str.isBlank(); + } + else { + return false; + } + } + Core.isBlank = isBlank; + function notification(type, message, options) { + if (options === void 0) { options = null; } + if (options === null) { + options = {}; + } + if (type === 'error' || type === 'warning') { + if (!angular.isDefined(options.onclick)) { + options.onclick = window['showLogPanel']; + } + } + toastr[type](message, '', options); + } + Core.notification = notification; + function clearNotifications() { + toastr.clear(); + } + Core.clearNotifications = clearNotifications; + function trimQuotes(text) { + if (text) { + while (text.endsWith('"') || text.endsWith("'")) { + text = text.substring(0, text.length - 1); + } + while (text.startsWith('"') || text.startsWith("'")) { + text = text.substring(1, text.length); + } + } + return text; + } + Core.trimQuotes = trimQuotes; + function humanizeValue(value) { + if (value) { + var text = value + ''; + try { + text = text.underscore(); + } + catch (e) { + } + try { + text = text.humanize(); + } + catch (e) { + } + return trimQuotes(text); + } + return value; + } + Core.humanizeValue = humanizeValue; +})(Core || (Core = {})); +var ControllerHelpers; +(function (ControllerHelpers) { + var log = Logger.get("ControllerHelpers"); + function createClassSelector(config) { + return function (selector, model) { + if (selector === model && selector in config) { + return config[selector]; + } + return ''; + }; + } + ControllerHelpers.createClassSelector = createClassSelector; + function createValueClassSelector(config) { + return function (model) { + if (model in config) { + return config[model]; + } + else { + return ''; + } + }; + } + ControllerHelpers.createValueClassSelector = createValueClassSelector; + function bindModelToSearchParam($scope, $location, modelName, paramName, initialValue, to, from) { + if (!(modelName in $scope)) { + $scope[modelName] = initialValue; + } + var toConverter = to || Core.doNothing; + var fromConverter = from || Core.doNothing; + function currentValue() { + return fromConverter($location.search()[paramName] || initialValue); + } + var value = currentValue(); + Core.pathSet($scope, modelName, value); + $scope.$watch(modelName, function (newValue, oldValue) { + if (newValue !== oldValue) { + if (newValue !== undefined && newValue !== null) { + $location.search(paramName, toConverter(newValue)); + } + else { + $location.search(paramName, ''); + } + } + }); + } + ControllerHelpers.bindModelToSearchParam = bindModelToSearchParam; + function reloadWhenParametersChange($route, $scope, $location, parameters) { + if (parameters === void 0) { parameters = ["nid"]; } + var initial = angular.copy($location.search()); + $scope.$on('$routeUpdate', function () { + var current = $location.search(); + var changed = []; + angular.forEach(parameters, function (param) { + if (current[param] !== initial[param]) { + changed.push(param); + } + }); + if (changed.length) { + $route.reload(); + } + }); + } + ControllerHelpers.reloadWhenParametersChange = reloadWhenParametersChange; +})(ControllerHelpers || (ControllerHelpers = {})); +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Core; +(function (Core) { + var log = Logger.get("Core"); + var TasksImpl = (function () { + function TasksImpl() { + this.tasks = {}; + this.tasksExecuted = false; + this._onComplete = null; + } + TasksImpl.prototype.addTask = function (name, task) { + this.tasks[name] = task; + if (this.tasksExecuted) { + this.executeTask(name, task); + } + }; + TasksImpl.prototype.executeTask = function (name, task) { + if (angular.isFunction(task)) { + log.debug("Executing task : ", name); + try { + task(); + } + catch (error) { + log.debug("Failed to execute task: ", name, " error: ", error); + } + } + }; + TasksImpl.prototype.onComplete = function (cb) { + this._onComplete = cb; + }; + TasksImpl.prototype.execute = function () { + var _this = this; + if (this.tasksExecuted) { + return; + } + angular.forEach(this.tasks, function (task, name) { + _this.executeTask(name, task); + }); + this.tasksExecuted = true; + if (angular.isFunction(this._onComplete)) { + this._onComplete(); + } + }; + TasksImpl.prototype.reset = function () { + this.tasksExecuted = false; + }; + return TasksImpl; + })(); + Core.TasksImpl = TasksImpl; + var ParameterizedTasksImpl = (function (_super) { + __extends(ParameterizedTasksImpl, _super); + function ParameterizedTasksImpl() { + var _this = this; + _super.call(this); + this.tasks = {}; + this.onComplete(function () { + _this.reset(); + }); + } + ParameterizedTasksImpl.prototype.addTask = function (name, task) { + this.tasks[name] = task; + }; + ParameterizedTasksImpl.prototype.execute = function () { + var _this = this; + var params = []; + for (var _i = 0; _i < arguments.length; _i++) { + params[_i - 0] = arguments[_i]; + } + if (this.tasksExecuted) { + return; + } + var theArgs = params; + var keys = Object.keys(this.tasks); + keys.forEach(function (name) { + var task = _this.tasks[name]; + if (angular.isFunction(task)) { + log.debug("Executing task: ", name, " with parameters: ", theArgs); + try { + task.apply(task, theArgs); + } + catch (e) { + log.debug("Failed to execute task: ", name, " error: ", e); + } + } + }); + this.tasksExecuted = true; + if (angular.isFunction(this._onComplete)) { + this._onComplete(); + } + }; + return ParameterizedTasksImpl; + })(TasksImpl); + Core.ParameterizedTasksImpl = ParameterizedTasksImpl; + Core.postLoginTasks = new Core.TasksImpl(); + Core.preLogoutTasks = new Core.TasksImpl(); +})(Core || (Core = {})); +var Core; +(function (Core) { + function operationToString(name, args) { + if (!args || args.length === 0) { + return name + '()'; + } + else { + return name + '(' + args.map(function (arg) { + if (angular.isString(arg)) { + arg = angular.fromJson(arg); + } + return arg.type; + }).join(',') + ')'; + } + } + Core.operationToString = operationToString; +})(Core || (Core = {})); +var Core; +(function (Core) { + var Folder = (function () { + function Folder(title) { + this.title = title; + this.key = null; + this.typeName = null; + this.children = []; + this.folderNames = []; + this.domain = null; + this.objectName = null; + this.map = {}; + this.entries = {}; + this.addClass = null; + this.parent = null; + this.isLazy = false; + this.icon = null; + this.tooltip = null; + this.entity = null; + this.version = null; + this.mbean = null; + this.addClass = escapeTreeCssStyles(title); + } + Folder.prototype.get = function (key) { + return this.map[key]; + }; + Folder.prototype.isFolder = function () { + return this.children.length > 0; + }; + Folder.prototype.navigate = function () { + var paths = []; + for (var _i = 0; _i < arguments.length; _i++) { + paths[_i - 0] = arguments[_i]; + } + var node = this; + paths.forEach(function (path) { + if (node) { + node = node.get(path); + } + }); + return node; + }; + Folder.prototype.hasEntry = function (key, value) { + var entries = this.entries; + if (entries) { + var actual = entries[key]; + return actual && value === actual; + } + return false; + }; + Folder.prototype.parentHasEntry = function (key, value) { + if (this.parent) { + return this.parent.hasEntry(key, value); + } + return false; + }; + Folder.prototype.ancestorHasEntry = function (key, value) { + var parent = this.parent; + while (parent) { + if (parent.hasEntry(key, value)) + return true; + parent = parent.parent; + } + return false; + }; + Folder.prototype.ancestorHasType = function (typeName) { + var parent = this.parent; + while (parent) { + if (typeName === parent.typeName) + return true; + parent = parent.parent; + } + return false; + }; + Folder.prototype.getOrElse = function (key, defaultValue) { + if (defaultValue === void 0) { defaultValue = new Folder(key); } + var answer = this.map[key]; + if (!answer) { + answer = defaultValue; + this.map[key] = answer; + this.children.push(answer); + answer.parent = this; + } + return answer; + }; + Folder.prototype.sortChildren = function (recursive) { + var children = this.children; + if (children) { + this.children = children.sortBy("title"); + if (recursive) { + angular.forEach(children, function (child) { return child.sortChildren(recursive); }); + } + } + }; + Folder.prototype.moveChild = function (child) { + if (child && child.parent !== this) { + child.detach(); + child.parent = this; + this.children.push(child); + } + }; + Folder.prototype.insertBefore = function (child, referenceFolder) { + child.detach(); + child.parent = this; + var idx = _.indexOf(this.children, referenceFolder); + if (idx >= 0) { + this.children.splice(idx, 0, child); + } + }; + Folder.prototype.insertAfter = function (child, referenceFolder) { + child.detach(); + child.parent = this; + var idx = _.indexOf(this.children, referenceFolder); + if (idx >= 0) { + this.children.splice(idx + 1, 0, child); + } + }; + Folder.prototype.detach = function () { + var oldParent = this.parent; + if (oldParent) { + var oldParentChildren = oldParent.children; + if (oldParentChildren) { + var idx = oldParentChildren.indexOf(this); + if (idx < 0) { + oldParent.children = oldParent.children.remove({ key: this.key }); + } + else { + oldParentChildren.splice(idx, 1); + } + } + this.parent = null; + } + }; + Folder.prototype.findDescendant = function (filter) { + if (filter(this)) { + return this; + } + var answer = null; + angular.forEach(this.children, function (child) { + if (!answer) { + answer = child.findDescendant(filter); + } + }); + return answer; + }; + Folder.prototype.findAncestor = function (filter) { + if (filter(this)) { + return this; + } + if (this.parent != null) { + return this.parent.findAncestor(filter); + } + else { + return null; + } + }; + return Folder; + })(); + Core.Folder = Folder; +})(Core || (Core = {})); +; +var Folder = (function (_super) { + __extends(Folder, _super); + function Folder() { + _super.apply(this, arguments); + } + return Folder; +})(Core.Folder); +; +var Core; +(function (Core) { + var log = Logger.get("Core"); + var Workspace = (function () { + function Workspace(jolokia, jolokiaStatus, jmxTreeLazyLoadRegistry, $location, $compile, $templateCache, localStorage, $rootScope, userDetails) { + this.jolokia = jolokia; + this.jolokiaStatus = jolokiaStatus; + this.jmxTreeLazyLoadRegistry = jmxTreeLazyLoadRegistry; + this.$location = $location; + this.$compile = $compile; + this.$templateCache = $templateCache; + this.localStorage = localStorage; + this.$rootScope = $rootScope; + this.userDetails = userDetails; + this.operationCounter = 0; + this.tree = new Core.Folder('MBeans'); + this.mbeanTypesToDomain = {}; + this.mbeanServicesToDomain = {}; + this.attributeColumnDefs = {}; + this.treePostProcessors = []; + this.topLevelTabs = []; + this.subLevelTabs = []; + this.keyToNodeMap = {}; + this.pluginRegisterHandle = null; + this.pluginUpdateCounter = null; + this.treeWatchRegisterHandle = null; + this.treeWatcherCounter = null; + this.treeElement = null; + this.mapData = {}; + if (!('autoRefresh' in localStorage)) { + localStorage['autoRefresh'] = true; + } + if (!('updateRate' in localStorage)) { + localStorage['updateRate'] = 5000; + } + } + Workspace.prototype.createChildWorkspace = function (location) { + var child = new Workspace(this.jolokia, this.jolokiaStatus, this.jmxTreeLazyLoadRegistry, this.$location, this.$compile, this.$templateCache, this.localStorage, this.$rootScope, this.userDetails); + angular.forEach(this, function (value, key) { return child[key] = value; }); + child.$location = location; + return child; + }; + Workspace.prototype.getLocalStorage = function (key) { + return this.localStorage[key]; + }; + Workspace.prototype.setLocalStorage = function (key, value) { + this.localStorage[key] = value; + }; + Workspace.prototype.loadTree = function () { + var flags = { ignoreErrors: true, maxDepth: 7 }; + var data = this.jolokia.list(null, onSuccess(null, flags)); + if (data) { + this.jolokiaStatus.xhr = null; + } + this.populateTree({ + value: data + }); + }; + Workspace.prototype.addTreePostProcessor = function (processor) { + this.treePostProcessors.push(processor); + var tree = this.tree; + if (tree) { + processor(tree); + } + }; + Workspace.prototype.maybeMonitorPlugins = function () { + if (this.treeContainsDomainAndProperties("hawtio", { type: "Registry" })) { + if (this.pluginRegisterHandle === null) { + this.pluginRegisterHandle = this.jolokia.register(angular.bind(this, this.maybeUpdatePlugins), { + type: "read", + mbean: "hawtio:type=Registry", + attribute: "UpdateCounter" + }); + } + } + else { + if (this.pluginRegisterHandle !== null) { + this.jolokia.unregister(this.pluginRegisterHandle); + this.pluginRegisterHandle = null; + this.pluginUpdateCounter = null; + } + } + if (this.treeContainsDomainAndProperties("hawtio", { type: "TreeWatcher" })) { + if (this.treeWatchRegisterHandle === null) { + this.treeWatchRegisterHandle = this.jolokia.register(angular.bind(this, this.maybeReloadTree), { + type: "read", + mbean: "hawtio:type=TreeWatcher", + attribute: "Counter" + }); + } + } + }; + Workspace.prototype.maybeUpdatePlugins = function (response) { + if (this.pluginUpdateCounter === null) { + this.pluginUpdateCounter = response.value; + return; + } + if (this.pluginUpdateCounter !== response.value) { + if (Core.parseBooleanValue(localStorage['autoRefresh'])) { + window.location.reload(); + } + } + }; + Workspace.prototype.maybeReloadTree = function (response) { + var counter = response.value; + if (this.treeWatcherCounter === null) { + this.treeWatcherCounter = counter; + return; + } + if (this.treeWatcherCounter !== counter) { + this.treeWatcherCounter = counter; + var workspace = this; + function wrapInValue(response) { + var wrapper = { + value: response + }; + workspace.populateTree(wrapper); + } + this.jolokia.list(null, onSuccess(wrapInValue, { ignoreErrors: true, maxDepth: 2 })); + } + }; + Workspace.prototype.folderGetOrElse = function (folder, value) { + if (folder) { + try { + return folder.getOrElse(value); + } + catch (e) { + log.warn("Failed to find value " + value + " on folder " + folder); + } + } + return null; + }; + Workspace.prototype.populateTree = function (response) { + log.debug("JMX tree has been loaded, data: ", response.value); + var rootId = 'root'; + var separator = '-'; + this.mbeanTypesToDomain = {}; + this.mbeanServicesToDomain = {}; + this.keyToNodeMap = {}; + var tree = new Core.Folder('MBeans'); + tree.key = rootId; + var domains = response.value; + for (var domainName in domains) { + var domainClass = escapeDots(domainName); + var domain = domains[domainName]; + for (var mbeanName in domain) { + var entries = {}; + var folder = this.folderGetOrElse(tree, domainName); + folder.domain = domainName; + if (!folder.key) { + folder.key = rootId + separator + domainName; + } + var folderNames = [domainName]; + folder.folderNames = folderNames; + folderNames = folderNames.clone(); + var items = mbeanName.split(','); + var paths = []; + var typeName = null; + var serviceName = null; + items.forEach(function (item) { + var kv = item.split('='); + var key = kv[0]; + var value = kv[1] || key; + entries[key] = value; + var moveToFront = false; + var lowerKey = key.toLowerCase(); + if (lowerKey === "type") { + typeName = value; + if (folder.map[value]) { + moveToFront = true; + } + } + if (lowerKey === "service") { + serviceName = value; + } + if (moveToFront) { + paths.splice(0, 0, value); + } + else { + paths.push(value); + } + }); + var configureFolder = function (folder, name) { + folder.domain = domainName; + if (!folder.key) { + folder.key = rootId + separator + folderNames.join(separator); + } + this.keyToNodeMap[folder.key] = folder; + folder.folderNames = folderNames.clone(); + var classes = ""; + var entries = folder.entries; + var entryKeys = Object.keys(entries).filter(function (n) { return n.toLowerCase().indexOf("type") >= 0; }); + if (entryKeys.length) { + angular.forEach(entryKeys, function (entryKey) { + var entryValue = entries[entryKey]; + if (!folder.ancestorHasEntry(entryKey, entryValue)) { + classes += " " + domainClass + separator + entryValue; + } + }); + } + else { + var kindName = folderNames.last(); + if (kindName === name) { + kindName += "-folder"; + } + if (kindName) { + classes += " " + domainClass + separator + kindName; + } + } + folder.addClass = escapeTreeCssStyles(classes); + return folder; + }; + var lastPath = paths.pop(); + var ws = this; + paths.forEach(function (value) { + folder = ws.folderGetOrElse(folder, value); + if (folder) { + folderNames.push(value); + angular.bind(ws, configureFolder, folder, value)(); + } + }); + var key = rootId + separator + folderNames.join(separator) + separator + lastPath; + var objectName = domainName + ":" + mbeanName; + if (folder) { + folder = this.folderGetOrElse(folder, lastPath); + if (folder) { + folder.entries = entries; + folder.key = key; + angular.bind(this, configureFolder, folder, lastPath)(); + folder.title = Core.trimQuotes(lastPath); + folder.objectName = objectName; + folder.mbean = domain[mbeanName]; + folder.typeName = typeName; + var addFolderByDomain = function (owner, typeName) { + var map = owner[typeName]; + if (!map) { + map = {}; + owner[typeName] = map; + } + var value = map[domainName]; + if (!value) { + map[domainName] = folder; + } + else { + var array = null; + if (angular.isArray(value)) { + array = value; + } + else { + array = [value]; + map[domainName] = array; + } + array.push(folder); + } + }; + if (serviceName) { + angular.bind(this, addFolderByDomain, this.mbeanServicesToDomain, serviceName)(); + } + if (typeName) { + angular.bind(this, addFolderByDomain, this.mbeanTypesToDomain, typeName)(); + } + } + } + else { + log.info("No folder found for lastPath: " + lastPath); + } + } + tree.sortChildren(true); + this.enableLazyLoading(tree); + this.tree = tree; + var processors = this.treePostProcessors; + angular.forEach(processors, function (processor) { return processor(tree); }); + this.maybeMonitorPlugins(); + var rootScope = this.$rootScope; + if (rootScope) { + rootScope.$broadcast('jmxTreeUpdated'); + } + } + }; + Workspace.prototype.enableLazyLoading = function (folder) { + var _this = this; + var children = folder.children; + if (children && children.length) { + angular.forEach(children, function (child) { + _this.enableLazyLoading(child); + }); + } + else { + var lazyFunction = Jmx.findLazyLoadingFunction(this, folder); + if (lazyFunction) { + folder.isLazy = true; + } + } + }; + Workspace.prototype.hash = function () { + var hash = this.$location.search(); + var params = Core.hashToString(hash); + if (params) { + return "?" + params; + } + return ""; + }; + Workspace.prototype.getActiveTab = function () { + var workspace = this; + return this.topLevelTabs.find(function (tab) { + if (!angular.isDefined(tab.isActive)) { + return workspace.isLinkActive(tab.href()); + } + else { + return tab.isActive(workspace); + } + }); + }; + Workspace.prototype.getStrippedPathName = function () { + var pathName = Core.trimLeading((this.$location.path() || '/'), "#"); + pathName = Core.trimLeading(pathName, "/"); + return pathName; + }; + Workspace.prototype.linkContains = function () { + var words = []; + for (var _i = 0; _i < arguments.length; _i++) { + words[_i - 0] = arguments[_i]; + } + var pathName = this.getStrippedPathName(); + return words.all(function (word) { + return pathName.has(word); + }); + }; + Workspace.prototype.isLinkActive = function (href) { + var pathName = this.getStrippedPathName(); + var link = Core.trimLeading(href, "#"); + link = Core.trimLeading(link, "/"); + var idx = link.indexOf('?'); + if (idx >= 0) { + link = link.substring(0, idx); + } + if (!pathName.length) { + return link === pathName; + } + else { + return pathName.startsWith(link); + } + }; + Workspace.prototype.isLinkPrefixActive = function (href) { + var pathName = this.getStrippedPathName(); + var link = Core.trimLeading(href, "#"); + link = Core.trimLeading(link, "/"); + var idx = link.indexOf('?'); + if (idx >= 0) { + link = link.substring(0, idx); + } + return pathName.startsWith(link); + }; + Workspace.prototype.isTopTabActive = function (path) { + var tab = this.$location.search()['tab']; + if (angular.isString(tab)) { + return tab.startsWith(path); + } + return this.isLinkActive(path); + }; + Workspace.prototype.getSelectedMBeanName = function () { + var selection = this.selection; + if (selection) { + return selection.objectName; + } + return null; + }; + Workspace.prototype.validSelection = function (uri) { + var workspace = this; + var filter = function (t) { + var fn = t.href; + if (fn) { + var href = fn(); + if (href) { + if (href.startsWith("#/")) { + href = href.substring(2); + } + return href === uri; + } + } + return false; + }; + var tab = this.subLevelTabs.find(filter); + if (!tab) { + tab = this.topLevelTabs.find(filter); + } + if (tab) { + var validFn = tab['isValid']; + return !angular.isDefined(validFn) || validFn(workspace); + } + else { + log.info("Could not find tab for " + uri); + return false; + } + }; + Workspace.prototype.removeAndSelectParentNode = function () { + var selection = this.selection; + if (selection) { + var parent = selection.parent; + if (parent) { + var idx = parent.children.indexOf(selection); + if (idx < 0) { + idx = parent.children.findIndex(function (n) { return n.key === selection.key; }); + } + if (idx >= 0) { + parent.children.splice(idx, 1); + } + this.updateSelectionNode(parent); + } + } + }; + Workspace.prototype.selectParentNode = function () { + var selection = this.selection; + if (selection) { + var parent = selection.parent; + if (parent) { + this.updateSelectionNode(parent); + } + } + }; + Workspace.prototype.selectionViewConfigKey = function () { + return this.selectionConfigKey("view/"); + }; + Workspace.prototype.selectionConfigKey = function (prefix) { + if (prefix === void 0) { prefix = ""; } + var key = null; + var selection = this.selection; + if (selection) { + key = prefix + selection.domain; + var typeName = selection.typeName; + if (!typeName) { + typeName = selection.title; + } + key += "/" + typeName; + if (selection.isFolder()) { + key += "/folder"; + } + } + return key; + }; + Workspace.prototype.moveIfViewInvalid = function () { + var workspace = this; + var uri = Core.trimLeading(this.$location.path(), "/"); + if (this.selection) { + var key = this.selectionViewConfigKey(); + if (this.validSelection(uri)) { + this.setLocalStorage(key, uri); + return false; + } + else { + log.info("the uri '" + uri + "' is not valid for this selection"); + var defaultPath = this.getLocalStorage(key); + if (!defaultPath || !this.validSelection(defaultPath)) { + defaultPath = null; + angular.forEach(this.subLevelTabs, function (tab) { + var fn = tab.isValid; + if (!defaultPath && tab.href && angular.isDefined(fn) && fn(workspace)) { + defaultPath = tab.href(); + } + }); + } + if (!defaultPath) { + defaultPath = "#/jmx/help"; + } + log.info("moving the URL to be " + defaultPath); + if (defaultPath.startsWith("#")) { + defaultPath = defaultPath.substring(1); + } + this.$location.path(defaultPath); + return true; + } + } + else { + return false; + } + }; + Workspace.prototype.updateSelectionNode = function (node) { + var originalSelection = this.selection; + this.selection = node; + var key = null; + if (node) { + key = node['key']; + } + var $location = this.$location; + var q = $location.search(); + if (key) { + q['nid'] = key; + } + $location.search(q); + if (originalSelection) { + key = this.selectionViewConfigKey(); + if (key) { + var defaultPath = this.getLocalStorage(key); + if (defaultPath) { + this.$location.path(defaultPath); + } + } + } + }; + Workspace.prototype.redrawTree = function () { + var treeElement = this.treeElement; + if (treeElement && angular.isDefined(treeElement.dynatree) && angular.isFunction(treeElement.dynatree)) { + var node = treeElement.dynatree("getTree"); + if (angular.isDefined(node)) { + try { + node.reload(); + } + catch (e) { + } + } + } + }; + Workspace.prototype.expandSelection = function (flag) { + var treeElement = this.treeElement; + if (treeElement && angular.isDefined(treeElement.dynatree) && angular.isFunction(treeElement.dynatree)) { + var node = treeElement.dynatree("getActiveNode"); + if (angular.isDefined(node)) { + node.expand(flag); + } + } + }; + Workspace.prototype.matchesProperties = function (entries, properties) { + if (!entries) + return false; + for (var key in properties) { + var value = properties[key]; + if (!value || entries[key] !== value) { + return false; + } + } + return true; + }; + Workspace.prototype.hasInvokeRightsForName = function (objectName) { + var methods = []; + for (var _i = 1; _i < arguments.length; _i++) { + methods[_i - 1] = arguments[_i]; + } + var canInvoke = true; + if (objectName) { + var mbean = Core.parseMBean(objectName); + if (mbean) { + var mbeanFolder = this.findMBeanWithProperties(mbean.domain, mbean.attributes); + if (mbeanFolder) { + return this.hasInvokeRights.apply(this, [mbeanFolder].concat(methods)); + } + else { + log.debug("Failed to find mbean folder with name " + objectName); + } + } + else { + log.debug("Failed to parse mbean name " + objectName); + } + } + return canInvoke; + }; + Workspace.prototype.hasInvokeRights = function (selection) { + var methods = []; + for (var _i = 1; _i < arguments.length; _i++) { + methods[_i - 1] = arguments[_i]; + } + var canInvoke = true; + if (selection) { + var selectionFolder = selection; + var mbean = selectionFolder.mbean; + if (mbean) { + if (angular.isDefined(mbean.canInvoke)) { + canInvoke = mbean.canInvoke; + } + if (canInvoke && methods && methods.length > 0) { + var opsByString = mbean['opByString']; + var ops = mbean['op']; + if (opsByString && ops) { + methods.forEach(function (method) { + if (!canInvoke) { + return; + } + var op = null; + if (method.endsWith(')')) { + op = opsByString[method]; + } + else { + op = ops[method]; + } + if (!op) { + log.debug("Could not find method:", method, " to check permissions, skipping"); + return; + } + if (angular.isDefined(op.canInvoke)) { + canInvoke = op.canInvoke; + } + }); + } + } + } + } + return canInvoke; + }; + Workspace.prototype.treeContainsDomainAndProperties = function (domainName, properties) { + var _this = this; + if (properties === void 0) { properties = null; } + var workspace = this; + var tree = workspace.tree; + if (tree) { + var folder = tree.get(domainName); + if (folder) { + if (properties) { + var children = folder.children || []; + var checkProperties = function (node) { + if (!_this.matchesProperties(node.entries, properties)) { + if (node.domain === domainName && node.children && node.children.length > 0) { + return node.children.some(checkProperties); + } + else { + return false; + } + } + else { + return true; + } + }; + return children.some(checkProperties); + } + return true; + } + else { + } + } + else { + } + return false; + }; + Workspace.prototype.matches = function (folder, properties, propertiesCount) { + if (folder) { + var entries = folder.entries; + if (properties) { + if (!entries) + return false; + for (var key in properties) { + var value = properties[key]; + if (!value || entries[key] !== value) { + return false; + } + } + } + if (propertiesCount) { + return entries && Object.keys(entries).length === propertiesCount; + } + return true; + } + return false; + }; + Workspace.prototype.hasDomainAndProperties = function (domainName, properties, propertiesCount) { + if (properties === void 0) { properties = null; } + if (propertiesCount === void 0) { propertiesCount = null; } + var node = this.selection; + if (node) { + return this.matches(node, properties, propertiesCount) && node.domain === domainName; + } + return false; + }; + Workspace.prototype.findMBeanWithProperties = function (domainName, properties, propertiesCount) { + if (properties === void 0) { properties = null; } + if (propertiesCount === void 0) { propertiesCount = null; } + var tree = this.tree; + if (tree) { + return this.findChildMBeanWithProperties(tree.get(domainName), properties, propertiesCount); + } + return null; + }; + Workspace.prototype.findChildMBeanWithProperties = function (folder, properties, propertiesCount) { + var _this = this; + if (properties === void 0) { properties = null; } + if (propertiesCount === void 0) { propertiesCount = null; } + var workspace = this; + if (folder) { + var children = folder.children; + if (children) { + var answer = children.find(function (node) { return _this.matches(node, properties, propertiesCount); }); + if (answer) { + return answer; + } + return children.map(function (node) { return workspace.findChildMBeanWithProperties(node, properties, propertiesCount); }).find(function (node) { return node; }); + } + } + return null; + }; + Workspace.prototype.selectionHasDomainAndLastFolderName = function (objectName, lastName) { + var lastNameLower = (lastName || "").toLowerCase(); + function isName(name) { + return (name || "").toLowerCase() === lastNameLower; + } + var node = this.selection; + if (node) { + if (objectName === node.domain) { + var folders = node.folderNames; + if (folders) { + var last = folders.last(); + return (isName(last) || isName(node.title)) && node.isFolder() && !node.objectName; + } + } + } + return false; + }; + Workspace.prototype.selectionHasDomain = function (domainName) { + var node = this.selection; + if (node) { + return domainName === node.domain; + } + return false; + }; + Workspace.prototype.selectionHasDomainAndType = function (objectName, typeName) { + var node = this.selection; + if (node) { + return objectName === node.domain && typeName === node.typeName; + } + return false; + }; + Workspace.prototype.hasMBeans = function () { + var answer = false; + var tree = this.tree; + if (tree) { + var children = tree.children; + if (angular.isArray(children) && children.length > 0) { + answer = true; + } + } + return answer; + }; + Workspace.prototype.hasFabricMBean = function () { + return this.hasDomainAndProperties('io.fabric8', { type: 'Fabric' }); + }; + Workspace.prototype.isFabricFolder = function () { + return this.hasDomainAndProperties('io.fabric8'); + }; + Workspace.prototype.isCamelContext = function () { + return this.hasDomainAndProperties('org.apache.camel', { type: 'context' }); + }; + Workspace.prototype.isCamelFolder = function () { + return this.hasDomainAndProperties('org.apache.camel'); + }; + Workspace.prototype.isEndpointsFolder = function () { + return this.selectionHasDomainAndLastFolderName('org.apache.camel', 'endpoints'); + }; + Workspace.prototype.isEndpoint = function () { + return this.hasDomainAndProperties('org.apache.camel', { type: 'endpoints' }); + }; + Workspace.prototype.isRoutesFolder = function () { + return this.selectionHasDomainAndLastFolderName('org.apache.camel', 'routes'); + }; + Workspace.prototype.isRoute = function () { + return this.hasDomainAndProperties('org.apache.camel', { type: 'routes' }); + }; + Workspace.prototype.isOsgiFolder = function () { + return this.hasDomainAndProperties('osgi.core'); + }; + Workspace.prototype.isKarafFolder = function () { + return this.hasDomainAndProperties('org.apache.karaf'); + }; + Workspace.prototype.isOsgiCompendiumFolder = function () { + return this.hasDomainAndProperties('osgi.compendium'); + }; + return Workspace; + })(); + Core.Workspace = Workspace; +})(Core || (Core = {})); +var Workspace = (function (_super) { + __extends(Workspace, _super); + function Workspace() { + _super.apply(this, arguments); + } + return Workspace; +})(Core.Workspace); +; +var UI; +(function (UI) { + UI.colors = ["#5484ED", "#A4BDFC", "#46D6DB", "#7AE7BF", "#51B749", "#FBD75B", "#FFB878", "#FF887C", "#DC2127", "#DBADFF", "#E1E1E1"]; +})(UI || (UI = {})); +var Core; +(function (Core) { + Core.log = Logger.get("Core"); + Core.lazyLoaders = {}; +})(Core || (Core = {})); +var numberTypeNames = { + 'byte': true, + 'short': true, + 'int': true, + 'long': true, + 'float': true, + 'double': true, + 'java.lang.byte': true, + 'java.lang.short': true, + 'java.lang.integer': true, + 'java.lang.long': true, + 'java.lang.float': true, + 'java.lang.double': true +}; +function lineCount(value) { + var rows = 0; + if (value) { + rows = 1; + value.toString().each(/\n/, function () { return rows++; }); + } + return rows; +} +function safeNull(value) { + if (typeof value === 'boolean') { + return value; + } + else if (typeof value === 'number') { + return value; + } + if (value) { + return value; + } + else { + return ""; + } +} +function safeNullAsString(value, type) { + if (typeof value === 'boolean') { + return "" + value; + } + else if (typeof value === 'number') { + return "" + value; + } + else if (typeof value === 'string') { + return "" + value; + } + else if (type === 'javax.management.openmbean.CompositeData' || type === '[Ljavax.management.openmbean.CompositeData;' || type === 'java.util.Map') { + var data = angular.toJson(value, true); + return data; + } + else if (type === 'javax.management.ObjectName') { + return "" + (value == null ? "" : value.canonicalName); + } + else if (type === 'javax.management.openmbean.TabularData') { + var arr = []; + for (var key in value) { + var val = value[key]; + var line = "" + key + "=" + val; + arr.push(line); + } + arr = arr.sortBy(function (row) { return row.toString(); }); + return arr.join("\n"); + } + else if (angular.isArray(value)) { + return value.join("\n"); + } + else if (value) { + return "" + value; + } + else { + return ""; + } +} +function toSearchArgumentArray(value) { + if (value) { + if (angular.isArray(value)) + return value; + if (angular.isString(value)) + return value.split(','); + } + return []; +} +function folderMatchesPatterns(node, patterns) { + if (node) { + var folderNames = node.folderNames; + if (folderNames) { + return patterns.any(function (ignorePaths) { + for (var i = 0; i < ignorePaths.length; i++) { + var folderName = folderNames[i]; + var ignorePath = ignorePaths[i]; + if (!folderName) + return false; + var idx = ignorePath.indexOf(folderName); + if (idx < 0) { + return false; + } + } + return true; + }); + } + } + return false; +} +function scopeStoreJolokiaHandle($scope, jolokia, jolokiaHandle) { + if (jolokiaHandle) { + $scope.$on('$destroy', function () { + closeHandle($scope, jolokia); + }); + $scope.jolokiaHandle = jolokiaHandle; + } +} +function closeHandle($scope, jolokia) { + var jolokiaHandle = $scope.jolokiaHandle; + if (jolokiaHandle) { + jolokia.unregister(jolokiaHandle); + $scope.jolokiaHandle = null; + } +} +function onSuccess(fn, options) { + if (options === void 0) { options = {}; } + options['mimeType'] = 'application/json'; + if (angular.isDefined(fn)) { + options['success'] = fn; + } + if (!options['method']) { + options['method'] = "POST"; + } + options['canonicalNaming'] = false; + options['canonicalProperties'] = false; + if (!options['error']) { + options['error'] = function (response) { + Core.defaultJolokiaErrorHandler(response, options); + }; + } + return options; +} +function supportsLocalStorage() { + try { + return 'localStorage' in window && window['localStorage'] !== null; + } + catch (e) { + return false; + } +} +function isNumberTypeName(typeName) { + if (typeName) { + var text = typeName.toString().toLowerCase(); + var flag = numberTypeNames[text]; + return flag; + } + return false; +} +function encodeMBeanPath(mbean) { + return mbean.replace(/\//g, '!/').replace(':', '/').escapeURL(); +} +function escapeMBeanPath(mbean) { + return mbean.replace(/\//g, '!/').replace(':', '/'); +} +function encodeMBean(mbean) { + return mbean.replace(/\//g, '!/').escapeURL(); +} +function escapeDots(text) { + return text.replace(/\./g, '-'); +} +function escapeTreeCssStyles(text) { + return escapeDots(text).replace(/span/g, 'sp-an'); +} +function showLogPanel() { + var log = $("#log-panel"); + var body = $('body'); + localStorage['showLog'] = 'true'; + log.css({ 'bottom': '50%' }); + body.css({ + 'overflow-y': 'hidden' + }); +} +function logLevelClass(level) { + if (level) { + var first = level[0]; + if (first === 'w' || first === "W") { + return "warning"; + } + else if (first === 'e' || first === "E") { + return "error"; + } + else if (first === 'i' || first === "I") { + return "info"; + } + else if (first === 'd' || first === "D") { + return ""; + } + } + return ""; +} +var Core; +(function (Core) { + function toPath(hashUrl) { + if (Core.isBlank(hashUrl)) { + return hashUrl; + } + if (hashUrl.startsWith("#")) { + return hashUrl.substring(1); + } + else { + return hashUrl; + } + } + Core.toPath = toPath; + function parseMBean(mbean) { + var answer = {}; + var parts = mbean.split(":"); + if (parts.length > 1) { + answer['domain'] = parts.first(); + parts = parts.exclude(parts.first()); + parts = parts.join(":"); + answer['attributes'] = {}; + var nameValues = parts.split(","); + nameValues.forEach(function (str) { + var nameValue = str.split('='); + var name = nameValue.first().trim(); + nameValue = nameValue.exclude(nameValue.first()); + answer['attributes'][name] = nameValue.join('=').trim(); + }); + } + return answer; + } + Core.parseMBean = parseMBean; + function executePostLoginTasks() { + Core.log.debug("Executing post login tasks"); + Core.postLoginTasks.execute(); + } + Core.executePostLoginTasks = executePostLoginTasks; + function executePreLogoutTasks(onComplete) { + Core.log.debug("Executing pre logout tasks"); + Core.preLogoutTasks.onComplete(onComplete); + Core.preLogoutTasks.execute(); + } + Core.executePreLogoutTasks = executePreLogoutTasks; + function logout(jolokiaUrl, userDetails, localStorage, $scope, successCB, errorCB) { + if (successCB === void 0) { successCB = null; } + if (errorCB === void 0) { errorCB = null; } + if (jolokiaUrl) { + var url = "auth/logout/"; + Core.executePreLogoutTasks(function () { + $.ajax(url, { + type: "POST", + success: function () { + userDetails.username = null; + userDetails.password = null; + userDetails.loginDetails = null; + userDetails.rememberMe = false; + delete localStorage['userDetails']; + var jvmConnect = angular.fromJson(localStorage['jvmConnect']); + _.each(jvmConnect, function (value) { + delete value['userName']; + delete value['password']; + }); + localStorage.setItem('jvmConnect', angular.toJson(jvmConnect)); + localStorage.removeItem('activemqUserName'); + localStorage.removeItem('activemqPassword'); + if (successCB && angular.isFunction(successCB)) { + successCB(); + } + Core.$apply($scope); + }, + error: function (xhr, textStatus, error) { + userDetails.username = null; + userDetails.password = null; + userDetails.loginDetails = null; + userDetails.rememberMe = false; + delete localStorage['userDetails']; + var jvmConnect = angular.fromJson(localStorage['jvmConnect']); + _.each(jvmConnect, function (value) { + delete value['userName']; + delete value['password']; + }); + localStorage.setItem('jvmConnect', angular.toJson(jvmConnect)); + localStorage.removeItem('activemqUserName'); + localStorage.removeItem('activemqPassword'); + switch (xhr.status) { + case 401: + Core.log.debug('Failed to log out, ', error); + break; + case 403: + Core.log.debug('Failed to log out, ', error); + break; + case 0: + break; + default: + Core.log.debug('Failed to log out, ', error); + break; + } + if (errorCB && angular.isFunction(errorCB)) { + errorCB(); + } + Core.$apply($scope); + } + }); + }); + } + } + Core.logout = logout; + function createHref($location, href, removeParams) { + if (removeParams === void 0) { removeParams = null; } + var hashMap = angular.copy($location.search()); + if (removeParams) { + angular.forEach(removeParams, function (param) { return delete hashMap[param]; }); + } + var hash = Core.hashToString(hashMap); + if (hash) { + var prefix = (href.indexOf("?") >= 0) ? "&" : "?"; + href += prefix + hash; + } + return href; + } + Core.createHref = createHref; + function hashToString(hash) { + var keyValuePairs = []; + angular.forEach(hash, function (value, key) { + keyValuePairs.push(key + "=" + value); + }); + var params = keyValuePairs.join("&"); + return encodeURI(params); + } + Core.hashToString = hashToString; + function stringToHash(hashAsString) { + var entries = {}; + if (hashAsString) { + var text = decodeURI(hashAsString); + var items = text.split('&'); + angular.forEach(items, function (item) { + var kv = item.split('='); + var key = kv[0]; + var value = kv[1] || key; + entries[key] = value; + }); + } + return entries; + } + Core.stringToHash = stringToHash; + function registerForChanges(jolokia, $scope, arguments, callback, options) { + var decorated = { + responseJson: '', + success: function (response) { + var json = angular.toJson(response.value); + if (decorated.responseJson !== json) { + decorated.responseJson = json; + callback(response); + } + } + }; + angular.extend(decorated, options); + return Core.register(jolokia, $scope, arguments, onSuccess(undefined, decorated)); + } + Core.registerForChanges = registerForChanges; + var responseHistory = null; + function getOrInitObjectFromLocalStorage(key) { + var answer = undefined; + if (!(key in localStorage)) { + localStorage[key] = angular.toJson({}); + } + return angular.fromJson(localStorage[key]); + } + Core.getOrInitObjectFromLocalStorage = getOrInitObjectFromLocalStorage; + function argumentsToString(arguments) { + return StringHelpers.toString(arguments); + } + function keyForArgument(argument) { + if (!('type' in argument)) { + return null; + } + var answer = argument['type']; + switch (answer.toLowerCase()) { + case 'exec': + answer += ':' + argument['mbean'] + ':' + argument['operation']; + var argString = argumentsToString(argument['arguments']); + if (!Core.isBlank(argString)) { + answer += ':' + argString; + } + break; + case 'read': + answer += ':' + argument['mbean'] + ':' + argument['attribute']; + break; + default: + return null; + } + return answer; + } + function createResponseKey(arguments) { + var answer = ''; + if (angular.isArray(arguments)) { + answer = arguments.map(function (arg) { + return keyForArgument(arg); + }).join(':'); + } + else { + answer = keyForArgument(arguments); + } + return answer; + } + function getResponseHistory() { + if (responseHistory === null) { + responseHistory = {}; + Core.log.debug("Created response history", responseHistory); + } + return responseHistory; + } + Core.getResponseHistory = getResponseHistory; + Core.MAX_RESPONSE_CACHE_SIZE = 20; + function getOldestKey(responseHistory) { + var oldest = null; + var oldestKey = null; + angular.forEach(responseHistory, function (value, key) { + if (!value || !value.timestamp) { + oldest = 0; + oldestKey = key; + } + else if (oldest === null || value.timestamp < oldest) { + oldest = value.timestamp; + oldestKey = key; + } + }); + return oldestKey; + } + function addResponse(arguments, value) { + var responseHistory = getResponseHistory(); + var key = createResponseKey(arguments); + if (key === null) { + Core.log.debug("key for arguments is null, not caching: ", StringHelpers.toString(arguments)); + return; + } + var keys = Object.extended(responseHistory).keys(); + if (keys.length >= Core.MAX_RESPONSE_CACHE_SIZE) { + Core.log.debug("Cache limit (", Core.MAX_RESPONSE_CACHE_SIZE, ") met or exceeded (", keys.length, "), trimming oldest response"); + var oldestKey = getOldestKey(responseHistory); + if (oldestKey !== null) { + Core.log.debug("Deleting key: ", oldestKey); + delete responseHistory[oldestKey]; + } + else { + Core.log.debug("Got null key, could be a cache problem, wiping cache"); + keys.forEach(function (key) { + Core.log.debug("Deleting key: ", key); + delete responseHistory[key]; + }); + } + } + responseHistory[key] = value; + } + function getResponse(jolokia, arguments, callback) { + var responseHistory = getResponseHistory(); + var key = createResponseKey(arguments); + if (key === null) { + jolokia.request(arguments, callback); + return; + } + if (key in responseHistory && 'success' in callback) { + var value = responseHistory[key]; + setTimeout(function () { + callback['success'](value); + }, 10); + } + else { + Core.log.debug("Unable to find existing response for key: ", key); + jolokia.request(arguments, callback); + } + } + function register(jolokia, scope, arguments, callback) { + if (!angular.isDefined(scope.$jhandle) || !angular.isArray(scope.$jhandle)) { + scope.$jhandle = []; + } + else { + } + if (angular.isDefined(scope.$on)) { + scope.$on('$destroy', function (event) { + unregister(jolokia, scope); + }); + } + var handle = null; + if ('success' in callback) { + var cb = callback.success; + var args = arguments; + callback.success = function (response) { + addResponse(args, response); + cb(response); + }; + } + if (angular.isArray(arguments)) { + if (arguments.length >= 1) { + var args = [callback]; + angular.forEach(arguments, function (value) { return args.push(value); }); + var registerFn = jolokia.register; + handle = registerFn.apply(jolokia, args); + scope.$jhandle.push(handle); + getResponse(jolokia, arguments, callback); + } + } + else { + handle = jolokia.register(callback, arguments); + scope.$jhandle.push(handle); + getResponse(jolokia, arguments, callback); + } + return function () { + if (handle !== null) { + scope.$jhandle.remove(handle); + jolokia.unregister(handle); + } + }; + } + Core.register = register; + function unregister(jolokia, scope) { + if (angular.isDefined(scope.$jhandle)) { + scope.$jhandle.forEach(function (handle) { + jolokia.unregister(handle); + }); + delete scope.$jhandle; + } + } + Core.unregister = unregister; + function defaultJolokiaErrorHandler(response, options) { + if (options === void 0) { options = {}; } + var stacktrace = response.stacktrace; + if (stacktrace) { + var silent = options['silent']; + if (!silent) { + var operation = Core.pathGet(response, ['request', 'operation']) || "unknown"; + if (stacktrace.indexOf("javax.management.InstanceNotFoundException") >= 0 || stacktrace.indexOf("javax.management.AttributeNotFoundException") >= 0 || stacktrace.indexOf("java.lang.IllegalArgumentException: No operation") >= 0) { + Core.log.debug("Operation ", operation, " failed due to: ", response['error']); + } + else { + Core.log.warn("Operation ", operation, " failed due to: ", response['error']); + } + } + else { + Core.log.debug("Operation ", operation, " failed due to: ", response['error']); + } + } + } + Core.defaultJolokiaErrorHandler = defaultJolokiaErrorHandler; + function logJolokiaStackTrace(response) { + var stacktrace = response.stacktrace; + if (stacktrace) { + var operation = Core.pathGet(response, ['request', 'operation']) || "unknown"; + Core.log.info("Operation ", operation, " failed due to: ", response['error']); + } + } + Core.logJolokiaStackTrace = logJolokiaStackTrace; + function xmlNodeToString(xmlNode) { + try { + return (new XMLSerializer()).serializeToString(xmlNode); + } + catch (e) { + try { + return xmlNode.xml; + } + catch (e) { + console.log('WARNING: XMLSerializer not supported'); + } + } + return false; + } + Core.xmlNodeToString = xmlNodeToString; + function isTextNode(node) { + return node && node.nodeType === 3; + } + Core.isTextNode = isTextNode; + function fileExtension(name, defaultValue) { + if (defaultValue === void 0) { defaultValue = ""; } + var extension = defaultValue; + if (name) { + var idx = name.lastIndexOf("."); + if (idx > 0) { + extension = name.substring(idx + 1, name.length).toLowerCase(); + } + } + return extension; + } + Core.fileExtension = fileExtension; + function getUUID() { + var d = new Date(); + var ms = (d.getTime() * 1000) + d.getUTCMilliseconds(); + var random = Math.floor((1 + Math.random()) * 0x10000); + return ms.toString(16) + random.toString(16); + } + Core.getUUID = getUUID; + var _versionRegex = /[^\d]*(\d+)\.(\d+)(\.(\d+))?.*/; + function parseVersionNumbers(text) { + if (text) { + var m = text.match(_versionRegex); + if (m && m.length > 4) { + var m1 = m[1]; + var m2 = m[2]; + var m4 = m[4]; + if (angular.isDefined(m4)) { + return [parseInt(m1), parseInt(m2), parseInt(m4)]; + } + else if (angular.isDefined(m2)) { + return [parseInt(m1), parseInt(m2)]; + } + else if (angular.isDefined(m1)) { + return [parseInt(m
<TRUNCATED> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
