Przeglądaj źródła

AMBARI-3791. Provide add/remove/rename/duplicate actions in manage-config-groups dialog (alexantonenko)

Alex Antonenko 11 lat temu
rodzic
commit
f44fb1050c

+ 138 - 1
ambari-web/app/controllers/main/service/manage_config_groups_controller.js

@@ -71,7 +71,8 @@ App.ManageConfigGroupsController = Em.Controller.extend({
           service: App.Service.find().findProperty('serviceName', configGroup.tag),
           hosts: configGroup.hosts.mapProperty('host_name'),
           configSiteTags: [],
-          properties: []
+          properties: [],
+          apiResponse: configGroup
         });
         usedHosts = usedHosts.concat(newConfigGroup.get('hosts'));
         configGroups.push(newConfigGroup);
@@ -162,6 +163,7 @@ App.ManageConfigGroupsController = Em.Controller.extend({
       }
     });
   },
+
   /**
    * delete hosts from group
    */
@@ -173,5 +175,140 @@ App.ManageConfigGroupsController = Em.Controller.extend({
       groupHosts.removeObject(hostName);
     });
     this.set('selectedHosts', []);
+  },
+
+  /**
+   * delete selected config group
+   */
+  deleteConfigGroup: function () {
+    var selectedConfigGroup = this.get('selectedConfigGroup');
+    if(selectedConfigGroup.get('name') == "Default") {
+      return;
+    }
+      App.ajax.send({
+        name: 'config_groups.delete_config_group',
+        sender: this,
+        data: {
+          configGroupName: selectedConfigGroup.get('name')
+        }
+      });
+      this.get('configGroups').removeObject(selectedConfigGroup);
+
+  },
+
+  /**
+   * rename new config group
+   */
+  renameConfigGroup: function () {
+    if(this.get('selectedConfigGroup.name') == "Default") {
+      return;
+    }
+    var content = this;
+    this.renameGroupPopup = App.ModalPopup.show({
+      primary: Em.I18n.t('ok'),
+      secondary: Em.I18n.t('common.cancel'),
+      header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'),
+      bodyClass: Ember.View.extend({
+        template: Ember.Handlebars.compile('' +
+          '<p>' +
+          '{{t services.service.config_groups_popup.group_name_lable }}: {{view Ember.TextField valueBinding="configGroupName"}}' +
+          '</p>')
+      }),
+      configGroupName: "",
+      content: content,
+      onPrimary: function () {
+        this.get('content.selectedConfigGroup').set('name', this.get('configGroupName'));
+        this.get('content.selectedConfigGroup.apiResponse').group_name = this.get('configGroupName');
+        var configGroup = {
+          ConfigGroup: this.get('content.selectedConfigGroup.apiResponse')
+        };
+        App.ajax.send({
+          name: 'config_groups.update_config_group',
+          sender: this,
+          data: {
+            id: this.get('content.selectedConfigGroup.id'),
+            configGroup: configGroup
+          }
+        });
+        this.hide();
+      },
+      onSecondary: function () {
+        this.hide();
+      }
+    });
+  },
+
+  /**
+   * add new config group
+   */
+  addConfigGroup: function () {
+    var content = this;
+    this.addGroupPopup = App.ModalPopup.show({
+      primary: Em.I18n.t('ok'),
+      secondary: Em.I18n.t('common.cancel'),
+      header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'),
+      bodyClass: Ember.View.extend({
+        templateName: require('templates/main/service/new_config_group')
+      }),
+      configGroupName: "",
+      configGroupDesc: "",
+      content: content,
+      onPrimary: function () {
+        this.get('content').set('configGroupName', this.get('configGroupName'));
+        this.get('content').set('configGroupDesc', this.get('configGroupDesc'));
+        App.ajax.send({
+          name: 'config_groups.create',
+          sender: this.get('content'),
+          data: {
+            'group_name': this.get('configGroupName'),
+            'service_id': this.get('content.serviceName'),
+            'description': this.get('configGroupDesc')
+          },
+          success: 'onAddNewConfigGroup'
+        });
+      },
+      onSecondary: function () {
+        this.hide();
+      }
+    });
+  },
+
+  /**
+   * On successful api resonse for creating new config group
+   */
+  onAddNewConfigGroup: function (data) {
+    var newConfigGroupData = App.ConfigGroup.create({
+      id: data.resources[0].ConfigGroup.id,
+      name: this.get('configGroupName'),
+      description: this.get('configGroupDesc'),
+      isDefault: false,
+      parentConfigGroup: null,
+      service: this.get('serviceName'),
+      hosts: [],
+      configSiteTags: []
+    });
+    var defaultConfigGroup = this.get('configGroups').popObject();
+    this.get('configGroups').pushObjects([newConfigGroupData, defaultConfigGroup]);
+    this.updateConfigGroup(data.resources[0].ConfigGroup.id);
+    this.addGroupPopup.hide();
+  },
+
+  /**
+   * update config group apiResponse property
+   */
+  updateConfigGroup: function (id) {
+    App.ajax.send({
+      name: 'config_groups.get_config_group_by_id',
+      sender: this,
+      data: {
+        'id': id
+      },
+      success: 'successLoadingConfigGroup'
+    });
+  },
+
+  successLoadingConfigGroup: function (data) {
+    var confGroup = this.get('configGroups').findProperty('id', data.ConfigGroup.id);
+    confGroup.set('apiResponse', data.ConfigGroup);
   }
 });

