2016-02-08 07:26:10 -05:00
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
2016-03-14 08:50:46 -04:00
import $ from 'jquery' ;
2016-03-23 04:06:08 +05:00
require ( 'perfect-scrollbar/jquery' ) ( $ ) ;
2016-03-14 08:50:46 -04:00
import 'bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css' ;
import 'google-fonts/google-fonts.css' ;
2016-03-17 08:43:11 +05:00
import 'sass/styles.scss' ;
2016-03-14 08:50:46 -04:00
import React from 'react' ;
import ReactDOM from 'react-dom' ;
2016-04-25 05:39:54 -07:00
import { IndexRedirect , Router , Route , IndexRoute , Redirect , browserHistory } from 'react-router' ;
2016-03-14 08:50:46 -04:00
import Root from 'components/root.jsx' ;
import LoggedIn from 'components/logged_in.jsx' ;
2016-04-21 22:37:01 -07:00
import HeaderFooterTemplate from 'components/header_footer_template.jsx' ;
2016-03-14 08:50:46 -04:00
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' ;
2016-03-24 20:04:40 -04:00
import PermalinkView from 'components/permalink_view.jsx' ;
2016-03-14 08:50:46 -04:00
import Sidebar from 'components/sidebar.jsx' ;
import * as AsyncClient from 'utils/async_client.jsx' ;
import ChannelStore from 'stores/channel_store.jsx' ;
import ErrorStore from 'stores/error_store.jsx' ;
2016-04-21 22:37:01 -07:00
import TeamStore from 'stores/team_store.jsx' ;
2016-05-16 19:09:37 -04:00
import BrowserStore from 'stores/browser_store.jsx' ;
2016-04-01 11:48:19 -04:00
import * as Utils from 'utils/utils.jsx' ;
2016-04-21 22:37:01 -07:00
import Client from 'utils/web_client.jsx' ;
2016-05-26 09:46:18 -04:00
import * as Websockets from 'actions/websocket_actions.jsx' ;
import * as GlobalActions from 'actions/global_actions.jsx' ;
2016-03-14 08:50:46 -04:00
import SignupUserComplete from 'components/signup_user_complete.jsx' ;
import ShouldVerifyEmail from 'components/should_verify_email.jsx' ;
import DoVerifyEmail from 'components/do_verify_email.jsx' ;
2016-03-24 20:04:40 -04:00
import TutorialView from 'components/tutorial/tutorial_view.jsx' ;
2016-03-17 10:30:49 -04:00
import BackstageNavbar from 'components/backstage/backstage_navbar.jsx' ;
import BackstageSidebar from 'components/backstage/backstage_sidebar.jsx' ;
2016-04-08 11:51:28 -04:00
import Integrations from 'components/backstage/integrations.jsx' ;
import InstalledIncomingWebhooks from 'components/backstage/installed_incoming_webhooks.jsx' ;
import InstalledOutgoingWebhooks from 'components/backstage/installed_outgoing_webhooks.jsx' ;
import InstalledCommands from 'components/backstage/installed_commands.jsx' ;
2016-03-28 09:41:03 -04:00
import AddIncomingWebhook from 'components/backstage/add_incoming_webhook.jsx' ;
2016-03-28 13:04:35 -04:00
import AddOutgoingWebhook from 'components/backstage/add_outgoing_webhook.jsx' ;
2016-04-05 09:29:01 -04:00
import AddCommand from 'components/backstage/add_command.jsx' ;
2016-04-01 11:48:19 -04:00
import ErrorPage from 'components/error_page.jsx' ;
2016-03-14 08:50:46 -04:00
2016-04-21 22:37:01 -07:00
import AppDispatcher from './dispatcher/app_dispatcher.jsx' ;
import Constants from './utils/constants.jsx' ;
const ActionTypes = Constants . ActionTypes ;
2016-03-14 08:50:46 -04:00
2016-05-17 07:21:39 -04:00
import AdminConsole from 'components/admin_console/admin_console.jsx' ;
import SystemAnalytics from 'components/analytics/system_analytics.jsx' ;
import ConfigurationSettings from 'components/admin_console/configuration_settings.jsx' ;
import UsersAndTeamsSettings from 'components/admin_console/users_and_teams_settings.jsx' ;
import PrivacySettings from 'components/admin_console/privacy_settings.jsx' ;
import LogSettings from 'components/admin_console/log_settings.jsx' ;
import EmailAuthenticationSettings from 'components/admin_console/email_authentication_settings.jsx' ;
import GitLabSettings from 'components/admin_console/gitlab_settings.jsx' ;
import LdapSettings from 'components/admin_console/ldap_settings.jsx' ;
import SignupSettings from 'components/admin_console/signup_settings.jsx' ;
import LoginSettings from 'components/admin_console/login_settings.jsx' ;
import PublicLinkSettings from 'components/admin_console/public_link_settings.jsx' ;
import SessionSettings from 'components/admin_console/session_settings.jsx' ;
import ConnectionSettings from 'components/admin_console/connection_settings.jsx' ;
import EmailSettings from 'components/admin_console/email_settings.jsx' ;
import PushSettings from 'components/admin_console/push_settings.jsx' ;
import WebhookSettings from 'components/admin_console/webhook_settings.jsx' ;
import ExternalServiceSettings from 'components/admin_console/external_service_settings.jsx' ;
import DatabaseSettings from 'components/admin_console/database_settings.jsx' ;
import StorageSettings from 'components/admin_console/storage_settings.jsx' ;
import ImageSettings from 'components/admin_console/image_settings.jsx' ;
import CustomBrandSettings from 'components/admin_console/custom_brand_settings.jsx' ;
import LegalAndSupportSettings from 'components/admin_console/legal_and_support_settings.jsx' ;
import ComplianceSettings from 'components/admin_console/compliance_settings.jsx' ;
import RateSettings from 'components/admin_console/rate_settings.jsx' ;
import DeveloperSettings from 'components/admin_console/developer_settings.jsx' ;
import TeamUsers from 'components/admin_console/team_users.jsx' ;
import TeamAnalytics from 'components/analytics/team_analytics.jsx' ;
import LicenseSettings from 'components/admin_console/license_settings.jsx' ;
import Audits from 'components/admin_console/audits.jsx' ;
import Logs from 'components/admin_console/logs.jsx' ;
2016-05-26 09:46:18 -04:00
import ClaimController from 'components/claim/claim_controller.jsx' ;
2016-03-17 15:46:16 -04:00
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' ;
2016-05-26 09:46:18 -04:00
import LoginController from 'components/login/login_controller.jsx' ;
2016-04-21 22:37:01 -07:00
import SelectTeam from 'components/select_team/select_team.jsx' ;
2016-05-26 09:46:18 -04:00
import CreateTeamController from 'components/create_team/create_team_controller.jsx' ;
2016-04-21 22:37:01 -07:00
import CreateTeamDisplayName from 'components/create_team/components/display_name.jsx' ;
import CreateTeamTeamUrl from 'components/create_team/components/team_url.jsx' ;
2016-03-30 12:49:29 -04:00
2016-03-24 12:05:50 -04:00
import * as I18n from 'i18n/i18n.jsx' ;
2016-02-08 07:26:10 -05:00
2016-04-01 11:48:19 -04:00
const notFoundParams = {
title : Utils . localizeMessage ( 'error.not_found.title' , 'Page not found' ) ,
message : Utils . localizeMessage ( 'error.not_found.message' , 'The page you where trying to reach does not exist' ) ,
link : '/' ,
linkmessage : Utils . localizeMessage ( 'error.not_found.link_message' , 'Back to Mattermost' )
} ;
2016-02-08 07:26:10 -05:00
// This is for anything that needs to be done for ALL react components.
// This runs before we start to render anything.
function preRenderSetup ( callwhendone ) {
2016-04-21 22:37:01 -07:00
window . onerror = ( msg , url , line , column , stack ) => {
var l = { } ;
l . level = 'ERROR' ;
l . message = 'msg: ' + msg + ' row: ' + line + ' col: ' + column + ' stack: ' + stack + ' url: ' + url ;
$ . ajax ( {
2016-05-24 14:31:30 -07:00
url : '/api/v3/general/log_client' ,
2016-04-21 22:37:01 -07:00
dataType : 'json' ,
contentType : 'application/json' ,
type : 'POST' ,
data : JSON . stringify ( l )
} ) ;
if ( window . mm _config && window . mm _config . EnableDeveloper === 'true' ) {
2016-04-25 05:38:41 -07:00
window . ErrorStore . storeLastError ( { type : 'developer' , message : 'DEVELOPER MODE: A javascript error has occured. Please use the javascript console to capture and report the error (row: ' + line + ' col: ' + column + ').' } ) ;
2016-04-21 22:37:01 -07:00
window . ErrorStore . emitChange ( ) ;
2016-02-08 07:26:10 -05:00
}
2016-04-21 22:37:01 -07:00
} ;
2016-02-08 07:26:10 -05:00
2016-04-21 22:37:01 -07:00
var d1 = $ . Deferred ( ) ; //eslint-disable-line new-cap
2016-02-08 07:26:10 -05:00
2016-04-21 22:37:01 -07:00
GlobalActions . emitInitialLoad (
( ) => {
d1 . resolve ( ) ;
2016-02-08 07:26:10 -05:00
}
) ;
2016-05-16 19:09:37 -04:00
// Make sure the websockets close and reset version
2016-03-14 08:50:46 -04:00
$ ( window ) . on ( 'beforeunload' ,
( ) => {
2016-05-16 19:09:37 -04:00
BrowserStore . setLastServerVersion ( '' ) ;
2016-03-23 10:20:52 -04:00
Websockets . close ( ) ;
2016-03-14 08:50:46 -04:00
}
) ;
2016-03-21 12:33:44 -04:00
function afterIntl ( ) {
2016-06-01 11:56:27 -04:00
I18n . doAddLocaleData ( ) ;
2016-04-21 22:37:01 -07:00
$ . when ( d1 ) . done ( ( ) => {
callwhendone ( ) ;
} ) ;
2016-03-21 12:33:44 -04:00
}
if ( global . Intl ) {
afterIntl ( ) ;
} else {
2016-03-25 22:36:55 -04:00
I18n . safariFix ( afterIntl ) ;
2016-03-21 12:33:44 -04:00
}
2016-02-08 07:26:10 -05:00
}
function preLoggedIn ( nextState , replace , callback ) {
2016-04-21 22:37:01 -07:00
ErrorStore . clearLastError ( ) ;
callback ( ) ;
}
function preNeedsTeam ( nextState , replace , callback ) {
// First check to make sure you're in the current team
// for the current url.
var teamName = Utils . getTeamNameFromUrl ( ) ;
var team = TeamStore . getByName ( teamName ) ;
2016-05-11 11:44:45 -04:00
const oldTeamId = TeamStore . getCurrentId ( ) ;
2016-04-21 22:37:01 -07:00
if ( ! team ) {
2016-04-25 05:39:54 -07:00
browserHistory . push ( '/' ) ;
2016-04-21 22:37:01 -07:00
return ;
}
GlobalActions . emitCloseRightHandSide ( ) ;
TeamStore . saveMyTeam ( team ) ;
TeamStore . emitChange ( ) ;
2016-05-11 11:44:45 -04:00
// If the old team id is null then we will already have the direct
// profiles from initial load
if ( oldTeamId != null ) {
AsyncClient . getDirectProfiles ( ) ;
}
2016-04-21 22:37:01 -07:00
var d1 = $ . Deferred ( ) ; //eslint-disable-line new-cap
var d2 = $ . Deferred ( ) ; //eslint-disable-line new-cap
Client . getChannels (
2016-02-08 07:26:10 -05:00
( data ) => {
2016-04-21 22:37:01 -07:00
AppDispatcher . handleServerAction ( {
type : ActionTypes . RECEIVED _CHANNELS ,
channels : data . channels ,
members : data . members
} ) ;
d1 . resolve ( ) ;
2016-02-08 07:26:10 -05:00
} ,
( err ) => {
2016-04-21 22:37:01 -07:00
AsyncClient . dispatchError ( err , 'getChannels' ) ;
d1 . resolve ( ) ;
2016-02-08 07:26:10 -05:00
}
) ;
2016-04-21 22:37:01 -07:00
Client . getProfiles (
( data ) => {
AppDispatcher . handleServerAction ( {
type : ActionTypes . RECEIVED _PROFILES ,
profiles : data
} ) ;
2016-02-08 07:26:10 -05:00
2016-04-21 22:37:01 -07:00
d2 . resolve ( ) ;
} ,
( err ) => {
AsyncClient . dispatchError ( err , 'getProfiles' ) ;
d2 . resolve ( ) ;
}
) ;
2016-03-30 11:07:03 -04:00
2016-03-24 20:04:40 -04:00
$ . when ( d1 , d2 ) . done ( ( ) => {
callback ( ) ;
} ) ;
2016-02-08 07:26:10 -05:00
}
function onPermalinkEnter ( nextState ) {
const postId = nextState . params . postid ;
GlobalActions . emitPostFocusEvent ( postId ) ;
}
2016-04-27 16:02:58 -04:00
function onChannelEnter ( nextState , replace , callback ) {
doChannelChange ( nextState , replace , callback ) ;
2016-03-24 20:04:40 -04:00
}
2016-04-27 16:02:58 -04:00
function doChannelChange ( state , replace , callback ) {
2016-03-24 20:04:40 -04:00
let channel ;
if ( state . location . query . fakechannel ) {
channel = JSON . parse ( state . location . query . fakechannel ) ;
} else {
channel = ChannelStore . getByName ( state . params . channel ) ;
2016-04-04 11:09:59 -04:00
if ( ! channel ) {
channel = ChannelStore . getMoreByName ( state . params . channel ) ;
}
if ( ! channel ) {
2016-04-27 16:02:58 -04:00
Client . joinChannelByName (
state . params . channel ,
( data ) => {
GlobalActions . emitChannelClickEvent ( data ) ;
callback ( ) ;
} ,
( ) => {
2016-05-02 08:08:11 -04:00
if ( state . params . team ) {
replace ( '/' + state . params . team + '/channels/town-square' ) ;
} else {
replace ( '/' ) ;
}
2016-04-27 16:02:58 -04:00
callback ( ) ;
}
) ;
2016-04-21 22:37:01 -07:00
return ;
2016-04-04 11:09:59 -04:00
}
2016-03-24 20:04:40 -04:00
}
GlobalActions . emitChannelClickEvent ( channel ) ;
2016-04-27 16:02:58 -04:00
callback ( ) ;
2016-03-24 20:04:40 -04:00
}
2016-02-08 07:26:10 -05:00
function renderRootComponent ( ) {
ReactDOM . render ( (
< Router
history = { browserHistory }
>
< Route
path = '/'
component = { Root }
>
2016-04-01 11:48:19 -04:00
< Route
path = 'error'
component = { ErrorPage }
/ >
2016-04-21 22:37:01 -07:00
< Route component = { HeaderFooterTemplate } >
2016-02-08 07:26:10 -05:00
< Route
2016-04-21 22:37:01 -07:00
path = 'login'
2016-05-26 09:46:18 -04:00
component = { LoginController }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'reset_password'
component = { PasswordResetSendLink }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'reset_password_complete'
component = { PasswordResetForm }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'claim'
2016-05-26 09:46:18 -04:00
component = { ClaimController }
2016-02-08 07:26:10 -05:00
>
< Route
2016-04-21 22:37:01 -07:00
path = 'oauth_to_email'
component = { OAuthToEmail }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'email_to_oauth'
component = { EmailToOAuth }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'email_to_ldap'
component = { EmailToLDAP }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'ldap_to_email'
component = { LDAPToEmail }
2016-02-08 07:26:10 -05:00
/ >
< / Route >
< Route
path = 'signup_user_complete'
component = { SignupUserComplete }
/ >
< Route
path = 'should_verify_email'
component = { ShouldVerifyEmail }
/ >
< Route
path = 'do_verify_email'
component = { DoVerifyEmail }
/ >
2016-04-21 22:37:01 -07:00
< / Route >
< Route
component = { LoggedIn }
onEnter = { preLoggedIn }
>
< Route component = { HeaderFooterTemplate } >
< Route
path = 'select_team'
component = { SelectTeam }
/ >
< Route
path = 'create_team'
2016-05-26 09:46:18 -04:00
component = { CreateTeamController }
2016-04-21 22:37:01 -07:00
>
< IndexRoute component = { CreateTeamDisplayName } / >
< Route
path = 'display_name'
component = { CreateTeamDisplayName }
/ >
< Route
path = 'team_url'
component = { CreateTeamTeamUrl }
/ >
< / Route >
< / Route >
< Route
path = 'admin_console'
component = { AdminConsole }
2016-05-17 07:21:39 -04:00
>
< IndexRedirect to = 'system_analytics' / >
< Route
path = 'system_analytics'
component = { SystemAnalytics }
/ >
< Route path = 'general' >
< IndexRedirect to = 'configuration' / >
< Route
path = 'configuration'
component = { ConfigurationSettings }
/ >
< Route
path = 'users_and_teams'
component = { UsersAndTeamsSettings }
/ >
< Route
path = 'privacy'
component = { PrivacySettings }
/ >
2016-06-03 00:33:52 +05:00
< Route
path = 'compliance'
component = { ComplianceSettings }
/ >
2016-05-17 07:21:39 -04:00
< Route
path = 'logging'
component = { LogSettings }
/ >
< / Route >
< Route path = 'authentication' >
< IndexRedirect to = 'email' / >
< Route
path = 'email'
component = { EmailAuthenticationSettings }
/ >
< Route
path = 'gitlab'
component = { GitLabSettings }
/ >
< Route
path = 'ldap'
component = { LdapSettings }
/ >
< / Route >
< Route path = 'security' >
< IndexRedirect to = 'sign_up' / >
< Route
path = 'sign_up'
component = { SignupSettings }
/ >
< Route
path = 'login'
component = { LoginSettings }
/ >
< Route
path = 'public_links'
component = { PublicLinkSettings }
/ >
< Route
path = 'sessions'
component = { SessionSettings }
/ >
< Route
path = 'connections'
component = { ConnectionSettings }
/ >
< / Route >
< Route path = 'notifications' >
< IndexRedirect to = 'email' / >
< Route
path = 'email'
component = { EmailSettings }
/ >
< Route
path = 'push'
component = { PushSettings }
/ >
< / Route >
< Route path = 'integrations' >
< IndexRedirect to = 'webhooks' / >
< Route
path = 'webhooks'
component = { WebhookSettings }
/ >
< Route
path = 'external'
component = { ExternalServiceSettings }
/ >
< / Route >
< Route path = 'files' >
< IndexRedirect to = 'storage' / >
< Route
path = 'storage'
component = { StorageSettings }
/ >
< Route
path = 'images'
component = { ImageSettings }
/ >
< / Route >
< Route path = 'customization' >
< IndexRedirect to = 'custom_brand' / >
< Route
path = 'custom_brand'
component = { CustomBrandSettings }
/ >
< Route
path = 'legal_and_support'
component = { LegalAndSupportSettings }
/ >
< / Route >
2016-06-03 00:33:52 +05:00
< Route path = 'advanced' >
< IndexRedirect to = 'rate' / >
< Route
path = 'rate'
component = { RateSettings }
/ >
< Route
path = 'database'
component = { DatabaseSettings }
/ >
< Route
path = 'developer'
component = { DeveloperSettings }
/ >
< / Route >
2016-05-17 07:21:39 -04:00
< Route path = 'team' >
< Redirect
from = ':team'
to = ':team/users'
/ >
< Route
path = ':team/users'
component = { TeamUsers }
/ >
< Route
path = ':team/analytics'
component = { TeamAnalytics }
/ >
< Redirect
from = '*'
to = '/error'
query = { notFoundParams }
/ >
< / Route >
< Route
path = 'license'
component = { LicenseSettings }
/ >
< Route
path = 'audits'
component = { Audits }
/ >
< Route
path = 'logs'
component = { Logs }
/ >
< / Route >
2016-02-08 07:26:10 -05:00
< Route
path = ':team'
component = { NeedsTeam }
2016-04-21 22:37:01 -07:00
onEnter = { preNeedsTeam }
2016-02-08 07:26:10 -05:00
>
2016-04-25 05:39:54 -07:00
< IndexRedirect to = 'channels/town-square' / >
2016-02-08 07:26:10 -05:00
< Route
2016-04-21 22:37:01 -07:00
path = 'channels/:channel'
onEnter = { onChannelEnter }
components = { {
sidebar : Sidebar ,
center : ChannelView
} }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'pl/:postid'
onEnter = { onPermalinkEnter }
components = { {
sidebar : Sidebar ,
center : PermalinkView
} }
2016-02-08 07:26:10 -05:00
/ >
< Route
2016-04-21 22:37:01 -07:00
path = 'tutorial'
components = { {
sidebar : Sidebar ,
center : TutorialView
} }
2016-02-08 07:26:10 -05:00
/ >
2016-04-21 22:37:01 -07:00
< Route path = 'settings/integrations' >
< IndexRoute
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : Integrations
} }
2016-03-17 15:46:16 -04:00
/ >
2016-04-21 22:37:01 -07:00
< Route path = 'incoming_webhooks' >
< IndexRoute
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : InstalledIncomingWebhooks
} }
/ >
< Route
path = 'add'
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : AddIncomingWebhook
} }
/ >
< / Route >
< Route path = 'outgoing_webhooks' >
< IndexRoute
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : InstalledOutgoingWebhooks
} }
/ >
< Route
path = 'add'
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : AddOutgoingWebhook
} }
/ >
< / Route >
< Route path = 'commands' >
< IndexRoute
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : InstalledCommands
} }
/ >
< Route
path = 'add'
components = { {
navbar : BackstageNavbar ,
sidebar : BackstageSidebar ,
center : AddCommand
} }
/ >
< / Route >
< Redirect
from = '*'
to = '/error'
query = { notFoundParams }
2016-03-17 15:46:16 -04:00
/ >
< / Route >
2016-02-08 07:26:10 -05:00
< / Route >
< / Route >
2016-04-21 22:37:01 -07:00
< Redirect
from = '*'
to = '/error'
query = { notFoundParams }
/ >
2016-02-08 07:26:10 -05:00
< / Route >
< / Router >
) ,
document . getElementById ( 'root' ) ) ;
}
global . window . setup _root = ( ) => {
// Do the pre-render setup and call renderRootComponent when done
preRenderSetup ( renderRootComponent ) ;
} ;