manage_config_groups_controller.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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 numberUtils = require('utils/number_utils');
  21. App.ManageConfigGroupsController = Em.Controller.extend({
  22. name: 'manageConfigGroupsController',
  23. isLoaded: false,
  24. isInstaller: false,
  25. isAddService: false,
  26. serviceName: null,
  27. configGroups: [],
  28. originalConfigGroups: [],
  29. selectedConfigGroup: null,
  30. selectedHosts: [],
  31. clusterHosts: [],
  32. resortConfigGroup: function() {
  33. var configGroups = Ember.copy(this.get('configGroups'));
  34. if(configGroups.length < 2){
  35. return;
  36. }
  37. var defaultConfigGroup = configGroups.findProperty('isDefault');
  38. configGroups.removeObject(defaultConfigGroup);
  39. var sorted = [defaultConfigGroup].concat(configGroups.sortProperty('name'));
  40. this.removeObserver('configGroups.@each.name', this, 'resortConfigGroup');
  41. this.set('configGroups', sorted);
  42. this.addObserver('configGroups.@each.name', this, 'resortConfigGroup');
  43. }.observes('configGroups.@each.name'),
  44. loadHosts: function() {
  45. this.set('isLoaded', false);
  46. if (this.get('isInstaller')) {
  47. var allHosts = this.get('isAddService') ? App.router.get('addServiceController').get('allHosts') : App.router.get('installerController').get('allHosts');
  48. this.set('clusterHosts', allHosts);
  49. this.loadConfigGroups(this.get('serviceName'));
  50. } else {
  51. this.loadHostsFromServer();
  52. }
  53. },
  54. /**
  55. * request all hosts directly from server
  56. */
  57. loadHostsFromServer: function() {
  58. App.ajax.send({
  59. name: 'hosts.config_groups',
  60. sender: this,
  61. data: {},
  62. success: 'loadHostsFromServerSuccessCallback',
  63. error: 'loadHostsFromServerErrorCallback'
  64. });
  65. },
  66. /**
  67. * parse hosts response and wrap them into Ember.Object
  68. * @param data
  69. */
  70. loadHostsFromServerSuccessCallback: function (data) {
  71. var wrappedHosts = [];
  72. data.items.forEach(function (host) {
  73. var hostComponents = [];
  74. var diskInfo = host.Hosts.disk_info.filter(function(item) {
  75. return /^ext|^ntfs|^fat|^xfs/i.test(item.type);
  76. });
  77. if (diskInfo.length) {
  78. diskInfo = diskInfo.reduce(function(a, b) {
  79. return {
  80. available: parseInt(a.available) + parseInt(b.available),
  81. size: parseInt(a.size) + parseInt(b.size)
  82. };
  83. });
  84. }
  85. host.host_components.forEach(function (hostComponent) {
  86. hostComponents.push(Em.Object.create({
  87. componentName: hostComponent.HostRoles.component_name,
  88. displayName: App.format.role(hostComponent.HostRoles.component_name)
  89. }));
  90. }, this);
  91. wrappedHosts.pushObject(Em.Object.create({
  92. id: host.Hosts.host_name,
  93. ip: host.Hosts.ip,
  94. osType: host.Hosts.os_type,
  95. osArch: host.Hosts.os_arch,
  96. hostName: host.Hosts.host_name,
  97. publicHostName: host.Hosts.public_host_name,
  98. cpu: host.Hosts.cpu_count,
  99. memory: host.Hosts.total_mem,
  100. diskTotal: numberUtils.bytesToSize(diskInfo.size, 0, undefined, 1024),
  101. diskFree: numberUtils.bytesToSize(diskInfo.available, 0, undefined, 1024),
  102. disksMounted: host.Hosts.disk_info.length,
  103. hostComponents: hostComponents
  104. }
  105. ));
  106. }, this);
  107. this.set('clusterHosts', wrappedHosts);
  108. this.loadConfigGroups(this.get('serviceName'));
  109. },
  110. loadHostsFromServerErrorCallback: function () {
  111. console.warn('ERROR: request to fetch all hosts failed');
  112. this.set('clusterHosts', []);
  113. this.loadConfigGroups(this.get('serviceName'));
  114. },
  115. loadConfigGroups: function (serviceName) {
  116. if (this.get('isInstaller')) {
  117. this.set('serviceName', serviceName);
  118. var configGroups = this.copyConfigGroups(App.router.get('wizardStep7Controller.selectedService.configGroups'));
  119. var originalConfigGroups = this.copyConfigGroups(configGroups);
  120. this.set('configGroups', configGroups);
  121. this.set('originalConfigGroups', originalConfigGroups);
  122. this.set('isLoaded', true);
  123. } else {
  124. this.set('serviceName', serviceName);
  125. App.ajax.send({
  126. name: 'service.load_config_groups',
  127. data: {
  128. serviceName: serviceName
  129. },
  130. sender: this,
  131. success: 'onLoadConfigGroupsSuccess',
  132. error: 'onLoadConfigGroupsError'
  133. });
  134. }
  135. },
  136. onLoadConfigGroupsSuccess: function (data) {
  137. var usedHosts = [];
  138. var unusedHosts = [];
  139. var serviceName = this.get('serviceName');
  140. var serviceDisplayName = App.StackService.find().findProperty('serviceName', this.get('serviceName')).get('displayName');
  141. var defaultConfigGroup = App.ConfigGroup.create({
  142. name: serviceDisplayName + " Default",
  143. description: "Default cluster level " + this.get('serviceName') + " configuration",
  144. isDefault: true,
  145. parentConfigGroup: null,
  146. service: this.get('content'),
  147. configSiteTags: [],
  148. serviceName: serviceName
  149. });
  150. if (data && data.items) {
  151. var groupToTypeToTagMap = {};
  152. var configGroups = [];
  153. data.items.forEach(function (configGroup) {
  154. configGroup = configGroup.ConfigGroup;
  155. var hostNames = configGroup.hosts.mapProperty('host_name');
  156. var publicHostNames = this.hostsToPublic(hostNames);
  157. var newConfigGroup = App.ConfigGroup.create({
  158. id: configGroup.id,
  159. name: configGroup.group_name,
  160. description: configGroup.description,
  161. isDefault: false,
  162. parentConfigGroup: defaultConfigGroup,
  163. service: App.Service.find().findProperty('serviceName', configGroup.tag),
  164. hosts: hostNames,
  165. publicHosts: publicHostNames,
  166. configSiteTags: [],
  167. properties: [],
  168. apiResponse: configGroup
  169. });
  170. usedHosts = usedHosts.concat(newConfigGroup.get('hosts'));
  171. configGroups.push(newConfigGroup);
  172. var newConfigGroupSiteTags = newConfigGroup.get('configSiteTags');
  173. configGroup.desired_configs.forEach(function (config) {
  174. newConfigGroupSiteTags.push(App.ConfigSiteTag.create({
  175. site: config.type,
  176. tag: config.tag
  177. }));
  178. if (!groupToTypeToTagMap[configGroup.group_name]) {
  179. groupToTypeToTagMap[configGroup.group_name] = {}
  180. }
  181. groupToTypeToTagMap[configGroup.group_name][config.type] = config.tag;
  182. });
  183. }, this);
  184. unusedHosts = this.get('clusterHosts').mapProperty('hostName');
  185. usedHosts.uniq().forEach(function (host) {
  186. unusedHosts = unusedHosts.without(host);
  187. }, this);
  188. defaultConfigGroup.set('childConfigGroups', configGroups);
  189. defaultConfigGroup.set('hosts', unusedHosts);
  190. defaultConfigGroup.set('publicHosts', this.hostsToPublic(unusedHosts));
  191. var allGroups = [defaultConfigGroup].concat(configGroups);
  192. this.set('configGroups', allGroups);
  193. var originalGroups = this.copyConfigGroups(allGroups);
  194. this.set('originalConfigGroups', originalGroups);
  195. this.loadProperties(groupToTypeToTagMap);
  196. this.set('isLoaded', true);
  197. }
  198. },
  199. /**
  200. * Get public_host_name by host_name.
  201. *
  202. * @param {Array|String} hostsList
  203. * @return {Array|String}
  204. **/
  205. hostsToPublic: function(hostsList) {
  206. return this.convertHostNames(hostsList, true);
  207. },
  208. /**
  209. * Get host_name by public_host_name
  210. *
  211. * @param {Array|String} hostsList
  212. * @return {Array|String}
  213. **/
  214. publicToHostName: function(hostsList) {
  215. return this.convertHostNames(hostsList, false);
  216. },
  217. /***
  218. * Switch between public_host_name and host_name
  219. *
  220. * @param {Array|String} hostsList
  221. * @param {Boolean} toPublic
  222. * @return {Array|String}
  223. **/
  224. convertHostNames: function(hostsList, toPublic) {
  225. var allHosts = this.get('clusterHosts');
  226. var convertTarget = !!toPublic ?
  227. { from: 'hostName', to: 'publicHostName' } : { from: 'publicHostName', to: 'hostName'};
  228. if (this.get('isInstaller')) {
  229. allHosts = App.router.get(!!this.get('isAddService') ? 'addServiceController' : 'installerController').get('allHosts');
  230. }
  231. if (typeof hostsList == 'string') return allHosts.findProperty(convertTarget.from, hostsList).get(convertTarget.to);
  232. return hostsList.map(function(hostName) {
  233. return allHosts.findProperty(convertTarget.from, hostName).get(convertTarget.to);
  234. }, this);
  235. },
  236. onLoadConfigGroupsError: function () {
  237. console.error('Unable to load config groups for service.');
  238. },
  239. loadProperties: function (groupToTypeToTagMap) {
  240. var typeTagToGroupMap = {};
  241. var urlParams = [];
  242. for (var group in groupToTypeToTagMap) {
  243. var overrideTypeTags = groupToTypeToTagMap[group];
  244. for (var type in overrideTypeTags) {
  245. var tag = overrideTypeTags[type];
  246. typeTagToGroupMap[type + "///" + tag] = group;
  247. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  248. }
  249. }
  250. var params = urlParams.join('|');
  251. if (urlParams.length) {
  252. App.ajax.send({
  253. name: 'config.host_overrides',
  254. sender: this,
  255. data: {
  256. params: params,
  257. typeTagToGroupMap: typeTagToGroupMap
  258. },
  259. success: 'onLoadPropertiesSuccess'
  260. });
  261. }
  262. },
  263. onLoadPropertiesSuccess: function (data, opt, params) {
  264. data.items.forEach(function (configs) {
  265. var typeTagConfigs = [];
  266. App.config.loadedConfigurationsCache[configs.type + "_" + configs.tag] = configs.properties;
  267. var group = params.typeTagToGroupMap[configs.type + "///" + configs.tag];
  268. for (var config in configs.properties) {
  269. typeTagConfigs.push(Em.Object.create({
  270. name: config,
  271. value: configs.properties[config]
  272. }));
  273. }
  274. this.get('configGroups').findProperty('name', group).get('properties').pushObjects(typeTagConfigs);
  275. }, this);
  276. },
  277. showProperties: function () {
  278. var properies = this.get('selectedConfigGroup.propertiesList').htmlSafe();
  279. if (properies) {
  280. App.showAlertPopup(Em.I18n.t('services.service.config_groups_popup.properties'), properies);
  281. }
  282. },
  283. addHosts: function () {
  284. if (this.get('selectedConfigGroup.isAddHostsDisabled')){
  285. return false;
  286. }
  287. var availableHosts = this.get('selectedConfigGroup.availableHosts');
  288. var popupDescription = {
  289. header: Em.I18n.t('hosts.selectHostsDialog.title'),
  290. dialogMessage: Em.I18n.t('hosts.selectHostsDialog.message').format(this.get('selectedConfigGroup.displayName'))
  291. };
  292. hostsManagement.launchHostsSelectionDialog(availableHosts, [], false, this.get('componentsForFilter'), this.addHostsCallback.bind(this), popupDescription);
  293. },
  294. /**
  295. * add hosts callback
  296. */
  297. addHostsCallback: function (selectedHosts) {
  298. var group = this.get('selectedConfigGroup');
  299. if (selectedHosts) {
  300. var defaultHosts = group.get('parentConfigGroup.hosts').slice();
  301. var defaultPublicHosts = group.get('parentConfigGroup.publicHosts').slice();
  302. var configGroupHosts = group.get('hosts');
  303. selectedHosts.forEach(function (hostName) {
  304. configGroupHosts.pushObject(hostName);
  305. group.get('publicHosts').pushObject(this.hostsToPublic(hostName));
  306. defaultHosts.removeObject(hostName);
  307. defaultPublicHosts.removeObject(this.hostsToPublic(hostName));
  308. }, this);
  309. group.set('parentConfigGroup.hosts', defaultHosts);
  310. group.set('parentConfigGroup.publicHosts', this.hostsToPublic(defaultHosts));
  311. }
  312. },
  313. /**
  314. * delete hosts from group
  315. */
  316. deleteHosts: function () {
  317. if (this.get('isDeleteHostsDisabled')) {
  318. return;
  319. }
  320. var groupHosts = this.get('selectedConfigGroup.hosts');
  321. var defaultGroupHosts = this.get('selectedConfigGroup.parentConfigGroup.hosts').slice();
  322. var defaultGroupPublicHosts = this.get('selectedConfigGroup.parentConfigGroup.publicHosts').slice();
  323. this.get('selectedHosts').slice().forEach(function (hostName) {
  324. defaultGroupHosts.pushObject(this.publicToHostName(hostName));
  325. defaultGroupPublicHosts.pushObject(hostName);
  326. groupHosts.removeObject(this.publicToHostName(hostName));
  327. this.get('selectedConfigGroup.publicHosts').removeObject(hostName);
  328. }, this);
  329. this.set('selectedConfigGroup.parentConfigGroup.hosts', defaultGroupHosts);
  330. this.set('selectedConfigGroup.parentConfigGroup.publicHosts', this.hostsToPublic(defaultGroupHosts));
  331. this.set('selectedHosts', []);
  332. },
  333. isDeleteHostsDisabled: function () {
  334. var selectedConfigGroup = this.get('selectedConfigGroup');
  335. if (selectedConfigGroup) {
  336. return selectedConfigGroup.isDefault || this.get('selectedHosts').length === 0;
  337. }
  338. return true;
  339. }.property('selectedConfigGroup', 'selectedConfigGroup.hosts.length', 'selectedHosts.length'),
  340. /**
  341. * confirm delete config group
  342. */
  343. confirmDelete : function () {
  344. var self = this;
  345. App.showConfirmationPopup(function() {
  346. self.deleteConfigGroup();
  347. });
  348. },
  349. /**
  350. * add hosts to group
  351. * @return {Array}
  352. */
  353. componentsForFilter: function () {
  354. return App.StackServiceComponent.find().filterProperty('serviceName', this.get('serviceName')).map(function (component) {
  355. return Em.Object.create({
  356. displayName: component.get('displayName'),
  357. componentName: component.get('componentName'),
  358. selected: false
  359. });
  360. });
  361. }.property('serviceName'),
  362. /**
  363. * delete selected config group
  364. */
  365. deleteConfigGroup: function () {
  366. var selectedConfigGroup = this.get('selectedConfigGroup');
  367. if (this.get('isDeleteGroupDisabled')) {
  368. return;
  369. }
  370. //move hosts of group to default group (available hosts)
  371. this.set('selectedHosts', selectedConfigGroup.get('hosts'));
  372. this.deleteHosts();
  373. this.get('configGroups').removeObject(selectedConfigGroup);
  374. this.set('selectedConfigGroup', this.get('configGroups').findProperty('isDefault'));
  375. },
  376. /**
  377. * rename new config group
  378. */
  379. renameConfigGroup: function () {
  380. if(this.get('selectedConfigGroup.isDefault')) {
  381. return;
  382. }
  383. var self = this;
  384. this.renameGroupPopup = App.ModalPopup.show({
  385. primary: Em.I18n.t('ok'),
  386. secondary: Em.I18n.t('common.cancel'),
  387. header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'),
  388. bodyClass: Ember.View.extend({
  389. templateName: require('templates/main/service/new_config_group')
  390. }),
  391. configGroupName: self.get('selectedConfigGroup.name'),
  392. configGroupDesc: self.get('selectedConfigGroup.description'),
  393. warningMessage: null,
  394. isDescriptionDirty: false,
  395. validate: function () {
  396. var warningMessage = '';
  397. var originalGroup = self.get('selectedConfigGroup');
  398. if (originalGroup.get('description') !== this.get('configGroupDesc') && !this.get('isDescriptionDirty')) {
  399. this.set('isDescriptionDirty', true);
  400. }
  401. if (originalGroup.get('name').trim() === this.get('configGroupName').trim()) {
  402. if (this.get('isDescriptionDirty')) {
  403. warningMessage = '';
  404. } else {
  405. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  406. }
  407. } else {
  408. if (self.get('configGroups').mapProperty('name').contains(this.get('configGroupName').trim())) {
  409. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  410. }
  411. }
  412. this.set('warningMessage', warningMessage);
  413. }.observes('configGroupName', 'configGroupDesc'),
  414. disablePrimary: function () {
  415. return !(this.get('configGroupName').trim().length > 0 && (this.get('warningMessage') !== null && !this.get('warningMessage')));
  416. }.property('warningMessage', 'configGroupName', 'configGroupDesc'),
  417. onPrimary: function () {
  418. self.set('selectedConfigGroup.name', this.get('configGroupName'));
  419. self.set('selectedConfigGroup.description', this.get('configGroupDesc'));
  420. self.get('selectedConfigGroup.properties').forEach(function(property){
  421. property.set('group', self.get('selectedConfigGroup'));
  422. });
  423. this.hide();
  424. }
  425. });
  426. },
  427. /**
  428. * add new config group
  429. */
  430. addConfigGroup: function (duplicated) {
  431. duplicated = (duplicated === true);
  432. var self = this;
  433. this.addGroupPopup = App.ModalPopup.show({
  434. primary: Em.I18n.t('ok'),
  435. secondary: Em.I18n.t('common.cancel'),
  436. header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'),
  437. bodyClass: Ember.View.extend({
  438. templateName: require('templates/main/service/new_config_group')
  439. }),
  440. configGroupName: duplicated ? self.get('selectedConfigGroup.name') + ' Copy' : "",
  441. configGroupDesc: duplicated ? self.get('selectedConfigGroup.description') + ' (Copy)' : "",
  442. warningMessage: '',
  443. didInsertElement: function(){
  444. this.validate();
  445. this.$('input').focus();
  446. },
  447. validate: function () {
  448. var warningMessage = '';
  449. if (self.get('configGroups').mapProperty('name').contains(this.get('configGroupName').trim())) {
  450. warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  451. }
  452. this.set('warningMessage', warningMessage);
  453. }.observes('configGroupName'),
  454. disablePrimary: function () {
  455. return !(this.get('configGroupName').trim().length > 0 && !this.get('warningMessage'));
  456. }.property('warningMessage', 'configGroupName'),
  457. onPrimary: function () {
  458. var defaultConfigGroup = self.get('configGroups').findProperty('isDefault');
  459. var properties = [];
  460. var newConfigGroupData = App.ConfigGroup.create({
  461. id: null,
  462. name: this.get('configGroupName').trim(),
  463. description: this.get('configGroupDesc'),
  464. isDefault: false,
  465. parentConfigGroup: defaultConfigGroup,
  466. service: Em.Object.create({id: self.get('serviceName')}),
  467. hosts: [],
  468. publicHosts: [],
  469. configSiteTags: [],
  470. properties: []
  471. });
  472. if (duplicated) {
  473. self.get('selectedConfigGroup.properties').forEach(function(property) {
  474. var property = App.ServiceConfigProperty.create($.extend(false, {}, property));
  475. property.set('group', newConfigGroupData);
  476. properties.push(property);
  477. });
  478. newConfigGroupData.set('properties', properties);
  479. } else {
  480. newConfigGroupData.set('properties', []);
  481. }
  482. self.get('configGroups').pushObject(newConfigGroupData);
  483. defaultConfigGroup.get('childConfigGroups').pushObject(newConfigGroupData);
  484. this.hide();
  485. }
  486. });
  487. },
  488. duplicateConfigGroup: function() {
  489. this.addConfigGroup(true);
  490. },
  491. hostsModifiedConfigGroups: function () {
  492. if (!this.get('isLoaded')) {
  493. return false;
  494. }
  495. var groupsToClearHosts = [];
  496. var groupsToDelete = [];
  497. var groupsToSetHosts = [];
  498. var groupsToCreate = [];
  499. var groups = this.get('configGroups');
  500. var originalGroups = this.get('originalConfigGroups');
  501. // remove default group
  502. originalGroups = originalGroups.without(originalGroups.findProperty('isDefault'));
  503. var originalGroupsIds = originalGroups.mapProperty('id');
  504. groups.forEach(function (group) {
  505. if (!group.get('isDefault')) {
  506. var originalGroup = originalGroups.findProperty('id', group.get('id'));
  507. if (originalGroup) {
  508. if (!(JSON.stringify(group.get('hosts').slice().sort()) === JSON.stringify(originalGroup.get('hosts').sort()))) {
  509. groupsToClearHosts.push(group.set('id', originalGroup.get('id')));
  510. if (group.get('hosts').length) {
  511. groupsToSetHosts.push(group.set('id', originalGroup.get('id')));
  512. }
  513. // should update name or description
  514. } else if (group.get('description') !== originalGroup.get('description') || group.get('name') !== originalGroup.get('name') ) {
  515. groupsToSetHosts.push(group.set('id', originalGroup.get('id')));
  516. }
  517. originalGroupsIds = originalGroupsIds.without(group.get('id'));
  518. } else {
  519. groupsToCreate.push(group);
  520. }
  521. }
  522. });
  523. originalGroupsIds.forEach(function (id) {
  524. groupsToDelete.push(originalGroups.findProperty('id', id));
  525. }, this);
  526. return {
  527. toClearHosts: groupsToClearHosts,
  528. toDelete: groupsToDelete,
  529. toSetHosts: groupsToSetHosts,
  530. toCreate: groupsToCreate
  531. };
  532. }.property('selectedConfigGroup.hosts.@each', 'selectedConfigGroup.hosts.length', 'selectedConfigGroup.description', 'configGroups', 'isLoaded'),
  533. isHostsModified: function () {
  534. var modifiedGroups = this.get('hostsModifiedConfigGroups');
  535. if (!this.get('isLoaded')) {
  536. return false;
  537. }
  538. return !!(modifiedGroups.toClearHosts.length || modifiedGroups.toSetHosts.length || modifiedGroups.toCreate.length || modifiedGroups.toDelete.length);
  539. }.property('hostsModifiedConfigGroups'),
  540. /**
  541. * copy config groups to manage popup to give user choice whether or not save changes
  542. * @param originGroups
  543. * @return {Array}
  544. */
  545. copyConfigGroups: function (originGroups) {
  546. var configGroups = [];
  547. var result = [];
  548. var defaultConfigGroup = App.ConfigGroup.create($.extend(true, {}, originGroups.findProperty('isDefault')));
  549. originGroups.forEach(function (configGroup) {
  550. if (!configGroup.get('isDefault')) {
  551. var copiedGroup = App.ConfigGroup.create($.extend(true, {}, configGroup));
  552. copiedGroup.set('parentConfigGroup', defaultConfigGroup);
  553. configGroups.pushObject(copiedGroup);
  554. }
  555. });
  556. defaultConfigGroup.set('childConfigGroups', configGroups.slice());
  557. configGroups.pushObject(defaultConfigGroup);
  558. configGroups.forEach(function (group) {
  559. var groupCopy = {};
  560. for (var prop in group) {
  561. if (group.hasOwnProperty(prop)) {
  562. groupCopy[prop] = group[prop];
  563. }
  564. }
  565. groupCopy.properties.forEach(function(property){
  566. property.set('group', group);
  567. });
  568. result.push(App.ConfigGroup.create(groupCopy));
  569. }, this);
  570. return result;
  571. }
  572. });