host.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. App.MainHostController = Em.ArrayController.extend({
  21. name:'mainHostController',
  22. content:[],
  23. comeWithFilter: false,
  24. fullContent:App.Host.find(),
  25. clusters:App.Cluster.find(),
  26. isAdmin: function(){
  27. return App.db.getUser().admin;
  28. }.property('App.router.loginController.loginName'),
  29. componentsForFilter:function() {
  30. var components = App.Component.find();
  31. var ret = new Array();
  32. if (!components) {
  33. return ret;
  34. }
  35. components.forEach(function(item) {
  36. var o = Ember.Object.create({
  37. id: item.get('id'),
  38. isMaster: item.get('isMaster'),
  39. isSlave: item.get('isSlave'),
  40. displayName: item.get('displayName'),
  41. componentName: item.get('componentName'),
  42. checkedForHostFilter: item.get('checkedForHostFilter')
  43. });
  44. ret.push(o);
  45. });
  46. return ret;
  47. }.property(),
  48. totalBinding:'fullContent.length',
  49. filters:{components:[]},
  50. isDisabled:true,
  51. checkRemoved:function (host_id) {
  52. var hosts = this.get('content');
  53. var selectedHosts = hosts.filterProperty('id', host_id);
  54. this.get('fullContent').removeObjects(selectedHosts);
  55. },
  56. masterComponents:function () {
  57. var components = [];
  58. this.get('componentsForFilter').forEach(function (component) {
  59. if (component.get('isMaster')) {
  60. components.push(component);
  61. }
  62. });
  63. return components;
  64. }.property('componentsForFilter'),
  65. slaveComponents:function () {
  66. var components = [];
  67. this.get('componentsForFilter').forEach(function (component) {
  68. if (component.get('isSlave')) {
  69. components.push(component);
  70. }
  71. });
  72. return components;
  73. }.property('componentsForFilter'),
  74. clientComponents: function() {
  75. var components = [];
  76. this.get('componentsForFilter').forEach(function(component) {
  77. if (!component.get('isMaster') && !component.get('isSlave')) {
  78. components.push(component);
  79. }
  80. });
  81. return components;
  82. }.property('componentsForFilter'),
  83. backgroundOperationsCount:function () {
  84. return 5;
  85. }.property(),
  86. checkedComponentsIds:function () {
  87. var checked = [];
  88. this.get('componentsForFilter').forEach(function (comp) {
  89. if (comp.get('checkedForHostFilter'))
  90. checked.push(comp.get('id'));
  91. });
  92. return checked;
  93. },
  94. filterByComponent:function (component) {
  95. var id = component.get('id');
  96. /*this.get('componentsForFilter').setEach('isChecked', false);
  97. component.set('isChecked', true);*/
  98. this.get('componentsForFilter').setEach('checkedForHostFilter', false);
  99. this.get('componentsForFilter').filterProperty('id', id).setEach('checkedForHostFilter', true);
  100. //component.set('checkedForHostFilter', true);
  101. this.set('filters.components', [component.get('id')]);
  102. console.log(this.get('filters.components').objectAt(0));
  103. this.set('comeWithFilter', true);
  104. },
  105. applyHostFilters:function (items) {
  106. var field = 'hostName'; // make this function universal
  107. var value = this.get('hostFilter' + field);
  108. var itemsToDelete = [];
  109. if (value) {
  110. items.forEach(function (host, index) {
  111. if (host) {
  112. var fieldValue = host.get(field);
  113. if (fieldValue) {
  114. if (fieldValue.indexOf(value) == -1) {
  115. itemsToDelete.push(host);
  116. }
  117. }
  118. }
  119. });
  120. }
  121. if (itemsToDelete.length) {
  122. itemsToDelete.forEach(function (hostToDelete) {
  123. var index = items.indexOf(hostToDelete);
  124. items.removeAt(index);
  125. })
  126. }
  127. return items;
  128. },
  129. changeContent:function () {
  130. var items = [];
  131. var filters = this.get('filters.components');
  132. this.get('fullContent').forEach(function (item) {
  133. if (filters.length) {
  134. var inFilters = false;
  135. item.get('components').forEach(function (component) {
  136. if (filters.indexOf(component.get('id')) != -1) {
  137. inFilters = true;
  138. }
  139. });
  140. if (inFilters) {
  141. items.push(item);
  142. }
  143. }
  144. else {
  145. items.push(item);
  146. }
  147. });
  148. items = this.applyHostFilters(items);
  149. this.set('total', items.length);
  150. this.replace(0, this.get('length'), items);
  151. }.observes('total'),
  152. decommissionButtonPopup:function () {
  153. var self = this;
  154. App.ModalPopup.show({
  155. header:Em.I18n.t('hosts.decommission.popup.header'),
  156. body:Em.I18n.t('hosts.decommission.popup.body'),
  157. primary:'Yes',
  158. secondary:'No',
  159. onPrimary:function () {
  160. alert('do');
  161. this.hide();
  162. },
  163. onSecondary:function () {
  164. this.hide();
  165. }
  166. });
  167. },
  168. deleteButtonPopup:function () {
  169. var self = this;
  170. App.ModalPopup.show({
  171. header:Em.I18n.t('hosts.delete.popup.header'),
  172. body:Em.I18n.t('hosts.delete.popup.body'),
  173. primary:'Yes',
  174. secondary:'No',
  175. onPrimary:function () {
  176. self.removeHosts();
  177. this.hide();
  178. },
  179. onSecondary:function () {
  180. this.hide();
  181. }
  182. });
  183. },
  184. removeHosts:function () {
  185. var hosts = this.get('content');
  186. var selectedHosts = hosts.filterProperty('isChecked', true);
  187. selectedHosts.forEach(function (_hostInfo) {
  188. console.log('Removing: ' + _hostInfo.hostName);
  189. });
  190. this.get('fullContent').removeObjects(selectedHosts);
  191. }
  192. });