host.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. hostsWithAlerts: function () {
  26. return App.Alert.find().mapProperty('hostName').uniq();
  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. * Filter hosts by componentName of <code>component</code>
  47. * @param component App.HostComponent
  48. */
  49. filterByComponent:function (component) {
  50. var id = component.get('componentName');
  51. this.get('componentsForFilter').setEach('checkedForHostFilter', false);
  52. this.get('componentsForFilter').filterProperty('id', id).setEach('checkedForHostFilter', true);
  53. this.set('comeWithFilter', true);
  54. },
  55. /**
  56. * On click callback for decommission button
  57. * @param event
  58. */
  59. decommissionButtonPopup:function () {
  60. var self = this;
  61. App.ModalPopup.show({
  62. header:Em.I18n.t('hosts.decommission.popup.header'),
  63. body:Em.I18n.t('hosts.decommission.popup.body'),
  64. primary:'Yes',
  65. secondary:'No',
  66. onPrimary:function () {
  67. alert('do');
  68. this.hide();
  69. },
  70. onSecondary:function () {
  71. this.hide();
  72. }
  73. });
  74. },
  75. /**
  76. * On click callback for delete button
  77. * @param event
  78. */
  79. deleteButtonPopup:function () {
  80. var self = this;
  81. App.ModalPopup.show({
  82. header:Em.I18n.t('hosts.delete.popup.header'),
  83. body:Em.I18n.t('hosts.delete.popup.body'),
  84. primary:'Yes',
  85. secondary:'No',
  86. onPrimary:function () {
  87. self.removeHosts();
  88. this.hide();
  89. },
  90. onSecondary:function () {
  91. this.hide();
  92. }
  93. });
  94. },
  95. showAlertsPopup: function (event) {
  96. var host = event.context;
  97. App.ModalPopup.show({
  98. header: this.t('services.alerts.headingOfList'),
  99. bodyClass: Ember.View.extend({
  100. hostAlerts: function () {
  101. var allAlerts = App.router.get('clusterController.alerts');
  102. if (host) {
  103. return allAlerts.filterProperty('hostName', host.get('hostName'));
  104. }
  105. return 0;
  106. }.property('App.router.clusterController.alerts'),
  107. closePopup: function () {
  108. this.get('parentView').hide();
  109. },
  110. templateName: require('templates/main/host/alerts_popup')
  111. }),
  112. primary: 'Close',
  113. onPrimary: function() {
  114. this.hide();
  115. },
  116. secondary : null,
  117. didInsertElement: function () {
  118. this.$().find('.modal-footer').addClass('align-center');
  119. this.$().children('.modal').css({'margin-top': '-350px'});
  120. }
  121. });
  122. event.stopPropagation();
  123. },
  124. /**
  125. * remove selected hosts
  126. */
  127. removeHosts:function () {
  128. var hosts = this.get('content');
  129. var selectedHosts = hosts.filterProperty('isChecked', true);
  130. selectedHosts.forEach(function (_hostInfo) {
  131. console.log('Removing: ' + _hostInfo.hostName);
  132. });
  133. this.get('fullContent').removeObjects(selectedHosts);
  134. },
  135. /**
  136. * remove hosts with id equal host_id
  137. * @param host_id
  138. */
  139. checkRemoved:function (host_id) {
  140. var hosts = this.get('content');
  141. var selectedHosts = hosts.filterProperty('id', host_id);
  142. this.get('fullContent').removeObjects(selectedHosts);
  143. }
  144. });