menu.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /**
  20. * this menu extended by other with modifying content and itemViewClass.template
  21. * @type {*}
  22. */
  23. App.MainMenuView = Em.CollectionView.extend({
  24. tagName:'ul',
  25. classNames:['nav', 'top-nav-menu'],
  26. views: function() {
  27. return App.router.get('clusterController.ambariViews');
  28. }.property('App.ClusterController.ambariViews'),
  29. content:function(){
  30. var result = [
  31. { label:Em.I18n.t('menu.item.dashboard'), routing:'dashboard', active:'active'},
  32. { label:Em.I18n.t('menu.item.services'), routing:'services'},
  33. { label:Em.I18n.t('menu.item.hosts'), routing:'hosts'}
  34. ];
  35. if (App.supports.mirroring && App.Service.find().findProperty('serviceName', 'FALCON')) {
  36. result.push({ label:Em.I18n.t('menu.item.mirroring'), routing:'mirroring'});
  37. }
  38. if (!App.get('isHadoop2Stack')) {
  39. result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'apps'});
  40. } else if( App.router.get('mainAdminController.isAccessAvailable') && App.supports.jobs
  41. && (App.router.get('mainAdminAccessController.showJobs') || App.get('isAdmin'))) {
  42. result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'jobs'});
  43. }
  44. if (App.get('isAdmin')) {
  45. result.push({ label:Em.I18n.t('menu.item.admin'), routing:'admin'});
  46. }
  47. if (App.supports.views) {
  48. result.push({ label:Em.I18n.t('menu.item.views'), routing:'views', isView:true, views: this.get('views')});
  49. }
  50. return result;
  51. }.property('App.supports.views', 'App.supports.mirroring', 'App.supports.secureCluster', 'App.supports.highAvailability', 'App.supports.jobs'),
  52. /**
  53. * Adds observer on lastSetURL and calls navigation sync procedure
  54. */
  55. didInsertElement:function () {
  56. App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
  57. this.renderOnRoute();
  58. },
  59. /**
  60. * Syncs navigation menu with requested URL
  61. */
  62. renderOnRoute:function () {
  63. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  64. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  65. return;
  66. }
  67. var reg = /^\/main\/([a-z]+)/g;
  68. var sub_url = reg.exec(last_url);
  69. var chunk = (null != sub_url) ? sub_url[1] : 'dashboard';
  70. $.each(this._childViews, function () {
  71. this.set('active', this.get('content.routing') == chunk ? "active" : "");
  72. });
  73. },
  74. itemViewClass:Em.View.extend({
  75. classNameBindings:['active', ':top-nav-dropdown'],
  76. active:'',
  77. alertsCount:function () {
  78. if (this.get('content').routing == 'hosts') {
  79. return App.router.get('mainHostController.content').mapProperty('criticalAlertsCount')
  80. .reduce(function(pv, cv) { return pv + parseInt(cv); }, 0);
  81. }
  82. }.property('App.router.mainHostController.content.@each.criticalAlertsCount'),
  83. templateName: require('templates/main/menu_item'),
  84. dropdownMenu: function () {
  85. var item = this.get('content').routing;
  86. var itemsWithDropdown = ['services', 'admin', 'views'];
  87. return itemsWithDropdown.contains(item);
  88. }.property(''),
  89. isAdminItem: function () {
  90. return this.get('content').routing == 'admin';
  91. }.property(''),
  92. isServicesItem: function () {
  93. return this.get('content').routing == 'services';
  94. }.property(''),
  95. isViewsItem: function () {
  96. return this.get('content').routing == 'views';
  97. }.property(''),
  98. goToCategory: function (event) {
  99. //App.router.transitionTo('admin.service.summary', service);
  100. var itemName = this.get('content').routing;
  101. // route to correct category of current menu item
  102. if (itemName == 'admin') {
  103. App.router.transitionTo('admin.' + event.context);
  104. }
  105. },
  106. dropdownCategories: function () {
  107. var itemName = this.get('content').routing;
  108. var categories = [];
  109. // create dropdown categories for each menu item
  110. if (itemName == 'admin') {
  111. categories = [{
  112. name: 'user',
  113. url: 'adminUser',
  114. label: Em.I18n.t('common.users')
  115. }];
  116. if (App.get('isHadoop2Stack') && App.supports.highAvailability) {
  117. categories.push({
  118. name: 'highAvailability',
  119. url: 'adminHighAvailability',
  120. label: Em.I18n.t('admin.highAvailability')
  121. });
  122. }
  123. if (App.supports.secureCluster) {
  124. categories.push({
  125. name: 'security',
  126. url: 'adminSecurity.index',
  127. label: Em.I18n.t('common.security')
  128. });
  129. }
  130. categories.push({
  131. name: 'cluster',
  132. url: 'adminCluster',
  133. label: Em.I18n.t('common.cluster')
  134. });
  135. categories.push({
  136. name: 'misc',
  137. url: 'adminMisc',
  138. label: Em.I18n.t('common.misc')
  139. });
  140. if (App.router.get('mainAdminController.isAccessAvailable')) {
  141. categories.push({
  142. name: 'access',
  143. url: 'adminAccess',
  144. label: Em.I18n.t('common.access')
  145. });
  146. }
  147. }
  148. return categories;
  149. }.property('')
  150. })
  151. });