blob: 6ef4906f56fb909cfb66a48089ac86915f30bce3 (
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
import ReactDOM from 'react-dom';
import TeamStore from 'stores/team_store.jsx';
import Constants from 'utils/constants.jsx';
import AboutBuildModal from 'components/about_build_modal.jsx';
import {sortTeamsByDisplayName} from 'utils/team_utils.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router/es6';
import React from 'react';
import * as Utils from 'utils/utils.jsx';
export default class AdminNavbarDropdown extends React.Component {
constructor(props) {
super(props);
this.blockToggle = false;
this.onTeamChange = this.onTeamChange.bind(this);
this.handleAboutModal = this.handleAboutModal.bind(this);
this.aboutModalDismissed = this.aboutModalDismissed.bind(this);
this.state = {
teams: TeamStore.getAll(),
teamMembers: TeamStore.getMyTeamMembers(),
showAboutModal: false
};
}
componentDidMount() {
$(ReactDOM.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => {
this.blockToggle = true;
setTimeout(() => {
this.blockToggle = false;
}, 100);
});
TeamStore.addChangeListener(this.onTeamChange);
}
componentWillUnmount() {
$(ReactDOM.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown');
TeamStore.removeChangeListener(this.onTeamChange);
}
handleAboutModal(e) {
e.preventDefault();
this.setState({showAboutModal: true});
}
aboutModalDismissed() {
this.setState({showAboutModal: false});
}
onTeamChange() {
this.setState({
teams: TeamStore.getAll(),
teamMembers: TeamStore.getMyTeamMembers()
});
}
render() {
var teamsArray = []; // Array of team objects
var teams = []; // Array of team components
let switchTeams;
if (this.state.teamMembers && this.state.teamMembers.length > 0) {
for (const index in this.state.teamMembers) {
if (this.state.teamMembers.hasOwnProperty(index)) {
const teamMember = this.state.teamMembers[index];
const team = this.state.teams[teamMember.team_id];
teamsArray.push(team);
}
}
// Sort teams alphabetically with display_name
teamsArray = teamsArray.sort(sortTeamsByDisplayName);
for (const team of teamsArray) {
teams.push(
<li key={'team_' + team.name}>
<Link
id={'swithTo' + Utils.createSafeId(team.name)}
to={'/' + team.name + '/channels/town-square'}
>
<FormattedMessage
id='navbar_dropdown.switchTo'
defaultMessage='Switch to '
/>
{team.display_name}
</Link>
</li>
);
}
teams.push(
<li
key='teamDiv'
className='divider'
/>
);
} else {
switchTeams = (
<li>
<Link
to={'/select_team'}
>
<i className='fa fa-exchange'/>
<FormattedMessage
id='admin.nav.switch'
defaultMessage='Team Selection'
/>
</Link>
</li>
);
}
return (
<ul className='nav navbar-nav navbar-right admin-navbar-dropdown'>
<li
ref='dropdown'
className='dropdown'
>
<a
href='#'
id='adminNavbarDropdownButton'
className='dropdown-toggle admin-navbar-dropdown__toggle'
data-toggle='dropdown'
role='button'
aria-expanded='false'
>
<span
className='dropdown__icon admin-navbar-dropdown__icon'
dangerouslySetInnerHTML={{__html: Constants.MENU_ICON}}
/>
</a>
<ul
className='dropdown-menu'
role='menu'
>
{teams}
{switchTeams}
<li
key='teamDiv'
className='divider'
/>
<li>
<Link
to='https://about.mattermost.com/administrators-guide/'
rel='noopener noreferrer'
target='_blank'
>
<FormattedMessage
id='admin.nav.administratorsGuide'
defaultMessage='Administrator Guide'
/>
</Link>
</li>
<li>
<Link
to='https://about.mattermost.com/troubleshooting-forum/'
rel='noopener noreferrer'
target='_blank'
>
<FormattedMessage
id='admin.nav.troubleshootingForum'
defaultMessage='Troubleshooting Forum'
/>
</Link>
</li>
<li>
<Link
to='https://about.mattermost.com/commercial-support/'
rel='noopener noreferrer'
target='_blank'
>
<FormattedMessage
id='admin.nav.commercialSupport'
defaultMessage='Commercial Support'
/>
</Link>
</li>
<li>
<a
href='#'
onClick={this.handleAboutModal}
>
<FormattedMessage
id='navbar_dropdown.about'
defaultMessage='About Mattermost'
/>
</a>
</li>
<li className='divider'/>
<li>
<a
href='#'
id='logout'
onClick={() => GlobalActions.emitUserLoggedOutEvent()}
>
<FormattedMessage
id='admin.nav.logout'
defaultMessage='Logout'
/>
</a>
</li>
<AboutBuildModal
show={this.state.showAboutModal}
onModalDismissed={this.aboutModalDismissed}
/>
</ul>
</li>
</ul>
);
}
}
|