host.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. isAdmin: function(){
  26. return App.router.getUser().admin;
  27. }.property('App.router.loginController.loginName'),
  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(),
  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. decommissionButtonPopup:function () {
  56. var self = this;
  57. App.ModalPopup.show({
  58. header:Em.I18n.t('hosts.decommission.popup.header'),
  59. body:Em.I18n.t('hosts.decommission.popup.body'),
  60. primary:'Yes',
  61. secondary:'No',
  62. onPrimary:function () {
  63. alert('do');
  64. this.hide();
  65. },
  66. onSecondary:function () {
  67. this.hide();
  68. }
  69. });
  70. },
  71. deleteButtonPopup:function () {
  72. var self = this;
  73. App.ModalPopup.show({
  74. header:Em.I18n.t('hosts.delete.popup.header'),
  75. body:Em.I18n.t('hosts.delete.popup.body'),
  76. primary:'Yes',
  77. secondary:'No',
  78. onPrimary:function () {
  79. self.removeHosts();
  80. this.hide();
  81. },
  82. onSecondary:function () {
  83. this.hide();
  84. }
  85. });
  86. },
  87. removeHosts:function () {
  88. var hosts = this.get('content');
  89. var selectedHosts = hosts.filterProperty('isChecked', true);
  90. selectedHosts.forEach(function (_hostInfo) {
  91. console.log('Removing: ' + _hostInfo.hostName);
  92. });
  93. this.get('fullContent').removeObjects(selectedHosts);
  94. },
  95. checkRemoved:function (host_id) {
  96. var hosts = this.get('content');
  97. var selectedHosts = hosts.filterProperty('id', host_id);
  98. this.get('fullContent').removeObjects(selectedHosts);
  99. }
  100. });