/*############################################################################## # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## */ define([ "dojo/_base/declare", "dojo/_base/lang", "dojo/i18n", "dojo/i18n!./nls/common", "dojo/i18n!./nls/GraphWidget", "dojo/aspect", "dojo/has", "dojo/dom", "dojo/dom-construct", "dojo/dom-class", "dijit/layout/_LayoutWidget", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/text!../templates/GraphWidget.html", "dijit/Toolbar", "dijit/ToolbarSeparator", "dijit/form/Button" ], function (declare, lang, i18n, nlsCommon, nlsSpecific, aspect, has, dom, domConstruct, domClass, _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, ContentPane, template) { return declare("GraphWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], { templateString: template, baseClass: "GraphWidget", i18n: lang.mixin(nlsCommon, nlsSpecific), borderContainer: null, graphContentPane: null, _isPluginInstalled: false, _plugin: null, eventsRegistered: false, xgmml: "", dot: "", svg: "", isIE11: false, isIE: false, // Known control properties --- DOT_META_ATTR: "DOT_META_ATTR", constructor: function() { if (has("ie")) { this.isIE = true; } else if (has("trident")) { this.isIE11 = true; } }, _onClickRefresh: function () { this.setMessage(this.i18n.PerformingLayout); this.startLayout("dot"); }, _onClickZoomOrig: function (args) { this.setScale(100); this.centerOnItem(0); }, _onClickZoomAll: function (args) { this.centerOnItem(0, true); }, _onClickZoomWidth: function (args) { this.centerOnItem(0, true, true); }, onSelectionChanged: function (items) { }, onDoubleClick: function (globalID) { }, onLayoutFinished: function () { }, buildRendering: function (args) { this.inherited(arguments); }, postCreate: function (args) { this.inherited(arguments); this.borderContainer = dijit.byId(this.id + "BorderContainer"); this.graphContentPane = dijit.byId(this.id + "GraphContentPane"); }, startup: function (args) { this.inherited(arguments); this._isPluginInstalled = this.isPluginInstalled(); this.createPlugin(); this.watchStyleChange(); }, resize: function (args) { this.inherited(arguments); this.borderContainer.resize(); }, layout: function (args) { this.inherited(arguments); }, // Plugin wrapper --- showToolbar: function (show) { if (show) { domClass.remove(this.id + "Toolbar", "hidden"); } else { domClass.add(this.id + "Toolbar", "hidden"); } this.resize(); }, clear: function () { if (this._plugin) { this.xgmml = ""; this.svg = ""; this.dot = ""; this._plugin.clear(); } }, loadXGMML: function (xgmml, merge) { this.registerEvents(); if (this._plugin && this.xgmml != xgmml) { this.setMessage(this.i18n.LoadingData); if (merge) this._plugin.mergeXGMML(xgmml); else this._plugin.loadXGMML(xgmml); this.setMessage(this.i18n.PerformingLayout); this._plugin.startLayout("dot"); this.xgmml = xgmml; } }, mergeXGMML: function (xgmml) { this.registerEvents(); if (this._plugin && this.xgmml != xgmml) { this._plugin.mergeXGMML(xgmml); this.xgmml = xgmml; } }, loadDOT: function (dot) { this.registerEvents(); this.load(dot, "dot"); }, load: function (dot, layout) { this.registerEvents(); if (this._plugin && this.dot != dot) { this.setMessage(this.i18n.LoadingData); this._plugin.loadDOT(dot); this.setMessage(this.i18n.PerformingLayout); this._plugin.startLayout(layout); this.dot = dot; } }, setLayout: function (layout) { if (this._plugin) { this.setMessage(this.i18n.PerformingLayout); this._plugin.startLayout(layout); } }, centerOn: function (globalID) { if (this._plugin) { var item = this._plugin.getItem(globalID); this._plugin.centerOnItem(item, true); var items = [item]; this._plugin.setSelected(items, true); } }, getVersion: function () { this.registerEvents(); if (this._plugin) { return this._plugin.version; } return ""; }, getSVG: function () { return this._plugin.getSVG(); }, getXGMML: function () { return this.xgmml; }, localLayout: function(callback) { var context = this; require( ["hpcc/viz"], function (viz) { callback(Viz(context.dot, "svg")); } ); }, displayProperties: function (globalID, place) { if (this._plugin) { var item = this._plugin.getItem(globalID); var props = this._plugin.getProperties(item); if (props.id) { var table = domConstruct.create("h3", { innerHTML: props.id, align: "center" }, place); delete props.id; } if (props.count) { var table = domConstruct.create("table", { border: 1, cellspacing: 0, width: "100%" }, place); var tr = domConstruct.create("tr", null, table); var td = domConstruct.create("td", { innerHTML: this.i18n.Count }, tr); var td = domConstruct.create("td", { align: "right", innerHTML: props.count }, tr); delete props.count; domConstruct.create("br", null, place); } if (props.max) { var table = domConstruct.create("table", { border: 1, cellspacing: 0, width: "100%" }, place); var tr = domConstruct.create("tr", null, table); domConstruct.create("th", { innerHTML: " " }, tr); domConstruct.create("th", { innerHTML: this.i18n.Skew }, tr); domConstruct.create("th", { innerHTML: this.i18n.Node }, tr); domConstruct.create("th", { innerHTML: this.i18n.Rows }, tr); tr = domConstruct.create("tr", null, table); domConstruct.create("td", { innerHTML: this.i18n.Max }, tr); domConstruct.create("td", { innerHTML: props.maxskew }, tr); domConstruct.create("td", { innerHTML: props.maxEndpoint }, tr); domConstruct.create("td", { innerHTML: props.max }, tr); tr = domConstruct.create("tr", null, table); domConstruct.create("td", { innerHTML: this.i18n.Min }, tr); domConstruct.create("td", { innerHTML: props.minskew }, tr); domConstruct.create("td", { innerHTML: props.minEndpoint }, tr); domConstruct.create("td", { innerHTML: props.min }, tr); delete props.maxskew; delete props.maxEndpoint; delete props.max; delete props.minskew; delete props.minEndpoint; delete props.min; domConstruct.create("br", null, place); } if (props.slaves) { var table = domConstruct.create("table", { border: 1, cellspacing: 0, width: "100%" }, place); var tr = domConstruct.create("tr", null, table); domConstruct.create("th", { innerHTML: this.i18n.Slaves }, tr); domConstruct.create("th", { innerHTML: this.i18n.Started }, tr); domConstruct.create("th", { innerHTML: this.i18n.Stopped }, tr); tr = domConstruct.create("tr", null, table); domConstruct.create("td", { innerHTML: props.slaves }, tr); domConstruct.create("td", { innerHTML: props.started }, tr); domConstruct.create("td", { innerHTML: props.stopped }, tr); delete props.slaves; delete props.started; delete props.stopped; domConstruct.create("br", null, place); } var first = true; var table = {}; var tr = {}; for (var key in props) { if (key[0] == "_") continue; if (first) { first = false; table = domConstruct.create("table", { border: 1, cellspacing: 0, width: "100%" }, place); tr = domConstruct.create("tr", null, table); domConstruct.create("th", { innerHTML: this.i18n.Property }, tr); domConstruct.create("th", { innerHTML: this.i18n.Value }, tr); } tr = domConstruct.create("tr", null, table); domConstruct.create("td", { innerHTML: key }, tr); domConstruct.create("td", { innerHTML: props[key] }, tr); } if (first == false) { domConstruct.create("br", null, place); } } }, isPluginInstalled: function () { if (this.isIE || this.isIE11) { try { var o = new ActiveXObject("HPCCSystems.HPCCSystemsGraphViewControl.1"); o = null; return true; } catch (e) { } return false; } else { for (var i = 0, p = navigator.plugins, l = p.length; i < l; i++) { if (p[i].name.indexOf("HPCCSystemsGraphViewControl") > -1) { return true; } } return false; } }, createPlugin: function () { if (this._plugin == null) { if (this._isPluginInstalled) { var pluginID = this.id + "Plugin"; if (this.isIE || this.isIE11) { this.graphContentPane.domNode.innerHTML = ''; } else { this.graphContentPane.domNode.innerHTML = ''; } this._plugin = dom.byId(pluginID); var context = this; } else { domConstruct.create("div", { innerHTML: "
" + this.i18n.Toenablegraphviews + ":
" + this.getResourceLinks() }, this.graphContentPane.domNode); } } }, getResourceLinks: function () { return "" + this.i18n.BinaryInstalls + "