host.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.showConfirmationPopup(function(){
  81. alert('do');
  82. });
  83. },
  84. /**
  85. * On click callback for delete button
  86. * @param event
  87. */
  88. deleteButtonPopup:function () {
  89. var self = this;
  90. App.showConfirmationPopup(function(){
  91. self.removeHosts();
  92. });
  93. },
  94. showAlertsPopup: function (event) {
  95. var host = event.context;
  96. App.ModalPopup.show({
  97. header: this.t('services.alerts.headingOfList'),
  98. bodyClass: Ember.View.extend({
  99. hostAlerts: function () {
  100. var allAlerts = App.router.get('clusterController.alerts').filterProperty('ignoredForHosts', false);
  101. if (host) {
  102. return allAlerts.filterProperty('hostName', host.get('hostName'));
  103. }
  104. return 0;
  105. }.property('App.router.clusterController.alerts'),
  106. closePopup: function () {
  107. this.get('parentView').hide();
  108. },
  109. templateName: require('templates/main/host/alerts_popup')
  110. }),
  111. primary: Em.I18n.t('common.close'),
  112. onPrimary: function() {
  113. this.hide();
  114. },
  115. secondary : null,
  116. didInsertElement: function () {
  117. this.$().find('.modal-footer').addClass('align-center');
  118. this.$().children('.modal').css({'margin-top': '-350px'});
  119. }
  120. });
  121. event.stopPropagation();
  122. },
  123. /**
  124. * remove selected hosts
  125. */
  126. removeHosts:function () {
  127. var hosts = this.get('content');
  128. var selectedHosts = hosts.filterProperty('isChecked', true);
  129. selectedHosts.forEach(function (_hostInfo) {
  130. console.log('Removing: ' + _hostInfo.hostName);
  131. });
  132. this.get('fullContent').removeObjects(selectedHosts);
  133. },
  134. /**
  135. * remove hosts with id equal host_id
  136. * @param host_id
  137. */
  138. checkRemoved:function (host_id) {
  139. var hosts = this.get('content');
  140. var selectedHosts = hosts.filterProperty('id', host_id);
  141. this.get('fullContent').removeObjects(selectedHosts);
  142. }
  143. });