From b463cc34faaf2fdb6607eeb09d0405ea4a78424e 2016-10-17 13:14:45 From: Marcin Lulek Date: 2016-10-17 13:14:45 Subject: [PATCH] frontend: move link definitions to javascript layer --- diff --git a/backend/src/appenlight/lib/configurator.py b/backend/src/appenlight/lib/configurator.py index 3e8fe9a..a3ed92d 100644 --- a/backend/src/appenlight/lib/configurator.py +++ b/backend/src/appenlight/lib/configurator.py @@ -71,7 +71,6 @@ def register_appenlight_plugin(config, plugin_name, plugin_config): 'javascript': None, 'static': None, 'css': None, - 'top_nav': None, 'celery_tasks': None, 'celery_beats': None, 'fulltext_indexer': None, diff --git a/backend/src/appenlight/static/js/appenlight.js b/backend/src/appenlight/static/js/appenlight.js index 8c0fb35..0fc383c 100644 --- a/backend/src/appenlight/static/js/appenlight.js +++ b/backend/src/appenlight/static/js/appenlight.js @@ -2744,6 +2744,7 @@ var pluginsToLoad = _.map(decodeEncodedJSON(window.AE.plugins), function(item){ return item.config.angular_module }); +console.info(pluginsToLoad); angular.module('appenlight.plugins', pluginsToLoad); @@ -2815,6 +2816,14 @@ function kickstartAE(initialUserData) { function ($rootScope, $timeout, stateHolder, $state, $location, $transitions, $window, AeConfig) { if (initialUserData){ stateHolder.AeUser.update(initialUserData); + + if (stateHolder.AeUser.hasAppPermission('root_administration' + )){ + AeConfig.topNav.menuAdminItems.push( + {'sref': 'admin', 'label': 'Admin Settings'} + ) + } + } $rootScope.$state = $state; $rootScope.stateHolder = stateHolder; @@ -2948,7 +2957,7 @@ function kickstartAE(initialUserData) { " \n" + " \n" + @@ -2973,11 +2982,11 @@ function kickstartAE(initialUserData) { "
  • \n" + " \n" + "
  • \n" + - "
  • \n" + + "
  • \n" + " \n" + " \n" + " \n" + @@ -6157,6 +6166,13 @@ function kickstartAE(initialUserData) { "
  • Create application
  • \n" + "
  • Purge logs
  • \n" + " \n" + + "\n" + + " \n" + + "\n" + " \n" + "\n" + "\n" + @@ -6168,6 +6184,13 @@ function kickstartAE(initialUserData) { "
  • External Identities
  • \n" + "
  • Auth Tokens
  • \n" + " \n" + + "\n" + + " \n" + + "\n" + " \n" + "\n" + "
    \n" + @@ -6176,7 +6199,15 @@ function kickstartAE(initialUserData) { "
  • Alert channels
  • \n" + "
  • Add email channel
  • \n" + " \n" + + "\n" + + " \n" + + "\n" + "
    \n" + + "\n" + " \n" + "\n" + "
    \n" + @@ -10465,10 +10496,11 @@ angular.module('appenlight.components.settingsView', []) controller: SettingsViewController }); -SettingsViewController.$inject = ['$state']; +SettingsViewController.$inject = ['$state', 'AeConfig']; -function SettingsViewController($state) { +function SettingsViewController($state, AeConfig) { this.$state = $state; + this.AeConfig = AeConfig; console.info('SettingsViewController'); } @@ -10921,7 +10953,19 @@ aeconfig.factory('AeConfig', function () { obj.flashMessages = decodeEncodedJSON(window.AE.flash_messages); obj.timeOptions = decodeEncodedJSON(window.AE.timeOptions); obj.plugins = decodeEncodedJSON(window.AE.plugins); - obj.topNav = decodeEncodedJSON(window.AE.topNav); + obj.topNav = { + menuDashboardsItems: [], + menuReportsItems: [], + menuLogsItems: [], + menuSettingsItems: [], + menuAdminItems: [] + }; + obj.settingsNav = { + menuApplicationsItems: [], + menuUserSettingsItems: [], + menuNotificationsItems: [] + }; + obj.adminNav = {}; obj.ws_url = window.AE.ws_url; obj.urls = window.AE.urls; // set keys on values because we wont be able to retrieve them everywhere @@ -13096,7 +13140,14 @@ angular.module('appenlight.services.stateHolder', []).factory('stateHolder', self.inclusions[name] = []; } self.inclusions[name].push(inclusion); - } + }, + addnavigation: function (name, inclusion) { + var self = this; + if (self.inclusions.hasOwnProperty(name) === false) { + self.inclusions[name] = []; + } + self.inclusions[name].push(inclusion); + }, }; var stateHolder = { diff --git a/backend/src/appenlight/subscribers.py b/backend/src/appenlight/subscribers.py index 25f1cc6..1ec18d3 100644 --- a/backend/src/appenlight/subscribers.py +++ b/backend/src/appenlight/subscribers.py @@ -38,8 +38,8 @@ def gen_urls(request): 'applicationsNoId': request.route_url('applications_no_id'), 'applications': request.route_url('applications', resource_id='REPLACE_ID').replace('REPLACE_ID',':resourceId'), 'applicationsProperty': request.route_url('applications_property',key='REPLACE_KEY', resource_id='REPLACE_ID').replace('REPLACE_ID',':resourceId').replace('REPLACE_KEY',':key'), - 'configsNoId': request.route_url('admin_configs'), - 'configs': request.route_url('admin_config', key='REPLACE_KEY', section='REPLACE_SECTION').replace('REPLACE_SECTION',':section').replace('REPLACE_KEY',':key'), + 'configsNoId': request.route_url('admin_configs'), + 'configs': request.route_url('admin_config', key='REPLACE_KEY', section='REPLACE_SECTION').replace('REPLACE_SECTION',':section').replace('REPLACE_KEY',':key'), 'docs': 'http://getappenlight.com/page/api/main.html', 'eventsNoId': request.route_url('events_no_id'), 'events': request.route_url('events', event_id='REPLACE_ID').replace('REPLACE_ID',':eventId'), @@ -47,34 +47,34 @@ def gen_urls(request): 'groupsNoId': request.route_url('groups_no_id'), 'groups': request.route_url('groups', group_id='REPLACE_ID').replace('REPLACE_ID',':groupId'), 'groupsProperty': request.route_url('groups_property',key='REPLACE_KEY', group_id='REPLACE_ID').replace('REPLACE_ID',':groupId').replace('REPLACE_KEY',':key'), - 'logsNoId': request.route_url('logs_no_id'), + 'logsNoId': request.route_url('logs_no_id'), 'integrationAction': request.route_url('integrations_id',action='REPLACE_ACT', resource_id='REPLACE_RID', integration='REPLACE_IID').replace('REPLACE_RID',':resourceId').replace('REPLACE_ACT',':action').replace('REPLACE_IID',':integration'), 'usersNoId': request.route_url('users_no_id'), 'users': request.route_url('users', user_id='REPLACE_ID').replace('REPLACE_ID',':userId'), 'usersProperty': request.route_url('users_property',key='REPLACE_KEY', user_id='REPLACE_ID').replace('REPLACE_ID',':userId').replace('REPLACE_KEY',':key'), 'userSelf': request.route_url('users_self'), 'userSelfProperty': request.route_url('users_self_property',key='REPLACE_KEY').replace('REPLACE_KEY',':key'), - 'reports': request.route_url('reports'), - 'reportGroup': request.route_url('report_groups', group_id='REPLACE_RID').replace('REPLACE_RID',':groupId'), - 'reportGroupProperty': request.route_url('report_groups_property', key='REPLACE_KEY', group_id='REPLACE_GID').replace('REPLACE_KEY',':key').replace('REPLACE_GID',':groupId'), - 'pluginConfigsNoId': request.route_url('plugin_configs', plugin_name='REPLACE_TYPE').replace('REPLACE_TYPE',':plugin_name'), - 'pluginConfigs': request.route_url('plugin_config', id='REPLACE_ID', plugin_name='REPLACE_TYPE').replace('REPLACE_ID',':id').replace('REPLACE_TYPE',':plugin_name'), + 'reports': request.route_url('reports'), + 'reportGroup': request.route_url('report_groups', group_id='REPLACE_RID').replace('REPLACE_RID',':groupId'), + 'reportGroupProperty': request.route_url('report_groups_property', key='REPLACE_KEY', group_id='REPLACE_GID').replace('REPLACE_KEY',':key').replace('REPLACE_GID',':groupId'), + 'pluginConfigsNoId': request.route_url('plugin_configs', plugin_name='REPLACE_TYPE').replace('REPLACE_TYPE',':plugin_name'), + 'pluginConfigs': request.route_url('plugin_config', id='REPLACE_ID', plugin_name='REPLACE_TYPE').replace('REPLACE_ID',':id').replace('REPLACE_TYPE',':plugin_name'), 'resourceProperty': request.route_url('resources_property',key='REPLACE_KEY', resource_id='REPLACE_ID').replace('REPLACE_ID',':resourceId').replace('REPLACE_KEY',':key'), - 'slowReports': request.route_url('slow_reports'), - 'sectionView': request.route_url('section_view', section='REPLACE_S', view='REPLACE_V').replace('REPLACE_S',':section').replace('REPLACE_V',':view'), + 'slowReports': request.route_url('slow_reports'), + 'sectionView': request.route_url('section_view', section='REPLACE_S', view='REPLACE_V').replace('REPLACE_S',':section').replace('REPLACE_V',':view'), 'otherRoutes': { - 'register': request.route_url('register') , - 'lostPassword': request.route_url('lost_password') , - 'lostPasswordGenerate': request.route_url('lost_password_generate'), + 'register': request.route_url('register'), + 'lostPassword': request.route_url('lost_password'), + 'lostPasswordGenerate': request.route_url('lost_password_generate'), 'signOut': request.route_url('ziggurat.routes.sign_out') }, 'social_auth': { - 'google':request.route_url('social_auth', provider='google'), - 'twitter':request.route_url('social_auth', provider='twitter'), - 'bitbucket':request.route_url('social_auth', provider='bitbucket'), - 'github':request.route_url('social_auth', provider='github'), + 'google': request.route_url('social_auth', provider='google'), + 'twitter': request.route_url('social_auth', provider='twitter'), + 'bitbucket': request.route_url('social_auth', provider='bitbucket'), + 'github': request.route_url('social_auth', provider='github'), }, - "plugins":{}, + "plugins": {}, "adminAction": request.route_url('admin', action="REPLACE_ACT").replace('REPLACE_ACT',':action') } return urls @@ -111,13 +111,6 @@ def add_renderer_globals(event): renderer_globals['security'] = security renderer_globals['flash_msgs'] = [] renderer_globals['js_plugins'] = [] - renderer_globals['top_nav'] = { - 'menu_dashboards_items': [], - 'menu_reports_items': [], - 'menu_logs_items': [], - 'menu_settings_items': [], - 'menu_admin_items': [], - } if 'jinja' in event['renderer_info'].type: renderer_globals['url_list'] = gen_urls(request) @@ -129,17 +122,7 @@ def add_renderer_globals(event): if config['javascript']: renderer_globals['js_plugins'].append( - ({'name':module, 'config':config['javascript']})) - for nav_key in renderer_globals['top_nav'].keys(): - if nav_key in config['top_nav'] and config['top_nav'][nav_key]: - renderer_globals['top_nav'][nav_key].append( - config['top_nav'][nav_key]) - - if request.has_permission('root_administration', - security.RootFactory(request)): - renderer_globals['top_nav']['menu_admin_items'].append( - {'sref': 'admin', 'label': 'Admin Settings'} - ) + ({'name': module, 'config': config['javascript']})) footer_config = ConfigService.by_key_and_section( 'template_footer_html', 'global', default_value='') diff --git a/backend/src/appenlight/templates/layout_base.jinja2 b/backend/src/appenlight/templates/layout_base.jinja2 index c79ef30..ad87794 100644 --- a/backend/src/appenlight/templates/layout_base.jinja2 +++ b/backend/src/appenlight/templates/layout_base.jinja2 @@ -27,7 +27,6 @@ AE.flash_messages = {{ flash_msgs|toJSONUnsafe }}; AE.timeOptions = {{ h.time_options|toJSONUnsafe }}; AE.plugins = {{ js_plugins|toJSONUnsafe }}; - AE.topNav = {{ top_nav|toJSONUnsafe }}; {% if request.registry.settings.get('appenlight.public_api_key') %}