step5_view.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. var stringUtils = require('utils/string_utils');
  20. App.WizardStep5View = Em.View.extend({
  21. templateName: require('templates/wizard/step5'),
  22. /**
  23. * If install more than 25 hosts, should use App.InputHostView for hosts selection
  24. * Otherwise - App.SelectHostView
  25. * @type {bool}
  26. */
  27. shouldUseInputs: function() {
  28. return this.get('controller.hosts.length') > 25;
  29. }.property('controller.hosts.length'),
  30. didInsertElement: function () {
  31. this.get('controller').loadStep();
  32. this.setCoHostedComponentText();
  33. },
  34. coHostedComponentText: '',
  35. setCoHostedComponentText: function () {
  36. var coHostedComponents = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted').filterProperty('stackService.isSelected');
  37. var coHostedComponentsText = '';
  38. coHostedComponents.forEach(function (serviceComponent, index) {
  39. var coHostedComponentsDisplayNames = serviceComponent.get('coHostedComponents').map(function (item) {
  40. return App.StackServiceComponent.find().findProperty('componentName', item).get('displayName');
  41. });
  42. var componentTextArr = [serviceComponent.get('displayName')].concat(coHostedComponentsDisplayNames);
  43. coHostedComponents[index] = stringUtils.getFormattedStringFromArray(componentTextArr);
  44. coHostedComponentsText += '<br/>' + Em.I18n.t('installer.step5.body.coHostedComponents').format(coHostedComponents[index]);
  45. }, this);
  46. this.set('coHostedComponentText', coHostedComponentsText);
  47. }
  48. });
  49. App.InputHostView = Em.TextField.extend(App.SelectHost, {
  50. attributeBindings: ['disabled'],
  51. /**
  52. * Saved typeahead component
  53. * @type {$}
  54. */
  55. typeahead: null,
  56. /**
  57. * When <code>value</code> (host_info) is changed this method is triggered
  58. * If new hostname is valid, this host is assigned to master component
  59. * @method changeHandler
  60. */
  61. changeHandler: function() {
  62. if (!this.shouldChangeHandlerBeCalled()) return;
  63. var host = this.get('controller.hosts').findProperty('host_info', this.get('value'));
  64. if (Em.isNone(host)) {
  65. this.get('controller').updateIsHostNameValidFlag(this.get("component.component_name"), this.get("component.zId"), false);
  66. return;
  67. }
  68. this.get('controller').assignHostToMaster(this.get("component.component_name"), host.get('host_name'), this.get("component.zId"));
  69. this.tryTriggerRebalanceForMultipleComponents();
  70. }.observes('controller.hostNameCheckTrigger'),
  71. didInsertElement: function () {
  72. this.initContent();
  73. var value = this.get('content').findProperty('host_name', this.get('component.selectedHost')).get('host_info');
  74. this.set("value", value);
  75. var content = this.get('content').mapProperty('host_info'),
  76. self = this,
  77. typeahead = this.$().typeahead({items: 10, source: content, minLength: 0});
  78. typeahead.on('blur', function() {
  79. self.change();
  80. }).on('keyup', function(e) {
  81. self.set('value', $(e.currentTarget).val());
  82. self.change();
  83. });
  84. this.set('typeahead', typeahead);
  85. },
  86. /**
  87. * Extract hosts from controller,
  88. * filter out available to selection and
  89. * push them into Em.Select content
  90. * @method initContent
  91. */
  92. initContent: function () {
  93. this._super();
  94. this.updateTypeaheadData(this.get('content').mapProperty('host_info'));
  95. },
  96. /**
  97. * Update <code>source</code> property of <code>typeahead</code> with a new list of hosts
  98. * @param {string[]} hosts
  99. * @method updateTypeaheadData
  100. */
  101. updateTypeaheadData: function(hosts) {
  102. if (this.get('typeahead')) {
  103. this.get('typeahead').data('typeahead').source = hosts;
  104. }
  105. }
  106. });
  107. App.SelectHostView = Em.Select.extend(App.SelectHost, {
  108. attributeBindings: ['disabled'],
  109. didInsertElement: function () {
  110. this.initContent();
  111. this.set("value", this.get("component.selectedHost"));
  112. },
  113. /**
  114. * Handler for selected value change
  115. * @method change
  116. */
  117. changeHandler: function () {
  118. if (!this.shouldChangeHandlerBeCalled()) return;
  119. this.get('controller').assignHostToMaster(this.get("component.component_name"), this.get("value"), this.get("component.zId"));
  120. this.tryTriggerRebalanceForMultipleComponents();
  121. }.observes('controller.hostNameCheckTrigger'),
  122. /**
  123. * On click handler
  124. * @method click
  125. */
  126. click: function () {
  127. this.initContent();
  128. }
  129. });
  130. App.AddControlView = Em.View.extend({
  131. /**
  132. * Current component name
  133. * @type {string}
  134. */
  135. componentName: null,
  136. tagName: "span",
  137. classNames: ["badge", "badge-important"],
  138. template: Em.Handlebars.compile('+'),
  139. /**
  140. * Onclick handler
  141. * Add selected component
  142. * @method click
  143. */
  144. click: function () {
  145. this.get('controller').addComponent(this.get('componentName'));
  146. }
  147. });
  148. App.RemoveControlView = Em.View.extend({
  149. /**
  150. * Index for multiple component
  151. * @type {number}
  152. */
  153. serviceComponentId: null,
  154. /**
  155. * Current component name
  156. * @type {string}
  157. */
  158. componentName: null,
  159. tagName: "span",
  160. classNames: ["badge", "badge-important"],
  161. template: Em.Handlebars.compile('-'),
  162. /**
  163. * Onclick handler
  164. * Remove current component
  165. * @method click
  166. */
  167. click: function () {
  168. this.get('controller').removeComponent(this.get('componentName'), this.get("serviceComponentId"));
  169. }
  170. });