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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
require('perfect-scrollbar/jquery')($);
import 'bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css';
import 'google-fonts/google-fonts.css';
import 'sass/styles.scss';
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, IndexRoute, IndexRedirect, browserHistory} from 'react-router';
import Root from 'components/root.jsx';
import Login from 'components/login.jsx';
import LoggedIn from 'components/logged_in.jsx';
import NotLoggedIn from 'components/not_logged_in.jsx';
import NeedsTeam from 'components/needs_team.jsx';
import PasswordResetSendLink from 'components/password_reset_send_link.jsx';
import PasswordResetForm from 'components/password_reset_form.jsx';
import ChannelView from 'components/channel_view.jsx';
import PermalinkView from 'components/permalink_view.jsx';
import Sidebar from 'components/sidebar.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import ErrorStore from 'stores/error_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import SignupTeam from 'components/signup_team.jsx';
import * as Client from 'utils/client.jsx';
import * as Websockets from 'action_creators/websocket_actions.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import SignupTeamConfirm from 'components/signup_team_confirm.jsx';
import SignupUserComplete from 'components/signup_user_complete.jsx';
import ShouldVerifyEmail from 'components/should_verify_email.jsx';
import DoVerifyEmail from 'components/do_verify_email.jsx';
import AdminConsole from 'components/admin_console/admin_controller.jsx';
import TutorialView from 'components/tutorial/tutorial_view.jsx';
import BackstageNavbar from 'components/backstage/backstage_navbar.jsx';
import BackstageSidebar from 'components/backstage/backstage_sidebar.jsx';
import InstalledIntegrations from 'components/backstage/installed_integrations.jsx';
import SignupTeamComplete from 'components/signup_team_complete/components/signup_team_complete.jsx';
import WelcomePage from 'components/signup_team_complete/components/team_signup_welcome_page.jsx';
import TeamDisplayNamePage from 'components/signup_team_complete/components/team_signup_display_name_page.jsx';
import TeamURLPage from 'components/signup_team_complete/components/team_signup_url_page.jsx';
import SendInivtesPage from 'components/signup_team_complete/components/team_signup_send_invites_page.jsx';
import UsernamePage from 'components/signup_team_complete/components/team_signup_username_page.jsx';
import PasswordPage from 'components/signup_team_complete/components/team_signup_password_page.jsx';
import FinishedPage from 'components/signup_team_complete/components/team_signup_finished.jsx';
import Claim from 'components/claim/claim.jsx';
import EmailToOAuth from 'components/claim/components/email_to_oauth.jsx';
import OAuthToEmail from 'components/claim/components/oauth_to_email.jsx';
import LDAPToEmail from 'components/claim/components/ldap_to_email.jsx';
import EmailToLDAP from 'components/claim/components/email_to_ldap.jsx';
import * as I18n from 'i18n/i18n.jsx';
// This is for anything that needs to be done for ALL react components.
// This runs before we start to render anything.
function preRenderSetup(callwhendone) {
const d1 = Client.getClientConfig(
(data, textStatus, xhr) => {
if (!data) {
return;
}
global.window.mm_config = data;
var serverVersion = xhr.getResponseHeader('X-Version-ID');
if (serverVersion !== BrowserStore.getLastServerVersion()) {
if (!BrowserStore.getLastServerVersion() || BrowserStore.getLastServerVersion() === '') {
BrowserStore.setLastServerVersion(serverVersion);
} else {
BrowserStore.setLastServerVersion(serverVersion);
window.location.reload(true);
console.log('Detected version update refreshing the page'); //eslint-disable-line no-console
}
}
},
(err) => {
AsyncClient.dispatchError(err, 'getClientConfig');
}
);
const d2 = Client.getClientLicenceConfig(
(data) => {
if (!data) {
return;
}
global.window.mm_license = data;
},
(err) => {
AsyncClient.dispatchError(err, 'getClientLicenceConfig');
}
);
// Set these here so they don't fail in client.jsx track
global.window.analytics = [];
global.window.analytics.page = () => {
// Do Nothing
};
global.window.analytics.track = () => {
// Do Nothing
};
// Make sure the websockets close
$(window).on('beforeunload',
() => {
Websockets.close();
}
);
function afterIntl() {
I18n.doAddLocaleData();
$.when(d1, d2).done(callwhendone);
}
if (global.Intl) {
afterIntl();
} else {
I18n.safariFix(afterIntl);
}
}
function preLoggedIn(nextState, replace, callback) {
const d1 = Client.getAllPreferences(
(data) => {
PreferenceStore.setPreferencesFromServer(data);
},
(err) => {
AsyncClient.dispatchError(err, 'getAllPreferences');
}
);
const d2 = AsyncClient.getChannels();
$.when(d1, d2).done(() => {
callback();
});
}
function onRootEnter(nextState, replace, callback) {
if (nextState.location.pathname === '/') {
Client.getMeLoggedIn((data) => {
if (!data || data.logged_in === 'false') {
replace({pathname: '/signup_team'});
callback();
} else {
replace({pathname: '/' + data.team_name + '/channels/town-square'});
callback();
}
});
return;
}
callback();
}
function onPermalinkEnter(nextState) {
const postId = nextState.params.postid;
GlobalActions.emitPostFocusEvent(postId);
}
function onChannelEnter(nextState) {
doChannelChange(nextState);
}
function onChannelChange(prevState, nextState) {
if (prevState.params.channel !== nextState.params.channel) {
doChannelChange(nextState);
}
}
function doChannelChange(state) {
let channel;
if (state.location.query.fakechannel) {
channel = JSON.parse(state.location.query.fakechannel);
} else {
channel = ChannelStore.getByName(state.params.channel);
}
GlobalActions.emitChannelClickEvent(channel);
}
function onLoggedOut(nextState) {
const teamName = nextState.params.team;
Client.logout(
() => {
browserHistory.push('/' + teamName + '/login');
BrowserStore.signalLogout();
BrowserStore.clear();
ErrorStore.clearLastError();
PreferenceStore.clear();
},
() => {
browserHistory.push('/' + teamName + '/login');
}
);
}
function renderRootComponent() {
ReactDOM.render((
<Router
history={browserHistory}
>
<Route
path='/'
component={Root}
onEnter={onRootEnter}
>
<Route
component={LoggedIn}
onEnter={preLoggedIn}
>
<Route
path=':team/channels/:channel'
onEnter={onChannelEnter}
onChange={onChannelChange}
components={{
sidebar: Sidebar,
center: ChannelView
}}
/>
<Route
path=':team/pl/:postid'
onEnter={onPermalinkEnter}
components={{
sidebar: Sidebar,
center: PermalinkView
}}
/>
<Route
path=':team/tutorial'
components={{
sidebar: Sidebar,
center: TutorialView
}}
/>
<Route
path=':team/logout'
onEnter={onLoggedOut}
/>
<Route
path=':team/team_settings'
components={{
navbar: BackstageNavbar,
sidebar: BackstageSidebar,
center: null
}}
/>
<Route path=':team/integrations'>
<IndexRedirect to='installed'/>
<Route
path='installed'
components={{
navbar: BackstageNavbar,
sidebar: BackstageSidebar,
center: InstalledIntegrations
}}
/>
<Route path='add'>
<IndexRoute
components={{
navbar: BackstageNavbar,
sidebar: BackstageSidebar,
center: null
}}
/>
<Route
path='incoming_webhook'
components={{
navbar: BackstageNavbar,
sidebar: BackstageSidebar,
center: null
}}
/>
<Route
path='outgoing_webhook'
components={{
navbar: BackstageNavbar,
sidebar: BackstageSidebar,
center: null
}}
/>
</Route>
</Route>
>>>>>>> Added initial backstage components and InstalledIntegrations page
<Route
path='admin_console'
component={AdminConsole}
/>
</Route>
<Route component={NotLoggedIn}>
<Route
path='signup_team'
component={SignupTeam}
/>
<Route
path='signup_team_complete'
component={SignupTeamComplete}
>
<IndexRoute component={FinishedPage}/>
<Route
path='welcome'
component={WelcomePage}
/>
<Route
path='team_display_name'
component={TeamDisplayNamePage}
/>
<Route
path='team_url'
component={TeamURLPage}
/>
<Route
path='invites'
component={SendInivtesPage}
/>
<Route
path='username'
component={UsernamePage}
/>
<Route
path='password'
component={PasswordPage}
/>
</Route>
<Route
path='signup_user_complete'
component={SignupUserComplete}
/>
<Route
path='signup_team_confirm'
component={SignupTeamConfirm}
/>
<Route
path='should_verify_email'
component={ShouldVerifyEmail}
/>
<Route
path='do_verify_email'
component={DoVerifyEmail}
/>
<Route
path=':team'
component={NeedsTeam}
>
<IndexRedirect to='login'/>
<Route
path='login'
component={Login}
/>
<Route
path='reset_password'
component={PasswordResetSendLink}
/>
<Route
path='reset_password_complete'
component={PasswordResetForm}
/>
<Route
path='claim'
component={Claim}
>
<Route
path='oauth_to_email'
component={OAuthToEmail}
/>
<Route
path='email_to_oauth'
component={EmailToOAuth}
/>
<Route
path='email_to_ldap'
component={EmailToLDAP}
/>
<Route
path='ldap_to_email'
component={LDAPToEmail}
/>
</Route>
</Route>
</Route>
</Route>
</Router>
),
document.getElementById('root'));
}
global.window.setup_root = () => {
// Do the pre-render setup and call renderRootComponent when done
preRenderSetup(renderRootComponent);
};
|