You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:52:50 UTC
[32/51] [abbrv] [partial] brooklyn-ui git commit: move subdir from
incubator up a level as it is promoted to its own repo (first non-incubator
commit!)
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/entity-sensors.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/entity-sensors.js b/brooklyn-ui/src/main/webapp/assets/js/view/entity-sensors.js
deleted file mode 100644
index 282c622..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/entity-sensors.js
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * 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.
-*/
-/**
- * Render entity sensors tab.
- *
- * @type {*}
- */
-define([
- "underscore", "jquery", "backbone", "brooklyn-utils", "zeroclipboard", "view/viewutils",
- "model/sensor-summary", "text!tpl/apps/sensors.html", "text!tpl/apps/sensor-name.html",
- "jquery-datatables", "datatables-extensions", "underscore", "jquery", "backbone", "uri",
-], function (_, $, Backbone, Util, ZeroClipboard, ViewUtils, SensorSummary, SensorsHtml, SensorNameHtml) {
-
- // TODO consider extracting all such usages to a shared ZeroClipboard wrapper?
- ZeroClipboard.config({ moviePath: '//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.3.1/ZeroClipboard.swf' });
-
- var sensorHtml = _.template(SensorsHtml),
- sensorNameHtml = _.template(SensorNameHtml);
-
- var EntitySensorsView = Backbone.View.extend({
- template: sensorHtml,
- sensorMetadata:{},
- refreshActive:true,
- zeroClipboard: null,
-
- events:{
- /* mouseup might technically be preferred, as moving out then releasing wouldn't
- * normally be expected to trigger the action; however this introduces complexity
- * as mouseup seems possibly to fire even if a widget has mouseoutted;
- * also i note many other places (including backbone examples) seem to use click
- * perhaps for this very reason. worth exploring, but as a low priority. */
- 'click .refresh': 'updateSensorsNow',
- 'click .filterEmpty':'toggleFilterEmpty',
- 'click .toggleAutoRefresh':'toggleAutoRefresh',
- 'click #sensors-table div.secret-info':'toggleSecrecyVisibility',
-
- 'mouseup .valueOpen':'valueOpen',
- 'mouseover #sensors-table tbody tr':'noteFloatMenuActive',
- 'mouseout #sensors-table tbody tr':'noteFloatMenuSeemsInactive',
- 'mouseover .floatGroup':'noteFloatMenuActive',
- 'mouseout .floatGroup':'noteFloatMenuSeemsInactive',
- 'mouseover .clipboard-item':'noteFloatMenuActiveCI',
- 'mouseout .clipboard-item':'noteFloatMenuSeemsInactiveCI',
- 'mouseover .hasFloatLeft':'showFloatLeft',
- 'mouseover .hasFloatDown':'enterFloatDown',
- 'mouseout .hasFloatDown':'exitFloatDown',
- 'mouseup .light-popup-menu-item':'closeFloatMenuNow'
-
- // these have no effect: you must register on the zeroclipboard object, below
- // (presumably the same for the .clipboard-item event listeners above, but unconfirmed)
-// 'mouseup .clipboard-item':'closeFloatMenuNow',
-// 'mouseup .global-zeroclipboard-container object':'closeFloatMenuNow',
- },
-
- initialize:function () {
- _.bindAll(this);
- this.$el.html(this.template());
-
- var $table = this.$('#sensors-table'),
- that = this;
- this.table = ViewUtils.myDataTable($table, {
- "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
- $(nRow).attr('id', aData[0]);
- $('td',nRow).each(function(i,v){
- if (i==1) $(v).attr('class','sensor-value');
- });
- return nRow;
- },
- "aoColumnDefs": [
- { // name (with tooltip)
- "mRender": function ( data, type, row ) {
- // name (column 1) should have tooltip title
- var actions = that.getSensorActions(data.name);
- // if data.description or .type is absent we get an error in html rendering (js)
- // unless we set it explicitly (there is probably a nicer way to do this however?)
- var context = _.extend(data, {
- description: data['description'], type: data['type']});
- return sensorNameHtml(context);
- },
- "aTargets": [ 1 ]
- },
- { // value
- "mRender": function ( data, type, row ) {
- var escapedValue = Util.toDisplayString(data);
- if (type!='display')
- return escapedValue;
-
- var hasEscapedValue = (escapedValue!=null && (""+escapedValue).length > 0);
- sensorName = row[0],
- actions = that.getSensorActions(sensorName);
-
- // NB: the row might not yet exist
- var $row = $('tr[id="'+sensorName+'"]');
-
- // datatables doesn't seem to expose any way to modify the html in place for a cell,
- // so we rebuild
-
- var result = "<span class='value'>"+(hasEscapedValue ? escapedValue : '')+"</span>";
-
- var isSecret = Util.isSecret(sensorName);
- if (isSecret) {
- result += "<span class='secret-indicator'>(hidden)</span>";
- }
-
- if (actions.open)
- result = "<a href='"+actions.open+"'>" + result + "</a>";
- if (escapedValue==null || escapedValue.length < 3)
- // include whitespace so we can click on it, if it's really small
- result += " ";
-
- var existing = $row.find('.dynamic-contents');
- // for the json url, use the full url (relative to window.location.href)
- var jsonUrl = actions.json ? new URI(actions.json).resolve(new URI(window.location.href)).toString() : null;
- // prefer to update in place, so menus don't disappear, also more efficient
- // (but if menu is changed, we do recreate it)
- if (existing.length>0) {
- if (that.checkFloatMenuUpToDate($row, actions.open, '.actions-open', 'open-target') &&
- that.checkFloatMenuUpToDate($row, escapedValue, '.actions-copy') &&
- that.checkFloatMenuUpToDate($row, actions.json, '.actions-json-open', 'open-target') &&
- that.checkFloatMenuUpToDate($row, jsonUrl, '.actions-json-copy', 'copy-value')) {
-// log("updating in place "+sensorName)
- existing.html(result);
- return $row.find('td.sensor-value').html();
- }
- }
-
- // build the menu - either because it is the first time, or the actions are stale
-// log("creating "+sensorName);
-
- var downMenu = "";
- if (actions.open)
- downMenu += "<div class='light-popup-menu-item valueOpen actions-open' open-target='"+actions.open+"'>" +
- "Open</div>";
- if (hasEscapedValue) downMenu +=
- "<div class='light-popup-menu-item handy valueCopy actions-copy clipboard-item'>Copy Value</div>";
- if (actions.json) downMenu +=
- "<div class='light-popup-menu-item handy valueOpen actions-json-open' open-target='"+actions.json+"'>" +
- "Open REST Link</div>";
- if (actions.json && hasEscapedValue) downMenu +=
- "<div class='light-popup-menu-item handy valueCopy actions-json-copy clipboard-item' copy-value='"+
- jsonUrl+"'>Copy REST Link</div>";
- if (downMenu=="") {
-// log("no actions for "+sensorName);
- downMenu +=
- "<div class='light-popup-menu-item'>(no actions)</div>";
- }
- downMenu = "<div class='floatDown'><div class='light-popup'><div class='light-popup-body'>"
- + downMenu +
- "</div></div></div>";
- result = "<span class='hasFloatLeft dynamic-contents'>" + result +
- "</span>" +
- "<div class='floatLeft'><span class='icon-chevron-down hasFloatDown'></span>" +
- downMenu +
- "</div>";
- result = "<div class='floatGroup"+
- (isSecret ? " secret-info" : "")+
- "'>" + result + "</div>";
- // also see updateFloatMenus which wires up the JS for these classes
-
- return result;
- },
- "aTargets": [ 2 ]
- },
- // ID in column 0 is standard (assumed in ViewUtils)
- { "bVisible": false, "aTargets": [ 0 ] }
- ]
- });
-
- this.zeroClipboard = new ZeroClipboard();
- this.zeroClipboard.on( "dataRequested" , function(client) {
- try {
- // the zeroClipboard instance is a singleton so check our scope first
- if (!$(this).closest("#sensors-table").length) return;
- var text = $(this).attr('copy-value');
- if (!text) text = $(this).closest('.floatGroup').find('.value').text();
-
-// log("Copying sensors text '"+text+"' to clipboard");
- client.setText(text);
-
- // show the word "copied" for feedback;
- // NB this occurs on mousedown, due to how flash plugin works
- // (same style of feedback and interaction as github)
- // the other "clicks" are now triggered by *mouseup*
- var $widget = $(this);
- var oldHtml = $widget.html();
- $widget.html('<b>Copied!</b>');
- // use a timeout to restore because mouseouts can leave corner cases (see history)
- setTimeout(function() { $widget.html(oldHtml); }, 600);
- } catch (e) {
- log("Zeroclipboard failure; falling back to prompt mechanism");
- log(e);
- Util.promptCopyToClipboard(text);
- }
- });
- // these seem to arrive delayed sometimes, so we also work with the clipboard-item class events
- this.zeroClipboard.on( "mouseover", function() { that.noteFloatMenuZeroClipboardItem(true, this); } );
- this.zeroClipboard.on( "mouseout", function() { that.noteFloatMenuZeroClipboardItem(false, this); } );
- this.zeroClipboard.on( "mouseup", function() { that.closeFloatMenuNow(); } );
-
- ViewUtils.addFilterEmptyButton(this.table);
- ViewUtils.addAutoRefreshButton(this.table);
- ViewUtils.addRefreshButton(this.table);
- this.loadSensorMetadata();
- this.updateSensorsPeriodically();
- this.toggleFilterEmpty();
- return this;
- },
-
- beforeClose: function () {
- if (this.zeroClipboard) {
- this.zeroClipboard.destroy();
- }
- },
-
- /* getting the float menu to pop-up and go away with all the right highlighting
- * is ridiculous. this is pretty good, but still not perfect. it seems some events
- * just don't fire, others occur out of order, and the root cause is that when
- * the SWF object (which has to accept the click, for copy to work) gets focus,
- * its ancestors *lose* focus - we have to suppress the event which makes the
- * float group disappear. i have left logging in, commented out, for more debugging.
- * there are notes that ZeroClipboard 2.0 will support hover properly.
- *
- * see git commit history and review comments in https://github.com/brooklyncentral/brooklyn/pull/1171
- * for more information.
- */
- floatMenuActive: false,
- lastFloatMenuRowId: null,
- lastFloatFocusInTextForEventUnmangling: null,
- updateFloatMenus: function() {
- $('#sensors-table *[rel="tooltip"]').tooltip();
- this.zeroClipboard.clip( $('.valueCopy') );
- },
- showFloatLeft: function(event) {
- this.noteFloatMenuFocusChange(true, event, "show-left");
- this.showFloatLeftOf($(event.currentTarget));
- },
- showFloatLeftOf: function($hasFloatLeft) {
- $hasFloatLeft.next('.floatLeft').show();
- },
- enterFloatDown: function(event) {
- this.noteFloatMenuFocusChange(true, event, "show-down");
-// log("entering float down");
- var fdTarget = $(event.currentTarget);
-// log( fdTarget );
- this.floatDownFocus = fdTarget;
- var that = this;
- setTimeout(function() {
- that.showFloatDownOf( fdTarget );
- }, 200);
- },
- exitFloatDown: function(event) {
-// log("exiting float down");
- this.floatDownFocus = null;
- },
- showFloatDownOf: function($hasFloatDown) {
- if ($hasFloatDown != this.floatDownFocus) {
-// log("float down did not hover long enough");
- return;
- }
- var down = $hasFloatDown.next('.floatDown');
- down.show();
- $('.light-popup', down).show(2000);
- },
- noteFloatMenuActive: function(focus) {
- this.noteFloatMenuFocusChange(true, focus, "menu");
-
- // remove dangling zc events (these don't always get removed, apparent bug in zc event framework)
- // this causes it to flash sometimes but that's better than leaving the old item highlighted
- if (focus.toElement && $(focus.toElement).hasClass('clipboard-item')) {
- // don't remove it
- } else {
- var zc = $(focus.target).closest('.floatGroup').find('div.zeroclipboard-is-hover');
- zc.removeClass('zeroclipboard-is-hover');
- }
- },
- noteFloatMenuSeemsInactive: function(focus) { this.noteFloatMenuFocusChange(false, focus, "menu"); },
- noteFloatMenuActiveCI: function(focus) { this.noteFloatMenuFocusChange(true, focus, "menu-clip-item"); },
- noteFloatMenuSeemsInactiveCI: function(focus) { this.noteFloatMenuFocusChange(false, focus, "menu-clip-item"); },
- noteFloatMenuZeroClipboardItem: function(seemsActive,focus) {
- this.noteFloatMenuFocusChange(seemsActive, focus, "clipboard");
- if (seemsActive) {
- // make the table row highlighted (as the default hover event is lost)
- // we remove it when the float group goes away
- $(focus).closest('tr').addClass('zeroclipboard-is-hover');
- } else {
- // sometimes does not get removed by framework - though this doesn't seem to help
- // as you can see by logging this before and after:
-// log(""+$(focus).attr('class'))
- // the problem is that the framework seems sometime to trigger this event before adding the class
- // see in noteFloatMenuActive where we do a different check
- $(focus).removeClass('zeroclipboard-is-hover');
- }
- },
- noteFloatMenuFocusChange: function(seemsActive, focus, caller) {
-// log(""+new Date().getTime()+" note active "+caller+" "+seemsActive);
- var delayCheckFloat = true;
- var focusRowId = null;
- var focusElement = null;
- if (focus) {
- focusElement = focus.target ? focus.target : focus;
- if (seemsActive) {
- this.lastFloatFocusInTextForEventUnmangling = $(focusElement).text();
- focusRowId = focus.target ? $(focus.target).closest('tr').attr('id') : $(focus).closest('tr').attr('id');
- if (this.floatMenuActive && focusRowId==this.lastFloatMenuRowId) {
- // lastFloatMenuRowId has not changed, when moving within a floatgroup
- // (but we still get mouseout events when the submenu changes)
-// log("redundant mousein from "+ focusRowId );
- return;
- }
- } else {
- // on mouseout, skip events which are bogus
- // first, if the toElement is in the same floatGroup
- focusRowId = focus.toElement ? $(focus.toElement).closest('tr').attr('id') : null;
- if (focusRowId==this.lastFloatMenuRowId) {
- // lastFloatMenuRowId has not changed, when moving within a floatgroup
- // (but we still get mouseout events when the submenu changes)
-// log("skipping, internal mouseout from "+ focusRowId );
- return;
- }
- // check (a) it is the 'out' event corresponding to the most recent 'in'
- // (because there is a race where it can say in1, in2, out1 rather than in1, out2, in2
- if ($(focusElement).text() != this.lastFloatFocusInTextForEventUnmangling) {
-// log("skipping, not most recent mouseout from "+ focusRowId );
- return;
- }
- if (focus.toElement) {
- if ($(focus.toElement).hasClass('global-zeroclipboard-container')) {
-// log("skipping out, as we are moving to clipboard container");
- return;
- }
- if (focus.toElement.name && focus.toElement.name=="global-zeroclipboard-flash-bridge") {
-// log("skipping out, as we are moving to clipboard movie");
- return;
- }
- }
- }
- }
-// log( "moving to "+focusRowId );
- if (seemsActive && focusRowId) {
-// log("setting lastFloat when "+this.floatMenuActive + ", from "+this.lastFloatMenuRowId );
- if (this.lastFloatMenuRowId != focusRowId) {
- if (this.lastFloatMenuRowId) {
- // the floating menu has changed, hide the old
-// log("hiding old menu on float-focus change");
- this.closeFloatMenuNow();
- }
- }
- // now show the new, if possible (might happen multiple times, but no matter
- if (focusElement) {
-// log("ensuring row "+focusRowId+" is showing on change");
- this.showFloatLeftOf($(focusElement).closest('tr').find('.hasFloatLeft'));
- this.lastFloatMenuRowId = focusRowId;
- } else {
- this.lastFloatMenuRowId = null;
- }
- }
- this.floatMenuActive = seemsActive;
- if (!seemsActive) {
- this.scheduleCheckFloatMenuNeedsHiding(delayCheckFloat);
- }
- },
- scheduleCheckFloatMenuNeedsHiding: function(delayCheckFloat) {
- if (delayCheckFloat) {
- this.checkTime = new Date().getTime()+299;
- setTimeout(this.checkFloatMenuNeedsHiding, 300);
- } else {
- this.checkTime = new Date().getTime()-1;
- this.checkFloatMenuNeedsHiding();
- }
- },
- closeFloatMenuNow: function() {
-// log("closing float menu due do direct call (eg click)");
- this.checkTime = new Date().getTime()-1;
- this.floatMenuActive = false;
- this.checkFloatMenuNeedsHiding();
- },
- checkFloatMenuNeedsHiding: function() {
-// log(""+new Date().getTime()+" checking float menu - "+this.floatMenuActive);
- if (new Date().getTime() <= this.checkTime) {
-// log("aborting check as another one scheduled");
- return;
- }
-
- // we use a flag to determine whether to hide the float menu
- // because the embedded zero-clipboard flash objects cause floatGroup
- // to get a mouseout event when the "Copy" menu item is hovered
- if (!this.floatMenuActive) {
-// log("HIDING FLOAT MENU")
- $('.floatLeft').hide();
- $('.floatDown').hide();
- $('.zeroclipboard-is-hover').removeClass('zeroclipboard-is-hover');
- lastFloatMenuRowId = null;
- } else {
-// log("we're still in")
- }
- },
- valueOpen: function(event) {
- window.open($(event.target).attr('open-target'),'_blank');
- },
-
- render: function() {
- return this;
- },
- checkFloatMenuUpToDate: function($row, actionValue, actionSelector, actionAttribute) {
- if (typeof actionValue === 'undefined' || actionValue==null || actionValue=="") {
- if ($row.find(actionSelector).length==0) return true;
- } else {
- if (actionAttribute) {
- if ($row.find(actionSelector).attr(actionAttribute)==actionValue) return true;
- } else {
- if ($row.find(actionSelector).length>0) return true;
- }
- }
- return false;
- },
-
- /**
- * Returns the actions loaded to view.sensorMetadata[name].actions
- * for the given name, or an empty object.
- */
- getSensorActions: function(sensorName) {
- var allMetadata = this.sensorMetadata || {};
- var metadata = allMetadata[sensorName] || {};
- return metadata.actions || {};
- },
-
- toggleFilterEmpty: function() {
- ViewUtils.toggleFilterEmpty(this.$('#sensors-table'), 2);
- return this;
- },
-
- toggleAutoRefresh: function() {
- ViewUtils.toggleAutoRefresh(this);
- return this;
- },
-
- enableAutoRefresh: function(isEnabled) {
- this.refreshActive = isEnabled;
- return this;
- },
-
- toggleSecrecyVisibility: function(event) {
- $(event.target).closest('.secret-info').toggleClass('secret-revealed');
- },
-
- /**
- * Loads current values for all sensors on an entity and updates sensors table.
- */
- isRefreshActive: function() { return this.refreshActive; },
- updateSensorsNow:function () {
- var that = this;
- ViewUtils.get(that, that.model.getSensorUpdateUrl(), that.updateWithData,
- { enablement: that.isRefreshActive });
- },
- updateSensorsPeriodically:function () {
- var that = this;
- ViewUtils.getRepeatedlyWithDelay(that, that.model.getSensorUpdateUrl(), function(data) { that.updateWithData(data); },
- { enablement: that.isRefreshActive });
- },
- updateWithData: function (data) {
- var that = this;
- $table = that.$('#sensors-table');
- var options = {};
- if (that.fullRedraw) {
- options.refreshAllRows = true;
- that.fullRedraw = false;
- }
- ViewUtils.updateMyDataTable($table, data, function(value, name) {
- var metadata = that.sensorMetadata[name];
- if (metadata==null) {
- // kick off reload metadata when this happens (new sensor for which no metadata known)
- // but only if we haven't loaded metadata for a while
- metadata = { 'name':name };
- that.sensorMetadata[name] = metadata;
- that.loadSensorMetadataIfStale(name, 10000);
- };
- return [name, metadata, value];
- }, options);
-
- that.updateFloatMenus();
- },
-
- /**
- * Loads all information about an entity's sensors. Populates view.sensorMetadata object
- * with a map of sensor names to description, actions and type (e.g. java.lang.Long).
- */
- loadSensorMetadata: function() {
- var url = this.model.getLinkByName('sensors'),
- that = this;
- that.lastSensorMetadataLoadTime = new Date().getTime();
- $.get(url, function (data) {
- _.each(data, function(sensor) {
- var actions = {};
- _.each(sensor.links, function(v, k) {
- if (k.slice(0, 7) == "action:") {
- actions[k.slice(7)] = v;
- }
- });
- that.sensorMetadata[sensor.name] = {
- name: sensor.name,
- description: sensor.description,
- actions: actions,
- type: sensor.type
- };
- });
- that.fullRedraw = true;
- that.updateSensorsNow();
- that.table.find('*[rel="tooltip"]').tooltip();
- });
- return this;
- },
-
- loadSensorMetadataIfStale: function(sensorName, recency) {
- var that = this;
- if (!that.lastSensorMetadataLoadTime || that.lastSensorMetadataLoadTime + recency < new Date().getTime()) {
-// log("reloading metadata because new sensor "+sensorName+" identified")
- that.loadSensorMetadata();
- }
- }
- });
-
- return EntitySensorsView;
-});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/entity-summary.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/entity-summary.js b/brooklyn-ui/src/main/webapp/assets/js/view/entity-summary.js
deleted file mode 100644
index 51a7c33..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/entity-summary.js
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * 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.
-*/
-/**
- * Render the application/entity summary tab.
- * @type {*}
- */
-define([
- "underscore", "jquery", "backbone", "brooklyn", "brooklyn-utils", "view/viewutils",
- "text!tpl/apps/summary.html", "view/entity-config",
-], function (_, $, Backbone, Brooklyn, Util, ViewUtils,
- SummaryHtml, EntityConfigView) {
-
- var EntitySummaryView = Backbone.View.extend({
- events:{
- 'click a.open-tab':'tabSelected'
- },
- template:_.template(SummaryHtml),
- initialize: function() {
- _.bindAll(this);
- var that = this;
- this.$el.html(this.template({
- entity:this.model,
- application:this.options.application,
- isApp: this.isApp()
- }));
- if (this.model.get('catalogItemId'))
- this.$("div.catalogItemId").show();
- else
- this.$("div.catalogItemId").hide();
-
- this.options.tabView.configView = new EntityConfigView({
- model:this.options.model,
- tabView:this.options.tabView,
- });
- this.$("div#advanced-config").html(this.options.tabView.configView.render().el);
-
- ViewUtils.attachToggler(this.$el);
-
- // TODO we should have a backbone object exported from the sensors view which we can listen to here
- // (currently we just take the URL from that view) - and do the same for active tasks;
- ViewUtils.getRepeatedlyWithDelay(this, this.model.getSensorUpdateUrl(),
- function(data) { that.updateWithData(data); });
- // however if we only use external objects we must either subscribe to their errors also
- // or do our own polling against the server, so we know when to disable ourselves
-// ViewUtils.fetchRepeatedlyWithDelay(this, this.model, { period: 10*1000 })
-
- this.loadSpec();
- },
- isApp: function() {
- var id = this.model.get('id');
- var selfLink = this.model.get('links').self;
- return selfLink.indexOf("/applications/" + id) != -1;
- },
- render:function () {
- return this;
- },
- revealIfHasValue: function(sensor, $div, renderer, values) {
- var that = this;
- if (!renderer) renderer = function(data) { return _.escape(data); }
-
- if (values) {
- var data = values[sensor]
- if (data || data===false) {
- $(".value", $div).html(renderer(data))
- $div.show()
- } else {
- $div.hide();
- }
- } else {
- // direct ajax call not used anymore - but left just in case
- $.ajax({
- url: that.model.getLinkByName("sensors")+"/"+sensor,
- contentType:"application/json",
- success:function (data) {
- if (data || data===false) {
- $(".value", $div).html(renderer(data))
- $div.show()
- } else {
- $div.hide();
- }
- that.updateStatusIcon();
- }})
- }
- },
- updateWithData: function (data) {
- this.revealIfHasValue("service.state", this.$(".status"), null, data)
- this.revealIfHasValue("service.isUp", this.$(".serviceUp"), null, data)
-
- var renderAsLink = function(data) { return "<a href='"+_.escape(data)+"'>"+_.escape(data)+"</a>" };
- this.revealIfHasValue("main.uri", this.$(".url"), renderAsLink, data)
-
- var status = this.updateStatusIcon();
-
- this.updateCachedProblemIndicator(data);
-
- if (status.problem) {
- this.updateAddlInfoForProblem();
- } else {
- this.$(".additional-info-on-problem").html("").hide()
- }
- },
- updateStatusIcon: function() {
- var statusIconInfo = ViewUtils.computeStatusIconInfo(this.$(".serviceUp .value").html(), this.$(".status .value").html());
- if (statusIconInfo.url) {
- this.$('#status-icon').html('<img src="'+statusIconInfo.url+'" '+
- 'style="max-width: 64px; max-height: 64px;"/>');
- } else {
- this.$('#status-icon').html('');
- }
- return statusIconInfo;
- },
- updateCachedProblemIndicator: function(data) {
- if (!data) return;
- this.problemIndicators = data['service.problems'];
- if (!this.problemIndicators || !_.size(this.problemIndicators))
- this.problemIndicators = data['service.notUp.indicators'];
- if (!this.problemIndicators || !_.size(this.problemIndicators))
- this.problemIndicators = null;
- },
- updateAddlInfoForProblem: function(tasksReloaded) {
- if (!this.options.tasks)
- // if tasks not supplied, then don't attempt to show status info!
- return;
-
- var problemDetails = "";
- var lastFailedTask = null, that = this;
- // ideally get the time the status changed, and return the last failure on or around that time
- // (or take it from some causal log)
- // but for now, we just return the most recent failed task
- this.options.tasks.each(function(it) {
- if (it.isError() && it.isLocalTopLevel()) {
- if (!lastFailedTask || it.attributes.endTimeUtc < lastFailedTask.attributes.endTimeUtc)
- lastFailedTask = it;
- }
- } );
-
- if (this.problemIndicators) {
- var indicatorText = _.values(this.problemIndicators);
- for (var error in indicatorText) {
- if (problemDetails) {
- problemDetails = problemDetails + "<br style='line-height: 24px;'>";
- }
- problemDetails = problemDetails + _.escape(indicatorText[error]);
- }
- }
- if (lastFailedTask) {
- var path = "activities/subtask/"+lastFailedTask.id;
- var base = this.model.getLinkByName("self");
- if (problemDetails)
- problemDetails = problemDetails + "<br style='line-height: 24px;'>";
- problemDetails = problemDetails + "<b>"+_.escape("Failure running task ")
- +"<a class='open-tab' tab-target='"+path+"'" +
- "href='#"+base+"/"+path+"'>" +
- "<i>"+_.escape(lastFailedTask.attributes.displayName)+"</i> "
- +"("+lastFailedTask.id+")</a>: </b>"+
- _.escape(lastFailedTask.attributes.result);
- }
- if (!that.problemTasksLoaded && this.options.tasks) {
- // trigger callback to get tasks
- if (!problemDetails)
- problemDetails = "<i>Loading problem details...</i>";
-
- ViewUtils.get(this, this.options.tasks.url, function() {
- that.problemTasksLoaded = true;
- that.updateAddlInfoForProblem();
- });
- }
-
- if (problemDetails) {
- this.$(".additional-info-on-problem").html(problemDetails).show();
- } else {
- var base = this.model.getLinkByName("self");
- this.$(".additional-info-on-problem").html(
- "The entity appears to have failed externally. " +
- "<br style='line-height: 24px;'>" +
- "No Brooklyn-managed task failures reported. " +
- "For more information, investigate " +
- "<a class='open-tab' tab-target='sensors' href='#"+base+"/sensors'>sensors</a> and " +
- "streams on recent " +
- "<a class='open-tab' tab-target='activities' href='#"+base+"/activities'>activity</a>, " +
- "as well as external systems and logs where necessary.").show();
- }
- },
- tabSelected: function(event) {
- if (event.metaKey || event.shiftKey)
- // trying to open in a new tab, do not act on it here!
- return;
- var tab = $(event.currentTarget).attr('tab-target');
- this.options.tabView.openTab(tab);
- // and prevent the a from firing
- event.preventDefault();
- return false;
- },
- loadSpec: function(flushCache) {
- if (!flushCache && this.spec) {
- this.renderSpec(this.spec);
- return;
- }
- ViewUtils.get(this, this.model.get('links').spec, this.renderSpec);
- },
- renderSpec: function(data) {
- if (!data) data=this.spec;
- if (!data) {
- this.$('#entity-spec-yaml-toggler').hide();
- } else {
- ViewUtils.updateTextareaWithData($("#entity-spec-yaml", this.$el), data, true, false, 150, 400);
- this.$('#entity-spec-yaml-toggler').show();
- }
- }
- });
-
- return EntitySummaryView;
-});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/googlemaps.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/googlemaps.js b/brooklyn-ui/src/main/webapp/assets/js/view/googlemaps.js
deleted file mode 100644
index fac3774..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/googlemaps.js
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * 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.
-*/
-//shim to access google maps with require.js -- courtesy https://github.com/p15martin/google-maps-hello-world/
-define(
- [ "async!https://maps.googleapis.com/maps/api/js?sensor=false" ],
- function() {
- var locationMarkers = {};
- // meters squared per entity
- var area_per_entity = 300000000000;
- var local = {
- addMapToCanvas: function( mapCanvas, lat, longitude, zoom ) {
- var myOptions = {
- center: new google.maps.LatLng( lat, longitude ),
- zoom: zoom,
- mapTypeId: google.maps.MapTypeId.SATELLITE
- };
-
- return new google.maps.Map(mapCanvas, myOptions);
- },
-
- // TODO info window; massive code tidy
- drawCircles: function(map, data) {
- var newLocs = {};
- var lm;
- _.each(data, function(it) {
- var id = it.id;
- if (it.latitude == null || it.longitude == null || (it.latitude == 0 && it.longitude == 0)) {
- // Suppress circle if not set or at (0,0); slightly clumsy, but workable
- } else if (lm = locationMarkers[id]) {
- // Update
- var latlng = new google.maps.LatLng(it.latitude, it.longitude);
-
- lm.circle.setRadius(local.radius(local.computeLocationArea(it.leafEntityCount)));
- lm.circle.setCenter(latlng);
- lm.marker.setPosition(latlng);
- lm.marker.setTitle(it.name);
-// lm.infoWindow.setPairs(l);
-
- newLocs[id] = lm;
- } else {
- // Add
- var circle = local.drawCircle(map, it.latitude, it.longitude, local.radius(local.computeLocationArea(it.leafEntityCount)));
-
- var marker = new google.maps.Marker({
- map: map,
- position: new google.maps.LatLng(it.latitude, it.longitude),
- title: it.name
- });
-
- // TODO from old grails app
-// var infoWindow = new Brooklyn.gmaps.ListInfoWindow(l, map, marker);
-
- circle.bindTo('center', marker, 'position');
- newLocs[id] = {circle: circle,
- marker: marker
-// ,
-// infoWindow: infoWindow
- };
- }
- })
-
- // TODO yuck, we assume location markers (static field) are tied to map (supplied)
- for (var marker in locationMarkers) {
- if (! newLocs[marker]) {
- // location has been removed
- lm = locationMarkers[marker];
- lm.circle.setMap(null);
- lm.marker.setMap(null);
- lm.infoWindow.getInfoWindow().setMap(null);
- }
- }
- locationMarkers = newLocs;
- },
- resetCircles: function() {
- locationMarkers = {};
- },
-
- drawCircle: function(map, lat, lng, radius) {
- var circle_latlong = new google.maps.LatLng(lat, lng);
- var circle_options = {
- map: map,
- center: circle_latlong,
- clickableboolean: false,
- fillColor: "#FF0000",
- fillOpacity: 0.4,
- radius: radius, // meters
- strokeColor: "#FF0000",
- strokeOpacity: 1,
- strokeWeight: 1,
- zIndex: 1
- };
-
- return new google.maps.Circle(circle_options);
- },
-
- /* Returns the area in square meters that a circle should be to represent
- * count entities at a location. */
- computeLocationArea: function(count) {
- return area_per_entity * count;
- },
-
- /* Returns the radius of a circle of the given area. */
- radius: function(area) {
- return Math.sqrt(area / Math.PI);
- }
-
-// function drawCirclesFromJSON(json) {
-// var newLocs = {};
-// var id;
-// var lm;
-//
-// for (id in json) {
-// var l = json[id];
-// if (l.lat == null || l.lng == null || (l.lat == 0 && l.lng == 0)) {
-// // Suppress circle if not set or at (0,0); slightly clumsy, but workable
-// } else if (lm = locationMarkers[id]) {
-// // Update
-// var latlng = new google.maps.LatLng(l.lat, l.lng);
-//
-// lm.circle.setRadius(radius(location_area(l.entity_count)));
-// lm.circle.setCenter(latlng);
-// lm.marker.setPosition(latlng);
-// lm.infoWindow.setPairs(l);
-//
-// newLocs[id] = lm;
-// } else {
-// // Add
-// var circle = drawCircle(l.lat, l.lng, radius(location_area(l.entity_count)));
-//
-// var marker = new google.maps.Marker({
-// map: map,
-// position: new google.maps.LatLng(l.lat, l.lng)
-// });
-//
-// var infoWindow = new Brooklyn.gmaps.ListInfoWindow(l, map, marker);
-//
-// circle.bindTo('center', marker, 'position');
-//
-// newLocs[id] = {circle: circle,
-// marker: marker,
-// infoWindow: infoWindow};
-// }
-// }
-//
-// for (id in locationMarkers) {
-// if (! newLocs[id]) {
-// // location has been removed
-// lm = locationMarkers[id];
-// lm.circle.setMap(null);
-// lm.marker.setMap(null);
-// lm.infoWindow.getInfoWindow().setMap(null);
-// }
-// }
-// locationMarkers = newLocs;
-// }
-
- }
-
- return local;
- }
-
-);
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/ha-summary.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/ha-summary.js b/brooklyn-ui/src/main/webapp/assets/js/view/ha-summary.js
deleted file mode 100644
index 250977e..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/ha-summary.js
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-*/
-define([
- "jquery", "underscore", "backbone", "moment", "view/viewutils",
- "model/server-extended-status",
- "text!tpl/home/ha-summary.html"
-], function ($, _, Backbone, moment, ViewUtils, serverStatus, HASummaryHtml) {
-
- var template = _.template(HASummaryHtml);
- var nodeRowTemplate = _.template(
- "<tr>" +
- "<td>" +
- "<% if (nodeUri && !isTerminated) { %><a href='<%= nodeUri %>'><%= nodeId %></a><% } else { %><%= nodeId %><% } %>" +
- "<% if (isSelf) { %><span class='pull-right badge badge-success'>this</span><% } %>" +
- "</td>" +
- "<td><% if (isPretendMaster) {%>EX-MASTER<%} else {%><%= status %><%} if (isStale) { %> (stale)<% } %></td>" +
- "<td><%= timestampDisplayPrefix %><span class='timestamp' data-timestamp='<%= timestamp %>'><%= timestampDisplay %><span><%= timestampDisplaySuffix %></td>" +
- "</tr>");
- var noServers = "<tr><td colspan='3'><i>Failed to load data of servers</i></td></tr>";
- var waitingServers = "<tr><td colspan='3'><i>Waiting on detail for servers...</i></td></tr>";
-
- var HASummaryView = Backbone.View.extend({
- initialize: function() {
- _.bindAll(this);
- this.updateTimestampCallback = setInterval(this.updateTimestamps, 1000);
- this.listenTo(serverStatus, "change", this.renderNodeStatus);
- },
- beforeClose: function() {
- clearInterval(this.updateTimestampCallback);
- this.stopListening();
- },
- updateNow: function() {
- serverStatus.fetch();
- },
- render: function() {
- this.$el.html(template());
- this.renderNodeStatus();
- return this;
- },
- renderNodeStatus: function() {
- var $target = this.$(".ha-summary-table-body");
- if (!serverStatus.loaded) {
- $target.html(waitingServers);
- return;
- }
-
- var serverHa = serverStatus.get("ha") || {};
- var master = serverHa.masterId,
- self = serverHa.ownId,
- nodes = serverHa.nodes;
-
- // undefined check just in case server returns something odd
- if (nodes == undefined || _.isEmpty(nodes)) {
- $target.html(noServers);
- return;
- }
-
- $target.empty();
- var masterTimestamp;
- _.each(nodes, function (n) {
- if (n.nodeId == master && n.remoteTimestamp) {
- masterTimestamp = n.remoteTimestamp;
- }
- });
-
- _.each(nodes, function (n) {
- var node = _.clone(n);
- node.timestampDisplayPrefix = "";
- node.timestampDisplaySuffix = "";
- if (node['remoteTimestamp']) {
- node.timestamp = node.remoteTimestamp;
- } else {
- node.timestamp = node.localTimestamp;
- node.timestampDisplaySuffix = " (local)";
- }
- if (node.timestamp >= moment().utc() + 10*1000) {
- // if server reports time significantly in future, report this, with no timestampe
- node.timestampDisplayPrefix = "server clock in future by "+
- moment.duration(moment(node.timestamp).diff(moment())).humanize();
- node.timestamp = "";
- node.timestampDisplay = "";
- } else {
- // else use timestamp
- if (node.timestamp >= moment().utc()) {
- // but if just a little bit in future, backdate to show "a few seconds ago"
- node.timestamp = moment().utc()-1;
- }
- node.timestampDisplay = moment(node.timestamp).fromNow();
- }
-
- node.isSelf = node.nodeId == self;
- node.isMaster = self == master;
- if (node.status == "TERMINATED") {
- node.isTerminated = true;
- node.isPretendMaster = false;
- node.isStale = false;
- } else {
- node.isTerminated = false;
- node.isPretendMaster = (!node.isMaster && node.status == "MASTER" && master != node.nodeId);
- node.isStale = (masterTimestamp && node.timestamp + 30*1000 < masterTimestamp);
- }
-
- $target.append(nodeRowTemplate(node));
- });
- },
- updateTimestamps: function() {
- this.$(".timestamp").each(function(index, t) {
- t = $(t);
- var timestamp = t.data("timestamp");
- t.html(moment(timestamp).fromNow());
- });
- }
- });
-
- return HASummaryView;
-});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/home.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/home.js b/brooklyn-ui/src/main/webapp/assets/js/view/home.js
deleted file mode 100644
index ae2ba3a..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/home.js
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * 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.
-*/
-/**
- * Renders the Applications page. From it we create all other application related views.
- */
-
-define([
- "jquery", "underscore", "backbone",
- "view/viewutils",
- "view/application-add-wizard",
- "view/ha-summary",
- "model/location",
- "text!tpl/home/applications.html",
- "text!tpl/home/summaries.html",
- "text!tpl/home/app-entry.html",
- "bootstrap", "brooklyn-utils"
-], function ($, _, Backbone, ViewUtils,
- AppAddWizard, HASummary, Location,
- ApplicationsHtml, HomeSummariesHtml, AppEntryHtml) {
-
- var HomeView = Backbone.View.extend({
- tagName:"div",
- events:{
- 'click #add-new-application':'createApplication',
- 'click #reload-brooklyn-properties': 'reloadBrooklynProperties',
- 'click #clear-ha-node-records': 'clearHaNodeRecords',
- 'click .addApplication':'createApplication'
- },
-
- initialize:function () {
- var that = this
- this.$el.html(_.template(ApplicationsHtml, {} ))
- $(".nav1").removeClass("active");
- $(".nav1_home").addClass("active");
- this._appViews = {}
- this.summariesView = new HomeView.HomeSummariesView({
- applications:this.collection,
- locations:this.options.locations
- })
- this.collection.on('reset', this.render, this)
- this.options.locations.on('reset', this.renderSummaries, this)
-
- ViewUtils.fetchRepeatedlyWithDelay(this, this.collection,
- { fetchOptions: { reset: true }, doitnow: true,
- /* max is short here so the console becomes usable quickly */
- backoffMaxPeriod: 10*1000 });
- ViewUtils.fetchRepeatedlyWithDelay(this, this.options.locations, { fetchOptions: { reset: true }, doitnow: true });
-
- var id = $(this.$el).find("#circles-map");
- if (this.options.offline) {
- id.find("#circles-map-message").html("(map off in offline mode)");
- } else {
- requirejs(["googlemaps"], function (GoogleMaps) {
- _.defer( function() {
- log("loading google maps")
- var map = GoogleMaps.addMapToCanvas(id[0], 0, 0, 1);
- var locatedLocations = new Location.UsageLocated()
- // googlemaps.js isn't re-loaded during tab-to-tab navigation so we need to reset it each time
- // the maps is re-drawn to reset the cached set of location markers
- GoogleMaps.resetCircles()
- that.updateCircles(that, locatedLocations, GoogleMaps, map)
- that.callPeriodically("circles", function() {
- that.updateCircles(that, locatedLocations, GoogleMaps, map)
- }, 10000)
- })
- }, function (error) {
- id.find("#circles-map-message").html("(map not available)");
- });
- }
- },
-
- updateCircles: function(that, locatedLocations, GoogleMaps, map) {
- locatedLocations.fetch({success:function() {
- GoogleMaps.drawCircles(map, locatedLocations.attributes)
- }})
- },
-
- // cleaning code goes here
- beforeClose:function () {
- this.haSummaryView.close();
- this.collection.off("reset", this.render)
- this.options.locations.off("reset", this.renderSummaries)
- _.invoke(this._appViews, "close");
- this._appViews = null
- },
-
- render:function () {
- this.renderSummaries();
- this.renderCollection();
- this.renderHighAvailabilitySummary();
- return this;
- },
-
- renderSummaries:function () {
- this.$('.home-summaries-row').html(this.summariesView.render().el )
- },
-
- renderHighAvailabilitySummary: function() {
- // The HA view handles updates itself.
- if (!this.haSummaryView)
- this.haSummaryView = new HASummary({ el: this.$("#ha-summary") }).render();
- },
-
- renderCollection:function () {
- var $tableBody = this.$('#applications-table-body').empty()
- if (this.collection==null)
- $tableBody.append("<tr><td colspan='3'><i>No data available</i></td></tr>");
- else if (this.collection.isEmpty())
- $tableBody.append("<tr><td colspan='3'><i>No applications deployed</i></td></tr>");
- else this.collection.each(function (app) {
- var appView = new HomeView.AppEntryView({model:app})
- if (this._appViews[app.cid]) {
- // if the application has a view destroy it
- this._appViews[app.cid].close()
- }
- this._appViews[app.cid] = appView
- $tableBody.append(appView.render().el)
- }, this)
- },
-
- createApplication:function () {
- if (this._modal) {
- this._modal.close()
- }
- var that = this;
- if (this.options.offline || (this.options.cautionOverlay && this.options.cautionOverlay.warningActive)) {
- // don't show wizard
- } else {
- var wizard = new AppAddWizard({appRouter:this.options.appRouter})
- this._modal = wizard
- this.$(".add-app #modal-container").html(wizard.render().el)
- this.$(".add-app #modal-container .modal")
- .on("hidden",function () {
- wizard.close()
- that.collection.fetch({reset:true});
- }).modal('show')
- }
- },
-
- reloadBrooklynProperties: function() {
- var self = this;
- // indicate submitted
- self.$('#reload-brooklyn-properties-indicator').show();
- $.ajax({
- type: "POST",
- url: "/v1/server/properties/reload",
- contentType: "application/json",
- success: function() {
- console.log("reloaded brooklyn properties");
- self.options.locations.fetch();
- // clear submitted indicator
- setTimeout(function() { self.$('#reload-brooklyn-properties-indicator').hide(); }, 250);
- },
- error: function(data) {
- // TODO render the error better than poor-man's flashing
- // (would just be connection error -- with timeout=0 we get a task even for invalid input)
- self.$el.fadeTo(100,1).delay(200).fadeTo(200,0.2).delay(200).fadeTo(200,1);
- self.$('#reload-brooklyn-properties-indicator').hide();
- console.error("ERROR reloading brooklyn properties");
- console.debug(data);
- }
- });
- },
-
- clearHaNodeRecords: function() {
- var self = this;
- // indicate submitted
- self.$('#clear-ha-node-records-indicator').show();
- $.ajax({
- type: "POST",
- url: "/v1/server/ha/states/clear",
- contentType: "application/json",
- success: function() {
- console.log("cleared HA node records");
- self.haSummaryView.updateNow();
- // clear submitted indicator
- setTimeout(function() { self.$('#clear-ha-node-records-indicator').hide(); }, 250);
- },
- error: function(data) {
- // TODO render the error better than poor-man's flashing
- // (would just be connection error -- with timeout=0 we get a task even for invalid input)
- self.$el.fadeTo(100,1).delay(200).fadeTo(200,0.2).delay(200).fadeTo(200,1);
- self.$('#clear-ha-node-records-indicator').hide();
- console.error("ERROR clearing HA nodes");
- console.debug(data);
- }
- });
- }
- })
-
- HomeView.HomeSummariesView = Backbone.View.extend({
- tagName:'div',
- template:_.template(HomeSummariesHtml),
- // no listening needed here; it's done by outer class
- render:function () {
- this.$el.html(this.template({
- apps:this.options.applications,
- locations:this.options.locations
- }))
- return this
- },
- })
-
- HomeView.AppEntryView = Backbone.View.extend({
- tagName:'tr',
-
- template:_.template(AppEntryHtml),
-
- initialize:function () {
- this.model.on('change', this.render, this)
- this.model.on('destroy', this.close, this)
- },
- render:function () {
- this.$el.html(this.template({
- cid:this.model.cid,
- link:this.model.getLinkByName("self"),
- name:this.model.getSpec().get("name"),
- status:this.model.get("status")
- }))
- return this
- },
- beforeClose:function () {
- this.off("change", this.render)
- this.off("destroy", this.close)
- }
- })
-
- return HomeView
-})
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/policy-config-invoke.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/policy-config-invoke.js b/brooklyn-ui/src/main/webapp/assets/js/view/policy-config-invoke.js
deleted file mode 100644
index 36b5d9f..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/policy-config-invoke.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.
-*/
-/**
- * Render a policy configuration key as a modal for reconfiguring.
- */
-define([
- "underscore", "jquery", "backbone",
- "text!tpl/apps/policy-parameter-config.html",
- "bootstrap"
-], function (_, $, Backbone, PolicyParameterConfigHtml) {
-
- var PolicyConfigInvokeView = Backbone.View.extend({
- template: _.template(PolicyParameterConfigHtml),
-
- initialize: function () {
- _.bindAll(this);
- },
-
- render: function () {
- this.$el.html(this.template({
- name: this.model.get("name"),
- description: this.model.get("description"),
- type: this.model.get("type"),
- value: this.options.currentValue || "",
- policyName: this.options.policy.get("name")
- }));
- return this;
- },
-
- onSubmit: function () {
- var that = this,
- url = that.model.getLinkByName("self"),
- val = that.$("#policy-config-value").val();
- try {
- JSON.parse(val);
- } catch (e) {
- // ignore error, it's just unparseable, so put it in a string
- val = JSON.stringify(val);
- }
- return $.ajax({
- type: "POST",
- url: url,
- contentType:"application/json",
- data: val
- }).fail(function(response) {
- var message = JSON.parse(response.responseText).message;
- that.showError(message);
- });
- },
-
- showError: function (message) {
- this.$(".policy-add-error-container").removeClass("hide");
- this.$(".policy-add-error-message").html(message);
- },
-
- title: function () {
- return "Reconfigure " + this.options.policy.get("name");
- }
- });
- return PolicyConfigInvokeView;
-});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/policy-new.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/policy-new.js b/brooklyn-ui/src/main/webapp/assets/js/view/policy-new.js
deleted file mode 100644
index c190f78..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/policy-new.js
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.
-*/
-/**
- * Render a policy configuration key as a modal for reconfiguring.
- */
-define([
- "jquery", "underscore", "backbone", "brooklyn",
- "text!tpl/apps/policy-new.html"
-], function ($, _, Backbone, Brooklyn, NewPolicyHtml) {
-
- return Backbone.View.extend({
- template: _.template(NewPolicyHtml),
-
- initialize: function () {
- if (!this.options.entity) {
- throw new Error("NewPolicy view requires entity to know where to post result");
- }
- this.title = "Attach New Policy to "+this.options.entity.get('name');
- },
-
- render: function() {
- this.$el.html(this.template);
- this.configKeyView = new Brooklyn.view.ConfigKeyInputPairList();
- this.$(".policy-add-config-keys").html(this.configKeyView.render().$el);
- return this;
- },
-
- beforeClose: function() {
- if (this.configKeyView) {
- this.configKeyView.close();
- }
- },
-
- onSubmit: function (event) {
- var type = this.$("#policy-add-type").val();
- var config = this.configKeyView.getConfigKeys();
- console.log("type", type, "config", config);
- // Required because request isn't handled correctly if the map is empty.
- // See comments on PolicyApi.addPolicy for details.
- if (_.isEmpty(config)) {
- config["___d_dummy"] = "dummyval";
- }
- var url = this.options.entity.get("links").policies + "/?type=" + type;
- var self = this;
- var ajax = $.ajax({
- url: url,
- type: "post",
- data: JSON.stringify(config),
- contentType: "application/json"
- }).fail(function (response) {
- var message = JSON.parse(response.responseText).message;
- self.showError(message);
- });
- if (_.isFunction(this.options.onSave)) {
- ajax.done(this.options.onSave);
- }
- return ajax;
- },
-
- showError: function (message) {
- this.$(".policy-add-error-container").removeClass("hide");
- this.$(".policy-add-error-message").html(message);
- }
- });
-
-});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/18b073a9/brooklyn-ui/src/main/webapp/assets/js/view/script-groovy.js
----------------------------------------------------------------------
diff --git a/brooklyn-ui/src/main/webapp/assets/js/view/script-groovy.js b/brooklyn-ui/src/main/webapp/assets/js/view/script-groovy.js
deleted file mode 100644
index 045e4f1..0000000
--- a/brooklyn-ui/src/main/webapp/assets/js/view/script-groovy.js
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-*/
-define([
- "underscore", "jquery", "backbone",
- "view/viewutils",
- "text!tpl/script/groovy.html",
-
- "jquery-slideto",
- "jquery-wiggle",
- "jquery-ba-bbq",
- "handlebars",
- "bootstrap"
-], function (_, $, Backbone, ViewUtils, GroovyHtml) {
-
- var ScriptGroovyView = Backbone.View.extend({
- tagName:"div",
- events:{
- "click #groovy-ui-container #submit":"submitScript",
- "click #load-example":"loadExample"
- },
- className:"container container-fluid",
- groovyTemplate:_.template(GroovyHtml),
-
- initialize:function () {
- this.reset();
- },
- reset: function() {
- this.$el.html(_.template(GroovyHtml, {}))
- $(".output", this.$el).hide()
- $(".output .toggler-region", this.$el).hide()
- ViewUtils.attachToggler(this.$el)
- },
- render:function (eventName) {
- return this
- },
- loadExample: function() {
- $(".input textarea").val(
- 'import static org.apache.brooklyn.entity.software.base.Entities.*\n'+
- '\n'+
- 'println "Last result: "+last\n'+
- 'data.exampleRunCount = (data.exampleRunCount ?: 0) + 1\n'+
- 'println "Example run count: ${data.exampleRunCount}"\n'+
- '\n'+
- 'println "Application count: ${mgmt.applications.size()}\\n"\n'+
- '\n'+
- 'mgmt.applications.each { dumpInfo(it) }\n'+
- '\n'+
- 'return mgmt.applications\n')
- },
- updateTextareaWithData: function($div, data, alwaysShow) {
- ViewUtils.updateTextareaWithData($div, data, alwaysShow, 50, 350)
- },
- submitScript: function() {
- var that = this;
- var script = $("#groovy-ui-container #script").val()
- $(".output .toggler-region", this.$el).hide()
- $(".output .throbber", this.$el).show()
- $(".output", this.$el).show()
- that.updateTextareaWithData($(".output .result"), undefined, false, false);
- that.updateTextareaWithData($(".output .error"), undefined, false, false);
- that.updateTextareaWithData($(".output .stdout"), undefined, false, false);
- that.updateTextareaWithData($(".output .stderr"), undefined, false, false);
- $.ajax({
- type:"POST",
- url:"/v1/script/groovy",
- data:script,
- contentType:"application/text",
- headers: { "Brooklyn-Allow-Non-Master-Access": true },
- success:function (data) {
- $(".output .throbber", that.$el).hide()
- that.updateTextareaWithData($(".output .result"), data.result, true, true);
- that.updateTextareaWithData($(".output .error"), data.problem, false, true);
- that.updateTextareaWithData($(".output .stdout"), data.stdout, false, true);
- that.updateTextareaWithData($(".output .stderr"), data.stderr, false, true);
- },
- error: function(data) {
- $(".output .throbber", that.$el).hide()
- $("#groovy-ui-container div.error").val("ERROR: "+data)
- $(".output .error").show()
-
- console.error("ERROR submitting groovy script")
- console.debug(data)
- }})
- }
-
- })
-
- return ScriptGroovyView
-})