menu.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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('clusterName')) {
  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'}
  37. );
  38. if (App.supports.mirroring && App.Service.find().findProperty('serviceName', 'FALCON')) {
  39. result.push({ label:Em.I18n.t('menu.item.mirroring'), routing:'mirroring'});
  40. }
  41. if (!App.get('isHadoop2Stack')) {
  42. result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'apps'});
  43. }
  44. if (App.get('isAdmin')) {
  45. result.push({ label:Em.I18n.t('menu.item.admin'), routing:'admin'});
  46. }
  47. }
  48. if (App.get('supports.views')) {
  49. result.push({ label:Em.I18n.t('menu.item.views'), routing:'views.index', isView:true, views: this.get('views').filterProperty('visible')});
  50. }
  51. }
  52. return result;
  53. }.property('App.router.loggedIn', 'App.router.clusterController.isLoaded', 'App.supports.views', 'App.supports.mirroring',
  54. 'App.supports.secureCluster', 'App.supports.highAvailability', 'views.length'),
  55. itemViewClass:Em.View.extend({
  56. classNameBindings: ['active', ':top-nav-dropdown'],
  57. active: function () {
  58. if (App.get('clusterName') && App.router.get('clusterController.isLoaded')) {
  59. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  60. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  61. return;
  62. }
  63. var reg = /^\/main\/([a-z]+)/g;
  64. var sub_url = reg.exec(last_url);
  65. var chunk = (null != sub_url) ? sub_url[1] : 'dashboard';
  66. return this.get('content.routing').indexOf(chunk) === 0 ? "active" : "";
  67. }
  68. return "";
  69. }.property('App.router.location.lastSetURL', 'App.router.clusterController.isLoaded'),
  70. alertsCount:function () {
  71. if (this.get('content').routing == 'hosts') {
  72. return App.router.get('mainHostController.content').mapProperty('criticalAlertsCount')
  73. .reduce(function(pv, cv) { return pv + parseInt(cv); }, 0);
  74. }
  75. }.property('App.router.mainHostController.content.@each.criticalAlertsCount'),
  76. templateName: require('templates/main/menu_item'),
  77. dropdownMenu: function () {
  78. var item = this.get('content').routing;
  79. var itemsWithDropdown = ['services', 'admin', 'views'];
  80. return itemsWithDropdown.contains(item);
  81. }.property(''),
  82. isAdminItem: function () {
  83. return this.get('content').routing == 'admin';
  84. }.property(''),
  85. isServicesItem: function () {
  86. return this.get('content').routing == 'services';
  87. }.property(''),
  88. isViewsItem: function () {
  89. return this.get('content').routing.contains('views');
  90. }.property(''),
  91. goToSection: function (event) {
  92. if (event.context === 'hosts') {
  93. App.router.set('mainHostController.showFilterConditionsFirstLoad', false);
  94. } else if (event.context === 'views') {
  95. App.router.route('views');
  96. return;
  97. }
  98. App.router.route('main/' + event.context);
  99. },
  100. goToCategory: function (event) {
  101. var itemName = this.get('content').routing;
  102. // route to correct category of current menu item
  103. if (itemName == 'admin') {
  104. App.router.route('main/admin/' + event.context);
  105. }
  106. },
  107. dropdownCategories: function () {
  108. var itemName = this.get('content').routing;
  109. var categories = [];
  110. // create dropdown categories for each menu item
  111. if (itemName == 'admin') {
  112. categories = [];
  113. categories.push({
  114. name: 'adminRepositories',
  115. url: 'repositories',
  116. label: Em.I18n.t('common.repositories')
  117. });
  118. categories.push({
  119. name: 'adminServiceAccounts',
  120. url: 'serviceAccounts',
  121. label: Em.I18n.t('common.serviceAccounts')
  122. });
  123. if (App.supports.secureCluster) {
  124. categories.push({
  125. name: 'security',
  126. url: 'security/',
  127. label: Em.I18n.t('common.security')
  128. });
  129. }
  130. }
  131. return categories;
  132. }.property('')
  133. })
  134. });