component.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /**
  19. * Here will be stored slave functions related to components
  20. * @type {Object}
  21. */
  22. var App = require('app');
  23. module.exports = {
  24. /**
  25. * This needs to be done because mapper functions like App.stackServiceComponentMapper.map(data) does not override
  26. * but unions the instances. So on re-navigation if the stack is switched and this function is not called then union of
  27. * StackServiceComponent of both the stacks will be mapped to the model.
  28. */
  29. clearStackModel: function() {
  30. if (App.StackServiceComponent.find().get('content').length) {
  31. App.StackServiceComponent.find().set('content', []);
  32. }
  33. },
  34. /**
  35. * Format and load info about components to StackServiceComponent model.
  36. *
  37. * @method loadStackServiceComponentModel
  38. * @param data {object} response from server
  39. * @return {object} formatted info about components
  40. */
  41. loadStackServiceComponentModel: function(data) {
  42. this.clearStackModel();
  43. var serviceComponents = {items: []};
  44. data.items.forEach(function(item){
  45. item.serviceComponents.forEach(function(_serviceComponent, indx){
  46. var stackServiceComponents = _serviceComponent.StackServiceComponents;
  47. var serviceComponent = {
  48. component_name: stackServiceComponents.component_name,
  49. service_name: stackServiceComponents.service_name,
  50. component_category: stackServiceComponents.component_category,
  51. is_master: stackServiceComponents.is_master,
  52. is_client: stackServiceComponents.is_client,
  53. stack_name: stackServiceComponents.stack_name,
  54. stack_version: stackServiceComponents.stack_version,
  55. id: indx
  56. };
  57. serviceComponents.items.pushObject(serviceComponent);
  58. }, this);
  59. }, this);
  60. App.stackServiceComponentMapper.map(serviceComponents);
  61. App.handleStackDependedComponents();
  62. return serviceComponents;
  63. }
  64. };