123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /**
- * 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('clusterController.ambariViews');
- }.property('App.ClusterController.ambariViews'),
- content:function(){
- var result = [
- { 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'}
- ];
- if (App.supports.mirroring && App.Service.find().findProperty('serviceName', 'FALCON')) {
- result.push({ label:Em.I18n.t('menu.item.mirroring'), routing:'mirroring'});
- }
- if (!App.get('isHadoop2Stack')) {
- result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'apps'});
- } else if( App.router.get('mainAdminController.isAccessAvailable') && App.supports.jobs
- && (App.router.get('mainAdminAccessController.showJobs') || App.get('isAdmin'))) {
- result.push({ label:Em.I18n.t('menu.item.jobs'), routing:'jobs'});
- }
- if (App.get('isAdmin')) {
- result.push({ label:Em.I18n.t('menu.item.admin'), routing:'admin'});
- }
- if (App.supports.views) {
- result.push({ label:Em.I18n.t('menu.item.views'), routing:'views', isView:true, views: this.get('views')});
- }
- return result;
- }.property('App.supports.views', 'App.supports.mirroring', 'App.supports.secureCluster', 'App.supports.highAvailability', 'App.supports.jobs'),
- /**
- * Adds observer on lastSetURL and calls navigation sync procedure
- */
- didInsertElement:function () {
- App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
- this.renderOnRoute();
- },
- /**
- * Syncs navigation menu with requested URL
- */
- renderOnRoute:function () {
- 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';
- $.each(this._childViews, function () {
- this.set('active', this.get('content.routing') == chunk ? "active" : "");
- });
- },
- itemViewClass:Em.View.extend({
- classNameBindings:['active', ':top-nav-dropdown'],
- active:'',
- alertsCount:function () {
- if (this.get('content').routing == 'hosts') {
- return App.router.get('mainHostController.content').mapProperty('criticalAlertsCount')
- .reduce(function(pv, cv) { return pv + parseInt(cv); }, 0);
- }
- }.property('App.router.mainHostController.content.@each.criticalAlertsCount'),
- 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 == 'views';
- }.property(''),
- goToCategory: function (event) {
- //App.router.transitionTo('admin.service.summary', service);
- var itemName = this.get('content').routing;
- // route to correct category of current menu item
- if (itemName == 'admin') {
- App.router.transitionTo('admin.' + event.context);
- }
- },
- dropdownCategories: function () {
- var itemName = this.get('content').routing;
- var categories = [];
- // create dropdown categories for each menu item
- if (itemName == 'admin') {
- categories = [{
- name: 'user',
- url: 'adminUser',
- label: Em.I18n.t('common.users')
- }];
- if (App.get('isHadoop2Stack') && App.supports.highAvailability) {
- categories.push({
- name: 'highAvailability',
- url: 'adminHighAvailability',
- label: Em.I18n.t('admin.highAvailability')
- });
- }
- if (App.supports.secureCluster) {
- categories.push({
- name: 'security',
- url: 'adminSecurity.index',
- label: Em.I18n.t('common.security')
- });
- }
- categories.push({
- name: 'cluster',
- url: 'adminCluster',
- label: Em.I18n.t('common.cluster')
- });
- categories.push({
- name: 'misc',
- url: 'adminMisc',
- label: Em.I18n.t('common.misc')
- });
- if (App.router.get('mainAdminController.isAccessAvailable')) {
- categories.push({
- name: 'access',
- url: 'adminAccess',
- label: Em.I18n.t('common.access')
- });
- }
- }
- return categories;
- }.property('')
- })
- });
|