step2.js 3.9 KB

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