definition_details_view.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.MainAlertDefinitionDetailsView = App.TableView.extend({
  20. templateName: require('templates/main/alerts/definition_details'),
  21. /**
  22. * Determines if <code>controller.content</code> is loaded
  23. * @type {bool}
  24. */
  25. isLoaded: false,
  26. /**
  27. * @type {string}
  28. */
  29. enabledDisplay: Em.I18n.t('alerts.table.state.enabled'),
  30. /**
  31. * @type {string}
  32. */
  33. disabledDisplay: Em.I18n.t('alerts.table.state.disabled'),
  34. content: function () {
  35. return this.get('controller.alerts');
  36. }.property('controller.alerts.@each'),
  37. willInsertElement: function () {
  38. this._super();
  39. this.get('controller').clearStep();
  40. var self = this,
  41. updater = App.router.get('updateController');
  42. if (self.get('controller.content.isLoaded')) {
  43. self.set('isLoaded', true);
  44. self.get('controller').loadAlertInstances();
  45. }
  46. else {
  47. updater.updateAlertGroups(function () {
  48. updater.updateAlertDefinitions(function () {
  49. updater.updateAlertDefinitionSummary(function () {
  50. self.set('isLoaded', true);
  51. // App.AlertDefinition doesn't represents real models
  52. // Real model (see AlertDefinition types) should be used
  53. self.set('controller.content', App.AlertDefinition.find().findProperty('id', parseInt(self.get('controller.content.id'))));
  54. self.get('controller').loadAlertInstances();
  55. });
  56. });
  57. });
  58. }
  59. },
  60. didInsertElement: function () {
  61. this.filter();
  62. this.tooltipsUpdater();
  63. },
  64. /**
  65. * Update tooltips when <code>pageContent</code> is changed
  66. * @method tooltipsUpdater
  67. */
  68. tooltipsUpdater: function () {
  69. Em.run.next(function () {
  70. App.tooltip($(".enable-disable-button"));
  71. });
  72. }.observes('controller.content.enabled'),
  73. /**
  74. * View calculates and represents count of alerts on appropriate host during last day
  75. */
  76. lastDayCount: Em.View.extend({
  77. hostName: '', // binding from template
  78. template: Ember.Handlebars.compile('<span>{{view.count}}</span>'),
  79. count: function () {
  80. var lastDayAlertsCount = this.get('parentView.controller.lastDayAlertsCount');
  81. return lastDayAlertsCount ? lastDayAlertsCount[this.get('hostName')] || 0 : Em.I18n.t('app.loadingPlaceholder');
  82. }.property('parentView.controller.lastDayAlertsCount', 'hostName')
  83. }),
  84. /**
  85. * View represents each row of instances table
  86. */
  87. instanceTableRow: Em.View.extend({
  88. tagName: 'tr',
  89. didInsertElement: function () {
  90. App.tooltip($("[rel=tooltip]"));
  91. }
  92. }),
  93. paginationLeftClass: function () {
  94. if (this.get("startIndex") > 1) {
  95. return "paginate_previous";
  96. }
  97. return "paginate_disabled_previous";
  98. }.property("startIndex", 'filteredCount'),
  99. /**
  100. * Determines how display "next"-link - as link or text
  101. * @type {string}
  102. */
  103. paginationRightClass: function () {
  104. if ((this.get("endIndex")) < this.get("filteredCount")) {
  105. return "paginate_next";
  106. }
  107. return "paginate_disabled_next";
  108. }.property("endIndex", 'filteredCount'),
  109. /**
  110. * Show previous-page if user not in the first page
  111. * @method previousPage
  112. */
  113. previousPage: function () {
  114. if (this.get('paginationLeftClass') === 'paginate_previous') {
  115. this._super();
  116. }
  117. },
  118. /**
  119. * Show next-page if user not in the last page
  120. * @method nextPage
  121. */
  122. nextPage: function () {
  123. if (this.get('paginationRightClass') === 'paginate_next') {
  124. this._super();
  125. }
  126. }
  127. });