Show More
@@ -1,135 +1,143 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | import logging |
|
23 | 23 | import collections |
|
24 | 24 | |
|
25 | 25 | from zope.interface import implementer |
|
26 | 26 | |
|
27 | 27 | from rhodecode.apps.admin.interfaces import IAdminNavigationRegistry |
|
28 | 28 | from rhodecode.lib.utils2 import str2bool |
|
29 | 29 | from rhodecode.translation import _ |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | log = logging.getLogger(__name__) |
|
33 | 33 | |
|
34 |
NavListEntry = collections.namedtuple( |
|
|
34 | NavListEntry = collections.namedtuple( | |
|
35 | 'NavListEntry', ['key', 'name', 'url', 'active_list']) | |
|
35 | 36 | |
|
36 | 37 | |
|
37 | 38 | class NavEntry(object): |
|
38 | 39 | """ |
|
39 | 40 | Represents an entry in the admin navigation. |
|
40 | 41 | |
|
41 | 42 | :param key: Unique identifier used to store reference in an OrderedDict. |
|
42 | 43 | :param name: Display name, usually a translation string. |
|
43 | 44 | :param view_name: Name of the view, used generate the URL. |
|
44 | :param pyramid: Indicator to use pyramid for URL generation. This should | |
|
45 | be removed as soon as we are fully migrated to pyramid. | |
|
45 | :param active_list: list of urls that we select active for this element | |
|
46 | 46 | """ |
|
47 | 47 | |
|
48 | def __init__(self, key, name, view_name): | |
|
48 | def __init__(self, key, name, view_name, active_list=None): | |
|
49 | 49 | self.key = key |
|
50 | 50 | self.name = name |
|
51 | 51 | self.view_name = view_name |
|
52 | self._active_list = active_list or [] | |
|
52 | 53 | |
|
53 | 54 | def generate_url(self, request): |
|
54 | 55 | return request.route_path(self.view_name) |
|
55 | 56 | |
|
56 | 57 | def get_localized_name(self, request): |
|
57 | 58 | return request.translate(self.name) |
|
58 | 59 | |
|
60 | @property | |
|
61 | def active_list(self): | |
|
62 | active_list = [self.key] | |
|
63 | if self._active_list: | |
|
64 | active_list = self._active_list | |
|
65 | return active_list | |
|
66 | ||
|
59 | 67 | |
|
60 | 68 | @implementer(IAdminNavigationRegistry) |
|
61 | 69 | class NavigationRegistry(object): |
|
62 | 70 | |
|
63 | 71 | _base_entries = [ |
|
64 | 72 | NavEntry('global', _('Global'), |
|
65 | 73 | 'admin_settings_global'), |
|
66 | 74 | NavEntry('vcs', _('VCS'), |
|
67 | 75 | 'admin_settings_vcs'), |
|
68 | 76 | NavEntry('visual', _('Visual'), |
|
69 | 77 | 'admin_settings_visual'), |
|
70 | 78 | NavEntry('mapping', _('Remap and Rescan'), |
|
71 | 79 | 'admin_settings_mapping'), |
|
72 | 80 | NavEntry('issuetracker', _('Issue Tracker'), |
|
73 | 81 | 'admin_settings_issuetracker'), |
|
74 | 82 | NavEntry('email', _('Email'), |
|
75 | 83 | 'admin_settings_email'), |
|
76 | 84 | NavEntry('hooks', _('Hooks'), |
|
77 | 85 | 'admin_settings_hooks'), |
|
78 | 86 | NavEntry('search', _('Full Text Search'), |
|
79 | 87 | 'admin_settings_search'), |
|
80 | 88 | NavEntry('integrations', _('Integrations'), |
|
81 | 89 | 'global_integrations_home'), |
|
82 | 90 | NavEntry('system', _('System Info'), |
|
83 | 91 | 'admin_settings_system'), |
|
84 | 92 | NavEntry('process_management', _('Processes'), |
|
85 | 93 | 'admin_settings_process_management'), |
|
86 | 94 | NavEntry('sessions', _('User Sessions'), |
|
87 | 95 | 'admin_settings_sessions'), |
|
88 | 96 | NavEntry('open_source', _('Open Source Licenses'), |
|
89 | 97 | 'admin_settings_open_source'), |
|
90 | 98 | |
|
91 | 99 | ] |
|
92 | 100 | |
|
93 | 101 | _labs_entry = NavEntry('labs', _('Labs'), |
|
94 | 102 | 'admin_settings_labs') |
|
95 | 103 | |
|
96 | 104 | def __init__(self, labs_active=False): |
|
97 | 105 | self._registered_entries = collections.OrderedDict() |
|
98 | 106 | for item in self.__class__._base_entries: |
|
99 | 107 | self._registered_entries[item.key] = item |
|
100 | 108 | |
|
101 | 109 | if labs_active: |
|
102 | 110 | self.add_entry(self._labs_entry) |
|
103 | 111 | |
|
104 | 112 | def add_entry(self, entry): |
|
105 | 113 | self._registered_entries[entry.key] = entry |
|
106 | 114 | |
|
107 | 115 | def get_navlist(self, request): |
|
108 | 116 | navlist = [NavListEntry(i.key, i.get_localized_name(request), |
|
109 | i.generate_url(request)) | |
|
117 | i.generate_url(request), i.active_list) | |
|
110 | 118 | for i in self._registered_entries.values()] |
|
111 | 119 | return navlist |
|
112 | 120 | |
|
113 | 121 | |
|
114 | 122 | def navigation_registry(request, registry=None): |
|
115 | 123 | """ |
|
116 | 124 | Helper that returns the admin navigation registry. |
|
117 | 125 | """ |
|
118 | 126 | pyramid_registry = registry or request.registry |
|
119 | 127 | nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) |
|
120 | 128 | return nav_registry |
|
121 | 129 | |
|
122 | 130 | |
|
123 | 131 | def navigation_list(request): |
|
124 | 132 | """ |
|
125 | 133 | Helper that returns the admin navigation as list of NavListEntry objects. |
|
126 | 134 | """ |
|
127 | 135 | return navigation_registry(request).get_navlist(request) |
|
128 | 136 | |
|
129 | 137 | |
|
130 | 138 | def includeme(config): |
|
131 | 139 | # Create admin navigation registry and add it to the pyramid registry. |
|
132 | 140 | settings = config.get_settings() |
|
133 | 141 | labs_active = str2bool(settings.get('labs_settings_active', False)) |
|
134 | 142 | navigation_registry = NavigationRegistry(labs_active=labs_active) |
|
135 | 143 | config.registry.registerUtility(navigation_registry) No newline at end of file |
@@ -1,53 +1,53 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | <%inherit file="/base/base.mako"/> |
|
3 | 3 | |
|
4 | 4 | <%def name="title()"> |
|
5 | 5 | ${_('Settings administration')} |
|
6 | 6 | %if c.rhodecode_name: |
|
7 | 7 | · ${h.branding(c.rhodecode_name)} |
|
8 | 8 | %endif |
|
9 | 9 | </%def> |
|
10 | 10 | |
|
11 | 11 | <%def name="breadcrumbs_links()"> |
|
12 | 12 | ${h.link_to(_('Admin'),h.route_path('admin_home'))} |
|
13 | 13 | » |
|
14 | 14 | ${_('Settings')} |
|
15 | 15 | </%def> |
|
16 | 16 | |
|
17 | 17 | <%def name="menu_bar_nav()"> |
|
18 | 18 | ${self.menu_items(active='admin')} |
|
19 | 19 | </%def> |
|
20 | 20 | |
|
21 | 21 | <%def name="side_bar_nav()"> |
|
22 | 22 | % for navitem in c.navlist: |
|
23 |
<li class="${'active' if c.active |
|
|
23 | <li class="${'active' if c.active in navitem.active_list else ''}"> | |
|
24 | 24 | <a href="${navitem.url}">${navitem.name}</a> |
|
25 | 25 | </li> |
|
26 | 26 | % endfor |
|
27 | 27 | </%def> |
|
28 | 28 | |
|
29 | 29 | <%def name="main_content()"> |
|
30 | 30 | <%include file="/admin/settings/settings_${c.active}.mako"/> |
|
31 | 31 | </%def> |
|
32 | 32 | |
|
33 | 33 | <%def name="main()"> |
|
34 | 34 | <div class="box"> |
|
35 | 35 | <div class="title"> |
|
36 | 36 | ${self.breadcrumbs()} |
|
37 | 37 | </div> |
|
38 | 38 | |
|
39 | 39 | ##main |
|
40 | 40 | <div class='sidebar-col-wrapper'> |
|
41 | 41 | <div class="sidebar"> |
|
42 | 42 | <ul class="nav nav-pills nav-stacked"> |
|
43 | 43 | ${self.side_bar_nav()} |
|
44 | 44 | </ul> |
|
45 | 45 | </div> |
|
46 | 46 | |
|
47 | 47 | <div class="main-content-full-width"> |
|
48 | 48 | ${self.main_content()} |
|
49 | 49 | </div> |
|
50 | 50 | </div> |
|
51 | 51 | </div> |
|
52 | 52 | |
|
53 | 53 | </%def> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now