manage_config_groups_controller.js 23 KB

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