menu.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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'],
  26. content:function(){
  27. var result = [
  28. { label:Em.I18n.t('menu.item.dashboard'), routing:'dashboard', active:'active'},
  29. { label:Em.I18n.t('menu.item.heatmaps'), routing:'charts'},
  30. { label:Em.I18n.t('menu.item.services'), routing:'services'},
  31. { label:Em.I18n.t('menu.item.hosts'), routing:'hosts'},
  32. { label:Em.I18n.t('menu.item.jobs'), routing:'apps'}
  33. ];
  34. if(App.db.getUser().admin) result.push({ label:Em.I18n.t('menu.item.admin'), routing:'admin'});
  35. return result;
  36. }.property(),
  37. /**
  38. * Adds observer on lastSetURL and calls navigation sync procedure
  39. */
  40. didInsertElement:function () {
  41. App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
  42. this.renderOnRoute();
  43. },
  44. /**
  45. * Syncs navigation menu with requested URL
  46. */
  47. renderOnRoute:function () {
  48. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  49. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  50. return;
  51. }
  52. var reg = /^\/main\/([a-z]+)/g;
  53. var sub_url = reg.exec(last_url);
  54. var chunk = (null != sub_url) ? sub_url[1] : 'dashboard';
  55. $.each(this._childViews, function () {
  56. this.set('active', this.get('content.routing') == chunk ? "active" : "");
  57. });
  58. },
  59. itemViewClass:Em.View.extend({
  60. classNameBindings:['active', ':span2'],
  61. active:'',
  62. alertsCount:function () {
  63. if (this.get('content').routing == 'dashboard') {
  64. return App.router.get('mainDashboardController.alertsCount');
  65. }
  66. }.property(),
  67. // hostDetailsOperationsCount:function () {
  68. // if (this.get('content').routing == 'hosts') {
  69. // if (App.router.currentState.parentState.name == 'hostDetails') {
  70. // return App.router.get('mainHostDetailsController.hostOperationsCount');
  71. // }
  72. // }
  73. // }.property('App.router.currentState.parentState.name', 'App.router.mainHostDetailsController.hostOperationsCount'),
  74. templateName: require('templates/main/menu_item')
  75. })
  76. });