step3_view.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.WizardStep3View = App.TableView.extend({
  20. templateName: require('templates/wizard/step3'),
  21. content:function () {
  22. return this.get('controller.hosts');
  23. }.property('controller.hosts.length'),
  24. message:'',
  25. linkText: '',
  26. status: '',
  27. selectedCategory: function() {
  28. return this.get('categories').findProperty('isActive');
  29. }.property('categories.@each.isActive'),
  30. registeredHostsMessage: '',
  31. displayLength: "25",
  32. didInsertElement: function () {
  33. this.get('controller').loadStep();
  34. },
  35. pageChecked: false,
  36. /**
  37. * select checkboxes of hosts on page
  38. */
  39. onPageChecked: function () {
  40. if (this.get('selectionInProgress')) return;
  41. this.get('pageContent').setEach('isChecked', this.get('pageChecked'));
  42. }.observes('pageChecked'),
  43. /**
  44. * select checkboxes of all hosts
  45. */
  46. selectAll: function () {
  47. this.get('content').setEach('isChecked', true);
  48. },
  49. /**
  50. * reset checkbox of all hosts
  51. */
  52. unSelectAll: function() {
  53. this.get('content').setEach('isChecked', false);
  54. },
  55. watchSelectionOnce: function () {
  56. Em.run.once(this, 'watchSelection');
  57. }.observes('content.@each.isChecked', 'pageContent'),
  58. /**
  59. * watch selection and calculate such flags as:
  60. * - noHostsSelected
  61. * - selectedHostsCount
  62. * - pageChecked
  63. */
  64. watchSelection: function() {
  65. this.set('selectionInProgress', true);
  66. this.set('pageChecked', !!this.get('pageContent.length') && this.get('pageContent').everyProperty('isChecked', true));
  67. this.set('selectionInProgress', false);
  68. var noHostsSelected = true;
  69. var selectedHostsCount = 0;
  70. this.get('content').forEach(function(host){
  71. selectedHostsCount += ~~host.get('isChecked');
  72. noHostsSelected = (noHostsSelected) ? !host.get('isChecked') : noHostsSelected;
  73. });
  74. this.set('noHostsSelected', noHostsSelected);
  75. this.set('selectedHostsCount', selectedHostsCount);
  76. },
  77. setRegisteredHosts: function(){
  78. this.set('registeredHostsMessage',Em.I18n.t('installer.step3.warning.registeredHosts').format(this.get('controller.registeredHosts').length));
  79. }.observes('controller.registeredHosts'),
  80. categoryObject: Em.Object.extend({
  81. hostsCount: 0,
  82. label: function () {
  83. return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount'));
  84. }.property('value', 'hostsCount'),
  85. isActive: false,
  86. itemClass: function () {
  87. return this.get('isActive') ? 'active' : '';
  88. }.property('isActive')
  89. }),
  90. categories: function () {
  91. return [
  92. this.categoryObject.create({value: Em.I18n.t('common.all'), hostsBootStatus: 'ALL', isActive: true}),
  93. this.categoryObject.create({value: Em.I18n.t('installer.step3.hosts.status.installing'), hostsBootStatus: 'RUNNING'}),
  94. this.categoryObject.create({value: Em.I18n.t('installer.step3.hosts.status.registering'), hostsBootStatus: 'REGISTERING'}),
  95. this.categoryObject.create({value: Em.I18n.t('common.success'), hostsBootStatus: 'REGISTERED' }),
  96. this.categoryObject.create({value: Em.I18n.t('common.fail'), hostsBootStatus: 'FAILED', last: true })
  97. ];
  98. }.property(),
  99. hostBootStatusObserver: function(){
  100. Ember.run.once(this, 'countCategoryHosts');
  101. Ember.run.once(this, 'filter');
  102. Ember.run.once(this, 'monitorStatuses');
  103. }.observes('content.@each.bootStatus'),
  104. countCategoryHosts: function () {
  105. var counters = {
  106. "RUNNING": 0,
  107. "REGISTERING": 0,
  108. "REGISTERED": 0,
  109. "FAILED": 0
  110. };
  111. this.get('content').forEach(function (host) {
  112. if (counters[host.get('bootStatus')] !== undefined) {
  113. counters[host.get('bootStatus')]++;
  114. }
  115. }, this);
  116. counters["ALL"] = this.get('content.length');
  117. this.get('categories').forEach(function(category) {
  118. category.set('hostsCount', counters[category.get('hostsBootStatus')]);
  119. }, this);
  120. },
  121. /**
  122. * filter hosts by category
  123. */
  124. filter: function () {
  125. var self = this;
  126. Em.run.next(function () {
  127. var result = [];
  128. var selectedCategory = self.get('selectedCategory');
  129. if (!selectedCategory || selectedCategory.get('hostsBootStatus') === 'ALL') {
  130. result = self.get('content');
  131. } else {
  132. result = self.get('content').filterProperty('bootStatus', self.get('selectedCategory.hostsBootStatus'));
  133. }
  134. self.set('filteredContent', result);
  135. });
  136. }.observes('selectedCategory'),
  137. /**
  138. * Trigger on Category click
  139. * @param {Object} event
  140. */
  141. selectCategory: function (event) {
  142. var categoryStatus = event.context.get('hostsBootStatus');
  143. var self = this;
  144. this.get('categories').forEach(function (category) {
  145. category.set('isActive', (category.get('hostsBootStatus') === categoryStatus));
  146. });
  147. this.watchSelection();
  148. },
  149. /**
  150. * Select "All" hosts category
  151. * run registration of failed hosts again
  152. */
  153. retrySelectedHosts: function () {
  154. var eventObject = {context: Em.Object.create({hostsBootStatus: 'ALL'})};
  155. this.selectCategory(eventObject);
  156. this.get('controller').retrySelectedHosts();
  157. },
  158. monitorStatuses: function() {
  159. var hosts = this.get('controller.bootHosts');
  160. var failedHosts = hosts.filterProperty('bootStatus', 'FAILED').length;
  161. if (hosts.length === 0) {
  162. this.set('status', 'alert-warn');
  163. this.set('linkText', '');
  164. this.set('message', Em.I18n.t('installer.step3.warnings.missingHosts'));
  165. } else if (!this.get('controller.isWarningsLoaded')) {
  166. this.set('status', 'alert-info');
  167. this.set('linkText', '');
  168. this.set('message', Em.I18n.t('installer.step3.warning.loading'));
  169. } else if (this.get('controller.isHostHaveWarnings') || this.get('controller.repoCategoryWarnings.length') || this.get('controller.diskCategoryWarnings.length')) {
  170. this.set('status', 'alert-warn');
  171. this.set('linkText', Em.I18n.t('installer.step3.warnings.linkText'));
  172. this.set('message', Em.I18n.t('installer.step3.warnings.fails').format(hosts.length - failedHosts));
  173. } else {
  174. this.set('status', 'alert-success');
  175. this.set('linkText', Em.I18n.t('installer.step3.noWarnings.linkText'));
  176. if (failedHosts == 0) {
  177. // all are ok
  178. this.set('message', Em.I18n.t('installer.step3.warnings.noWarnings').format(hosts.length));
  179. } else if (failedHosts == hosts.length) {
  180. // all failed
  181. this.set('status', 'alert-warn');
  182. this.set('linkText', '');
  183. this.set('message', Em.I18n.t('installer.step3.warnings.allFailed').format(failedHosts));
  184. } else {
  185. // some failed
  186. this.set('message', Em.I18n.t('installer.step3.warnings.someWarnings').format((hosts.length - failedHosts), failedHosts));
  187. }
  188. }
  189. }.observes('controller.isWarningsLoaded', 'controller.isHostHaveWarnings', 'controller.repoCategoryWarnings', 'controller.diskCategoryWarnings')
  190. });
  191. //todo: move it inside WizardStep3View
  192. App.WizardHostView = Em.View.extend({
  193. tagName: 'tr',
  194. classNameBindings: ['hostInfo.bootStatus'],
  195. hostInfo: null,
  196. remove: function () {
  197. this.get('controller').removeHost(this.get('hostInfo'));
  198. },
  199. retry: function() {
  200. this.get('controller').retryHost(this.get('hostInfo'));
  201. },
  202. isRemovable: function () {
  203. return true;
  204. }.property(),
  205. isRetryable: function() {
  206. // return ['FAILED'].contains(this.get('hostInfo.bootStatus'));
  207. return false;
  208. }.property('hostInfo.bootStatus')
  209. });