menu.js 8.3 KB

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