host.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. clearFilters: null,
  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. * Filter hosts by componentName of <code>component</code>
  47. * @param component App.HostComponent
  48. */
  49. filterByComponent:function (component) {
  50. if(!component)
  51. return;
  52. var id = component.get('componentName');
  53. var column = 6;
  54. this.get('componentsForFilter').setEach('checkedForHostFilter', false);
  55. var filterForComponent = {
  56. iColumn: column,
  57. value: id,
  58. type: 'multiple'
  59. };
  60. App.db.setFilterConditions(this.get('name'), [filterForComponent]);
  61. },
  62. /**
  63. * On click callback for delete button
  64. */
  65. deleteButtonPopup:function () {
  66. var self = this;
  67. App.showConfirmationPopup(function(){
  68. self.removeHosts();
  69. });
  70. },
  71. showAlertsPopup: function (event) {
  72. var host = event.context;
  73. App.ModalPopup.show({
  74. header: this.t('services.alerts.headingOfList'),
  75. bodyClass: Ember.View.extend({
  76. hostAlerts: function () {
  77. var allAlerts = App.router.get('clusterController.alerts').filterProperty('ignoredForHosts', false);
  78. if (host) {
  79. return allAlerts.filterProperty('hostName', host.get('hostName'));
  80. }
  81. return 0;
  82. }.property('App.router.clusterController.alerts'),
  83. closePopup: function () {
  84. this.get('parentView').hide();
  85. },
  86. templateName: require('templates/main/host/alerts_popup')
  87. }),
  88. primary: Em.I18n.t('common.close'),
  89. onPrimary: function() {
  90. this.hide();
  91. },
  92. secondary : null,
  93. didInsertElement: function () {
  94. this.$().find('.modal-footer').addClass('align-center');
  95. this.$().children('.modal').css({'margin-top': '-350px'});
  96. }
  97. });
  98. event.stopPropagation();
  99. },
  100. /**
  101. * remove selected hosts
  102. */
  103. removeHosts:function () {
  104. var hosts = this.get('content');
  105. var selectedHosts = hosts.filterProperty('isChecked', true);
  106. selectedHosts.forEach(function (_hostInfo) {
  107. console.log('Removing: ' + _hostInfo.hostName);
  108. });
  109. this.get('fullContent').removeObjects(selectedHosts);
  110. },
  111. /**
  112. * remove hosts with id equal host_id
  113. * @param host_id
  114. */
  115. checkRemoved:function (host_id) {
  116. var hosts = this.get('content');
  117. var selectedHosts = hosts.filterProperty('id', host_id);
  118. this.get('fullContent').removeObjects(selectedHosts);
  119. }
  120. });