123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- /**
- * this menu extended by other with modifying content and itemViewClass.template
- * @type {*}
- */
- App.MainMenuView = Em.CollectionView.extend({
- tagName: 'ul',
- classNames: ['nav', 'top-nav-menu'],
- views: function () {
- return App.router.get('mainViewsController.ambariViews');
- }.property('App.router.mainViewsController.ambariViews'),
- content: function () {
- var result = [];
- if (App.router.get('loggedIn')) {
- if (App.router.get('clusterController.isLoaded') && App.get('router.clusterInstallCompleted')) {
- result.push(
- { label: Em.I18n.t('menu.item.dashboard'), routing: 'dashboard', active: 'active'},
- { label: Em.I18n.t('menu.item.services'), routing: 'services'},
- { label: Em.I18n.t('menu.item.hosts'), routing: 'hosts', hasAlertsLabel: true}
- );
- if (App.get('supports.alerts')) {
- result.push({ label: Em.I18n.t('menu.item.alerts'), routing: 'alerts'});
- }
- if (!App.get('isHadoop2Stack')) {
- result.push({ label: Em.I18n.t('menu.item.jobs'), routing: 'apps'});
- }
- if (App.isAccessible('upgrade_ADMIN')) {
- result.push({ label: Em.I18n.t('menu.item.admin'), routing: 'admin'});
- }
- }
- result.push({ label: Em.I18n.t('menu.item.views'), routing: 'views.index', isView: true, views: this.get('views').filterProperty('visible')});
- }
- return result;
- }.property('App.router.loggedIn', 'views.length',
- 'App.router.clusterController.isLoaded', 'App.router.clusterInstallCompleted', 'App.supports.alerts'),
- itemViewClass: Em.View.extend({
- classNameBindings: ['active', ':top-nav-dropdown'],
- active: function () {
- if (App.get('clusterName') && App.router.get('clusterController.isLoaded')) {
- var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
- if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
- return;
- }
- var reg = /^\/main\/([a-z]+)/g;
- var sub_url = reg.exec(last_url);
- var chunk = (null != sub_url) ? sub_url[1] : 'dashboard';
- return this.get('content.routing').indexOf(chunk) === 0 ? "active" : "";
- }
- return "";
- }.property('App.router.location.lastSetURL', 'App.router.clusterController.isLoaded'),
- alertsCount: function () {
- return App.router.get('mainHostController.hostsCountMap.health-status-WITH-ALERTS');
- }.property('App.router.mainHostController.hostsCountMap'),
- hasAlertsLabel: function () {
- return this.get('content.hasAlertsLabel') && this.get('alertsCount') > 0;
- }.property('content.hasAlertsLabel', 'alertsCount'),
- templateName: require('templates/main/menu_item'),
- dropdownMenu: function () {
- var item = this.get('content').routing;
- var itemsWithDropdown = ['services', 'admin', 'views'];
- return itemsWithDropdown.contains(item);
- }.property(''),
- isAdminItem: function () {
- return this.get('content').routing == 'admin';
- }.property(''),
- isServicesItem: function () {
- return this.get('content').routing == 'services';
- }.property(''),
- isViewsItem: function () {
- return this.get('content').routing.contains('views');
- }.property(''),
- goToSection: function (event) {
- if (event.context === 'hosts') {
- App.router.set('mainHostController.showFilterConditionsFirstLoad', false);
- } else if (event.context === 'views') {
- App.router.route('views');
- return;
- }
- App.router.route('main/' + event.context);
- },
- goToCategory: function (event) {
- var itemName = this.get('content').routing;
- // route to correct category of current menu item
- if (itemName == 'admin') {
- App.router.route('main/admin/' + event.context);
- }
- },
- dropdownCategories: function () {
- var itemName = this.get('content').routing;
- var categories = [];
- // create dropdown categories for each menu item
- if (itemName == 'admin') {
- categories = [];
- categories.push({
- name: 'stackAndUpgrade',
- url: 'stack',
- label: Em.I18n.t('admin.stackUpgrade.title')
- });
- if (App.get('supports.stackUpgrade')) {
- categories.push({
- name: 'adminStackVersions.index',
- url: 'versions',
- label: Em.I18n.t('common.stack.versions')
- });
- }
- categories.push({
- name: 'adminServiceAccounts',
- url: 'serviceAccounts',
- label: Em.I18n.t('common.serviceAccounts')
- });
- if (!App.get('isHadoopWindowsStack')) {
- if (App.get('supports.automatedKerberos')) {
- categories.push({
- name: 'kerberos',
- url: 'kerberos/',
- label: Em.I18n.t('common.kerberos')
- });
- } else {
- categories.push({
- name: 'security',
- url: 'security/',
- label: Em.I18n.t('common.security')
- });
- }
- }
- }
- return categories;
- }.property('')
- })
- });
|