+ 5 - 0
ambari-web/app/messages.js

@@ -1124,7 +1124,12 @@ Em.I18n.translations = {
   'services.service.config_groups_popup.config_groups':'Configuration Groups',
   'services.service.config_groups_popup.rename':'Rename',
   'services.service.config_groups_popup.duplicate':'Duplicate',
+  'services.service.config_groups_popup.group_name_lable':'Group name',
+  'services.service.config_groups_popup.group_desc_lable':'Group description',
   'services.service.config_groups_popup.properties':'Properties',
+  'services.service.config_groups.add_config_group_popup.header':'Create new config group',
+  'services.service.config_groups.duplicate_config_group_popup.header':'Duplicate config group',
+  'services.service.config_groups.rename_config_group_popup.header':'Rename config group',
   'services.reassign.closePopup':'Reassign {0} wizard is in progress. It\'s necessary to complete the wizard for Ambari to be in usable state. If you choose to quit, you must follow manual instructions to complete or revert reassign {0} wizard as documented in the Ambari User Guide. Are you sure you want to exit the wizard ?',
 
   'services.reassign.step1.header':'Get Started',

+ 2 - 0
ambari-web/app/models/config_group.js

@@ -80,6 +80,8 @@ App.ConfigGroup = Ember.Object.extend({
     return this.get('name') + ' (' + this.get('hosts.length') + ')';
   }.property('name', 'hosts.length'),
 
+  apiResponse: null,
+
   /**
    * Provides hosts which are available for inclusion in
    * non-default configuration groups.

+ 4 - 4
ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs

@@ -29,10 +29,10 @@
           class="group-select"
         }}
         <div class="button-group pull-right">
-          <a class="btn">+</a>
-          <a class="btn">-</a>
-          <a class="btn">{{t services.service.config_groups_popup.rename}}</a>
-          <a class="btn">{{t services.service.config_groups_popup.duplicate}}</a>
+          <a class="btn" {{action addConfigGroup target="controller"}}>+</a>
+          <a class="btn" {{action deleteConfigGroup target="controller"}}>-</a>
+          <a class="btn" {{action renameConfigGroup target="controller"}}>{{t services.service.config_groups_popup.rename}}</a>
+          <a class="btn" {{action addConfigGroup target="controller"}}>{{t services.service.config_groups_popup.duplicate}}</a>
         </div>
       </div>
       <div class="span6">

+ 30 - 0
ambari-web/app/templates/main/service/new_config_group.hbs

@@ -0,0 +1,30 @@
+{{!
+* 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.
+}}
+
+<p>
+  <table>
+    <tr>
+      <td>{{t services.service.config_groups_popup.group_name_lable }}:</td>
+      <td>{{view Ember.TextField valueBinding="configGroupName"}}</td>
+    </tr>
+    <tr>
+      <td>{{t services.service.config_groups_popup.group_desc_lable }}:</td>
+      <td>{{view Ember.TextField valueBinding="configGroupDesc"}}</td>
+    </tr>
+  </table>
+</p>

+ 8 - 0
ambari-web/app/utils/ajax.js

@@ -216,6 +216,9 @@ var urls = {
   'config_groups.all_fields': {
     'real': '/clusters/{clusterName}/config_groups?fields=*'
   },
+  'config_groups.get_config_group_by_id': {
+    'real': '/clusters/{clusterName}/config_groups/{id}'
+  },
   'config_groups.update_config_group': {
     'real': '/clusters/{clusterName}/config_groups/{id}',
     'mock': '',
@@ -230,6 +233,11 @@ var urls = {
       }
     }
   },
+  'config_groups.delete_config_group': {
+    'real': '/clusters/{clusterName}/config_groups/{configGroupName}',
+    'mock': '',
+    'type': 'DELETE'
+  },
   'config.on_site': {
     'real': '/clusters/{clusterName}/configurations?{params}',
     'mock': '/data/configurations/cluster_level_configs.json?{params}',