/** * 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'); App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({ name: 'mainAdminSecurityAddStep2Controller', stepConfigs: [], installedServices: [], selectedService: null, isSubmitDisabled: function () { return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0); }.property('stepConfigs.@each.errorCount'), clearStep: function () { this.get('stepConfigs').clear(); }, /** * Function is called whenever the step is loaded */ loadStep: function () { console.log("TRACE: Loading addSecurity step2: Configure Services"); this.clearStep(); this.renderServiceConfigs(this.get('content.services')); 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); } // this.set('installedServices', App.Service.find().mapProperty('serviceName')); console.log("The services are: " + this.get('installedServices')); // }, /** * Render configs for active services * @param serviceConfigs */ renderServiceConfigs: function (serviceConfigs) { serviceConfigs.forEach(function (_serviceConfig) { var serviceConfig = App.ServiceConfig.create({ filename: _serviceConfig.filename, serviceName: _serviceConfig.serviceName, displayName: _serviceConfig.displayName, configCategories: _serviceConfig.configCategories, showConfig: true, configs: [] }); this.loadComponentConfigs(_serviceConfig, serviceConfig); console.log('pushing ' + serviceConfig.serviceName, serviceConfig); this.get('stepConfigs').pushObject(serviceConfig); }, this); this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).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.set('isEditable', serviceConfigProperty.get('isReconfigurable')); serviceConfigProperty.validate(); }, this); }, /** * submit and move to step3 */ submit: function () { if (!this.get('isSubmitDisabled')) { App.router.send('next'); } } });