|
@@ -0,0 +1,311 @@
|
|
|
+/**
|
|
|
+ * 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.
|
|
|
+ */
|
|
|
+
|
|
|
+var App = require('app');
|
|
|
+
|
|
|
+App.DashboardWidgetView = Em.View.extend({
|
|
|
+
|
|
|
+ title: null,
|
|
|
+
|
|
|
+ model : function () {
|
|
|
+ if (this.get('model_type') == 'hdfs') {
|
|
|
+ return this.get('parentView').get('hdfs_model');
|
|
|
+ } else if (this.get('model_type') == 'mapreduce') {
|
|
|
+ return this.get('parentView').get('mapreduce_model');
|
|
|
+ } else if (this.get('model_type') == 'hbase') {
|
|
|
+ return this.get('parentView').get('hbase_model');
|
|
|
+ }
|
|
|
+ }.property(''), //data bind from parent view
|
|
|
+
|
|
|
+ id: null, // id 1-10 used to identify
|
|
|
+ viewID: function(){ // used by re-sort
|
|
|
+ return 'widget-' + this.id;
|
|
|
+ }.property('id'), //html id bind to view-class: widget-(1-10)
|
|
|
+ attributeBindings: ['viewID'],
|
|
|
+
|
|
|
+ isPieChart: false,
|
|
|
+ isText: false,
|
|
|
+ isProgressBar: false,
|
|
|
+ isLinks: false,
|
|
|
+ content: null, // widget content pieChart/ text/ progress bar. etc
|
|
|
+ hiddenInfo: null, // more info details
|
|
|
+
|
|
|
+ thresh1: null, //num not string
|
|
|
+ thresh2: null,
|
|
|
+
|
|
|
+ didInsertElement: function () {
|
|
|
+ this.$("[rel='ZoomInTooltip']").tooltip({
|
|
|
+ placement : 'left'
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ template: Ember.Handlebars.compile([
|
|
|
+
|
|
|
+ '{{#if view.isPieChart}}',
|
|
|
+ '<div class="has-hidden-info">',
|
|
|
+ '<li class="thumbnail row">',
|
|
|
+ '<a class="corner-icon" href="#" {{action deleteWidget target="view"}}>','<i class="icon-remove-sign icon-large"></i>','</a>',
|
|
|
+ '<div class="caption span10">', '{{view.title}}','</div>',
|
|
|
+ '<a class="corner-icon span1" href="#" {{action editWidget target="view"}}>','<i class="icon-edit"></i>','</a>',
|
|
|
+ '<div class="hidden-info">', '<table align="center">{{#each line in view.hiddenInfo}}', '<tr><td>{{line}}</td></tr>','{{/each}}</table>','</div>',
|
|
|
+
|
|
|
+ '<div class="widget-content" >','{{view view.content modelBinding="view.model" thresh1Binding="view.thresh1" thresh2Binding="view.thresh2"}}','</div>',
|
|
|
+ '</li>',
|
|
|
+ '</div>',
|
|
|
+ '{{/if}}',
|
|
|
+
|
|
|
+ '{{#if view.isText }}',
|
|
|
+ '<div class="has-hidden-info">',
|
|
|
+ '<li class="thumbnail row" >',
|
|
|
+ '<a class="corner-icon" href="#" {{action deleteWidget target="view"}}>','<i class="icon-remove-sign icon-large"></i>','</a>',
|
|
|
+ '<div class="caption span10">', '{{view.title}}','</div>',
|
|
|
+ '<a class="corner-icon span1" href="#" {{action editWidget target="view"}}>','<i class="icon-edit"></i>','</a>',
|
|
|
+ '<div class="hidden-info">', '<table align="center">{{#each line in view.hiddenInfo}}', '<tr><td>{{line}}</td></tr>','{{/each}}</table>','</div>',
|
|
|
+
|
|
|
+ '<div class="widget-content">{{view.content}}</div>',
|
|
|
+ '</li>',
|
|
|
+ '</div>',
|
|
|
+ '{{/if}}',
|
|
|
+
|
|
|
+ '{{#if view.isProgressBar}}',
|
|
|
+ '<div class="has-hidden-info">',
|
|
|
+ '<li class="thumbnail row" >',
|
|
|
+ '<a class="corner-icon" href="#" {{action deleteWidget target="view"}}>','<i class="icon-remove-sign icon-large"></i>','</a>',
|
|
|
+ '<div class="caption span10">', '{{view.title}}','</div>',
|
|
|
+ '<a class="span1">', '</a>',
|
|
|
+ '<div class="hidden-info">', '<table align="center">{{#each line in view.hiddenInfo}}', '<tr><td>{{line}}</td></tr>','{{/each}}</table>','</div>',
|
|
|
+
|
|
|
+ '<div class="widget-content row-fluid" id="map-reduce-slots-text" >',
|
|
|
+
|
|
|
+ '<ul class="span12">',
|
|
|
+ '<div class="span3"> {{t dashboard.widgets.mapSlots}}</div>',
|
|
|
+ '<div class="progress span5" id="map-reduce-slots-bar1">',
|
|
|
+ '<div class="bar bar-success" {{bindAttr style="view.map_occupied"}}></div>',
|
|
|
+ '<div class="bar bar-warning" {{bindAttr style="view.map_reserved"}}></div>',
|
|
|
+ ' </div>',
|
|
|
+ '<div class="span3" id="map-reduce-slots-num1"> {{view.map_display_text}}</div>',
|
|
|
+ '</ul>',
|
|
|
+ '<ul class="span12">',
|
|
|
+ '<div class="span3"> {{t dashboard.widgets.reduceSlots}}</div>',
|
|
|
+ '<div class="progress span5" id="map-reduce-slots-bar2">',
|
|
|
+ '<div class="bar bar-success" {{bindAttr style="view.reduce_occupied"}}></div>',
|
|
|
+ '<div class="bar bar-warning" {{bindAttr style="view.reduce_reserved"}}></div>',
|
|
|
+ '</div>',
|
|
|
+ '<div class="span3" id="map-reduce-slots-num2"> {{view.reduce_display_text}}</div>',
|
|
|
+ '</ul>',
|
|
|
+
|
|
|
+ '</div>',
|
|
|
+ '</li>',
|
|
|
+ '</div>',
|
|
|
+ '{{/if}}',
|
|
|
+
|
|
|
+ '{{#if view.isClusterMetrics}}',
|
|
|
+ '<div class="cluster-metrics">',
|
|
|
+ '<li class="thumbnail row">',
|
|
|
+ '<a class="corner-icon" href="#" {{action deleteWidget target="view"}}>','<i class="icon-remove-sign icon-large"></i>','</a>',
|
|
|
+ '<div class="caption span10">', '{{view.title}}','</div>',
|
|
|
+ '<div class="widget-content" >','{{view view.content}}','</div>',
|
|
|
+ //'<p class="hidden-info">', '{{view.hiddenInfo}}', '</p>',
|
|
|
+ '</li>',
|
|
|
+ '</div>',
|
|
|
+ '{{/if}}'
|
|
|
+
|
|
|
+ ].join('\n')),
|
|
|
+
|
|
|
+ deleteWidget: function (event) {
|
|
|
+ var parent = this.get('parentView');
|
|
|
+
|
|
|
+ if (!App.testMode) {
|
|
|
+ //reconstruct new persist value then post in persist
|
|
|
+ parent.getUserPref(parent.get('persistKey'));
|
|
|
+ var oldValue = parent.get('currentPrefObject');
|
|
|
+ var deletedId = this.id;
|
|
|
+ var newValue = Em.Object.create({
|
|
|
+ visible: [],
|
|
|
+ hidden: oldValue.hidden,
|
|
|
+ threshold: oldValue.threshold
|
|
|
+ });
|
|
|
+ for(var i = 0; i <= oldValue.visible.length -1; i++){
|
|
|
+ if(oldValue.visible[i] != deletedId){
|
|
|
+ newValue.visible.push(oldValue.visible[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newValue.hidden.push([deletedId, this.title]);
|
|
|
+ parent.postUserPref(parent.get('persistKey'), newValue);
|
|
|
+ }
|
|
|
+ //update view on dashboard
|
|
|
+ var obj_class = parent.widgetsMapper(this.id);
|
|
|
+ parent.get('visibleWidgets').removeObject(obj_class);
|
|
|
+ parent.get('hiddenWidgets').pushObject(Em.Object.create({displayName: this.title, id: this.id, checked: false}));
|
|
|
+ },
|
|
|
+
|
|
|
+ editWidget: function (event) {
|
|
|
+ var self = this;
|
|
|
+ var max_tmp = parseFloat(self.get('maxValue'));
|
|
|
+ var configObj = Ember.Object.create({
|
|
|
+ thresh1: self.get('thresh1') + '',
|
|
|
+ thresh2: self.get('thresh2') + '',
|
|
|
+ hintInfo: 'Edit the percentage thresholds to change the color of current pie chart. ' + ' '+
|
|
|
+ ' Enter two numbers between 0 to ' + max_tmp,
|
|
|
+ isThresh1Error: false,
|
|
|
+ isThresh2Error: false,
|
|
|
+ errorMessage1: "",
|
|
|
+ errorMessage2: "",
|
|
|
+ maxValue: max_tmp,
|
|
|
+ observeNewThresholdValue: function () {
|
|
|
+ var thresh1 = this.get('thresh1');
|
|
|
+ var thresh2 = this.get('thresh2');
|
|
|
+ if(thresh1.trim() != ""){
|
|
|
+ if (isNaN(thresh1) || thresh1 > max_tmp || thresh1 < 0) {
|
|
|
+ this.set('isThresh1Error', true);
|
|
|
+ this.set('errorMessage1', 'Invalid! Enter a number between 0 - ' + max_tmp);
|
|
|
+ } else if (this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)) {
|
|
|
+ this.set('isThresh1Error', true);
|
|
|
+ this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
|
|
|
+ } else {
|
|
|
+ this.set('isThresh1Error', false);
|
|
|
+ this.set('errorMessage1', '');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.set('isThresh1Error', true);
|
|
|
+ this.set('errorMessage1', 'This is required');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (thresh2.trim() != "") {
|
|
|
+ if (isNaN(thresh2) || thresh2 > max_tmp || thresh2 < 0) {
|
|
|
+ this.set('isThresh2Error', true);
|
|
|
+ this.set('errorMessage2', 'Invalid! Enter a number between 0 - ' + max_tmp);
|
|
|
+ } else {
|
|
|
+ this.set('isThresh2Error', false);
|
|
|
+ this.set('errorMessage2', '');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.set('isThresh2Error', true);
|
|
|
+ this.set('errorMessage2', 'This is required');
|
|
|
+ }
|
|
|
+
|
|
|
+ // update the slider handles and color
|
|
|
+ if (this.get('isThresh1Error') === false && this.get('isThresh2Error') === false) {
|
|
|
+ $("#slider-range").slider('values', 0 , parseFloat(thresh1));
|
|
|
+ $("#slider-range").slider('values', 1 , parseFloat(thresh2));
|
|
|
+ }
|
|
|
+ }.observes('thresh1', 'thresh2')
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ var browserVerion = this.getInternetExplorerVersion();
|
|
|
+ App.ModalPopup.show({
|
|
|
+ header: 'Customize Widget',
|
|
|
+ classNames: [ 'sixty-percent-width-modal-edit-widget' ],
|
|
|
+ bodyClass: Ember.View.extend({
|
|
|
+ templateName: require('templates/main/dashboard/edit_widget_popup'),
|
|
|
+ configPropertyObj: configObj
|
|
|
+ }),
|
|
|
+ primary: Em.I18n.t('common.apply'),
|
|
|
+ onPrimary: function() {
|
|
|
+ configObj.observeNewThresholdValue();
|
|
|
+ if (!configObj.isThresh1Error && !configObj.isThresh2Error) {
|
|
|
+ self.set('thresh1', parseFloat(configObj.get('thresh1')) );
|
|
|
+ self.set('thresh2', parseFloat(configObj.get('thresh2')) );
|
|
|
+
|
|
|
+ if (!App.testMode) {
|
|
|
+ // save to persist
|
|
|
+ var parent = self.get('parentView');
|
|
|
+ parent.getUserPref(parent.get('persistKey'));
|
|
|
+ var oldValue = parent.get('currentPrefObject');
|
|
|
+ oldValue.threshold[parseInt(self.id)] = [configObj.get('thresh1'), configObj.get('thresh2')];
|
|
|
+ parent.postUserPref(parent.get('persistKey'), oldValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hide();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ secondary : Em.I18n.t('common.cancel'),
|
|
|
+ onSecondary: function () {
|
|
|
+ this.hide();
|
|
|
+ },
|
|
|
+
|
|
|
+ didInsertElement: function () {
|
|
|
+ var handlers = [configObj.get('thresh1'), configObj.get('thresh2')];
|
|
|
+ var colors = ['#95A800', '#FF8E00', '#B80000']; //color green, orange ,red
|
|
|
+
|
|
|
+ if (browserVerion == -1 || browserVerion > 9) {
|
|
|
+ configObj.set('isIE9', false);
|
|
|
+ configObj.set('isGreenOrangeRed', true);
|
|
|
+ $("#slider-range").slider({
|
|
|
+ range: true,
|
|
|
+ min: 0,
|
|
|
+ max: max_tmp,
|
|
|
+ values: handlers,
|
|
|
+ create: function (event, ui) {
|
|
|
+ updateColors(handlers);
|
|
|
+ },
|
|
|
+ slide: function (event, ui) {
|
|
|
+ updateColors(ui.values);
|
|
|
+ configObj.set('thresh1', ui.values[0] + '');
|
|
|
+ configObj.set('thresh2', ui.values[1] + '');
|
|
|
+ },
|
|
|
+ change: function (event, ui) {
|
|
|
+ updateColors(ui.values);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function updateColors (handlers) {
|
|
|
+ var colorstops = colors[0] + ", "; // start with the first color
|
|
|
+ for (var i = 0; i < handlers.length; i++) {
|
|
|
+ colorstops += colors[i] + " " + handlers[i]*100/max_tmp + "%,";
|
|
|
+ colorstops += colors[i+1] + " " + handlers[i]*100/max_tmp + "%,";
|
|
|
+ }
|
|
|
+ colorstops += colors[colors.length - 1];
|
|
|
+ var css1 = '-webkit-linear-gradient(left,' + colorstops + ')'; // chrome & safari
|
|
|
+ $('#slider-range').css('background-image', css1);
|
|
|
+ var css2 = '-ms-linear-gradient(left,' + colorstops + ')'; // IE 10+
|
|
|
+ $('#slider-range').css('background-image', css2);
|
|
|
+ //$('#slider-range').css('filter', 'progid:DXImageTransform.Microsoft.gradient( startColorStr= ' + colors[0] + ', endColorStr= ' + colors[2] +', GradientType=1 )' ); // IE 10-
|
|
|
+ var css3 = '-moz-linear-gradient(left,' + colorstops + ')'; // Firefox
|
|
|
+ $('#slider-range').css('background-image', css3);
|
|
|
+
|
|
|
+ $('#slider-range .ui-widget-header').css({'background-color': '#FF8E00', 'background-image': 'none'}); // change the original ranger color
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ configObj.set('isIE9', true);
|
|
|
+ configObj.set('isGreenOrangeRed', true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getInternetExplorerVersion: function(){
|
|
|
+ var rv = -1; //return -1 for other browsers
|
|
|
+ if (navigator.appName == 'Microsoft Internet Explorer') {
|
|
|
+ var ua = navigator.userAgent;
|
|
|
+ var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
|
|
|
+ if (re.exec(ua) != null)
|
|
|
+ rv = parseFloat( RegExp.$1 ); // IE version 1-10
|
|
|
+ }
|
|
|
+ var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
|
|
|
+ if(isFirefox) {
|
|
|
+ return -2;
|
|
|
+ }else{
|
|
|
+ return rv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+});
|
|
|
+
|
|
|
+
|