You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2013/11/09 02:55:22 UTC
git commit: AMBARI-3732. Extract hosts selection dialog into a
utility method. (srimanth)
Updated Branches:
refs/heads/trunk d23cdc160 -> 8fd02c7c4
AMBARI-3732. Extract hosts selection dialog into a utility method. (srimanth)
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/8fd02c7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/8fd02c7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/8fd02c7c
Branch: refs/heads/trunk
Commit: 8fd02c7c4b87b1b10fbf9d2c5024374f0e4cceba
Parents: d23cdc1
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Fri Nov 8 17:48:41 2013 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Fri Nov 8 17:48:47 2013 -0800
----------------------------------------------------------------------
ambari-web/app/utils/hosts.js | 181 +++++++++++++++++++
.../app/views/common/configs/services_config.js | 153 +---------------
2 files changed, 190 insertions(+), 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/8fd02c7c/ambari-web/app/utils/hosts.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/hosts.js b/ambari-web/app/utils/hosts.js
new file mode 100644
index 0000000..80c50a8
--- /dev/null
+++ b/ambari-web/app/utils/hosts.js
@@ -0,0 +1,181 @@
+/**
+ * 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.
+ */
+module.exports = {
+
+ /**
+ * Launches a dialog to select hosts from the provided available hosts.
+ *
+ * Once the user clicks OK or Cancel, the callback is called with the
+ * array of hosts (App.Host[]) selected. If the dialog was cancelled
+ * or closed, <code>null</code> is provided to the callback. Else
+ * an array (maybe empty) will be provided to the callback.
+ *
+ * @param availableHosts {App.Host[]} List of hosts to pick from
+ * @param selectedHosts {App.Host[]} List of hosts already selected from the available hosts
+ * @param selectAtleastOneHost {boolean} If true atleast one host has to be selected
+ * @param validComponents {App.HostComponent[]} List of host-component types to pick from.
+ * @param callback Callback function which is invoked when dialog
+ * is closed, cancelled or OK is pressed.
+ */
+ launchHostsSelectionDialog : function(availableHosts, selectedHosts,
+ selectAtleastOneHost, validComponents, callback) {
+ App.ModalPopup.show({
+ classNames: [ 'sixty-percent-width-modal' ],
+ header: Em.I18n.t('hosts.selectHostsDialog.title'),
+ primary: Em.I18n.t('ok'),
+ secondary: Em.I18n.t('common.cancel'),
+ warningMessage: null,
+ onPrimary: function () {
+ console.debug('(old-selectedHosts)=', selectedHosts);
+ this.set('warningMessage', null);
+ var arrayOfSelectedHosts = [];
+ var selectedHosts = availableHosts.filterProperty('selected', true);
+ selectedHosts.forEach(function (host) {
+ arrayOfSelectedHosts.push(host.get('host.id'));
+ });
+ if (selectAtleastOneHost && arrayOfSelectedHosts.length<1) {
+ this.set('warningMessage', 'Atleast one host needs to be selected.');
+ return;
+ }
+ callback(arrayOfSelectedHosts);
+ console.debug('(new-selectedHosts)=', arrayOfSelectedHosts);
+ this.hide();
+ },
+ onSecondary: function () {
+ callback(null);
+ this.hide();
+ },
+ bodyClass: Ember.View.extend({
+ templateName: require('templates/common/configs/overrideWindow'),
+ controllerBinding: 'App.router.mainServiceInfoConfigsController',
+ filterText: '',
+ filterTextPlaceholder: Em.I18n.t('hosts.selectHostsDialog.filter.placeHolder'),
+ availableHosts: availableHosts,
+ filterColumn: Ember.Object.create({id: 'ip', name: 'IP Address', selected: false}),
+ filterColumns: Ember.A([
+ Ember.Object.create({id: 'ip', name: 'IP Address', selected: false}),
+ Ember.Object.create({id: 'cpu', name: 'CPU', selected: false}),
+ Ember.Object.create({id: 'memory', name: 'RAM', selected: false}),
+ Ember.Object.create({id: 'diskUsage', name: 'Disk Usage', selected: false}),
+ Ember.Object.create({id: 'loadAvg', name: 'Load Average', selected: false}),
+ Ember.Object.create({id: 'osArch', name: 'OS Architecture', selected: false}),
+ Ember.Object.create({id: 'osType', name: 'OS Type', selected: false})
+ ]),
+ showOnlySelectedHosts: false,
+ filterComponents: validComponents,
+ filterComponent: null,
+ filteredHosts: function () {
+ var hosts = this.get('availableHosts');
+ var filterText = this.get('filterText');
+ var showOnlySelectedHosts = this.get('showOnlySelectedHosts');
+ var filteredHosts = Ember.A([]);
+ var self = this;
+ hosts.forEach(function (host) {
+ var skip = false;
+ var ahost = host.get('host');
+ var filterColumn = self.get('filterColumn');
+ if (filterColumn == null) {
+ filterColumn = self.get('filterColumns').objectAt(0);
+ }
+ var value = ahost.get(filterColumn.id);
+ host.set('filterColumnValue', value);
+ if (filterText != null && filterText.length > 0) {
+ if ((value == null || !value.match(filterText)) && !host.get('host.publicHostName').match(filterText)) {
+ skip = true;
+ }
+ }
+ var filterComponent = self.get('filterComponent');
+ if (!skip && filterComponent != null) {
+ var componentFound = false;
+ var fcn = filterComponent.get('componentName');
+ var hcs = ahost.get('hostComponents');
+ if (hcs != null) {
+ hcs.forEach(function (hc) {
+ if (fcn === hc.get('componentName')) {
+ componentFound = true;
+ }
+ });
+ }
+ if (!componentFound) {
+ skip = true;
+ }
+ }
+ if (!skip && showOnlySelectedHosts && !host.get('selected')) {
+ skip = true;
+ }
+ if (!skip) {
+ filteredHosts.pushObject(host);
+ }
+ });
+ return filteredHosts;
+ }.property('availableHosts', 'filterText', 'filterColumn', 'filterComponent', 'filterComponent.componentName', 'showOnlySelectedHosts'),
+ hostColumnValue: function (host, column) {
+ return host.get(column.id);
+ },
+ hostSelectMessage: function () {
+ var hosts = this.get('availableHosts');
+ var selectedHosts = hosts.filterProperty('selected', true);
+ return this.t('hosts.selectHostsDialog.selectedHostsLink').format(selectedHosts.get('length'), hosts.get('length'))
+ }.property('availableHosts.@each.selected'),
+ selectFilterColumn: function (event) {
+ if (event != null && event.context != null && event.context.id != null) {
+ var filterColumn = this.get('filterColumn');
+ if (filterColumn != null) {
+ filterColumn.set('selected', false);
+ }
+ event.context.set('selected', true);
+ this.set('filterColumn', event.context);
+ }
+ },
+ selectFilterComponent: function (event) {
+ if (event != null && event.context != null && event.context.componentName != null) {
+ var currentFilter = this.get('filterComponent');
+ if (currentFilter != null) {
+ currentFilter.set('selected', false);
+ }
+ if (currentFilter != null && currentFilter.componentName === event.context.componentName) {
+ // selecting the same filter deselects it.
+ this.set('filterComponent', null);
+ } else {
+ this.set('filterComponent', event.context);
+ event.context.set('selected', true);
+ }
+ }
+ },
+ allHostsSelected: false,
+ toggleSelectAllHosts: function (event) {
+ if (this.get('allHostsSelected')) {
+ // Select all hosts
+ this.get('availableHosts').setEach('selected', true);
+ } else {
+ // Deselect all hosts
+ this.get('availableHosts').setEach('selected', false);
+ }
+ }.observes('allHostsSelected'),
+ toggleShowSelectedHosts: function () {
+ var currentFilter = this.get('filterComponent');
+ if (currentFilter != null) {
+ currentFilter.set('selected', false);
+ }
+ this.set('filterComponent', null);
+ this.set('filterText', null);
+ this.set('showOnlySelectedHosts', !this.get('showOnlySelectedHosts'));
+ }
+ })
+ });
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/8fd02c7c/ambari-web/app/views/common/configs/services_config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/services_config.js b/ambari-web/app/views/common/configs/services_config.js
index cbda51c..030e673 100644
--- a/ambari-web/app/views/common/configs/services_config.js
+++ b/ambari-web/app/views/common/configs/services_config.js
@@ -19,6 +19,7 @@
var App = require('app');
var validator = require('utils/validator');
var stringUtils = require('utils/string_utils');
+var hostsUtils = require('utils/hosts');
App.ServicesConfigView = Em.View.extend({
templateName: require('templates/common/configs/services_config'),
@@ -541,30 +542,13 @@ App.ServiceConfigsByCategoryView = Ember.View.extend({
* we ask for a normalized array back.
*/
var validComponents = this.get('controller.getCurrentServiceComponents');
- App.ModalPopup.show({
- classNames: [ 'sixty-percent-width-modal' ],
- header: Em.I18n.t('hosts.selectHostsDialog.title'),
- primary: Em.I18n.t('ok'),
- secondary: Em.I18n.t('common.cancel'),
- warningMessage: null,
- onPrimary: function () {
- console.debug('serviceConfigProperty.(old-selectedHosts)=' + serviceConfigProperty.get('selectedHosts'));
- var arrayOfSelectedHosts = [];
- var selectedHosts = availableHosts.filterProperty('selected', true);
- selectedHosts.forEach(function (host) {
- arrayOfSelectedHosts.push(host.get('host.id'));
- });
- if (arrayOfSelectedHosts.length > 0) {
- this.set('warningMessage', null);
- serviceConfigProperty.set('selectedHostOptions', arrayOfSelectedHosts);
- serviceConfigProperty.validate();
- console.debug('serviceConfigProperty.(new-selectedHosts)=', arrayOfSelectedHosts);
- this.hide();
- } else {
- this.set('warningMessage', 'Atleast one host needs to be selected.');
- }
- },
- onSecondary: function () {
+ hostsUtils.launchHostsSelectionDialog(availableHosts, selectedHosts,
+ false, validComponents, function(newSelectedHosts){
+ if (newSelectedHosts!=null) {
+ serviceConfigProperty.set('selectedHostOptions', newSelectedHosts);
+ serviceConfigProperty.validate();
+ } else {
+ // Dialog cancelled
// If property has no hosts already, then remove it from the parent.
var hostCount = serviceConfigProperty.get('selectedHostOptions.length');
if (hostCount < 1) {
@@ -572,126 +556,7 @@ App.ServiceConfigsByCategoryView = Ember.View.extend({
var overrides = parentSCP.get('overrides');
overrides.removeObject(serviceConfigProperty);
}
- this.hide();
- },
- bodyClass: Ember.View.extend({
- templateName: require('templates/common/configs/overrideWindow'),
- controllerBinding: 'App.router.mainServiceInfoConfigsController',
- serviceConfigProperty: serviceConfigProperty,
- filterText: '',
- filterTextPlaceholder: Em.I18n.t('hosts.selectHostsDialog.filter.placeHolder'),
- availableHosts: availableHosts,
- filterColumn: Ember.Object.create({id: 'ip', name: 'IP Address', selected: false}),
- filterColumns: Ember.A([
- Ember.Object.create({id: 'ip', name: 'IP Address', selected: false}),
- Ember.Object.create({id: 'cpu', name: 'CPU', selected: false}),
- Ember.Object.create({id: 'memory', name: 'RAM', selected: false}),
- Ember.Object.create({id: 'diskUsage', name: 'Disk Usage', selected: false}),
- Ember.Object.create({id: 'loadAvg', name: 'Load Average', selected: false}),
- Ember.Object.create({id: 'osArch', name: 'OS Architecture', selected: false}),
- Ember.Object.create({id: 'osType', name: 'OS Type', selected: false})
- ]),
- showOnlySelectedHosts: false,
- filterComponents: validComponents,
- filterComponent: null,
- filteredHosts: function () {
- var hosts = this.get('availableHosts');
- var filterText = this.get('filterText');
- var showOnlySelectedHosts = this.get('showOnlySelectedHosts');
- var filteredHosts = Ember.A([]);
- var self = this;
- hosts.forEach(function (host) {
- var skip = false;
- var ahost = host.get('host');
- var filterColumn = self.get('filterColumn');
- if (filterColumn == null) {
- filterColumn = self.get('filterColumns').objectAt(0);
- }
- var value = ahost.get(filterColumn.id);
- host.set('filterColumnValue', value);
- if (filterText != null && filterText.length > 0) {
- if ((value == null || !value.match(filterText)) && !host.get('host.publicHostName').match(filterText)) {
- skip = true;
- }
- }
- var filterComponent = self.get('filterComponent');
- if (!skip && filterComponent != null) {
- var componentFound = false;
- var fcn = filterComponent.get('componentName');
- var hcs = ahost.get('hostComponents');
- if (hcs != null) {
- hcs.forEach(function (hc) {
- if (fcn === hc.get('componentName')) {
- componentFound = true;
- }
- });
- }
- if (!componentFound) {
- skip = true;
- }
- }
- if (!skip && showOnlySelectedHosts && !host.get('selected')) {
- skip = true;
- }
- if (!skip) {
- filteredHosts.pushObject(host);
- }
- });
- return filteredHosts;
- }.property('availableHosts', 'filterText', 'filterColumn', 'filterComponent', 'filterComponent.componentName', 'showOnlySelectedHosts'),
- hostColumnValue: function (host, column) {
- return host.get(column.id);
- },
- hostSelectMessage: function () {
- var hosts = this.get('availableHosts');
- var selectedHosts = hosts.filterProperty('selected', true);
- return this.t('hosts.selectHostsDialog.selectedHostsLink').format(selectedHosts.get('length'), hosts.get('length'))
- }.property('availableHosts.@each.selected'),
- selectFilterColumn: function (event) {
- if (event != null && event.context != null && event.context.id != null) {
- var filterColumn = this.get('filterColumn');
- if (filterColumn != null) {
- filterColumn.set('selected', false);
- }
- event.context.set('selected', true);
- this.set('filterColumn', event.context);
- }
- },
- selectFilterComponent: function (event) {
- if (event != null && event.context != null && event.context.componentName != null) {
- var currentFilter = this.get('filterComponent');
- if (currentFilter != null) {
- currentFilter.set('selected', false);
- }
- if (currentFilter != null && currentFilter.componentName === event.context.componentName) {
- // selecting the same filter deselects it.
- this.set('filterComponent', null);
- } else {
- this.set('filterComponent', event.context);
- event.context.set('selected', true);
- }
- }
- },
- allHostsSelected: false,
- toggleSelectAllHosts: function (event) {
- if (this.get('allHostsSelected')) {
- // Select all hosts
- this.get('availableHosts').setEach('selected', true);
- } else {
- // Deselect all hosts
- this.get('availableHosts').setEach('selected', false);
- }
- }.observes('allHostsSelected'),
- toggleShowSelectedHosts: function () {
- var currentFilter = this.get('filterComponent');
- if (currentFilter != null) {
- currentFilter.set('selected', false);
- }
- this.set('filterComponent', null);
- this.set('filterText', null);
- this.set('showOnlySelectedHosts', !this.get('showOnlySelectedHosts'));
- }
- })
+ }
});
}
});