manage_config_groups_controller.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var hostsManagement = require('utils/hosts');
  20. var serviceComponents = require('data/service_components');
  21. App.ManageConfigGroupsController = Em.Controller.extend({
  22. name: 'manageConfigGroupsController',
  23. isLoaded: false,
  24. serviceName: null,
  25. configGroups: [],
  26. selectedConfigGroup: null,
  27. selectedHosts: [],
  28. loadedHostsToGroupMap: {},
  29. usedConfigGroupNames: [],
  30. resortConfigGroup: function() {
  31. var configGroups = Ember.copy(this.get('configGroups'));
  32. if(configGroups.length < 2){
  33. return;
  34. }
  35. var defaultConfigGroup = configGroups.findProperty('isDefault');
  36. configGroups.removeObject(defaultConfigGroup);
  37. var sorted = configGroups.sort(function(configGroupA, configGroupB){
  38. return String(configGroupA.get('name')) >= String(configGroupB.get('name'));
  39. });
  40. sorted = [defaultConfigGroup].concat(sorted);
  41. this.removeObserver('configGroups.@each.name', this, 'resortConfigGroup');
  42. this.set('configGroups', sorted);
  43. this.addObserver('configGroups.@each.name', this, 'resortConfigGroup');
  44. }.observes('configGroups.@each.name'),
  45. loadConfigGroups: function (serviceName) {
  46. this.set('serviceName', serviceName);
  47. App.ajax.send({
  48. name: 'service.load_config_groups',
  49. sender: this,
  50. success: 'onLoadConfigGroupsSuccess',
  51. error: 'onLoadConfigGroupsError'
  52. });
  53. },
  54. onLoadConfigGroupsSuccess: function (data) {
  55. var loadedHostsToGroupMap = this.get('loadedHostsToGroupMap');
  56. var usedHosts = [];
  57. var unusedHosts = [];
  58. var defaultConfigGroup = App.ConfigGroup.create({
  59. name: "Default",
  60. description: "Default cluster level " + this.get('serviceName') + " configuration",
  61. isDefault: true,
  62. parentConfigGroup: null,
  63. service: this.get('content'),
  64. configSiteTags: [],
  65. serviceName: this.get('serviceName')
  66. });
  67. if (data && data.items) {
  68. var groupToTypeToTagMap = {};
  69. var configGroups = [];
  70. var serviceName = this.get('serviceName');
  71. var usedConfigGroupNames = [];
  72. data.items.forEach(function (configGroup) {
  73. configGroup = configGroup.ConfigGroup;
  74. if (configGroup.tag === serviceName) {
  75. var hostNames = configGroup.hosts.mapProperty('host_name');
  76. loadedHostsToGroupMap[configGroup.group_name] = hostNames.slice();
  77. var newConfigGroup = App.ConfigGroup.create({
  78. id: configGroup.id,
  79. name: configGroup.group_name,
  80. description: configGroup.description,
  81. isDefault: false,
  82. parentConfigGroup: defaultConfigGroup,
  83. service: App.Service.find().findProperty('serviceName', configGroup.tag),
  84. hosts: hostNames,
  85. configSiteTags: [],
  86. properties: [],
  87. apiResponse: configGroup
  88. });
  89. usedHosts = usedHosts.concat(newConfigGroup.get('hosts'));
  90. configGroups.push(newConfigGroup);
  91. var newConfigGroupSiteTags = newConfigGroup.get('configSiteTags');
  92. configGroup.desired_configs.forEach(function (config) {
  93. newConfigGroupSiteTags.push(App.ConfigSiteTag.create({
  94. site: config.type,
  95. tag: config.tag
  96. }));
  97. if (!groupToTypeToTagMap[configGroup.group_name]) {
  98. groupToTypeToTagMap[configGroup.group_name] = {}
  99. }
  100. groupToTypeToTagMap[configGroup.group_name][config.type] = config.tag;
  101. });
  102. } else {
  103. usedConfigGroupNames.push(configGroup.group_name);
  104. }
  105. }, this);
  106. this.set('usedConfigGroupNames', usedConfigGroupNames);
  107. unusedHosts = App.Host.find().mapProperty('hostName');
  108. usedHosts.uniq().forEach(function (host) {
  109. unusedHosts = unusedHosts.without(host);
  110. }, this);
  111. defaultConfigGroup.set('childConfigGroups', configGroups);
  112. defaultConfigGroup.set('hosts', unusedHosts);
  113. this.set('configGroups', [defaultConfigGroup].concat(configGroups));
  114. this.loadProperties(groupToTypeToTagMap);
  115. this.set('isLoaded', true);
  116. }
  117. },
  118. onLoadConfigGroupsError: function () {
  119. console.error('Unable to load config groups for service.');
  120. },
  121. loadProperties: function (groupToTypeToTagMap) {
  122. var typeTagToGroupMap = {};
  123. var urlParams = [];
  124. for (var group in groupToTypeToTagMap) {
  125. var overrideTypeTags = groupToTypeToTagMap[group];
  126. for (var type in overrideTypeTags) {
  127. var tag = overrideTypeTags[type];
  128. typeTagToGroupMap[type + "///" + tag] = group;
  129. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  130. }
  131. }
  132. var params = urlParams.join('|');
  133. if (urlParams.length) {
  134. App.ajax.send({
  135. name: 'config.host_overrides',
  136. sender: this,
  137. data: {
  138. params: params,
  139. typeTagToGroupMap: typeTagToGroupMap
  140. },
  141. success: 'onLoadPropertiesSuccess'
  142. });
  143. }
  144. },
  145. onLoadPropertiesSuccess: function (data, opt, params) {
  146. data.items.forEach(function (configs) {
  147. var typeTagConfigs = [];
  148. App.config.loadedConfigurationsCache[configs.type + "_" + configs.tag] = configs.properties;
  149. var group = params.typeTagToGroupMap[configs.type + "///" + configs.tag];
  150. for (var config in configs.properties) {
  151. typeTagConfigs.push({
  152. name: config,
  153. value: configs.properties[config]
  154. });
  155. }
  156. this.get('configGroups').findProperty('name', group).get('properties').pushObjects(typeTagConfigs);
  157. }, this);
  158. },
  159. showProperties: function () {
  160. var properies = this.get('selectedConfigGroup.propertiesList').htmlSafe();
  161. if (properies) {
  162. App.showAlertPopup(Em.I18n.t('services.service.config_groups_popup.properties'), properies);
  163. }
  164. },
  165. /**
  166. * add hosts to group
  167. * @return {Array}
  168. */
  169. componentsForFilter: function() {
  170. var components = serviceComponents.filterProperty('service_name',this.get('serviceName'));
  171. return components.map(function(component) {
  172. return Em.Object.create({
  173. displayName: component.display_name,
  174. componentName: component.component_name,
  175. selected: false
  176. });
  177. });
  178. }.property('serviceName'),
  179. addHosts: function () {
  180. if (this.get('selectedConfigGroup.isAddHostsDisabled')){
  181. return false;
  182. }
  183. var availableHosts = this.get('selectedConfigGroup.availableHosts');
  184. var popupDescription = {
  185. header: Em.I18n.t('hosts.selectHostsDialog.title'),
  186. dialogMessage: Em.I18n.t('hosts.selectHostsDialog.message').format(App.Service.DisplayNames[this.get('serviceName')])
  187. };
  188. hostsManagement.launchHostsSelectionDialog(availableHosts, [], false, this.get('componentsForFilter'), this.addHostsCallback.bind(this), popupDescription);
  189. },
  190. /**
  191. * add hosts callback
  192. */
  193. addHostsCallback: function (selectedHosts) {
  194. var group = this.get('selectedConfigGroup');
  195. if (selectedHosts) {
  196. var defaultHosts = group.get('parentConfigGroup.hosts');
  197. var configGroupHosts = group.get('hosts');
  198. selectedHosts.forEach(function (hostName) {
  199. configGroupHosts.pushObject(hostName);
  200. defaultHosts.removeObject(hostName);
  201. });
  202. }
  203. },
  204. /**
  205. * delete hosts from group
  206. */
  207. deleteHosts: function () {
  208. if (this.get('isDeleteHostsDisabled')) {
  209. return false;
  210. }
  211. var groupHosts = this.get('selectedConfigGroup.hosts');
  212. var defaultGroupHosts = this.get('selectedConfigGroup.parentConfigGroup.hosts');
  213. this.get('selectedHosts').slice().forEach(function (hostName) {
  214. defaultGroupHosts.pushObject(hostName);
  215. groupHosts.removeObject(hostName);
  216. });
  217. this.set('selectedHosts', []);
  218. },
  219. isDeleteHostsDisabled: function () {
  220. var selectedConfigGroup = this.get('selectedConfigGroup');
  221. if (selectedConfigGroup) {
  222. if (selectedConfigGroup.isDefault || this.get('selectedHosts').length === 0) {
  223. return true;
  224. } else {
  225. return false;
  226. }
  227. }
  228. return true;
  229. }.property('selectedConfigGroup', 'selectedConfigGroup.hosts.length', 'selectedHosts.length'),
  230. /**
  231. * confirm delete config group
  232. */
  233. confirmDelete : function () {
  234. var self = this;
  235. App.showConfirmationPopup(function() {
  236. self.deleteConfigGroup();
  237. });
  238. },
  239. /**
  240. * delete selected config group
  241. */
  242. deleteConfigGroup: function () {
  243. var selectedConfigGroup = this.get('selectedConfigGroup');
  244. if (this.get('isDeleteGroupDisabled')) {
  245. return;
  246. }
  247. App.ajax.send({
  248. name: 'config_groups.delete_config_group',
  249. sender: this,
  250. data: {
  251. id: selectedConfigGroup.get('id')
  252. }
  253. });
  254. //move hosts of group to default group (available hosts)
  255. this.set('selectedHosts', selectedConfigGroup.get('hosts'));
  256. this.deleteHosts();
  257. this.get('configGroups').removeObject(selectedConfigGroup);
  258. delete this.get('loadedHostsToGroupMap')[selectedConfigGroup.get('name')];
  259. this.set('selectedConfigGroup', this.get('configGroups').findProperty('isDefault'));
  260. },
  261. /**
  262. * rename new config group
  263. */
  264. renameConfigGroup: function () {
  265. if(this.get('selectedConfigGroup.name') == "Default") {
  266. return;
  267. }
  268. var content = this;
  269. var self = this;
  270. this.renameGroupPopup = App.ModalPopup.show({
  271. primary: Em.I18n.t('ok'),
  272. secondary: Em.I18n.t('common.cancel'),
  273. header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'),
  274. bodyClass: Ember.View.extend({
  275. templateName: require('templates/main/service/new_config_group')
  276. }),
  277. configGroupName: "",
  278. content: content,
  279. validate: function () {
  280. var warningMessage = '';
  281. if (self.get('usedConfigGroupNames').concat(self.get('configGroups').mapProperty('name')).contains(this.get('configGroupName'))) {
  282. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  283. }
  284. this.set('warningMessage', warningMessage);
  285. }.observes('configGroupName'),
  286. enablePrimary: function () {
  287. return this.get('configGroupName').length > 0 && !this.get('warningMessage');
  288. }.property('warningMessage', 'configGroupName'),
  289. onPrimary: function () {
  290. if (!this.get('enablePrimary')) {
  291. return false;
  292. }
  293. var copyHsots = this.get('content.loadedHostsToGroupMap')[this.get('content.selectedConfigGroup.name')];
  294. delete this.get('content.loadedHostsToGroupMap')[this.get('content.selectedConfigGroup.name')];
  295. this.get('content.loadedHostsToGroupMap')[this.get('configGroupName')] = copyHsots;
  296. this.get('content.selectedConfigGroup').set('name', this.get('configGroupName'));
  297. this.get('content.selectedConfigGroup').set('description', this.get('configGroupDesc'));
  298. this.get('content.selectedConfigGroup.apiResponse').group_name = this.get('configGroupName');
  299. this.get('content.selectedConfigGroup.apiResponse').description = this.get('configGroupDesc');
  300. var configGroup = {
  301. ConfigGroup: this.get('content.selectedConfigGroup.apiResponse')
  302. };
  303. App.ajax.send({
  304. name: 'config_groups.update_config_group',
  305. sender: this,
  306. data: {
  307. id: this.get('content.selectedConfigGroup.id'),
  308. configGroup: configGroup
  309. }
  310. });
  311. this.hide();
  312. },
  313. onSecondary: function () {
  314. this.hide();
  315. }
  316. });
  317. this.get('renameGroupPopup').set('configGroupName', this.get('selectedConfigGroup.name'));
  318. this.get('renameGroupPopup').set('configGroupDesc', this.get('selectedConfigGroup.description'));
  319. },
  320. /**
  321. * add new config group
  322. */
  323. addConfigGroup: function (isDuplicated) {
  324. isDuplicated = isDuplicated === true ? true : false;
  325. var content = this;
  326. var self = this;
  327. this.addGroupPopup = App.ModalPopup.show({
  328. primary: Em.I18n.t('ok'),
  329. secondary: Em.I18n.t('common.cancel'),
  330. header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'),
  331. bodyClass: Ember.View.extend({
  332. templateName: require('templates/main/service/new_config_group')
  333. }),
  334. configGroupName: "",
  335. configGroupDesc: "",
  336. content: content,
  337. warningMessage: '',
  338. validate: function () {
  339. var warningMessage = '';
  340. if (self.get('usedConfigGroupNames').concat(self.get('configGroups').mapProperty('name')).contains(this.get('configGroupName').trim())) {
  341. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  342. }
  343. this.set('warningMessage', warningMessage);
  344. }.observes('configGroupName'),
  345. enablePrimary: function () {
  346. return this.get('configGroupName').trim().length > 0 && !this.get('warningMessage');
  347. }.property('warningMessage', 'configGroupName'),
  348. onPrimary: function () {
  349. if (!this.get('enablePrimary')) {
  350. return false;
  351. }
  352. this.get('content').set('configGroupName', this.get('configGroupName').trim());
  353. this.get('content').set('configGroupDesc', this.get('configGroupDesc'));
  354. var desiredConfig = [];
  355. if (isDuplicated) {
  356. this.get('content.selectedConfigGroup.apiResponse.desired_configs').forEach(function(desired_config){
  357. var properties = {};
  358. this.get('content.selectedConfigGroup.properties').forEach(function(property){
  359. properties[property.name] = property.value;
  360. });
  361. desiredConfig.push({
  362. tag: 'version' + (new Date).getTime(),
  363. type: desired_config.type,
  364. properties : properties
  365. })
  366. }, this);
  367. }
  368. self.createNewConfigurationGroup(this.get('configGroupName').trim(),this.get('content.serviceName'),this.get('configGroupDesc'), desiredConfig, this.get('content'));
  369. },
  370. onSecondary: function () {
  371. this.hide();
  372. }
  373. });
  374. },
  375. createNewConfigurationGroup: function(configGroupName, serviceName, configGroupDesc, desiredConfigs, sender) {
  376. App.ajax.send({
  377. name: 'config_groups.create',
  378. sender: sender,
  379. data: {
  380. 'group_name': configGroupName,
  381. 'service_id': serviceName,
  382. 'description': configGroupDesc,
  383. 'desired_configs': desiredConfigs
  384. },
  385. success: 'onAddNewConfigGroup',
  386. error: 'onAddNewConfigGroupError'
  387. });
  388. },
  389. /**
  390. * On successful api resonse for creating new config group
  391. */
  392. onAddNewConfigGroup: function (data,response) {
  393. var defaultConfigGroup = this.get('configGroups').findProperty('isDefault');
  394. var desiredConfigs = jQuery.parseJSON(response.data)[0].ConfigGroup.desired_configs;
  395. var properties = [];
  396. var configSiteTags = [];
  397. if (desiredConfigs && desiredConfigs.length > 0) {
  398. desiredConfigs.forEach(function(configs){
  399. var configSiteTag = App.ConfigSiteTag.create({
  400. site: configs.type,
  401. tag: configs.tag
  402. });
  403. configSiteTags.push(configSiteTag);
  404. });
  405. properties = this.get('selectedConfigGroup.properties');
  406. }
  407. var newConfigGroupData = App.ConfigGroup.create({
  408. id: data.resources[0].ConfigGroup.id,
  409. name: this.get('configGroupName'),
  410. description: this.get('configGroupDesc'),
  411. isDefault: false,
  412. parentConfigGroup: defaultConfigGroup,
  413. service: App.Service.find().findProperty('serviceName', this.get('serviceName')),
  414. hosts: [],
  415. configSiteTags: configSiteTags,
  416. properties: properties
  417. });
  418. this.get('loadedHostsToGroupMap')[newConfigGroupData.get('name')] = [];
  419. defaultConfigGroup.get('childConfigGroups').push(newConfigGroupData);
  420. this.get('configGroups').pushObject(newConfigGroupData);
  421. this.updateConfigGroup(data.resources[0].ConfigGroup.id);
  422. this.addGroupPopup.hide();
  423. },
  424. onAddNewConfigGroupError: function() {
  425. console.warn('Can\'t add configuration group');
  426. },
  427. /**
  428. * update config group apiResponse property
  429. */
  430. updateConfigGroup: function (id) {
  431. App.ajax.send({
  432. name: 'config_groups.get_config_group_by_id',
  433. sender: this,
  434. data: {
  435. 'id': id
  436. },
  437. success: 'successLoadingConfigGroup'
  438. });
  439. },
  440. successLoadingConfigGroup: function (data) {
  441. if(data.ConfigGroup) {
  442. var confGroup = this.get('configGroups').findProperty('id', data.ConfigGroup.id);
  443. confGroup.set('apiResponse', data.ConfigGroup);
  444. }
  445. },
  446. /**
  447. * duplicate config group
  448. */
  449. duplicateConfigGroup: function() {
  450. if(this.get('selectedConfigGroup.name') == "Default") {
  451. return;
  452. }
  453. this.addConfigGroup(true);
  454. this.get('addGroupPopup').set('header',Em.I18n.t('services.service.config_groups.duplicate_config_group_popup.header'));
  455. this.get('addGroupPopup').set('configGroupName', this.get('selectedConfigGroup.name') + ' Copy');
  456. this.get('addGroupPopup').set('configGroupDesc', this.get('selectedConfigGroup.description') + ' (Copy)');
  457. },
  458. hostsModifiedConfigGroups: function () {
  459. var groupsToClearHosts = [];
  460. var groupsToSetHosts = [];
  461. var groups = this.get('configGroups');
  462. var loadedHostsToGroupMap = this.get('loadedHostsToGroupMap');
  463. groups.forEach(function (group) {
  464. if (!group.get('isDefault')) {
  465. if (!(JSON.stringify(group.get('hosts').slice().sort()) === JSON.stringify(loadedHostsToGroupMap[group.get('name')].sort()))) {
  466. groupsToClearHosts.push(group);
  467. if (group.get('hosts').length) {
  468. groupsToSetHosts.push(group);
  469. }
  470. }
  471. }
  472. });
  473. return {
  474. toClearHosts: groupsToClearHosts,
  475. toSetHosts: groupsToSetHosts
  476. };
  477. }.property('selectedConfigGroup', 'selectedConfigGroup.hosts.@each'),
  478. isHostsModified: function () {
  479. var modifiedGroups = this.get('hostsModifiedConfigGroups');
  480. return !!(modifiedGroups.toClearHosts.length || modifiedGroups.toSetHosts.length);
  481. }.property('hostsModifiedConfigGroups', 'hostsModifiedConfigGroups.length')
  482. });
  483. App.InstallerManageConfigGroupsController = App.ManageConfigGroupsController.extend({
  484. name: 'installerManageConfigGroupsController',
  485. loadConfigGroups: function (serviceName, usedConfigGroupNames) {
  486. this.set('serviceName', serviceName);
  487. this.set('usedConfigGroupNames', usedConfigGroupNames);
  488. var loadedHostsToGroupMap = this.get('loadedHostsToGroupMap');
  489. var configGroups = this.copyConfigGroups(App.router.get('wizardStep7Controller.selectedService.configGroups'));
  490. configGroups.forEach(function (configGroup) {
  491. if (!configGroup.get('isDefault')) {
  492. loadedHostsToGroupMap[configGroup.name] = configGroup.hosts.slice();
  493. }
  494. });
  495. this.set('configGroups', configGroups);
  496. this.set('isLoaded', true);
  497. },
  498. /**
  499. * copy config groups to manage popup to give user choice whether or not save changes
  500. * @param originGroups
  501. * @return {Array}
  502. */
  503. copyConfigGroups: function (originGroups) {
  504. var configGroups = [];
  505. var defaultConfigGroup = App.ConfigGroup.create(originGroups.findProperty('isDefault'));
  506. originGroups.forEach(function (configGroup) {
  507. if (!configGroup.get('isDefault')) {
  508. var copiedGroup = App.ConfigGroup.create($.extend(true, {}, configGroup));
  509. copiedGroup.set('parentConfigGroup', defaultConfigGroup);
  510. configGroups.pushObject(copiedGroup);
  511. }
  512. });
  513. defaultConfigGroup.set('childConfigGroups', configGroups.slice());
  514. configGroups.pushObject(defaultConfigGroup);
  515. return configGroups;
  516. },
  517. /**
  518. * delete selected config group
  519. */
  520. deleteConfigGroup: function () {
  521. var selectedConfigGroup = this.get('selectedConfigGroup');
  522. if (this.get('isDeleteGroupDisabled')) {
  523. return;
  524. }
  525. //move hosts of group to default group (available hosts)
  526. this.set('selectedHosts', selectedConfigGroup.get('hosts'));
  527. this.deleteHosts();
  528. this.get('configGroups').removeObject(selectedConfigGroup);
  529. delete this.get('loadedHostsToGroupMap')[selectedConfigGroup.get('name')];
  530. this.set('selectedConfigGroup', this.get('configGroups').findProperty('isDefault'));
  531. },
  532. /**
  533. * rename new config group
  534. */
  535. renameConfigGroup: function () {
  536. if(this.get('selectedConfigGroup.name') == "Default") {
  537. return;
  538. }
  539. var self = this;
  540. App.ModalPopup.show({
  541. primary: Em.I18n.t('ok'),
  542. secondary: Em.I18n.t('common.cancel'),
  543. header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'),
  544. bodyClass: Ember.View.extend({
  545. templateName: require('templates/main/service/new_config_group')
  546. }),
  547. configGroupName: self.get('selectedConfigGroup.name'),
  548. configGroupDesc: self.get('selectedConfigGroup.description'),
  549. warningMessage: '',
  550. validate: function () {
  551. var warningMessage = '';
  552. if (self.get('usedConfigGroupNames').concat(self.get('configGroups').mapProperty('name')).contains(this.get('configGroupName'))) {
  553. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  554. }
  555. this.set('warningMessage', warningMessage);
  556. }.observes('configGroupName'),
  557. enablePrimary: function () {
  558. return this.get('configGroupName').length > 0 && !this.get('warningMessage');
  559. }.property('warningMessage', 'configGroupName'),
  560. onPrimary: function () {
  561. if (!this.get('enablePrimary')) {
  562. return false;
  563. }
  564. var copyHsots = self.get('loadedHostsToGroupMap')[self.get('selectedConfigGroup.name')];
  565. delete self.get('loadedHostsToGroupMap')[self.get('selectedConfigGroup.name')];
  566. self.get('loadedHostsToGroupMap')[this.get('configGroupName')] = copyHsots;
  567. self.set('selectedConfigGroup.name', this.get('configGroupName'));
  568. self.set('selectedConfigGroup.description', this.get('configGroupDesc'));
  569. this.hide();
  570. }
  571. });
  572. },
  573. /**
  574. * add new config group
  575. */
  576. addConfigGroup: function () {
  577. var self = this;
  578. this.addGroupPopup = App.ModalPopup.show({
  579. primary: Em.I18n.t('ok'),
  580. secondary: Em.I18n.t('common.cancel'),
  581. header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'),
  582. bodyClass: Ember.View.extend({
  583. templateName: require('templates/main/service/new_config_group')
  584. }),
  585. configGroupName: "",
  586. configGroupDesc: "",
  587. warningMessage: '',
  588. validate: function () {
  589. var warningMessage = '';
  590. if (self.get('usedConfigGroupNames').concat(self.get('configGroups').mapProperty('name')).contains(this.get('configGroupName'))) {
  591. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  592. }
  593. this.set('warningMessage', warningMessage);
  594. }.observes('configGroupName'),
  595. enablePrimary: function () {
  596. return this.get('configGroupName').length > 0 && !this.get('warningMessage');
  597. }.property('warningMessage', 'configGroupName'),
  598. onPrimary: function () {
  599. if (!this.get('enablePrimary')) {
  600. return false;
  601. }
  602. var defaultConfigGroup = self.get('configGroups').findProperty('isDefault');
  603. var newConfigGroupData = App.ConfigGroup.create({
  604. id: null,
  605. name: this.get('configGroupName'),
  606. description: this.get('configGroupDesc'),
  607. isDefault: false,
  608. parentConfigGroup: defaultConfigGroup,
  609. service: Em.Object.create({id: self.get('serviceName')}),
  610. hosts: [],
  611. configSiteTags: [],
  612. properties: []
  613. });
  614. self.get('loadedHostsToGroupMap')[newConfigGroupData.get('name')] = [];
  615. self.get('configGroups').pushObject(newConfigGroupData);
  616. defaultConfigGroup.get('childConfigGroups').pushObject(newConfigGroupData);
  617. this.hide();
  618. }
  619. });
  620. }
  621. })