host.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. App.MainHostView = Em.View.extend({
  20. templateName: require('templates/main/host'),
  21. content:function(){
  22. return App.router.get('mainHostController.content');
  23. }.property('App.router.mainHostController.content'),
  24. componentsIds: [1, 2, 3, 4, 5, 6, 7, 8],
  25. isFilterOpen: false,
  26. isApplyDisabled: function(){
  27. return !this.get('isFilterOpen')
  28. }.property('isFilterOpen'),
  29. btnGroupClass: function(){
  30. return this.get('isFilterOpen') ? 'btn-group open' : 'btn-group';
  31. }.property('isFilterOpen'),
  32. applyFilters: function(){
  33. this.set('isFilterOpen', false);
  34. App.router.get('mainHostController').filterByComponentsIds(this.get('componentsIds'));
  35. },
  36. clickFilterButton: function(){
  37. var self = this;
  38. this.set('isFilterOpen', !this.get('isFilterOpen'));
  39. if (this.get('isFilterOpen')){
  40. var filters = App.router.get('mainHostController.filters.components');
  41. $('.filter-component').each(function () {
  42. var componentId = parseInt($(this).attr('id').replace('component-',''));
  43. var index = filters.indexOf(componentId);
  44. $(this).attr('checked', index == -1);
  45. });
  46. this.set('componentsIds', filters.toArray());
  47. var dropDown = $('#filter-dropdown');
  48. var firstClick = true;
  49. $(document).bind('click', function(e) {
  50. if (!firstClick && $(e.target).closest(dropDown).length == 0) {
  51. self.set('isFilterOpen', false);
  52. $(document).unbind('click');
  53. }
  54. firstClick = false;
  55. });
  56. }
  57. },
  58. HostView: Em.View.extend({
  59. content: null,
  60. labels: '',
  61. init: function(){
  62. this._super();
  63. var labels = this.get('content.components').getEach('label');
  64. this.set('labels', labels.join(', '));
  65. },
  66. HostCheckboxView: Em.Checkbox.extend({
  67. content: null,
  68. isChecked: false,
  69. change: function(event) {
  70. this.set('isChecked', !this.get('content.isChecked'));
  71. App.router.get('mainHostController').onHostChecked(this.get('content'));
  72. }
  73. })
  74. }),
  75. ComponentCheckboxView: Em.Checkbox.extend({
  76. content: null,
  77. elementId: function(){
  78. return 'component-' + this.get('content.id');
  79. }.property('content.id'),
  80. classNames: ['filter-component'],
  81. parentView: function(){
  82. return this._parentView.templateData.view;
  83. }.property(),
  84. change: function(event) {
  85. var parent = this._parentView.templateData.view;
  86. var componentsIds = parent.get('componentsIds');
  87. var componentId = this.get('content.id');
  88. var index = componentsIds.indexOf(componentId);
  89. if(index==-1) componentsIds.push(componentId);
  90. else componentsIds.splice(index, 1);
  91. }
  92. })
  93. });
  94. App.MainBackgroundOperation = Em.View.extend({
  95. content: null,
  96. classNames: ['background-operations'],
  97. classNameBindings: ['isOpen'],
  98. isOpen: false,
  99. logDetails: null,
  100. isOpenShowLog: false,
  101. iconClass: function(){
  102. return this.get('isOpen') ? 'icon-minus' : 'icon-plus';
  103. }.property('isOpen'),
  104. openDetails: function(){
  105. this.set('isOpen', !this.get('isOpen'))
  106. },
  107. showOperationLog:function(){
  108. var operation = this.get('content');
  109. var self = this;
  110. if (!this.get('isOpenShowLog') && !this.get('logDetails')) {
  111. jQuery.getJSON('data/hosts/background_operations/logs/task' +operation.taskId + '.json',
  112. function (data) {
  113. self.set('logDetails', data);
  114. }
  115. );
  116. }
  117. this.set('isOpenShowLog', !this.get('isOpenShowLog'))
  118. }
  119. });