step2.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
  20. name: 'mainAdminSecurityAddStep2Controller',
  21. stepConfigs: [],
  22. installedServices: [],
  23. serviceConfigs: require('data/secure_configs'),
  24. selectedService: null,
  25. isSubmitDisabled: function () {
  26. return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
  27. }.property('stepConfigs.@each.errorCount'),
  28. clearStep: function () {
  29. this.get('stepConfigs').clear();
  30. },
  31. /**
  32. * Function is called whenever the step is loaded
  33. */
  34. loadStep: function () {
  35. console.log("TRACE: Loading addSecurity step2: Configure Services");
  36. this.clearStep();
  37. var serviceConfigs = this.get('serviceConfigs');
  38. this.renderServiceConfigs(this.get('content.services'));
  39. var storedServices = this.get('content.serviceConfigProperties');
  40. if (storedServices) {
  41. var configs = new Ember.Set();
  42. // for all services`
  43. this.get('stepConfigs').forEach(function (_content) {
  44. //for all components
  45. _content.get('configs').forEach(function (_config) {
  46. var componentVal = storedServices.findProperty('name', _config.get('name'));
  47. //if we have config for specified component
  48. if (componentVal) {
  49. //set it
  50. _config.set('value', componentVal.value)
  51. }
  52. }, this);
  53. }, this);
  54. }
  55. //
  56. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  57. console.log("The services are: " + this.get('installedServices'));
  58. //
  59. },
  60. /**
  61. * Render configs for active services
  62. * @param serviceConfigs
  63. */
  64. renderServiceConfigs: function (serviceConfigs) {
  65. this.get('serviceConfigs').forEach(function (_serviceConfig) {
  66. var serviceConfig = App.ServiceConfig.create({
  67. filename: _serviceConfig.filename,
  68. serviceName: _serviceConfig.serviceName,
  69. displayName: _serviceConfig.displayName,
  70. configCategories: _serviceConfig.configCategories,
  71. showConfig: false,
  72. configs: []
  73. });
  74. if (serviceConfigs.someProperty('serviceName', serviceConfig.serviceName)) {
  75. serviceConfig.showConfig = true;
  76. }
  77. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  78. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  79. this.get('stepConfigs').pushObject(serviceConfig);
  80. }, this);
  81. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  82. },
  83. /**
  84. * Load child components to service config object
  85. * @param _componentConfig
  86. * @param componentConfig
  87. */
  88. loadComponentConfigs: function (_componentConfig, componentConfig) {
  89. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  90. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  91. //serviceConfigProperty.serviceConfig = componentConfig;
  92. //serviceConfigProperty.initialValue();
  93. componentConfig.configs.pushObject(serviceConfigProperty);
  94. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  95. serviceConfigProperty.validate();
  96. }, this);
  97. },
  98. /**
  99. * submit and move to step3
  100. */
  101. submit: function () {
  102. if (!this.get('isSubmitDisabled')) {
  103. App.router.send('next');
  104. }
  105. }
  106. });