service.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. require('models/alert');
  20. App.MainDashboardServiceHealthView = Em.View.extend({
  21. classNameBindings: ["healthStatus"],
  22. template: Em.Handlebars.compile(""),
  23. blink: false,
  24. tagName: 'span',
  25. /**
  26. * When set to true, extending classes should
  27. * show only tabular rows as they will be
  28. * embedded into other tables.
  29. */
  30. showOnlyRows: false,
  31. startBlink: function () {
  32. this.set('blink', true);
  33. },
  34. doBlink: function () {
  35. if (this.get('blink') && (this.get("state") == "inDOM")) {
  36. this.$().effect("pulsate", { times: 1 }, "slow", function () {
  37. var view = Em.View.views[$(this).attr('id')];
  38. view.doBlink();
  39. });
  40. }
  41. }.observes('blink'),
  42. stopBlink: function () {
  43. this.set('blink', false);
  44. },
  45. healthStatus: function () {
  46. var status = this.get('service.healthStatus');
  47. switch (status) {
  48. case 'green':
  49. status = App.Service.Health.live;
  50. this.stopBlink();
  51. break;
  52. case 'green-blinking':
  53. status = App.Service.Health.live;
  54. this.startBlink();
  55. break;
  56. case 'red-blinking':
  57. status = App.Service.Health.dead;
  58. this.startBlink();
  59. break;
  60. default:
  61. status = App.Service.Health.dead;
  62. this.stopBlink();
  63. break;
  64. }
  65. return 'health-status-' + status + " span";
  66. }.property('service.healthStatus'),
  67. didInsertElement: function () {
  68. this.doBlink(); // check for blink availability
  69. }
  70. });
  71. App.MainDashboardServiceView = Em.View.extend({
  72. classNames: ['service', 'clearfix'],
  73. data: function () {
  74. return this.get('controller.data.' + this.get('serviceName'));
  75. }.property('controller.data'),
  76. criticalAlertsCount: function () {
  77. var alerts = App.router.get('clusterController.alerts');
  78. return alerts.filterProperty('serviceType', this.get('service.id')).filterProperty('status', '1').length;
  79. }.property('service.alerts')
  80. });