menu.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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('mainViewsController.ambariViews');
  28. }.property('App.router.mainViewsController.ambariViews'),
  29. content: function () {
  30. var result = [];
  31. if (App.router.get('loggedIn')) {
  32. if (App.router.get('clusterController.isLoaded') && App.get('router.clusterInstallCompleted')) {
  33. result.push(
  34. { label: Em.I18n.t('menu.item.dashboard'), routing: 'dashboard', active: 'active'},
  35. { label: Em.I18n.t('menu.item.services'), routing: 'services'},
  36. { label: Em.I18n.t('menu.item.hosts'), routing: 'hosts', hasAlertsLabel: true}
  37. );
  38. if (App.get('supports.alerts')) {
  39. result.push({ label: Em.I18n.t('menu.item.alerts'), routing: 'alerts'});
  40. }
  41. if (!App.get('isHadoop2Stack')) {
  42. result.push({ label: Em.I18n.t('menu.item.jobs'), routing: 'apps'});
  43. }
  44. if (App.isAccessible('upgrade_ADMIN')) {
  45. result.push({ label: Em.I18n.t('menu.item.admin'), routing: 'admin'});
  46. }
  47. }
  48. result.push({ label: Em.I18n.t('menu.item.views'), routing: 'views.index', isView: true, views: this.get('views').filterProperty('visible')});
  49. }
  50. return result;
  51. }.property('App.router.loggedIn', 'views.length',
  52. 'App.router.clusterController.isLoaded', 'App.router.clusterInstallCompleted', 'App.supports.alerts'),
  53. itemViewClass: Em.View.extend({
  54. classNameBindings: ['active', ':top-nav-dropdown'],
  55. active: function () {
  56. if (App.get('clusterName') && App.router.get('clusterController.isLoaded')) {
  57. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  58. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  59. return;
  60. }
  61. var reg = /^\/main\/([a-z]+)/g;
  62. var sub_url = reg.exec(last_url);
  63. var chunk = (null != sub_url) ? sub_url[1] : 'dashboard';
  64. return this.get('content.routing').indexOf(chunk) === 0 ? "active" : "";
  65. }
  66. return "";
  67. }.property('App.router.location.lastSetURL', 'App.router.clusterController.isLoaded'),
  68. alertsCount: function () {
  69. return App.router.get('mainHostController.hostsCountMap.health-status-WITH-ALERTS');
  70. }.property('App.router.mainHostController.hostsCountMap'),
  71. hasAlertsLabel: function () {
  72. return this.get('content.hasAlertsLabel') && this.get('alertsCount') > 0;
  73. }.property('content.hasAlertsLabel', 'alertsCount'),
  74. templateName: require('templates/main/menu_item'),
  75. dropdownMenu: function () {
  76. var item = this.get('content').routing;
  77. var itemsWithDropdown = ['services', 'admin', 'views'];
  78. return itemsWithDropdown.contains(item);
  79. }.property(''),
  80. isAdminItem: function () {
  81. return this.get('content').routing == 'admin';
  82. }.property(''),
  83. isServicesItem: function () {
  84. return this.get('content').routing == 'services';
  85. }.property(''),
  86. isViewsItem: function () {
  87. return this.get('content').routing.contains('views');
  88. }.property(''),
  89. goToSection: function (event) {
  90. if (event.context === 'hosts') {
  91. App.router.set('mainHostController.showFilterConditionsFirstLoad', false);
  92. } else if (event.context === 'views') {
  93. App.router.route('views');
  94. return;
  95. }
  96. App.router.route('main/' + event.context);
  97. },
  98. goToCategory: function (event) {
  99. var itemName = this.get('content').routing;
  100. // route to correct category of current menu item
  101. if (itemName == 'admin') {
  102. App.router.route('main/admin/' + event.context);
  103. }
  104. },
  105. dropdownCategories: function () {
  106. var itemName = this.get('content').routing;
  107. var categories = [];
  108. // create dropdown categories for each menu item
  109. if (itemName == 'admin') {
  110. categories = [];
  111. categories.push({
  112. name: 'stackAndUpgrade',
  113. url: 'stack',
  114. label: Em.I18n.t('admin.stackUpgrade.title')
  115. });
  116. if (App.get('supports.stackUpgrade')) {
  117. categories.push({
  118. name: 'adminStackVersions.index',
  119. url: 'versions',
  120. label: Em.I18n.t('common.stack.versions')
  121. });
  122. }
  123. categories.push({
  124. name: 'adminServiceAccounts',
  125. url: 'serviceAccounts',
  126. label: Em.I18n.t('common.serviceAccounts')
  127. });
  128. if (!App.get('isHadoopWindowsStack')) {
  129. if (App.get('supports.automatedKerberos')) {
  130. categories.push({
  131. name: 'kerberos',
  132. url: 'kerberos/',
  133. label: Em.I18n.t('common.kerberos')
  134. });
  135. } else {
  136. categories.push({
  137. name: 'security',
  138. url: 'security/',
  139. label: Em.I18n.t('common.security')
  140. });
  141. }
  142. }
  143. }
  144. return categories;
  145. }.property('')
  146. })
  147. });