aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.js
blob: afe8b25f1f26390ee313e859f71fbca152439e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * SonarQube
 * Copyright (C) 2009-2016 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import React from 'react';
import classNames from 'classnames';
import { translate } from '../../../../helpers/l10n';

export default class SettingsNav extends React.Component {
  static defaultProps = {
    extensions: []
  };

  isSomethingActive (urls) {
    const path = window.location.pathname;
    return urls.some(url => path.indexOf(window.baseUrl + url) === 0);
  }

  isSecurityActive () {
    const urls = ['/users', '/groups', '/roles/global', '/permission_templates'];
    return this.isSomethingActive(urls);
  }

  isProjectsActive () {
    const urls = ['/projects_admin', '/background_tasks'];
    return this.isSomethingActive(urls);
  }

  isSystemActive () {
    const urls = ['/updatecenter', '/system'];
    return this.isSomethingActive(urls);
  }

  renderLink(url, title, highlightUrl = url) {
    const fullUrl = window.baseUrl + url;
    const isActive = typeof highlightUrl === 'string' ?
    window.location.pathname.indexOf(window.baseUrl + highlightUrl) === 0 :
        highlightUrl(fullUrl);

    return (
        <li key={url} className={classNames({ 'active': isActive })}>
          <a href={fullUrl}>{title}</a>
        </li>
    );
  }

  render () {
    const isSecurity = this.isSecurityActive();
    const isProjects = this.isProjectsActive();
    const isSystem = this.isSystemActive();

    const securityClassName = classNames('dropdown', { active: isSecurity });
    const projectsClassName = classNames('dropdown', { active: isProjects });
    const systemClassName = classNames('dropdown', { active: isSystem });
    const configurationClassNames = classNames('dropdown', {
      active: !isSecurity && !isProjects && !isSystem
    });

    return (
        <nav className="navbar navbar-context page-container" id="context-navigation">
          <div className="navbar-context-inner">
            <div className="container">
              <ul className="nav navbar-nav nav-crumbs">
                {this.renderLink('/settings', translate('layout.settings'))}
              </ul>

              <ul className="nav navbar-nav nav-tabs">
                <li className={configurationClassNames}>
                  <a className="dropdown-toggle" data-toggle="dropdown" href="#">
                    {translate('sidebar.project_settings')} <i className="icon-dropdown"/>
                  </a>
                  <ul className="dropdown-menu">
                    {this.renderLink('/settings', translate('settings.page'), url => window.location.pathname === url)}
                    {this.renderLink('/settings/licenses', translate('property.category.licenses'))}
                    {this.renderLink('/settings/encryption', translate('property.category.security.encryption'))}
                    {this.renderLink('/settings/server_id', translate('property.category.server_id'))}
                    {this.renderLink('/metrics', 'Custom Metrics')}
                    {this.props.extensions.map(e => this.renderLink(e.url, e.name))}
                  </ul>
                </li>

                <li className={securityClassName}>
                  <a className="dropdown-toggle" data-toggle="dropdown" href="#">
                    {translate('sidebar.security')} <i className="icon-dropdown"/>
                  </a>
                  <ul className="dropdown-menu">
                    {this.renderLink('/users', translate('users.page'))}
                    {this.renderLink('/groups', translate('user_groups.page'))}
                    {this.renderLink('/roles/global', translate('global_permissions.page'))}
                    {this.renderLink('/permission_templates', translate('permission_templates'))}
                  </ul>
                </li>

                <li className={projectsClassName}>
                  <a className="dropdown-toggle" data-toggle="dropdown" href="#">
                    {translate('sidebar.projects')} <i className="icon-dropdown"/>
                  </a>
                  <ul className="dropdown-menu">
                    {this.renderLink('/projects_admin', 'Management')}
                    {this.renderLink('/background_tasks', translate('background_tasks.page'))}
                  </ul>
                </li>

                <li className={systemClassName}>
                  <a className="dropdown-toggle" data-toggle="dropdown" href="#">
                    {translate('sidebar.system')} <i className="icon-dropdown"/>
                  </a>
                  <ul className="dropdown-menu">
                    {this.renderLink('/updatecenter', translate('update_center.page'))}
                    {this.renderLink('/system', translate('system_info.page'))}
                  </ul>
                </li>
              </ul>
            </div>
          </div>
        </nav>
    );
  }
}