Repository: ambari Updated Branches: refs/heads/trunk 6236d6245 -> 02215416f
AMBARI-7427 It is not possible to change "Custom" Created dates again. (Buzhor Denys via ababiichuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/af150a1b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/af150a1b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/af150a1b Branch: refs/heads/trunk Commit: af150a1be3dd007625397c5dc03aa6547343cf28 Parents: 3590d7d Author: aBabiichuk <ababiic...@cybervisiontech.com> Authored: Mon Sep 22 14:40:03 2014 +0300 Committer: aBabiichuk <ababiic...@cybervisiontech.com> Committed: Mon Sep 22 14:40:03 2014 +0300 ---------------------------------------------------------------------- .../main/dashboard/config_history_controller.js | 1 + ambari-web/app/views/common/filter_view.js | 74 +++++++++++++++++++- .../views/main/dashboard/config_history_view.js | 10 ++- 3 files changed, 82 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/af150a1b/ambari-web/app/controllers/main/dashboard/config_history_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/dashboard/config_history_controller.js b/ambari-web/app/controllers/main/dashboard/config_history_controller.js index e6d8614..582874c 100644 --- a/ambari-web/app/controllers/main/dashboard/config_history_controller.js +++ b/ambari-web/app/controllers/main/dashboard/config_history_controller.js @@ -127,6 +127,7 @@ App.MainConfigHistoryController = Em.ArrayController.extend(App.TableServerMixin time = curTime - 2592000000; break; case 'Custom': + case 'Custom2': customDatePopup.showCustomDatePopup(this, this.get('actualValues')); break; case 'Any': http://git-wip-us.apache.org/repos/asf/ambari/blob/af150a1b/ambari-web/app/views/common/filter_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/filter_view.js b/ambari-web/app/views/common/filter_view.js index f279fd3..83d23a7 100644 --- a/ambari-web/app/views/common/filter_view.js +++ b/ambari-web/app/views/common/filter_view.js @@ -50,6 +50,24 @@ var wrapperView = Ember.View.extend({ */ fieldId: null, + /** + * This option is useful for Em.Select, if you want get events when same option selected more than one time a raw. + * This property is Object[] (for example see App.MainConfigHistoryView.modifiedFilterView), + * that have followed structure: + * + * <code> + * [ + * { + * values: ['DefinedValue1', 'DefinedValue2'], // this properties should be defined in `content` property + * displayAs: 'Choose me' // this value will be displayed + * } + * ] + * </code> + * @type {Array} + * + **/ + triggeredOnSameValue: null, + clearFilter: function(){ this.set('value', this.get('emptyValue')); if(this.get('setPropertyOnApply')){ @@ -136,6 +154,60 @@ var wrapperView = Ember.View.extend({ var parent = this.$().parent(); this.set('parentNode', parent); parent.addClass('notActive'); + this.checkSelectSpecialOptions(); + }, + + /** + * Check for Em.Select that should use dispatching event when option with same value selected more than one time. + **/ + checkSelectSpecialOptions: function() { + // check predefined property + if (!this.get('triggeredOnSameValue') || !this.get('triggeredOnSameValue').length) return; + // add custom additional observer that will handle property changes + this.addObserver('value', this, 'valueCustomObserver'); + // get the full class attribute to find our select + var classInlineAttr = this.get('fieldType').split(',') + .map(function(className) { + return '.' + className.trim(); + }).join(''); + this.set('classInlineAttr', classInlineAttr); + this.get('triggeredOnSameValue').forEach(function(triggeredValue) { + triggeredValue.values.forEach(function(value, index) { + // option with property `value` + var $optionEl = $(this.get('element')).find(classInlineAttr) + .find('option[value="' + value + '"]'); + // should be displayed with `displayAs` caption + $optionEl.text(triggeredValue.displayAs); + // the second one option should be hidden + // as the result, on init stage we show only one option that could be selected + if (index == 1) { + $optionEl.css('display', 'none'); + } + }, this); + }, this); + }, + /** + * + * Custom observer that used for special case of Em.Select related to dispatching event + * when option with same value selected more than one time. + * + **/ + valueCustomObserver: function() { + var hiddenValue; + this.get('triggeredOnSameValue').forEach(function(triggeredValue) { + var values = triggeredValue.values; + // find current selected value from `values` list + var currentValueIndex = values.indexOf(this.get('value')); + if (currentValueIndex < 0) return; + // value assigned to hidden option + hiddenValue = values[Number(currentValueIndex == 0)]; + }, this); + // our select + var $select = $(this.get('element')).find(this.get('classInlineAttr')); + // now hide option with current value + $select.find('option[value="{0}"]'.format(this.get('value'))).css('display', 'none'); + // and show option that was hidden + $select.find('option[value="{0}"'.format(hiddenValue)).css('display', 'block'); } }); @@ -274,7 +346,7 @@ module.exports = { config.fieldType = config.fieldType || 'input-medium'; config.filterView = selectFieldView.extend({ - classNames : [ config.fieldType ], + classNames : config.fieldType.split(','), attributeBindings: ['disabled','multiple'], disabled: false }); http://git-wip-us.apache.org/repos/asf/ambari/blob/af150a1b/ambari-web/app/views/main/dashboard/config_history_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/dashboard/config_history_view.js b/ambari-web/app/views/main/dashboard/config_history_view.js index 792e31f..49e1d82 100644 --- a/ambari-web/app/views/main/dashboard/config_history_view.js +++ b/ambari-web/app/views/main/dashboard/config_history_view.js @@ -149,8 +149,14 @@ App.MainConfigHistoryView = App.TableView.extend({ modifiedFilterView: filters.createSelectView({ column: 3, - fieldType: 'filter-input-width', - content: ['Any', 'Past 1 hour', 'Past 1 Day', 'Past 2 Days', 'Past 7 Days', 'Past 14 Days', 'Past 30 Days', 'Custom'], + triggeredOnSameValue: [ + { + values: ['Custom', 'Custom2'], + displayAs: 'Custom' + } + ], + fieldType: 'filter-input-width,modified-filter', + content: ['Any', 'Past 1 hour', 'Past 1 Day', 'Past 2 Days', 'Past 7 Days', 'Past 14 Days', 'Past 30 Days', 'Custom', 'Custom2'], valueBinding: "controller.modifiedFilter.optionValue", startTimeBinding: "controller.modifiedFilter.actualValues.startTime", endTimeBinding: "controller.modifiedFilter.actualValues.endTime",