menu.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if (!App.get('isOnlyViewUser')) {
  34. result.push(
  35. {label: Em.I18n.t('menu.item.dashboard'), routing: 'dashboard', active: 'active'},
  36. {label: Em.I18n.t('menu.item.services'), routing: 'services'},
  37. {label: Em.I18n.t('menu.item.hosts'), routing: 'hosts'},
  38. {label: Em.I18n.t('menu.item.alerts'), routing: 'alerts'}
  39. );
  40. }
  41. if (App.isAuthorized('CLUSTER.TOGGLE_KERBEROS, CLUSTER.MODIFY_CONFIGS, SERVICE.START_STOP, AMBARI.SET_SERVICE_USERS_GROUPS, CLUSTER.UPGRADE_DOWNGRADE_STACK, CLUSTER.VIEW_STACK_DETAILS')
  42. || (App.get('upgradeInProgress') || App.get('upgradeHolding'))) {
  43. result.push({ label: Em.I18n.t('menu.item.admin'), routing: 'admin'});
  44. }
  45. }
  46. result.push({ label: Em.I18n.t('menu.item.views'), routing: 'views.index', isView: true, views: this.get('views').filterProperty('visible')});
  47. }
  48. return result;
  49. }.property(
  50. 'App.router.loggedIn',
  51. 'views.length',
  52. 'App.router.clusterController.isLoaded',
  53. 'App.router.clusterInstallCompleted',
  54. 'App.router.wizardWatcherController.isWizardRunning'
  55. ),
  56. itemViewClass: Em.View.extend({
  57. classNameBindings: ['active', ':top-nav-dropdown'],
  58. active: function () {
  59. if (App.get('clusterName') && App.router.get('clusterController.isLoaded')) {
  60. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  61. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  62. return;
  63. }
  64. var reg = /^\/main\/([a-z]+)/g;
  65. var sub_url = reg.exec(last_url);
  66. var chunk = (null != sub_url) ? sub_url[1] : 'dashboard';
  67. return this.get('content.routing').indexOf(chunk) === 0 ? "active" : "";
  68. }
  69. return "";
  70. }.property('App.router.location.lastSetURL', 'App.router.clusterController.isLoaded'),
  71. templateName: require('templates/main/menu_item'),
  72. dropdownMenu: Em.computed.existsIn('content.routing', ['services', 'admin', 'views']),
  73. isAdminItem: Em.computed.equal('content.routing', 'admin'),
  74. isServicesItem: Em.computed.equal('content.routing', 'services'),
  75. isViewsItem: function () {
  76. return this.get('content').routing.contains('views');
  77. }.property(''),
  78. goToSection: function (event) {
  79. if (event.context === 'hosts') {
  80. App.router.set('mainHostController.showFilterConditionsFirstLoad', false);
  81. } else if (event.context === 'views') {
  82. App.router.route('views');
  83. return;
  84. } else if (event.context === 'alerts') {
  85. App.router.set('mainAlertDefinitionsController.showFilterConditionsFirstLoad', false);
  86. }
  87. App.router.route('main/' + event.context);
  88. },
  89. selectedAdminItemBinding: 'App.router.mainAdminController.category',
  90. dropdownCategories: function () {
  91. var itemName = this.get('content').routing;
  92. var categories = [];
  93. // create dropdown categories for each menu item
  94. if (itemName == 'admin') {
  95. categories = [];
  96. if(App.isAuthorized('CLUSTER.VIEW_STACK_DETAILS, CLUSTER.UPGRADE_DOWNGRADE_STACK') || (App.get('upgradeInProgress') || App.get('upgradeHolding'))) {
  97. categories.push({
  98. name: 'stackAndUpgrade',
  99. url: 'stack',
  100. label: Em.I18n.t('admin.stackUpgrade.title')
  101. });
  102. }
  103. if(App.isAuthorized('AMBARI.SET_SERVICE_USERS_GROUPS') || (App.get('upgradeInProgress') || App.get('upgradeHolding'))) {
  104. categories.push({
  105. name: 'adminServiceAccounts',
  106. url: 'serviceAccounts',
  107. label: Em.I18n.t('common.serviceAccounts')
  108. });
  109. }
  110. if (!App.get('isHadoopWindowsStack') && App.isAuthorized('CLUSTER.TOGGLE_KERBEROS') || (App.get('upgradeInProgress') || App.get('upgradeHolding'))) {
  111. categories.push({
  112. name: 'kerberos',
  113. url: 'kerberos/',
  114. label: Em.I18n.t('common.kerberos')
  115. });
  116. }
  117. if (App.isAuthorized('SERVICE.START_STOP, CLUSTER.MODIFY_CONFIGS') || (App.get('upgradeInProgress') || App.get('upgradeHolding'))) {
  118. if (App.supports.serviceAutoStart) {
  119. categories.push({
  120. name: 'serviceAutoStart',
  121. url: 'serviceAutoStart',
  122. label: Em.I18n.t('admin.serviceAutoStart.title')
  123. });
  124. }
  125. }
  126. }
  127. return categories;
  128. }.property(''),
  129. AdminDropdownItemView: Ember.View.extend({
  130. tagName: 'li',
  131. classNameBindings: 'isActive:active'.w(),
  132. isActive: Em.computed.equalProperties('item', 'parentView.selectedAdminItem'),
  133. goToCategory: function (event) {
  134. var itemName = this.get('parentView').get('content').routing;
  135. // route to correct category of current menu item
  136. // skip routing to already selected category
  137. if (itemName === 'admin' && !this.get('isActive')) {
  138. App.router.route('main/admin/' + event.context);
  139. }
  140. }
  141. })
  142. })
  143. });