service.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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"],
  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. getHostComponentStatus: function(){
  30. var popupText = "";
  31. this.get("service").get("hostComponents").filterProperty('isMaster', true).forEach(function(item){
  32. popupText += item.get("displayName") + " " + item.get("componentTextStatus") + "<br/>";
  33. });
  34. this.set('data-original-title',popupText);
  35. }.observes('service.hostComponents.@each.workStatus'),
  36. /**
  37. * When set to true, extending classes should
  38. * show only tabular rows as they will be
  39. * embedded into other tables.
  40. */
  41. showOnlyRows: false,
  42. startBlink: function () {
  43. this.set('blink', true);
  44. },
  45. doBlink: function () {
  46. var self = this;
  47. if (this.get('blink') && (this.get("state") == "inDOM")) {
  48. uiEffects.pulsate(self.$(), 1000, function(){
  49. self.doBlink();
  50. });
  51. }
  52. }.observes('blink'),
  53. stopBlink: function () {
  54. this.set('blink', false);
  55. },
  56. healthStatus: function () {
  57. var status = this.get('service.healthStatus');
  58. switch (status) {
  59. case 'green':
  60. status = App.Service.Health.live;
  61. this.stopBlink();
  62. break;
  63. case 'green-blinking':
  64. status = App.Service.Health.live;
  65. this.startBlink();
  66. break;
  67. case 'red-blinking':
  68. status = App.Service.Health.dead;
  69. this.startBlink();
  70. break;
  71. case 'yellow':
  72. status = App.Service.Health.unknown;
  73. break;
  74. default:
  75. status = App.Service.Health.dead;
  76. this.stopBlink();
  77. break;
  78. }
  79. return 'health-status-' + status;
  80. }.property('service.healthStatus'),
  81. didInsertElement: function () {
  82. this.getHostComponentStatus();
  83. $("[rel='HealthTooltip']").tooltip();
  84. this.doBlink(); // check for blink availability
  85. }
  86. });
  87. App.ComponentLiveTextView = Em.View.extend({
  88. classNameBindings: ['color:service-summary-component-red-dead:service-summary-component-green-live'],
  89. service: function() { return this.get("parentView").get("service")}.property("parentView.service"),
  90. liveComponents: function() {
  91. }.property(),
  92. totalComponents: function() {
  93. }.property(),
  94. color: function() {
  95. return this.get("liveComponents") == 0;
  96. }.property("liveComponents")
  97. });
  98. App.MainDashboardServiceView = Em.View.extend({
  99. classNames: ['service', 'clearfix'],
  100. data: function () {
  101. return this.get('controller.data.' + this.get('serviceName'));
  102. }.property('controller.data'),
  103. dashboardMasterComponentView : Em.View.extend({
  104. templateName: require('templates/main/service/info/summary/master_components'),
  105. mastersComp : function(){
  106. return this.get('parentView.service.hostComponents').filterProperty('isMaster', true);
  107. }.property("service")
  108. }),
  109. formatUnavailable: function(value){
  110. return (value || value == 0) ? value : this.t('services.service.summary.notAvailable');
  111. },
  112. criticalAlertsCount: function () {
  113. var alerts = App.router.get('clusterController.alerts');
  114. return alerts.filterProperty('serviceType', this.get('service.id')).filterProperty('isOk', false).filterProperty('ignoredForServices', false).length;
  115. }.property('App.router.clusterController.alerts'),
  116. isCollapsed: false,
  117. toggleInfoView: function () {
  118. this.$('.service-body').toggle('blind', 200);
  119. this.set('isCollapsed', !this.isCollapsed);
  120. },
  121. masters: function(){
  122. return this.get('service.hostComponents').filterProperty('isMaster', true);
  123. }.property('service'),
  124. clients: function(){
  125. var clients = this.get('service.hostComponents').filterProperty('isClient', true);
  126. var len = clients.length;
  127. var template = 'dashboard.services.{0}.client'.format(this.get('serviceName').toLowerCase());
  128. if(len > 1){
  129. template += 's';
  130. }
  131. return {
  132. title: this.t(template).format(len),
  133. component: clients.objectAt(0)
  134. };
  135. }.property('service')
  136. });