service.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 uiEffects = require('utils/ui_effects');
  20. require('models/alert');
  21. App.MainDashboardServiceHealthView = Em.View.extend({
  22. classNameBindings: ["healthStatus", "healthStatusClass"],
  23. //template: Em.Handlebars.compile(""),
  24. blink: false,
  25. tagName: 'span',
  26. attributeBindings:['rel', 'title','data-original-title'],
  27. rel: 'HealthTooltip',
  28. 'data-original-title': '',
  29. updateToolTip: function () {
  30. this.set('data-original-title', this.get('service.toolTipContent'));
  31. }.observes('service.toolTipContent'),
  32. startBlink: function () {
  33. this.set('blink', true);
  34. },
  35. doBlink: function () {
  36. var self = this;
  37. if (this.get('blink') && (this.get("state") == "inDOM")) {
  38. uiEffects.pulsate(self.$(), 1000, function(){
  39. self.doBlink();
  40. });
  41. }
  42. }.observes('blink'),
  43. stopBlink: function () {
  44. this.set('blink', false);
  45. },
  46. healthStatus: function () {
  47. if (this.get('service.isClientsOnly')) {
  48. return 'icon-laptop';
  49. }
  50. if (this.get('service.passiveState') != 'OFF') {
  51. return 'icon-medkit';
  52. }
  53. var status = this.get('service.healthStatus');
  54. switch (status) {
  55. case 'green':
  56. status = App.Service.Health.live;
  57. this.stopBlink();
  58. break;
  59. case 'green-blinking':
  60. status = App.Service.Health.live;
  61. this.startBlink();
  62. break;
  63. case 'red-blinking':
  64. status = App.Service.Health.dead;
  65. this.startBlink();
  66. break;
  67. case 'yellow':
  68. status = App.Service.Health.unknown;
  69. break;
  70. default:
  71. status = App.Service.Health.dead;
  72. this.stopBlink();
  73. break;
  74. }
  75. return 'health-status-' + status;
  76. }.property('service.healthStatus','service.passiveState','service.isClientsOnly'),
  77. healthStatusClass: function () {
  78. switch (this.get('healthStatus')) {
  79. case 'health-status-LIVE':
  80. return App.healthIconClassGreen;
  81. break;
  82. case 'health-status-DEAD-RED':
  83. return App.healthIconClassRed;
  84. break;
  85. case 'health-status-DEAD-YELLOW':
  86. return App.healthIconClassYellow;
  87. break;
  88. case 'health-status-DEAD-ORANGE':
  89. return App.healthIconClassOrange;
  90. break;
  91. default:
  92. return "";
  93. break;
  94. }
  95. }.property('healthStatus'),
  96. didInsertElement: function () {
  97. this.updateToolTip();
  98. App.tooltip($("[rel='HealthTooltip']"));
  99. this.doBlink(); // check for blink availability
  100. }
  101. });
  102. App.ComponentLiveTextView = Em.View.extend({
  103. classNameBindings: ['color:service-summary-component-red-dead:service-summary-component-green-live'],
  104. service: function() { return this.get("parentView").get("service")}.property("parentView.service"),
  105. liveComponents: function() {
  106. }.property(),
  107. totalComponents: function() {
  108. }.property(),
  109. color: function() {
  110. return this.get("liveComponents") == 0;
  111. }.property("liveComponents")
  112. });
  113. App.MainDashboardServiceView = Em.View.extend({
  114. classNames: ['service', 'clearfix'],
  115. data: function () {
  116. return this.get('controller.data.' + this.get('serviceName'));
  117. }.property('controller.data'),
  118. dashboardMasterComponentView : Em.View.extend({
  119. didInsertElement: function() {
  120. App.tooltip($('[rel=healthTooltip]'));
  121. },
  122. templateName: require('templates/main/service/info/summary/master_components'),
  123. mastersComp : function(){
  124. return this.get('parentView.service.hostComponents').filterProperty('isMaster', true);
  125. }.property("service")
  126. }),
  127. formatUnavailable: function(value){
  128. return (value || value == 0) ? value : this.t('services.service.summary.notAvailable');
  129. },
  130. criticalAlertsCount: function () {
  131. return this.get('service.criticalAlertsCount');
  132. }.property('service.criticalAlertsCount'),
  133. isCollapsed: false,
  134. toggleInfoView: function () {
  135. this.$('.service-body').toggle('blind', 200);
  136. this.set('isCollapsed', !this.isCollapsed);
  137. },
  138. masters: function(){
  139. return this.get('service.hostComponents').filterProperty('isMaster', true);
  140. }.property('service'),
  141. clients: function(){
  142. var clients = this.get('service.hostComponents').filterProperty('isClient', true);
  143. var len = clients.length;
  144. var template = 'dashboard.services.{0}.client'.format(this.get('serviceName').toLowerCase());
  145. if(len > 1){
  146. template += 's';
  147. }
  148. return {
  149. title: this.t(template).format(len),
  150. component: clients.objectAt(0)
  151. };
  152. }.property('service')
  153. });