manage_config_groups_controller.js 23 KB

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