1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | 1 1 1 1 4 4 4 4 4 1077 759 35 3 3 2 2 1 3 2 2 1 1 1 36 8 2 6 1 5 5 4 4 2 2 1 11 9 9 4 4 4 4 4 4 4 2 2 2 2 1 2 2 2 2 2 1 1 1 2 2 3 1 1 1 1 1 1 1 1 3 3 3 3 3 4 4 1 3 2 1 1 1 1 1 1 1 2 2 2 2 2 5 2 1 1 1 7 6 1 5 5 5 6 6 3 3 2 3 5 5 5 3 3 3 3 1 5 2 2 2 2 6 4 2 2 5 5 5 1 4 4 3 4 5 2 2 2 2 1 1 1 2 4 4 4 1 1 1 3 6 4 3 2 1 1 2 1 1 1 9 9 9 9 9 9 9 9 5 4 3 1 2 1 1 1 1 3 3 1 2 1 1 1 5 1 3 3 3 3 3 | 'use strict'; ;require.register("mixins/common/configs/enhanced_configs", function (exports, require, module) { /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var App = require('app'); var blueprintUtils = require('utils/blueprint'); App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationParser, { /** * this value is used for observing * whether recommendations for dependent properties was received from server * @type {number} */ recommendationTimeStamp: null, /** * this property is used to force update min/max values * for not default config groups * @type {boolean} */ forceUpdateBoundaries: false, /** * object with loaded recommendations * * @type {?Object} */ recommendationsConfigs: null, /** * list of recommendations that should be applied without any config changes * * @type {Object[]} */ initialRecommendations: [], /** * flag is true when Ambari changes some of the dependent properties * @type {boolean} */ hasChangedDependencies: Em.computed.and('isControllerSupportsEnhancedConfigs', 'changedProperties.length'), /** * defines is block with changed dependent configs should be shown * rely on controller * @type {boolean} */ isControllerSupportsEnhancedConfigs: Em.computed.existsIn('name', ['wizardStep7Controller', 'mainServiceInfoConfigsController']), /** * Stores name and file name of changed config * This used only for capacity-scheduler * * @property {object} */ currentlyChangedConfig: null, dependenciesGroupMessage: Em.I18n.t('popup.dependent.configs.dependencies.for.groups'), /** * ConfigType-Widget map * key - widget type * value - widget view * @type {object} */ widgetTypeMap: { checkbox: 'CheckboxConfigWidgetView', combo: 'ComboConfigWidgetView', directory: 'TextFieldConfigWidgetView', directories: 'DirectoryConfigWidgetView', list: 'ListConfigWidgetView', password: 'PasswordConfigWidgetView', 'radio-buttons': 'RadioButtonConfigWidgetView', slider: 'SliderConfigWidgetView', 'text-field': 'TextFieldConfigWidgetView', 'time-interval-spinner': 'TimeIntervalSpinnerView', toggle: 'ToggleConfigWidgetView', 'text-area': 'StringConfigWidgetView', 'label': 'LabelView', 'test-db-connection': 'TestDbConnectionWidgetView' }, configNameWidgetMixinMap: { num_llap_nodes: App.NumLlapNodesWidgetMixin }, /** * message for alert box for dependent configs * @type {string} */ dependenciesMessage: function () { var changedProperties = this.get('changedProperties').filterProperty('saveRecommended'); var changedServices = changedProperties.mapProperty('serviceName').uniq(); var cfgLenSuffix = changedProperties.length === 1 ? 'singular' : 'plural'; var sLenSuffix = changedServices.length === 1 ? 'singular' : 'plural'; return Em.I18n.t('popup.dependent.configs.dependencies.config.' + cfgLenSuffix).format(changedProperties.length) + Em.I18n.t('popup.dependent.configs.dependencies.service.' + sLenSuffix).format(changedServices.length); }.property('changedProperties.length'), /** * dependent properties that was changed by Ambari * @type {Object[]} */ changedProperties: function () { return this.get('recommendations').filter(function (dp) { return this.get('selectedConfigGroup.isDefault') && Em.get(dp, 'configGroup').contains('Default') || [this.get('selectedConfigGroup.name'), this.get('selectedConfigGroup.dependentConfigGroups') && this.get('selectedConfigGroup.dependentConfigGroups')[Em.get(dp, 'serviceName')]].contains(Em.get(dp, 'configGroup')); }, this); }.property('recommendations.@each.saveRecommended', 'recommendations.@each.recommendedValue', 'selectedConfigGroup'), /** * defines if change dependent group message should be shown * @type {boolean} */ showSelectGroupsPopup: Em.computed.and('!selectedConfigGroup.isDefault', 'selectedService.dependentServiceNames.length'), /** * set default values for dependentGroups * @method setDependentGroups */ setDependentGroups: function () { if (this.shouldSetDependentConfigs()) { this.get('selectedService.dependentServiceNames').forEach(function (serviceName) { if (!this.get('selectedConfigGroup.dependentConfigGroups')[serviceName]) { var stepConfig = this.get('stepConfigs').findProperty('serviceName', serviceName); if (stepConfig) { this.setDependentConfigGroups(stepConfig, serviceName); } } }, this); } }.observes('selectedConfigGroup'), /** * * @param {Em.Object} stepConfig * @param {string} serviceName */ setDependentConfigGroups: function setDependentConfigGroups(stepConfig, serviceName) { stepConfig.get('configGroups').filterProperty('isDefault', false).forEach(function (configGroup) { this.get('selectedService.configGroups').filterProperty('isDefault', false).forEach(function (currentServiceGroup) { if (currentServiceGroup.get('dependentConfigGroups')[serviceName] !== configGroup.get('name')) { var dependentGroups = $.extend({}, this.get('selectedConfigGroup.dependentConfigGroups')); dependentGroups[serviceName] = configGroup.get('name'); this.set('selectedConfigGroup.dependentConfigGroups', dependentGroups); } }, this); }, this); }, /** * * @returns {boolean} */ shouldSetDependentConfigs: function shouldSetDependentConfigs() { return Boolean(this.get('selectedConfigGroup') && this.get('isControllerSupportsEnhancedConfigs') && !this.get('selectedConfigGroup.isDefault') && this.get('selectedService.dependentServiceNames.length')); }, /******************************METHODS THAT WORKS WITH DEPENDENT CONFIGS *************************************/ /** * get config group object for current service * @param serviceName * @returns {App.ConfigGroup|null} */ getGroupForService: function getGroupForService(serviceName) { if (!this.get('stepConfigs') || this.get('stepConfigs.length') === 0) { return null; } if (this.get('selectedService.serviceName') === serviceName) { return this.get('selectedConfigGroup'); } else { var stepConfig = this.get('stepConfigs').findProperty('serviceName', serviceName); if (stepConfig) { var groups = stepConfig.get('configGroups'); if (this.get('selectedConfigGroup.isDefault')) { return groups.length ? groups.findProperty('isDefault') : null; } else { return groups.length ? groups.findProperty('name', this.get('selectedConfigGroup.dependentConfigGroups')[serviceName]) : null; } } else { return null; } } }, clearRecommendationsInfo: function clearRecommendationsInfo() { this.set('recommendationsConfigs', null); }, clearRecommendations: function clearRecommendations() { this.clearRecommendationsInfo(); this.clearAllRecommendations(); }, /** * sends request to get values for dependent configs * @param {{type: string, name: string}[]} changedConfigs - list of changed configs to track recommendations * @param {Function} [onComplete] * @returns {$.ajax|null} */ loadConfigRecommendations: function loadConfigRecommendations(changedConfigs, onComplete) { var updateDependencies = Em.isArray(changedConfigs) && changedConfigs.length > 0; var stepConfigs = this.get('stepConfigs'); var requiredTags = []; var isAutoComplete = !updateDependencies && this.get('isRecommendationsAutoComplete') !== undefined; Eif (this.get('isRecommendationsAutoComplete') !== undefined) { this.set('isRecommendationsAutoComplete', isAutoComplete); } if (updateDependencies || Em.isNone(this.get('recommendationsConfigs'))) { var recommendations = isAutoComplete ? {} : this.get('hostGroups'); var dataToSend = this.getConfigRecommendationsParams(updateDependencies, changedConfigs, isAutoComplete); this.modifyRecommendationConfigGroups(recommendations, isAutoComplete); if (!stepConfigs.someProperty('serviceName', 'MISC')) { requiredTags.push({ site: 'cluster-env', serviceName: 'MISC' }); } Iif (Em.isArray(changedConfigs) && changedConfigs.mapProperty('type').uniq()[0] === 'capacity-scheduler') { this.set('currentlyChangedConfig', { name: 'capacity-scheduler', fileName: 'capacity-scheduler.xml' }); } else { this.set('currentlyChangedConfig', null); } Iif (App.Service.find().someProperty('serviceName', 'HDFS') && !stepConfigs.someProperty('serviceName', 'HDFS')) { requiredTags.push({ site: 'core-site', serviceName: 'HDFS' }); } this.setUserContext(dataToSend); if (requiredTags.length) { this.loadAdditionalSites(requiredTags, stepConfigs, recommendations, dataToSend, onComplete); } else { this.addRecommendationRequestParams(recommendations, dataToSend, stepConfigs); return this.getRecommendationsRequest(dataToSend, onComplete); } } else { Eif (onComplete) { onComplete(); } } return $.Deferred().resolve().promise(); }, /** * * @param recommendations * @param dataToSend * @param stepConfigs */ addRecommendationRequestParams: function addRecommendationRequestParams(recommendations, dataToSend, stepConfigs) { var isAutoComplete = Boolean(this.get('isRecommendationsAutoComplete')); Eif (!isAutoComplete) { recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(stepConfigs); } dataToSend.recommendations = recommendations; dataToSend.serviceName = this.get('content.serviceName'); dataToSend.clusterId = App.get('clusterId'); dataToSend.autoComplete = String(isAutoComplete); // configsResponse - tells server to return only configurations in recommendations call dataToSend.configsResponse = String(isAutoComplete); }, /** * * @param {Array} stepConfigs * @param {object} recommendations * @param {object} dataToSend * @param {Function} onComplete */ loadAdditionalSites: function loadAdditionalSites(sites, stepConfigs, recommendations, dataToSend, onComplete) { var self = this; App.router.get('configurationController').getCurrentConfigsBySites(sites).done(function (configs) { stepConfigs = stepConfigs.concat(configs); self.addRecommendationRequestParams(recommendations, dataToSend, stepConfigs); self.getRecommendationsRequest(dataToSend, onComplete); }); }, /** * * @param {object} recommendations * @param {boolean} isAutoComplete */ modifyRecommendationConfigGroups: function modifyRecommendationConfigGroups(recommendations, isAutoComplete) { var configGroup = this.get('selectedConfigGroup'); if (configGroup && !configGroup.get('isDefault') && configGroup.get('hosts.length') > 0) { recommendations.config_groups = [this.buildConfigGroupJSON(this.get('selectedService.configs'), configGroup, isAutoComplete)]; } else { delete recommendations.config_groups; } }, /** * * @param {boolean} updateDependencies * @param {Array} changedConfigs * @param {boolean} isAutoComplete * @returns {{recommend: string, hosts: *, services: *, changed_configurations: *}} */ getConfigRecommendationsParams: function getConfigRecommendationsParams(updateDependencies, changedConfigs, isAutoComplete) { return { recommend: updateDependencies ? 'configuration-dependencies' : 'configurations', hosts: isAutoComplete ? undefined : this.get('hostNames'), services: isAutoComplete ? undefined : this.get('serviceNames'), changed_configurations: updateDependencies ? changedConfigs : undefined }; }, getRecommendationsRequest: function getRecommendationsRequest(dataToSend, _callback) { var self = this; this.set('recommendationsInProgress', true); return App.ajax.send({ name: 'config.recommendations', sender: self, data: { stackVersionUrl: App.get('stackVersionURL'), dataToSend: dataToSend }, success: 'loadRecommendationsSuccess', error: 'loadRecommendationsError', callback: function callback() { self.set('recommendationsInProgress', false); self.set('recommendationTimeStamp', new Date().getTime()); Eif (_callback) { _callback(); } } }); }, setUserContext: function setUserContext(dataToSend) { var controllerName = this.get('content.controllerName'); var changes = dataToSend.changed_configurations; Iif (changes) { dataToSend['user_context'] = { "operation": "EditConfig" }; } else { Eif (!controllerName) { dataToSend['user_context'] = { "operation": "RecommendAttribute" }; } else if (controllerName == 'addServiceController') { dataToSend['user_context'] = { "operation": "AddService", "operation_details": (this.get('content.services') || []).filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName').join(',') }; } else if (controllerName == 'installerController') { dataToSend['user_context'] = { "operation": "ClusterCreate" }; } } }, /** * Defines if there is any changes made by user. * Check all properties except recommended properties from popup * * @returns {boolean} */ isConfigHasInitialState: function isConfigHasInitialState() { return Boolean(this.get('selectedConfigGroup.isDefault') && !Em.isNone(this.get('recommendationsConfigs')) && !this.get('stepConfigs').filter(function (stepConfig) { return stepConfig.get('changedConfigProperties').filter(function (c) { var changedConfigIds = this.get('changedProperties').map(function (changed) { return App.config.configId(changed.propertyName, changed.propertyFileName); }); return !changedConfigIds.contains(App.config.configId(c.get('name'), c.get('filename'))); }, this).length; }, this).length); }, /** * generates JSON with config group info to send it for recommendations * @param configs * @param configGroup * @param {boolean} isAutoComplete * @returns {{configurations: Object[], hosts: string[]}} */ buildConfigGroupJSON: function buildConfigGroupJSON(configs, configGroup, isAutoComplete) { Em.assert('configGroup can\'t be null', configGroup); if (isAutoComplete) { return { group_id: Number(configGroup.get('id')) }; } var hosts = configGroup.get('hosts'); var configurations = {}; var overrides = configs.forEach(function (cp) { var override = cp.get('overrides') && cp.get('overrides').findProperty('group.name', configGroup.get('name')); if (override) { var tag = App.config.getConfigTagFromFileName(cp.get('filename')); if (!configurations[tag]) { configurations[tag] = { properties: {} }; } configurations[tag].properties[cp.get('name')] = override.get('value'); } }); return { configurations: [configurations], hosts: hosts, group_id: Number(configGroup.get('id')) }; }, /** * shows popup with results for recommended value * if case properties that was changes belongs to not default group * user should pick to what config group from dependent service dependent properties will be saved * @param data * @param opt * @param params * @method dependenciesSuccess */ loadRecommendationsSuccess: function loadRecommendationsSuccess(data, opt, params) { this._saveRecommendedValues(data, params.dataToSend.changed_configurations); if (this.isConfigHasInitialState()) { /** clearing all recommendations info **/ this.undoRedoRecommended(this.get('recommendations'), false); this.clearAllRecommendations(); /** * resetting recommendations to initial state * this case can be present when installed services depends on new added service on ADW **/ this.undoRedoRecommended(this.get('initialRecommendations'), true); this.get('initialRecommendations').forEach(function (r) { this.get('recommendations').pushObject(r); }, this); } this.set("recommendationsConfigs", Em.get(data, "resources.0.recommendations.blueprint.configurations")); }, loadRecommendationsError: Em.K, changedDependentGroup: function changedDependentGroup() { var dependentServices = this.get('selectedService.dependentServiceNames'); var isInstallWizard = this.get('content.controllerName') === 'installerController'; var installedServices = App.Service.find().mapProperty('serviceName'); var services = this.get('stepConfigs').filter(function (stepConfig) { if (dependentServices.contains(stepConfig.get('serviceName'))) { return isInstallWizard ? true : installedServices.contains(stepConfig.get('serviceName')); } return false; }, this); App.showSelectGroupsPopup(this.get('selectedService.serviceName'), this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name')), services, this.get('recommendations')); }, /** * saves values from response for dependent config properties to <code>recommendations<code> * @param data * @param [changedConfigs=null] * @method saveRecommendedValues * @private */ _saveRecommendedValues: function _saveRecommendedValues(data, changedConfigs) { Em.assert('invalid data - `data.resources[0].recommendations.blueprint.configurations` not defined ', data && data.resources[0] && Em.get(data.resources[0], 'recommendations.blueprint.configurations')); var recommendations = data.resources[0].recommendations; if (recommendations['config-groups'] && this.get('selectedConfigGroup') && !this.get('selectedConfigGroup.isDefault')) { this.saveConfigGroupsRecommendations(recommendations, changedConfigs); } else { var configObject = recommendations.blueprint.configurations; this.get('stepConfigs').forEach(function (stepConfig) { this.updateConfigsByRecommendations(configObject, stepConfig.get('configs'), changedConfigs); }, this); this.addByRecommendations(configObject, changedConfigs); } this.cleanUpRecommendations(); }, /** * * @param {object} recommendations * @param {?Array} changedConfigs */ saveConfigGroupsRecommendations: function saveConfigGroupsRecommendations(recommendations, changedConfigs) { var configForGroup = recommendations['config-groups'][0]; this.get('stepConfigs').forEach(function (stepConfig) { var configGroup = this.getGroupForService(stepConfig.get('serviceName')); if (configGroup && this.isConfigGroupAffected(configForGroup.hosts, configGroup.get('hosts'))) { this.updateOverridesByRecommendations(configForGroup.configurations, stepConfig.get('configs'), changedConfigs, configGroup); this.updateOverridesByRecommendations(configForGroup.dependent_configurations, stepConfig.get('configs'), changedConfigs, configGroup); this.toggleProperty('forceUpdateBoundaries'); } }, this); }, /** * determine whether hosts of group affected by config modifications * @param {Array} affectedHosts * @param {Array} groupHosts * @returns {boolean} */ isConfigGroupAffected: function isConfigGroupAffected(affectedHosts, groupHosts) { return _.intersection(affectedHosts, groupHosts).length > 0; }, /** * method to show popup with dependent configs * @method showChangedDependentConfigs */ showChangedDependentConfigs: function showChangedDependentConfigs(event, callback, secondary) { var self = this; var recommendations = event ? this.get('changedProperties') : this.get('recommendations'), recommendedChanges = recommendations.filterProperty('isEditable'), requiredChanges = this.filterRequiredChanges(recommendations); if (recommendedChanges.length > 0 || requiredChanges.length > 0) { App.showDependentConfigsPopup(recommendedChanges, requiredChanges, function () { self.onSaveRecommendedPopup(recommendedChanges.concat(requiredChanges)); Eif (callback) callback(); }, secondary, this); } else { Eif (callback) callback(); } }, /** * * @param {Array} recommendations * @returns {Array} */ filterRequiredChanges: function filterRequiredChanges(recommendations) { return recommendations.filter(function (recommendation) { if (recommendation.isEditable === false) { if (!this.get('selectedConfigGroup.isDefault')) { return App.ServiceConfigGroup.defaultGroupName !== recommendation.configGroup; } else { return true; } } }, this); }, /** * update configs when toggle checkbox on dependent configs popup */ onSaveRecommendedPopup: function onSaveRecommendedPopup(recommendations) { var propertiesToUpdate = recommendations.filter(function (c) { return Em.get(c, 'saveRecommendedDefault') !== Em.get(c, 'saveRecommended'); }), propertiesToUndo = propertiesToUpdate.filterProperty('saveRecommended', false), propertiesToRedo = propertiesToUpdate.filterProperty('saveRecommended', true); this.undoRedoRecommended(propertiesToUndo, false); this.undoRedoRecommended(propertiesToRedo, true); this.set('recommendationTimeStamp', new Date().getTime()); }, /** * run through config properties list (form dependent popup) * and set value to default (undo) or recommended (redo) * this happens when toggle checkbox in popup * @param {Object[]} propertiesToUpdate * @param {boolean} redo */ undoRedoRecommended: function undoRedoRecommended(propertiesToUpdate, redo) { propertiesToUpdate.forEach(function (p) { var initial = redo ? Em.get(p, 'initialValue') : Em.get(p, 'recommendedValue'); var recommended = redo ? Em.get(p, 'recommendedValue') : Em.get(p, 'initialValue'); var stepConfig = this.get('stepConfigs').findProperty('serviceName', Em.get(p, 'serviceName')); var config = stepConfig.get('configs').find(function (scp) { return scp.get('name') === Em.get(p, 'propertyName') && scp.get('filename') === App.config.getOriginalFileName(Em.get(p, 'propertyFileName')); }); var selectedGroup = App.ServiceConfigGroup.find().filterProperty('serviceName', Em.get(p, 'serviceName')).findProperty('name', Em.get(p, 'configGroup')); if (selectedGroup.get('isDefault')) { this.setRecommendedForDefaultGroup(recommended, stepConfig, p, initial, config); } else { this.setRecommendedForGroup(recommended, selectedGroup, config, initial); } }, this); }, /** * * @param {string} recommended * @param {Em.Object} selectedGroup * @param {object} config * @param {string}initial */ setRecommendedForGroup: function setRecommendedForGroup(recommended, selectedGroup, config, initial) { if (Em.isNone(recommended)) { config.get('overrides').removeObject(config.getOverride(selectedGroup.get('name'))); } else if (Em.isNone(initial)) { this._addConfigOverrideRecommendation(config, recommended, null, selectedGroup); } else { var override = config.getOverride(selectedGroup.get('name')); Eif (override) { override.set('value', recommended); } } }, /** * * @param {string} recommended * @param {Em.Object} stepConfig * @param {object|Em.Object} prop * @param {string} initial * @param {object} config */ setRecommendedForDefaultGroup: function setRecommendedForDefaultGroup(recommended, stepConfig, prop, initial, config) { var name = Em.get(prop, 'propertyName'), filename = Em.get(prop, 'propertyFileName'); if (Em.isNone(recommended)) { stepConfig.get('configs').removeObject(config); } else if (Em.isNone(initial)) { var stackConfigProperty = App.configsCollection.getConfigByName(name, filename); stepConfig.get('configs').pushObject(this._createNewProperty(name, filename, Em.get(prop, 'serviceName'), recommended, stackConfigProperty ? stackConfigProperty.propertyDependsOn : [])); } else { Em.set(config, 'value', recommended); } }, saveInitialRecommendations: function saveInitialRecommendations() { this.get('recommendations').forEach(function (r) { this.get('initialRecommendations').pushObject(r); }, this); }, /** * disable saving recommended value for current config. Remove recommendation for useroverriden values * @param config * @param {boolean} saveRecommended * @method removeCurrentFromDependentList */ removeCurrentFromDependentList: function removeCurrentFromDependentList(config, saveRecommended) { var name = config.get('name'), fileName = config.get('filename'), group = config.get('group.name'); var recommendation = this.getRecommendation(name, fileName, group); Eif (recommendation) { Iif (config.get('didUserOverrideValue')) { this.removeRecommendation(name, fileName, group); } else { this.saveRecommendation(recommendation, saveRecommended); } } }, updateAttributesFromTheme: function updateAttributesFromTheme(serviceName) { this.prepareSectionsConfigProperties(serviceName); var service = this.get('stepConfigs').findProperty('serviceName', serviceName); if (service) { var serviceConfigs = service.get('configs'), configConditions = App.ThemeCondition.find().filter(function (condition) { var dependentConfigName = condition.get('configName'), dependentConfigFileName = condition.get('fileName'), configsToDependOn = condition.getWithDefault('configs', []); return serviceConfigs.some(function (serviceConfig) { var serviceConfigName = Em.get(serviceConfig, 'name'), serviceConfigFileName = Em.get(serviceConfig, 'filename'); return serviceConfigName === dependentConfigName && serviceConfigFileName === dependentConfigFileName || configsToDependOn.some(function (config) { var configName = config.configName, fileName = config.fileName; return serviceConfigName === configName && serviceConfigFileName === fileName; }); }); }); this.updateAttributesFromConditions(configConditions, serviceConfigs, serviceName); } }, prepareSectionsConfigProperties: function prepareSectionsConfigProperties(serviceName) { var _this = this; var tabs = App.Tab.find().filterProperty('serviceName', serviceName); tabs.forEach(function (tab) { _this.processTab(tab); tab.get('sectionRows').forEach(function (row) { row.forEach(function (section) { section.get('subsectionRows').forEach(function (subRow) { subRow.forEach(function (subsection) { _this.setConfigsToContainer(subsection); subsection.get('subSectionTabs').forEach(function (subSectionTab) { _this.setConfigsToContainer(subSectionTab); }); }); }); }); }); }); }, /** * set {code} configs {code} array of subsection or subsection tab. * Also correct widget should be used for each config (it's selected according to <code>widget.type</code> and * <code>widgetTypeMap</code>). It may throw an error if needed widget can't be found in the <code>widgetTypeMap</code> * @param containerObject */ setConfigsToContainer: function setConfigsToContainer(containerObject) { containerObject.set('configs', []); containerObject.get('configProperties').forEach(function (configId) { var config = App.configsCollection.getConfig(configId); if (Em.get(config, 'widgetType')) { var stepConfig = this.get('stepConfigs').findProperty('serviceName', Em.get(config, 'serviceName')); if (!stepConfig) return; var configProperty = stepConfig.get('configs').findProperty('id', Em.get(config, 'id')); if (!configProperty) return; containerObject.get('configs').pushObject(configProperty); var widget = this.getWidgetView(config); Em.assert('Unknown config widget view for config ' + configProperty.get('id') + ' with type ' + Em.get(config, 'widgetType'), widget); var additionalProperties = { widget: widget, stackConfigProperty: config }; var configConditions = App.ThemeCondition.find().filter(function (_configCondition) { // Filter config condition depending on the value of another config var conditionalConfigs = _configCondition.getWithDefault('configs', []).filterProperty('fileName', Em.get(config, 'filename')).filterProperty('configName', Em.get(config, 'name')); // Filter config condition depending on the service existence or service state var serviceConfigConditionFlag = _configCondition.get('configName') === Em.get(config, 'name') && _configCondition.get('fileName') === Em.get(config, 'filename') && _configCondition.get('resource') === 'service'; var conditions = void 0; if (serviceConfigConditionFlag) { var configCondition = { configName: _configCondition.get('configName'), fileName: _configCondition.get('fileName') }; conditions = conditionalConfigs.concat(configCondition); } else { conditions = conditionalConfigs; } return conditions && conditions.length; }); if (configConditions && configConditions.length) { additionalProperties.configConditions = configConditions; } var configAction = App.ConfigAction.find().filterProperty('fileName', Em.get(config, 'filename')).findProperty('configName', Em.get(config, 'name')); if (configAction) { additionalProperties.configAction = configAction; } configProperty.setProperties(additionalProperties); if (configProperty.get('overrides')) { configProperty.get('overrides').setEach('stackConfigProperty', config); } if (configProperty.get('compareConfigs')) { configProperty.get('compareConfigs').invoke('setProperties', { isComparison: false, stackConfigProperty: config }); } } }, this); }, /** * * @param {object} config * @returns {Em.View} */ getWidgetView: function getWidgetView(config) { var configWidgetType = Em.get(config, 'widgetType'), name = Em.get(config, 'name'), mixin = this.get('configNameWidgetMixinMap')[name], viewClass = App[this.get('widgetTypeMap')[configWidgetType]]; return Em.isNone(mixin) ? viewClass : viewClass.extend(mixin); }, updateAttributesFromConditions: function updateAttributesFromConditions(configConditions, serviceConfigs, serviceName) { var _this2 = this; var isConditionTrue = void 0; configConditions.forEach(function (configCondition) { var ifStatement = configCondition.get('if'); if (configCondition.get('resource') === 'config') { isConditionTrue = App.configTheme.calculateConfigCondition(ifStatement, serviceConfigs); if (configCondition.get('type') === 'subsection' || configCondition.get('type') === 'subsectionTab') { _this2.changeSubsectionAttribute(configCondition, isConditionTrue); } else { _this2.changeConfigAttribute(configCondition, isConditionTrue, serviceName); } } else if (configCondition.get('resource') === 'service') { var service = App.Service.find().findProperty('serviceName', ifStatement); if (service) { isConditionTrue = true; } else if (!service && _this2.get('allSelectedServiceNames') && _this2.get('allSelectedServiceNames').length) { isConditionTrue = _this2.get('allSelectedServiceNames').contains(ifStatement); } else { isConditionTrue = false; } _this2.changeConfigAttribute(configCondition, isConditionTrue, serviceName); } }); }, /** * * @param configCondition {App.ThemeCondition} * @param isConditionTrue {boolean} */ changeConfigAttribute: function changeConfigAttribute(configCondition, isConditionTrue, serviceName) { var conditionalConfigName = configCondition.get('configName'), conditionalConfigFileName = configCondition.get('fileName'), serviceConfigs = this.get('stepConfigs').findProperty('serviceName', serviceName).get('configs'), action = isConditionTrue ? configCondition.get('then') : configCondition.get('else'), valueAttributes = action.property_value_attributes; this.set('isChangingConfigAttributes', true); for (var key in valueAttributes) { if (valueAttributes.hasOwnProperty(key)) { var valueAttribute = App.StackConfigValAttributesMap[key] || key, conditionalConfig = serviceConfigs.filterProperty('filename', conditionalConfigFileName).findProperty('name', conditionalConfigName); if (conditionalConfig) { if (key === 'visible') { conditionalConfig.set('hiddenBySection', !valueAttributes[key]); } conditionalConfig.set(valueAttribute, valueAttributes[key]); } } } this.set('isChangingConfigAttributes', false); }, /** * * @param subsectionCondition {App.ThemeCondition} * @param isConditionTrue {boolean} */ changeSubsectionAttribute: function changeSubsectionAttribute(subsectionCondition, isConditionTrue) { var subsectionConditionName = subsectionCondition.get('name'); var action = isConditionTrue ? subsectionCondition.get('then') : subsectionCondition.get('else'); if (subsectionCondition.get('id')) { var valueAttributes = action.property_value_attributes; if (valueAttributes && !Em.none(valueAttributes.visible)) { var themeResource = void 0; if (subsectionCondition.get('type') === 'subsection') { themeResource = App.SubSection.find().find(function (subsection) { return subsection.get('name') === subsectionConditionName && subsectionCondition.get('themeName') === subsection.get('themeName'); }); } else if (subsectionCondition.get('type') === 'subsectionTab') { themeResource = App.SubSectionTab.find().find(function (subsectionTab) { return subsectionTab.get('name') === subsectionConditionName && subsectionCondition.get('themeName') === subsectionTab.get('themeName'); }); } themeResource.set('isHiddenByConfig', !valueAttributes.visible); themeResource.get('configs').setEach('hiddenBySection', !valueAttributes.visible); themeResource.get('configs').setEach('hiddenBySubSection', !valueAttributes.visible); } } }, /** * Data reordering before tabs rendering. * Reorder all sections/subsections into rows based on their rowIndex * @param tab */ processTab: function processTab(tab) { // process sections var sectionRows = []; var sections = tab.get('sections'); for (var j = 0; j < sections.get('length'); j++) { var section = sections.objectAt(j); var sectionRow = sectionRows[section.get('rowIndex')]; if (!sectionRow) { sectionRow = sectionRows[section.get('rowIndex')] = []; } sectionRow.push(section); //process subsections var subsections = section.get('subSections'); var subsectionRows = []; for (var k = 0; k < subsections.get('length'); k++) { var subsection = subsections.objectAt(k); var subsectionRow = subsectionRows[subsection.get('rowIndex')]; if (!subsectionRow) { subsectionRow = subsectionRows[subsection.get('rowIndex')] = []; } subsectionRow.push(subsection); // leave a title gap if one of the subsection on the same row within the same section has title if (subsection.get('displayName')) { subsectionRow.hasTitleGap = true; } } section.set('subsectionRows', subsectionRows); } tab.set('sectionRows', sectionRows); } }); }); |