host.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 validator = require('utils/validator');
  20. var componentHelper = require('utils/component');
  21. App.MainHostController = Em.ArrayController.extend({
  22. name:'mainHostController',
  23. content: App.Host.find(),
  24. comeWithFilter: false,
  25. alerts: function () {
  26. return App.router.get('clusterController.alerts').filterProperty('isOk', false).filterProperty('ignoredForHosts', false);
  27. }.property('App.router.clusterController.alerts.length'),
  28. /**
  29. * Components which will be shown in component filter
  30. */
  31. componentsForFilter:function() {
  32. var installedComponents = componentHelper.getInstalledComponents();
  33. installedComponents.setEach('checkedForHostFilter', false);
  34. return installedComponents;
  35. }.property('App.router.clusterController.isLoaded'),
  36. masterComponents:function () {
  37. return this.get('componentsForFilter').filterProperty('isMaster', true);
  38. }.property('componentsForFilter'),
  39. slaveComponents:function () {
  40. return this.get('componentsForFilter').filterProperty('isSlave', true);
  41. }.property('componentsForFilter'),
  42. clientComponents: function() {
  43. return this.get('componentsForFilter').filterProperty('isClient', true);
  44. }.property('componentsForFilter'),
  45. /**
  46. * Is true if alets filter is active
  47. */
  48. filteredByAlerts:false,
  49. /**
  50. * Is true if Hosts page was opened by clicking on alerts count badge
  51. */
  52. comeWithAlertsFilter: false,
  53. /**
  54. * Enable or disable filtering by alets
  55. */
  56. filterByAlerts: function () {
  57. if (App.router.get('currentState.name') == 'index') {
  58. this.set('filteredByAlerts', !this.get('filteredByAlerts'));
  59. } else {
  60. App.router.transitionTo('hosts.index');
  61. this.set('comeWithAlertsFilter', true);
  62. }
  63. },
  64. /**
  65. * Filter hosts by componentName of <code>component</code>
  66. * @param component App.HostComponent
  67. */
  68. filterByComponent:function (component) {
  69. var id = component.get('componentName');
  70. this.get('componentsForFilter').setEach('checkedForHostFilter', false);
  71. this.get('componentsForFilter').filterProperty('id', id).setEach('checkedForHostFilter', true);
  72. this.set('comeWithFilter', true);
  73. },
  74. /**
  75. * On click callback for decommission button
  76. * @param event
  77. */
  78. decommissionButtonPopup:function () {
  79. var self = this;
  80. App.ModalPopup.show({
  81. header:Em.I18n.t('hosts.decommission.popup.header'),
  82. body:Em.I18n.t('hosts.decommission.popup.body'),
  83. primary:'Yes',
  84. secondary:'No',
  85. onPrimary:function () {
  86. alert('do');
  87. this.hide();
  88. },
  89. onSecondary:function () {
  90. this.hide();
  91. }
  92. });
  93. },
  94. /**
  95. * On click callback for delete button
  96. * @param event
  97. */
  98. deleteButtonPopup:function () {
  99. var self = this;
  100. App.ModalPopup.show({
  101. header:Em.I18n.t('hosts.delete.popup.header'),
  102. body:Em.I18n.t('hosts.delete.popup.body'),
  103. primary:'Yes',
  104. secondary:'No',
  105. onPrimary:function () {
  106. self.removeHosts();
  107. this.hide();
  108. },
  109. onSecondary:function () {
  110. this.hide();
  111. }
  112. });
  113. },
  114. showAlertsPopup: function (event) {
  115. var host = event.context;
  116. App.ModalPopup.show({
  117. header: this.t('services.alerts.headingOfList'),
  118. bodyClass: Ember.View.extend({
  119. hostAlerts: function () {
  120. var allAlerts = App.router.get('clusterController.alerts').filterProperty('ignoredForHosts', false);
  121. if (host) {
  122. return allAlerts.filterProperty('hostName', host.get('hostName'));
  123. }
  124. return 0;
  125. }.property('App.router.clusterController.alerts'),
  126. closePopup: function () {
  127. this.get('parentView').hide();
  128. },
  129. templateName: require('templates/main/host/alerts_popup')
  130. }),
  131. primary: 'Close',
  132. onPrimary: function() {
  133. this.hide();
  134. },
  135. secondary : null,
  136. didInsertElement: function () {
  137. this.$().find('.modal-footer').addClass('align-center');
  138. this.$().children('.modal').css({'margin-top': '-350px'});
  139. }
  140. });
  141. event.stopPropagation();
  142. },
  143. /**
  144. * remove selected hosts
  145. */
  146. removeHosts:function () {
  147. var hosts = this.get('content');
  148. var selectedHosts = hosts.filterProperty('isChecked', true);
  149. selectedHosts.forEach(function (_hostInfo) {
  150. console.log('Removing: ' + _hostInfo.hostName);
  151. });
  152. this.get('fullContent').removeObjects(selectedHosts);
  153. },
  154. /**
  155. * remove hosts with id equal host_id
  156. * @param host_id
  157. */
  158. checkRemoved:function (host_id) {
  159. var hosts = this.get('content');
  160. var selectedHosts = hosts.filterProperty('id', host_id);
  161. this.get('fullContent').removeObjects(selectedHosts);
  162. }
  163. });