menu.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 misc = require('utils/misc');
  20. App.MainServiceMenuView = Em.CollectionView.extend({
  21. disabledServices: ['HCATALOG'],
  22. content:function () {
  23. var items = App.router.get('mainServiceController.content').filter(function(item){
  24. return !this.get('disabledServices').contains(item.get('id'));
  25. }, this);
  26. return misc.sortByOrder(App.Service.servicesSortOrder, items);
  27. }.property('App.router.mainServiceController.content', 'App.router.mainServiceController.content.length'),
  28. didInsertElement:function () {
  29. App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
  30. this.renderOnRoute();
  31. App.tooltip($(".restart-required-service"), {html:true, placement:"right"});
  32. },
  33. activeServiceId:null,
  34. /**
  35. * Syncs navigation menu with requested URL
  36. */
  37. renderOnRoute:function () {
  38. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  39. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  40. return;
  41. }
  42. var reg = /^\/main\/services\/(\S+)\//g;
  43. var sub_url = reg.exec(last_url);
  44. var service_id = (null != sub_url) ? sub_url[1] : 1;
  45. this.set('activeServiceId', service_id);
  46. },
  47. tagName:'ul',
  48. classNames:[ "nav", "nav-list", "nav-services"],
  49. itemViewClass:Em.View.extend({
  50. classNameBindings:["active", "clients"],
  51. templateName:require('templates/main/service/menu_item'),
  52. restartRequiredMessage: null,
  53. shouldBeRestarted: function() {
  54. return this.get('content.hostComponents').someProperty('staleConfigs', true);
  55. }.property('content.hostComponents.@each.staleConfigs'),
  56. active:function () {
  57. return this.get('content.id') == this.get('parentView.activeServiceId') ? 'active' : '';
  58. }.property('parentView.activeServiceId'),
  59. alertsCount: function () {
  60. return this.get('content.criticalAlertsCount');
  61. }.property('content.criticalAlertsCount'),
  62. link: function() {
  63. var stateName = (['summary','configs'].contains(App.router.get('currentState.name')))
  64. ? this.get('content.isConfigurable') ? App.router.get('currentState.name') : 'summary'
  65. : 'summary';
  66. return "#/main/services/" + this.get('content.id') + "/" + stateName;
  67. }.property('App.router.currentState.name', 'parentView.activeServiceId'),
  68. refreshRestartRequiredMessage: function() {
  69. var restarted, componentsCount, hostsCount, message, tHosts, tComponents;
  70. restarted = this.get('content.restartRequiredHostsAndComponents');
  71. componentsCount = 0;
  72. hostsCount = 0;
  73. message = "";
  74. for (var host in restarted) {
  75. hostsCount++;
  76. componentsCount += restarted[host].length;
  77. }
  78. if (hostsCount > 1) {
  79. tHosts = Em.I18n.t('common.hosts');
  80. } else {
  81. tHosts = Em.I18n.t('common.host');
  82. }
  83. if (componentsCount > 1) {
  84. tComponents = Em.I18n.t('common.components');
  85. } else {
  86. tComponents = Em.I18n.t('common.component');
  87. }
  88. message += componentsCount + ' ' + tComponents + ' ' + Em.I18n.t('on') + ' ' +
  89. hostsCount + ' ' + tHosts + ' ' + Em.I18n.t('services.service.config.restartService.needToRestartEnd');
  90. this.set('restartRequiredMessage', message);
  91. }.observes('content.restartRequiredHostsAndComponents')
  92. })
  93. });
  94. App.TopNavServiceMenuView = Em.CollectionView.extend({
  95. disabledServices: ['HCATALOG'],
  96. content:function () {
  97. var items = App.router.get('mainServiceController.content').filter(function(item){
  98. return !this.get('disabledServices').contains(item.get('id'));
  99. }, this);
  100. return misc.sortByOrder(App.Service.servicesSortOrder, items);
  101. }.property('App.router.mainServiceController.content', 'App.router.mainServiceController.content.length'),
  102. didInsertElement:function () {
  103. App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
  104. this.renderOnRoute();
  105. App.tooltip($(".restart-required-service"), {html:true, placement:"right"});
  106. },
  107. activeServiceId:null,
  108. /**
  109. * Syncs navigation menu with requested URL
  110. */
  111. renderOnRoute:function () {
  112. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  113. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  114. return;
  115. }
  116. var reg = /^\/main\/services\/(\S+)\//g;
  117. var sub_url = reg.exec(last_url);
  118. var service_id = (null != sub_url) ? sub_url[1] : 1;
  119. this.set('activeServiceId', service_id);
  120. },
  121. tagName:'ul',
  122. classNames:[ "top-nav-dropdown-menu"],
  123. itemViewClass:Em.View.extend({
  124. classNameBindings:["active", "clients"],
  125. templateName:require('templates/main/service/menu_item'),
  126. restartRequiredMessage: null,
  127. shouldBeRestarted: function() {
  128. return this.get('content.hostComponents').someProperty('staleConfigs', true);
  129. }.property('content.hostComponents.@each.staleConfigs'),
  130. active:function () {
  131. return this.get('content.id') == this.get('parentView.activeServiceId') ? 'active' : '';
  132. }.property('parentView.activeServiceId'),
  133. alertsCount: function () {
  134. return this.get('content.criticalAlertsCount');
  135. }.property('content.criticalAlertsCount'),
  136. link: function() {
  137. var stateName = (['summary','configs'].contains(App.router.get('currentState.name')))
  138. ? this.get('content.isConfigurable') ? App.router.get('currentState.name') : 'summary'
  139. : 'summary';
  140. return "#/main/services/" + this.get('content.id') + "/" + stateName;
  141. }.property('App.router.currentState.name', 'parentView.activeServiceId'),
  142. refreshRestartRequiredMessage: function() {
  143. var restarted, componentsCount, hostsCount, message, tHosts, tComponents;
  144. restarted = this.get('content.restartRequiredHostsAndComponents');
  145. componentsCount = 0;
  146. hostsCount = 0;
  147. message = "";
  148. for (var host in restarted) {
  149. hostsCount++;
  150. componentsCount += restarted[host].length;
  151. }
  152. if (hostsCount > 1) {
  153. tHosts = Em.I18n.t('common.hosts');
  154. } else {
  155. tHosts = Em.I18n.t('common.host');
  156. }
  157. if (componentsCount > 1) {
  158. tComponents = Em.I18n.t('common.components');
  159. } else {
  160. tComponents = Em.I18n.t('common.component');
  161. }
  162. message += componentsCount + ' ' + tComponents + ' ' + Em.I18n.t('on') + ' ' +
  163. hostsCount + ' ' + tHosts + ' ' + Em.I18n.t('services.service.config.restartService.needToRestartEnd');
  164. this.set('restartRequiredMessage', message);
  165. }.observes('content.restartRequiredHostsAndComponents')
  166. })
  167. });