/** * 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'); /** * By Step 7, we have the following information stored in App.db and set on this * controller by the router. * * selectedServices: App.db.selectedServices (the services that the user selected in Step 4) * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5) * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6) * */ App.WizardStep7Controller = Em.Controller.extend({ name: 'wizardStep7Controller', stepConfigs: [], //contains all field properties that are viewed in this step selectedService: null, slaveHostToGroup: null, isSubmitDisabled: function () { return !this.stepConfigs.everyProperty('errorCount', 0); }.property('stepConfigs.@each.errorCount'), selectedServiceNames : function(){ return this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName'); }.property('content.services').cacheable(), masterComponentHosts : function(){ return this.get('content.masterComponentHosts'); }.property('content.masterComponentHosts'), slaveComponentHosts : function(){ return this.get('content.slaveComponentHosts'); }.property('content.slaveComponentHosts'), serviceConfigs: require('data/service_configs'), clearStep: function () { this.get('stepConfigs').clear(); }, /** * On load function */ loadStep: function () { console.log("TRACE: Loading step7: Configure Services"); this.clearStep(); this.renderServiceConfigs(this.serviceConfigs); var storedServices = this.get('content.serviceConfigProperties'); if (storedServices) { var configs = new Ember.Set(); // for all services` this.get('stepConfigs').forEach(function (_content) { //for all components _content.get('configs').forEach(function (_config) { var componentVal = storedServices.findProperty('name', _config.get('name')); //if we have config for specified component if(componentVal){ //set it _config.set('value', componentVal.value) } }, this); }, this); } }, /** * Render configs for active services * @param serviceConfigs */ renderServiceConfigs: function (serviceConfigs) { serviceConfigs.forEach(function (_serviceConfig) { var serviceConfig = App.ServiceConfig.create({ serviceName: _serviceConfig.serviceName, displayName: _serviceConfig.displayName, configCategories: _serviceConfig.configCategories, configs: [] }); if (this.get('selectedServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') { this.loadComponentConfigs(_serviceConfig, serviceConfig); console.log('pushing ' + serviceConfig.serviceName); this.get('stepConfigs').pushObject(serviceConfig); } else { console.log('skipping ' + serviceConfig.serviceName); } }, this); this.set('selectedService', this.get('stepConfigs').objectAt(0)); }, /** * Load child components to service config object * @param _componentConfig * @param componentConfig */ loadComponentConfigs: function (_componentConfig, componentConfig) { _componentConfig.configs.forEach(function (_serviceConfigProperty) { var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty); serviceConfigProperty.serviceConfig = componentConfig; serviceConfigProperty.initialValue(); componentConfig.configs.pushObject(serviceConfigProperty); serviceConfigProperty.validate(); }, this); }, submit: function () { if (!this.get('isSubmitDisabled')) { App.router.send('next'); } } });