step2_controller.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.ReassignMasterWizardStep2Controller = Em.Controller.extend(App.BlueprintMixin, App.AssignMasterComponents, {
  20. name: "reassignMasterWizardStep2Controller",
  21. useServerValidation: false,
  22. mastersToShow: function () {
  23. return [this.get('content.reassign.component_name')];
  24. }.property('content.reassign.component_name'),
  25. mastersToMove: function () {
  26. return [this.get('content.reassign.component_name')];
  27. }.property('content.reassign.component_name'),
  28. /**
  29. * Show 'Current: <host>' for masters with single instance
  30. */
  31. additionalHostsList: function () {
  32. if (this.get('servicesMastersToShow.length') === 1) {
  33. return [
  34. {
  35. label: Em.I18n.t('services.reassign.step2.currentHost'),
  36. host: App.HostComponent.find().findProperty('componentName', this.get('content.reassign.component_name')).get('hostName')
  37. }
  38. ];
  39. }
  40. return [];
  41. }.property('content.reassign.component_name', 'servicesMastersToShow.length'),
  42. /**
  43. * Assignment is valid only if for one master component host was changed
  44. * @returns {boolean}
  45. */
  46. customClientSideValidation: function () {
  47. var reassigned = 0;
  48. var existedComponents = App.HostComponent.find().filterProperty('componentName', this.get('content.reassign.component_name')).mapProperty('hostName');
  49. var newComponents = this.get('servicesMasters').filterProperty('component_name', this.get('content.reassign.component_name')).mapProperty('selectedHost');
  50. existedComponents.forEach(function (host) {
  51. if (!newComponents.contains(host)) {
  52. reassigned++;
  53. }
  54. }, this);
  55. return reassigned === 1;
  56. }
  57. });