From 44714dfcb18b9a393dc34be3c182b0c092eec28a Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 17 Sep 2015 21:00:59 -0700 Subject: PLT-11 Adding ability to save config file --- .../components/admin_console/admin_controller.jsx | 49 +++- .../components/admin_console/admin_sidebar.jsx | 154 +++--------- .../admin_console/admin_sidebar_header.jsx | 67 ++++++ .../components/admin_console/log_settings.jsx | 261 +++++++++++++++++++++ web/react/components/admin_console/logs.jsx | 2 + web/react/stores/admin_store.jsx | 30 +++ web/react/utils/async_client.jsx | 26 ++ web/react/utils/client.jsx | 31 ++- 8 files changed, 489 insertions(+), 131 deletions(-) create mode 100644 web/react/components/admin_console/admin_sidebar_header.jsx create mode 100644 web/react/components/admin_console/log_settings.jsx (limited to 'web') diff --git a/web/react/components/admin_console/admin_controller.jsx b/web/react/components/admin_console/admin_controller.jsx index 68984c9e0..7593e50a4 100644 --- a/web/react/components/admin_console/admin_controller.jsx +++ b/web/react/components/admin_console/admin_controller.jsx @@ -1,36 +1,63 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. +var Navbar = require('../../components/navbar.jsx'); var AdminSidebar = require('./admin_sidebar.jsx'); -var EmailTab = require('./email_settings.jsx'); -var JobsTab = require('./jobs_settings.jsx'); +var AdminStore = require('../../stores/admin_store.jsx'); +var AsyncClient = require('../../utils/async_client.jsx'); +var LoadingScreen = require('../loading_screen.jsx'); + +var EmailSettingsTab = require('./email_settings.jsx'); +var JobsSettingsTab = require('./jobs_settings.jsx'); +var LogSettingsTab = require('./log_settings.jsx'); var LogsTab = require('./logs.jsx'); -var Navbar = require('../../components/navbar.jsx'); export default class AdminController extends React.Component { constructor(props) { super(props); this.selectTab = this.selectTab.bind(this); + this.onConfigListenerChange = this.onConfigListenerChange.bind(this); this.state = { + config: null, selected: 'email_settings' }; } + componentDidMount() { + AdminStore.addConfigChangeListener(this.onConfigListenerChange); + AsyncClient.getConfig(); + } + + componentWillUnmount() { + AdminStore.removeConfigChangeListener(this.onConfigListenerChange); + } + + onConfigListenerChange() { + this.setState({ + config: AdminStore.getConfig(), + selected: this.state.selected + }); + } + selectTab(tab) { this.setState({selected: tab}); } render() { - var tab = ''; - - if (this.state.selected === 'email_settings') { - tab = ; - } else if (this.state.selected === 'job_settings') { - tab = ; - } else if (this.state.selected === 'logs') { - tab = ; + var tab = ; + + if (this.state.config != null) { + if (this.state.selected === 'email_settings') { + tab = ; + } else if (this.state.selected === 'job_settings') { + tab = ; + } else if (this.state.selected === 'logs') { + tab = ; + } else if (this.state.selected === 'log_settings') { + tab = ; + } } return ( diff --git a/web/react/components/admin_console/admin_sidebar.jsx b/web/react/components/admin_console/admin_sidebar.jsx index a04bceef5..855da398b 100644 --- a/web/react/components/admin_console/admin_sidebar.jsx +++ b/web/react/components/admin_console/admin_sidebar.jsx @@ -27,36 +27,36 @@ export default class AdminSidebar extends React.Component { } componentDidMount() { - $('.nav__menu-item').on('click', function clickme(e) { - e.preventDefault(); - $(this).closest('.sidebar--collapsable').find('.nav__menu-item').removeClass('active'); - $(this).addClass('active'); - $(this).closest('.sidebar--collapsable').find('.nav__sub-menu').addClass('hide'); - $(this).next('.nav__sub-menu').removeClass('hide'); - }); + // $('.nav__menu-item').on('click', function clickme(e) { + // e.preventDefault(); + // $(this).closest('.sidebar--collapsable').find('.nav__menu-item').removeClass('active'); + // $(this).addClass('active'); + // $(this).closest('.sidebar--collapsable').find('.nav__sub-menu').addClass('hide'); + // $(this).next('.nav__sub-menu').removeClass('hide'); + // }); - $('.nav__sub-menu a').on('click', function clickme(e) { - e.preventDefault(); - $(this).closest('.nav__sub-menu').find('a').removeClass('active'); - $(this).addClass('active'); - }); + // $('.nav__sub-menu a').on('click', function clickme(e) { + // e.preventDefault(); + // $(this).closest('.nav__sub-menu').find('a').removeClass('active'); + // $(this).addClass('active'); + // }); - $('.nav__sub-menu-item').on('click', function clickme(e) { - e.preventDefault(); - $(this).closest('.sidebar--collapsable').find('.nav__inner-menu').addClass('hide'); - $(this).closest('li').next('li').find('.nav__inner-menu').removeClass('hide'); - $(this).closest('li').next('li').find('.nav__inner-menu li:first a').addClass('active'); - }); + // $('.nav__sub-menu-item').on('click', function clickme(e) { + // e.preventDefault(); + // $(this).closest('.sidebar--collapsable').find('.nav__inner-menu').addClass('hide'); + // $(this).closest('li').next('li').find('.nav__inner-menu').removeClass('hide'); + // $(this).closest('li').next('li').find('.nav__inner-menu li:first a').addClass('active'); + // }); - $('.nav__inner-menu a').on('click', function clickme() { - $(this).closest('.nav__inner-menu').closest('li').prev('li').find('a').addClass('active'); - }); + // $('.nav__inner-menu a').on('click', function clickme() { + // $(this).closest('.nav__inner-menu').closest('li').prev('li').find('a').addClass('active'); + // }); - $('.nav__sub-menu .menu__close').on('click', function close() { - var menuItem = $(this).closest('li'); - menuItem.next('li').remove(); - menuItem.remove(); - }); + // $('.nav__sub-menu .menu__close').on('click', function close() { + // var menuItem = $(this).closest('li'); + // menuItem.next('li').remove(); + // menuItem.remove(); + // }); } render() { @@ -69,10 +69,6 @@ export default class AdminSidebar extends React.Component { /> diff --git a/web/react/components/admin_console/admin_sidebar_header.jsx b/web/react/components/admin_console/admin_sidebar_header.jsx new file mode 100644 index 000000000..959411f1e --- /dev/null +++ b/web/react/components/admin_console/admin_sidebar_header.jsx @@ -0,0 +1,67 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var NavbarDropdown = require('./navbar_dropdown.jsx'); +var UserStore = require('../stores/user_store.jsx'); + +export default class SidebarHeader extends React.Component { + constructor(props) { + super(props); + + this.toggleDropdown = this.toggleDropdown.bind(this); + + this.state = {}; + } + toggleDropdown() { + if (this.refs.dropdown.blockToggle) { + this.refs.dropdown.blockToggle = false; + return; + } + $('.team__header').find('.dropdown-toggle').dropdown('toggle'); + } + render() { + var me = UserStore.getCurrentUser(); + var profilePicture = null; + + if (!me) { + return null; + } + + if (me.last_picture_update) { + profilePicture = ( + + + {profilePicture} +
+
{'@' + me.username}
+
{this.props.teamDisplayName}
+
+
+ + + ); + } +} + +SidebarHeader.defaultProps = { + teamDisplayName: global.window.config.SiteName, + teamType: '' +}; +SidebarHeader.propTypes = { + teamDisplayName: React.PropTypes.string, + teamType: React.PropTypes.string +}; diff --git a/web/react/components/admin_console/log_settings.jsx b/web/react/components/admin_console/log_settings.jsx new file mode 100644 index 000000000..4e3db8f68 --- /dev/null +++ b/web/react/components/admin_console/log_settings.jsx @@ -0,0 +1,261 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var Client = require('../../utils/client.jsx'); +var AsyncClient = require('../../utils/async_client.jsx'); + +export default class LogSettings extends React.Component { + constructor(props) { + super(props); + + this.handleChange = this.handleChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + + this.state = { + saveNeeded: false, + serverError: null + }; + } + + handleChange() { + this.setState({saveNeeded: true, serverError: this.state.serverError}); + } + + handleSubmit(e) { + e.preventDefault(); + $('#save-button').button('loading'); + + var config = this.props.config; + config.LogSettings.ConsoleEnable = React.findDOMNode(this.refs.consoleEnable).checked; + config.LogSettings.ConsoleLevel = React.findDOMNode(this.refs.consoleLevel).value; + config.LogSettings.FileEnable = React.findDOMNode(this.refs.fileEnable).checked; + config.LogSettings.FileLevel = React.findDOMNode(this.refs.fileLevel).value; + config.LogSettings.FileLocation = React.findDOMNode(this.refs.fileLocation).value.trim(); + config.LogSettings.FileFormat = React.findDOMNode(this.refs.fileFormat).value.trim(); + + Client.saveConfig( + config, + () => { + AsyncClient.getConfig(); + this.setState({serverError: null, saveNeeded: false}); + $('#save-button').button('reset'); + }, + (err) => { + this.setState({serverError: err.message, saveNeeded: true}); + $('#save-button').button('reset'); + } + ); + } + + render() { + var serverError = ''; + if (this.state.serverError) { + serverError =
; + } + + var saveClass = 'btn'; + if (this.state.saveNeeded) { + saveClass = 'btn btn-primary'; + } + + return ( +
+

{'Log Settings'}

+
+ +
+ +
+ + +

{'Typically set to false in production. Developers may set this field to true to output log messages to console based on the console level option. If true then the server will output messages to the standard output stream (stdout).'}

+
+
+ +
+ +
+ +

{'This setting determines the level of detail at which log events are written to the console. ERROR: Outputs only error messages. INFO: Outputs error messages and information around startup and initialization. DEBUG: Prints high detail for developers debugging issues working on debugging issues.'}

+
+
+ +
+ +
+ + +

{'Typically set to true in production. When true log files are written to the file specified in file location field below.'}

+
+
+ +
+ +
+ +

{'This setting determines the level of detail at which log events are written to the file. ERROR: Outputs only error messages. INFO: Outputs error messages and information around startup and initialization. DEBUG: Prints high detail for developers debugging issues working on debugging issues.'}

+
+
+ +
+ +
+ +

{'File to which log files are written. If blank, will be set to ./logs/mattermost.log. Log rotation is enabled and new files may be created in the same directory.'}

+
+
+ +
+ +
+ +

+ {'Format of log message output. If blank will be set to "[%D %T] [%L] %M", where:'} +

+ + + + + + + +
{'%T'}{'Time (15:04:05 MST)'}
{'%D'}{'Date (2006/01/02)'}
{'%d'}{'Date (01/02/06)'}
{'%L'}{'Level (DEBG, INFO, EROR)'}
{'%S'}{'Source'}
{'%M'}{'Message'}
+
+

+
+
+ +
+
+ {serverError} + +
+
+ +
+
+ ); + } +} + +LogSettings.propTypes = { + config: React.PropTypes.object +}; diff --git a/web/react/components/admin_console/logs.jsx b/web/react/components/admin_console/logs.jsx index d7de76a94..0bb749bbd 100644 --- a/web/react/components/admin_console/logs.jsx +++ b/web/react/components/admin_console/logs.jsx @@ -21,9 +21,11 @@ export default class Logs extends React.Component { AdminStore.addLogChangeListener(this.onLogListenerChange); AsyncClient.getLogs(); } + componentWillUnmount() { AdminStore.removeLogChangeListener(this.onLogListenerChange); } + onLogListenerChange() { this.setState({ logs: AdminStore.getLogs() diff --git a/web/react/stores/admin_store.jsx b/web/react/stores/admin_store.jsx index 591b52d05..dd5b60a24 100644 --- a/web/react/stores/admin_store.jsx +++ b/web/react/stores/admin_store.jsx @@ -8,16 +8,22 @@ var Constants = require('../utils/constants.jsx'); var ActionTypes = Constants.ActionTypes; var LOG_CHANGE_EVENT = 'log_change'; +var CONFIG_CHANGE_EVENT = 'config_change'; class AdminStoreClass extends EventEmitter { constructor() { super(); this.logs = null; + this.config = null; this.emitLogChange = this.emitLogChange.bind(this); this.addLogChangeListener = this.addLogChangeListener.bind(this); this.removeLogChangeListener = this.removeLogChangeListener.bind(this); + + this.emitConfigChange = this.emitConfigChange.bind(this); + this.addConfigChangeListener = this.addConfigChangeListener.bind(this); + this.removeConfigChangeListener = this.removeConfigChangeListener.bind(this); } emitLogChange() { @@ -32,6 +38,18 @@ class AdminStoreClass extends EventEmitter { this.removeListener(LOG_CHANGE_EVENT, callback); } + emitConfigChange() { + this.emit(CONFIG_CHANGE_EVENT); + } + + addConfigChangeListener(callback) { + this.on(CONFIG_CHANGE_EVENT, callback); + } + + removeConfigChangeListener(callback) { + this.removeListener(CONFIG_CHANGE_EVENT, callback); + } + getLogs() { return this.logs; } @@ -39,6 +57,14 @@ class AdminStoreClass extends EventEmitter { saveLogs(logs) { this.logs = logs; } + + getConfig() { + return this.config; + } + + saveConfig(config) { + this.config = config; + } } var AdminStore = new AdminStoreClass(); @@ -51,6 +77,10 @@ AdminStoreClass.dispatchToken = AppDispatcher.register((payload) => { AdminStore.saveLogs(action.logs); AdminStore.emitLogChange(); break; + case ActionTypes.RECIEVED_CONFIG: + AdminStore.saveConfig(action.config); + AdminStore.emitConfigChange(); + break; default: } }); diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index 3e23e5c33..ed228f6c4 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -345,6 +345,32 @@ export function getLogs() { ); } +export function getConfig() { + if (isCallInProgress('getConfig')) { + return; + } + + callTracker.getConfig = utils.getTimestamp(); + client.getConfig( + (data, textStatus, xhr) => { + callTracker.getConfig = 0; + + if (xhr.status === 304 || !data) { + return; + } + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_CONFIG, + config: data + }); + }, + (err) => { + callTracker.getConfig = 0; + dispatchError(err, 'getConfig'); + } + ); +} + export function findTeams(email) { if (isCallInProgress('findTeams_' + email)) { return; diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index ba3042d78..c9eb09c00 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -297,7 +297,7 @@ export function getLogs(success, error) { dataType: 'json', contentType: 'application/json', type: 'GET', - success: success, + success, error: function onError(xhr, status, err) { var e = handleError('getLogs', xhr, status, err); error(e); @@ -305,6 +305,35 @@ export function getLogs(success, error) { }); } +export function getConfig(success, error) { + $.ajax({ + url: '/api/v1/admin/config', + dataType: 'json', + contentType: 'application/json', + type: 'GET', + success, + error: function onError(xhr, status, err) { + var e = handleError('getConfig', xhr, status, err); + error(e); + } + }); +} + +export function saveConfig(config, success, error) { + $.ajax({ + url: '/api/v1/admin/save_config', + dataType: 'json', + contentType: 'application/json', + type: 'POST', + data: JSON.stringify(config), + success, + error: function onError(xhr, status, err) { + var e = handleError('saveConfig', xhr, status, err); + error(e); + } + }); +} + export function getMeSynchronous(success, error) { var currentUser = null; $.ajax({ -- cgit v1.2.3-1-g7c22 From 804b696bdc7d0b68701ce80e6ff5fba7ff3677c3 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 17 Sep 2015 22:00:33 -0700 Subject: PLT-11 adding config for logs to UI --- .../components/admin_console/admin_controller.jsx | 9 +- .../admin_console/admin_navbar_dropdown.jsx | 102 ++++++++++++ .../components/admin_console/admin_sidebar.jsx | 55 +------ .../admin_console/admin_sidebar_header.jsx | 29 ++-- .../components/admin_console/jobs_settings.jsx | 183 --------------------- web/react/components/channel_header.jsx | 2 +- web/react/components/channel_invite_modal.jsx | 2 +- web/react/components/channel_members.jsx | 2 +- web/react/components/member_list_item.jsx | 3 +- web/react/components/navbar.jsx | 3 +- web/react/components/navbar_dropdown.jsx | 77 ++++++--- web/react/components/post_info.jsx | 2 +- web/react/components/post_list.jsx | 2 +- web/react/components/sidebar_header.jsx | 3 +- web/react/components/sidebar_right_menu.jsx | 2 +- web/react/utils/utils.jsx | 23 +++ web/sass-files/sass/partials/_sidebar--left.scss | 2 +- 17 files changed, 208 insertions(+), 293 deletions(-) create mode 100644 web/react/components/admin_console/admin_navbar_dropdown.jsx delete mode 100644 web/react/components/admin_console/jobs_settings.jsx (limited to 'web') diff --git a/web/react/components/admin_console/admin_controller.jsx b/web/react/components/admin_console/admin_controller.jsx index 7593e50a4..e82fe1b76 100644 --- a/web/react/components/admin_console/admin_controller.jsx +++ b/web/react/components/admin_console/admin_controller.jsx @@ -1,14 +1,12 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. -var Navbar = require('../../components/navbar.jsx'); var AdminSidebar = require('./admin_sidebar.jsx'); var AdminStore = require('../../stores/admin_store.jsx'); var AsyncClient = require('../../utils/async_client.jsx'); var LoadingScreen = require('../loading_screen.jsx'); var EmailSettingsTab = require('./email_settings.jsx'); -var JobsSettingsTab = require('./jobs_settings.jsx'); var LogSettingsTab = require('./log_settings.jsx'); var LogsTab = require('./logs.jsx'); @@ -51,12 +49,10 @@ export default class AdminController extends React.Component { if (this.state.config != null) { if (this.state.selected === 'email_settings') { tab = ; - } else if (this.state.selected === 'job_settings') { - tab = ; - } else if (this.state.selected === 'logs') { - tab = ; } else if (this.state.selected === 'log_settings') { tab = ; + } else if (this.state.selected === 'logs') { + tab = ; } } @@ -72,7 +68,6 @@ export default class AdminController extends React.Component { />
-
{ + this.blockToggle = true; + setTimeout(() => { + this.blockToggle = false; + }, 100); + }); + } + + componentWillUnmount() { + $(React.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); + } + + render() { + return ( + + ); + } +} \ No newline at end of file diff --git a/web/react/components/admin_console/admin_sidebar.jsx b/web/react/components/admin_console/admin_sidebar.jsx index 855da398b..a6e689490 100644 --- a/web/react/components/admin_console/admin_sidebar.jsx +++ b/web/react/components/admin_console/admin_sidebar.jsx @@ -1,7 +1,7 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. -var SidebarHeader = require('../sidebar_header.jsx'); +var AdminSidebarHeader = require('./admin_sidebar_header.jsx'); export default class AdminSidebar extends React.Component { constructor(props) { @@ -14,7 +14,8 @@ export default class AdminSidebar extends React.Component { }; } - handleClick(name) { + handleClick(name, e) { + e.preventDefault(); this.props.selectTab(name); } @@ -27,46 +28,13 @@ export default class AdminSidebar extends React.Component { } componentDidMount() { - // $('.nav__menu-item').on('click', function clickme(e) { - // e.preventDefault(); - // $(this).closest('.sidebar--collapsable').find('.nav__menu-item').removeClass('active'); - // $(this).addClass('active'); - // $(this).closest('.sidebar--collapsable').find('.nav__sub-menu').addClass('hide'); - // $(this).next('.nav__sub-menu').removeClass('hide'); - // }); - - // $('.nav__sub-menu a').on('click', function clickme(e) { - // e.preventDefault(); - // $(this).closest('.nav__sub-menu').find('a').removeClass('active'); - // $(this).addClass('active'); - // }); - - // $('.nav__sub-menu-item').on('click', function clickme(e) { - // e.preventDefault(); - // $(this).closest('.sidebar--collapsable').find('.nav__inner-menu').addClass('hide'); - // $(this).closest('li').next('li').find('.nav__inner-menu').removeClass('hide'); - // $(this).closest('li').next('li').find('.nav__inner-menu li:first a').addClass('active'); - // }); - - // $('.nav__inner-menu a').on('click', function clickme() { - // $(this).closest('.nav__inner-menu').closest('li').prev('li').find('a').addClass('active'); - // }); - - // $('.nav__sub-menu .menu__close').on('click', function close() { - // var menuItem = $(this).closest('li'); - // menuItem.next('li').remove(); - // menuItem.remove(); - // }); } render() { return (
- + diff --git a/web/react/components/admin_console/admin_sidebar_header.jsx b/web/react/components/admin_console/admin_sidebar_header.jsx index 959411f1e..81798da45 100644 --- a/web/react/components/admin_console/admin_sidebar_header.jsx +++ b/web/react/components/admin_console/admin_sidebar_header.jsx @@ -1,8 +1,8 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. -var NavbarDropdown = require('./navbar_dropdown.jsx'); -var UserStore = require('../stores/user_store.jsx'); +var AdminNavbarDropdown = require('./admin_navbar_dropdown.jsx'); +var UserStore = require('../../stores/user_store.jsx'); export default class SidebarHeader extends React.Component { constructor(props) { @@ -12,13 +12,18 @@ export default class SidebarHeader extends React.Component { this.state = {}; } - toggleDropdown() { + + toggleDropdown(e) { + e.preventDefault(); + if (this.refs.dropdown.blockToggle) { this.refs.dropdown.blockToggle = false; return; } + $('.team__header').find('.dropdown-toggle').dropdown('toggle'); } + render() { var me = UserStore.getCurrentUser(); var profilePicture = null; @@ -45,23 +50,11 @@ export default class SidebarHeader extends React.Component { {profilePicture}
{'@' + me.username}
-
{this.props.teamDisplayName}
+
{'System Console'}
- +
); } -} - -SidebarHeader.defaultProps = { - teamDisplayName: global.window.config.SiteName, - teamType: '' -}; -SidebarHeader.propTypes = { - teamDisplayName: React.PropTypes.string, - teamType: React.PropTypes.string -}; +} \ No newline at end of file diff --git a/web/react/components/admin_console/jobs_settings.jsx b/web/react/components/admin_console/jobs_settings.jsx deleted file mode 100644 index 0b4fc4185..000000000 --- a/web/react/components/admin_console/jobs_settings.jsx +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. -// See License.txt for license information. - -export default class Jobs extends React.Component { - constructor(props) { - super(props); - - this.state = { - }; - } - - render() { - return ( -
-

{' ************** JOB Settings'}

-
-
- -
- - -

{'This is some sample help text for the Bypass Email field'}

-
-
-
- -
- -
-
{' This is some error text for the Bypass Email field'}
-
-

{'This is some sample help text for the SMTP username field'}

-
-
-
-
- -
-
-
- -
- -

{'This is some sample help text for the Apple push server field'}

-
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
-
- -
-
-
-
- ); - } -} \ No newline at end of file diff --git a/web/react/components/channel_header.jsx b/web/react/components/channel_header.jsx index 0dbbc20d4..8d23ec646 100644 --- a/web/react/components/channel_header.jsx +++ b/web/react/components/channel_header.jsx @@ -111,7 +111,7 @@ export default class ChannelHeader extends React.Component { const popoverContent = React.renderToString(); let channelTitle = channel.display_name; const currentId = UserStore.getCurrentId(); - const isAdmin = this.state.memberChannel.roles.indexOf('admin') > -1 || this.state.memberTeam.roles.indexOf('admin') > -1; + const isAdmin = Utils.isAdmin(this.state.memberChannel.roles) || Utils.isAdmin(this.state.memberTeam.roles); const isDirect = (this.state.channel.type === 'D'); if (isDirect) { diff --git a/web/react/components/channel_invite_modal.jsx b/web/react/components/channel_invite_modal.jsx index 5feeb4e88..82fc51184 100644 --- a/web/react/components/channel_invite_modal.jsx +++ b/web/react/components/channel_invite_modal.jsx @@ -121,7 +121,7 @@ export default class ChannelInviteModal extends React.Component { var currentMember = ChannelStore.getCurrentMember(); var isAdmin = false; if (currentMember) { - isAdmin = currentMember.roles.indexOf('admin') > -1 || UserStore.getCurrentUser().roles.indexOf('admin') > -1; + isAdmin = utils.isAdmin(currentMember.roles) || utils.isAdmin(UserStore.getCurrentUser().roles); } var content; diff --git a/web/react/components/channel_members.jsx b/web/react/components/channel_members.jsx index 04fa2c7a2..1eda6a104 100644 --- a/web/react/components/channel_members.jsx +++ b/web/react/components/channel_members.jsx @@ -130,7 +130,7 @@ export default class ChannelMembers extends React.Component { const currentMember = ChannelStore.getCurrentMember(); let isAdmin = false; if (currentMember) { - isAdmin = currentMember.roles.indexOf('admin') > -1 || UserStore.getCurrentUser().roles.indexOf('admin') > -1; + isAdmin = Utils.isAdmin(currentMember.roles) || Utils.isAdmin(UserStore.getCurrentUser().roles); } var memberList = null; diff --git a/web/react/components/member_list_item.jsx b/web/react/components/member_list_item.jsx index 9a31a2e30..158ff65be 100644 --- a/web/react/components/member_list_item.jsx +++ b/web/react/components/member_list_item.jsx @@ -2,6 +2,7 @@ // See License.txt for license information. var UserStore = require('../stores/user_store.jsx'); +const Utils = require('../utils/utils.jsx'); export default class MemberListItem extends React.Component { constructor(props) { @@ -26,7 +27,7 @@ export default class MemberListItem extends React.Component { render() { var member = this.props.member; var isAdmin = this.props.isAdmin; - var isMemberAdmin = member.roles.indexOf('admin') > -1; + var isMemberAdmin = Utils.isAdmin(member.roles); var timestamp = UserStore.getCurrentUser().update_at; var invite; diff --git a/web/react/components/navbar.jsx b/web/react/components/navbar.jsx index cae9f12e4..da9874b0b 100644 --- a/web/react/components/navbar.jsx +++ b/web/react/components/navbar.jsx @@ -8,6 +8,7 @@ var ChannelStore = require('../stores/channel_store.jsx'); var TeamStore = require('../stores/team_store.jsx'); var MessageWrapper = require('./message_wrapper.jsx'); var NotifyCounts = require('./notify_counts.jsx'); +const Utils = require('../utils/utils.jsx'); var Constants = require('../utils/constants.jsx'); var ActionTypes = Constants.ActionTypes; @@ -335,7 +336,7 @@ export default class Navbar extends React.Component { options={{singleline: true, mentionHighlight: false}} /> ); - isAdmin = this.state.member.roles.indexOf('admin') > -1; + isAdmin = Utils.isAdmin(this.state.member.roles); if (channel.type === 'O') { channelTitle = channel.display_name; diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index b7566cfb9..65f741e4b 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -30,12 +30,12 @@ export default class NavbarDropdown extends React.Component { UserStore.addTeamsChangeListener(this.onListenerChange); TeamStore.addChangeListener(this.onListenerChange); - $(React.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', function resetDropdown() { + $(React.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => { this.blockToggle = true; - setTimeout(function blockTimeout() { + setTimeout(() => { this.blockToggle = false; - }.bind(this), 100); - }.bind(this)); + }, 100); + }); } componentWillUnmount() { UserStore.removeTeamsChangeListener(this.onListenerChange); @@ -53,12 +53,16 @@ export default class NavbarDropdown extends React.Component { var teamLink = ''; var inviteLink = ''; var manageLink = ''; + var sysAdminLink = ''; + var adminDivider = ''; var currentUser = UserStore.getCurrentUser(); var isAdmin = false; + var isSystemAdmin = false; var teamSettings = null; if (currentUser != null) { - isAdmin = currentUser.roles.indexOf('admin') > -1; + isAdmin = Utils.isAdmin(currentUser.roles); + isSystemAdmin = Utils.isInRole(currentUser.roles, 'system_admin'); inviteLink = (
  • @@ -67,7 +71,7 @@ export default class NavbarDropdown extends React.Component { data-toggle='modal' data-target='#invite_member' > - Invite New Member + {'Invite New Member'}
  • ); @@ -82,7 +86,7 @@ export default class NavbarDropdown extends React.Component { data-title='Team Invite' data-value={Utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + currentUser.team_id} > - Get Team Invite Link + {'Get Team Invite Link'} ); @@ -97,19 +101,36 @@ export default class NavbarDropdown extends React.Component { data-toggle='modal' data-target='#team_members' > - Manage Team + {'Manage Team'} + + + ); + + adminDivider = (
  • ); + + teamSettings = ( +
  • + + {'Team Settings'} + +
  • + ); + } + + if (isSystemAdmin) { + sysAdminLink = ( +
  • + + {'System Console'}
  • ); - teamSettings = (
  • - - Team Settings - -
  • ); } var teams = []; @@ -123,9 +144,9 @@ export default class NavbarDropdown extends React.Component { ); if (this.state.teams.length > 1 && this.state.currentTeam) { var curTeamName = this.state.currentTeam.name; - this.state.teams.forEach(function listTeams(teamName) { + this.state.teams.forEach((teamName) => { if (teamName !== curTeamName) { - teams.push(
  • Switch to {teamName}
  • ); + teams.push(
  • {'Switch to ' + teamName}
  • ); } }); } @@ -135,7 +156,7 @@ export default class NavbarDropdown extends React.Component { target='_blank' href={Utils.getWindowLocationOrigin() + '/signup_team'} > - Create a New Team + {'Create a New Team'} ); @@ -167,29 +188,31 @@ export default class NavbarDropdown extends React.Component { data-toggle='modal' data-target='#user_settings' > - Account Settings + {'Account Settings'} - {teamSettings} {inviteLink} {teamLink} + {adminDivider} + {teamSettings} {manageLink} + {sysAdminLink} + {teams} +
  • - Logout + {'Logout'}
  • - {teams} -
  • - Help + {'Help'}
  • @@ -197,7 +220,7 @@ export default class NavbarDropdown extends React.Component { target='_blank' href='/static/help/report_problem.html' > - Report a Problem + {'Report a Problem'}
  • diff --git a/web/react/components/post_info.jsx b/web/react/components/post_info.jsx index c80b287a3..34ac9e759 100644 --- a/web/react/components/post_info.jsx +++ b/web/react/components/post_info.jsx @@ -20,7 +20,7 @@ export default class PostInfo extends React.Component { createDropdown() { var post = this.props.post; var isOwner = UserStore.getCurrentId() === post.user_id; - var isAdmin = UserStore.getCurrentUser().roles.indexOf('admin') > -1; + var isAdmin = utils.isAdmin(UserStore.getCurrentUser().roles); if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || post.state === Constants.POST_DELETED) { return ''; diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index faa5e5f0b..94cccaac3 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -419,7 +419,7 @@ export default class PostList extends React.Component { var members = ChannelStore.getExtraInfo(channel.id).members; for (var i = 0; i < members.length; i++) { - if (members[i].roles.indexOf('admin') > -1) { + if (utils.isAdmin(members[i].roles)) { return members[i].username; } } diff --git a/web/react/components/sidebar_header.jsx b/web/react/components/sidebar_header.jsx index 959411f1e..072c14e0a 100644 --- a/web/react/components/sidebar_header.jsx +++ b/web/react/components/sidebar_header.jsx @@ -12,7 +12,8 @@ export default class SidebarHeader extends React.Component { this.state = {}; } - toggleDropdown() { + toggleDropdown(e) { + e.preventDefault(); if (this.refs.dropdown.blockToggle) { this.refs.dropdown.blockToggle = false; return; diff --git a/web/react/components/sidebar_right_menu.jsx b/web/react/components/sidebar_right_menu.jsx index 5ecd502ba..2671d560b 100644 --- a/web/react/components/sidebar_right_menu.jsx +++ b/web/react/components/sidebar_right_menu.jsx @@ -26,7 +26,7 @@ export default class SidebarRightMenu extends React.Component { var isAdmin = false; if (currentUser != null) { - isAdmin = currentUser.roles.indexOf('admin') > -1; + isAdmin = utils.isAdmin(currentUser.roles); inviteLink = (
  • diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 032cf4ff4..074591489 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -54,6 +54,29 @@ export function isTestDomain() { return false; } +export function isInRole(roles, inRole) { + var parts = roles.split(' '); + for (var i = 0; i < parts.length; i++) { + if (parts[i] === inRole) { + return true; + } + } + + return false; +} + +export function isAdmin(roles) { + if (isInRole(roles, 'admin')) { + return true; + } + + if (isInRole(roles, 'system_admin')) { + return true; + } + + return false; +} + export function getDomainWithOutSub() { var parts = window.location.host.split('.'); diff --git a/web/sass-files/sass/partials/_sidebar--left.scss b/web/sass-files/sass/partials/_sidebar--left.scss index f714a23f8..94583b153 100644 --- a/web/sass-files/sass/partials/_sidebar--left.scss +++ b/web/sass-files/sass/partials/_sidebar--left.scss @@ -11,7 +11,7 @@ padding-top: 44px; } .dropdown-menu { - max-height: 300px; + max-height: 400px; overflow-x: hidden; overflow-y: auto; max-width: 200px; -- cgit v1.2.3-1-g7c22 From 60af1fad1f4f88dbfbda58336711d3184e57a1e4 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 17 Sep 2015 22:25:37 -0700 Subject: Moving logout item --- web/react/components/navbar_dropdown.jsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'web') diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index 65f741e4b..4c01d2c43 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -193,12 +193,6 @@ export default class NavbarDropdown extends React.Component {
  • {inviteLink} {teamLink} - {adminDivider} - {teamSettings} - {manageLink} - {sysAdminLink} - {teams} -
  • + {adminDivider} + {teamSettings} + {manageLink} + {sysAdminLink} + {teams} +