From 1626a6de6f16ba0878160b0a7eae9f49b8d34d4f Mon Sep 17 00:00:00 2001
From: =Corey Hulen <corey@hulen.com>
Date: Wed, 23 Sep 2015 12:49:28 -0700
Subject: PLT-349 adding team mgt to admin console

---
 .../components/admin_console/admin_sidebar.jsx     | 157 +++++++++++++++++++--
 1 file changed, 143 insertions(+), 14 deletions(-)

(limited to 'web/react/components/admin_console/admin_sidebar.jsx')

diff --git a/web/react/components/admin_console/admin_sidebar.jsx b/web/react/components/admin_console/admin_sidebar.jsx
index 0983c1276..b8413d6c7 100644
--- a/web/react/components/admin_console/admin_sidebar.jsx
+++ b/web/react/components/admin_console/admin_sidebar.jsx
@@ -2,6 +2,7 @@
 // See License.txt for license information.
 
 var AdminSidebarHeader = require('./admin_sidebar_header.jsx');
+var SelectTeamModal = require('./select_team_modal.jsx');
 
 export default class AdminSidebar extends React.Component {
     constructor(props) {
@@ -9,28 +10,121 @@ export default class AdminSidebar extends React.Component {
 
         this.isSelected = this.isSelected.bind(this);
         this.handleClick = this.handleClick.bind(this);
+        this.removeTeam = this.removeTeam.bind(this);
+
+        this.showTeamSelect = this.showTeamSelect.bind(this);
+        this.teamSelectedModal = this.teamSelectedModal.bind(this);
+        this.teamSelectedModalDismissed = this.teamSelectedModalDismissed.bind(this);
 
         this.state = {
+            showSelectModal: false
         };
     }
 
-    handleClick(name, e) {
+    handleClick(name, teamId, e) {
         e.preventDefault();
-        this.props.selectTab(name);
+        this.props.selectTab(name, teamId);
     }
 
-    isSelected(name) {
+    isSelected(name, teamId) {
         if (this.props.selected === name) {
-            return 'active';
+            if (name === 'team_users') {
+                if (this.props.selectedTeam != null && this.props.selectedTeam === teamId) {
+                    return 'active';
+                }
+            } else {
+                return 'active';
+            }
         }
 
         return '';
     }
 
+    removeTeam(teamId, e) {
+        e.preventDefault();
+        Reflect.deleteProperty(this.props.selectedTeams, teamId);
+        this.props.removeSelectedTeam(teamId);
+
+        if (this.props.selected === 'team_users') {
+            if (this.props.selectedTeam != null && this.props.selectedTeam === teamId) {
+                this.props.selectTab('service_settings', null);
+            }
+        }
+    }
+
     componentDidMount() {
     }
 
+    showTeamSelect(e) {
+        e.preventDefault();
+        this.setState({showSelectModal: true});
+    }
+
+    teamSelectedModal(teamId) {
+        this.props.selectedTeams[teamId] = 'true';
+        this.setState({showSelectModal: false});
+        this.props.addSelectedTeam(teamId);
+        this.forceUpdate();
+    }
+
+    teamSelectedModalDismissed() {
+        this.setState({showSelectModal: false});
+    }
+
     render() {
+        var count = '*';
+        var teams = 'Loading';
+
+        if (this.props.teams != null) {
+            count = '' + Object.keys(this.props.teams).length;
+
+            teams = [];
+            for (var key in this.props.selectedTeams) {
+                if (this.props.selectedTeams.hasOwnProperty(key)) {
+                    var team = this.props.teams[key];
+
+                    if (team != null) {
+                        teams.push(
+                            <ul
+                                key={'team_' + team.id}
+                                className='nav nav__sub-menu'
+                            >
+                                <li>
+                                    <a
+                                        href='#'
+                                        onClick={this.handleClick.bind(this, 'team_users', team.id)}
+                                        className={'nav__sub-menu-item ' + this.isSelected('team_users', team.id)}
+                                    >
+                                        {team.name}
+                                        <span
+                                            className='menu-icon--right menu__close'
+                                            onClick={this.removeTeam.bind(this, team.id)}
+                                            style={{cursor: 'pointer'}}
+                                        >
+                                            {'x'}
+                                        </span>
+                                    </a>
+                                </li>
+                                <li>
+                                    <ul className='nav nav__inner-menu'>
+                                        <li>
+                                            <a
+                                                href='#'
+                                                className={this.isSelected('team_users', team.id)}
+                                                onClick={this.handleClick.bind(this, 'team_users', team.id)}
+                                            >
+                                                {'- Users'}
+                                            </a>
+                                        </li>
+                                    </ul>
+                                </li>
+                            </ul>
+                        );
+                    }
+                }
+            }
+        }
+
         return (
             <div className='sidebar--left sidebar--collapsable'>
                 <div>
@@ -38,11 +132,17 @@ export default class AdminSidebar extends React.Component {
                     <ul className='nav nav-pills nav-stacked'>
                         <li>
                             <ul className='nav nav__sub-menu'>
+                                <li>
+                                    <h4>
+                                        <span className='icon fa fa-gear'></span>
+                                        <span>{'SETTINGS'}</span>
+                                    </h4>
+                                </li>
                                 <li>
                                     <a
                                         href='#'
                                         className={this.isSelected('service_settings')}
-                                        onClick={this.handleClick.bind(this, 'service_settings')}
+                                        onClick={this.handleClick.bind(this, 'service_settings', null)}
                                     >
                                         {'Service Settings'}
                                     </a>
@@ -51,7 +151,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('team_settings')}
-                                        onClick={this.handleClick.bind(this, 'team_settings')}
+                                        onClick={this.handleClick.bind(this, 'team_settings', null)}
                                     >
                                         {'Team Settings'}
                                     </a>
@@ -60,7 +160,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('sql_settings')}
-                                        onClick={this.handleClick.bind(this, 'sql_settings')}
+                                        onClick={this.handleClick.bind(this, 'sql_settings', null)}
                                     >
                                         {'SQL Settings'}
                                     </a>
@@ -69,7 +169,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('email_settings')}
-                                        onClick={this.handleClick.bind(this, 'email_settings')}
+                                        onClick={this.handleClick.bind(this, 'email_settings', null)}
                                     >
                                         {'Email Settings'}
                                     </a>
@@ -78,7 +178,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('image_settings')}
-                                        onClick={this.handleClick.bind(this, 'image_settings')}
+                                        onClick={this.handleClick.bind(this, 'image_settings', null)}
                                     >
                                         {'Image Settings'}
                                     </a>
@@ -87,7 +187,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('log_settings')}
-                                        onClick={this.handleClick.bind(this, 'log_settings')}
+                                        onClick={this.handleClick.bind(this, 'log_settings', null)}
                                     >
                                         {'Log Settings'}
                                     </a>
@@ -96,7 +196,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('logs')}
-                                        onClick={this.handleClick.bind(this, 'logs')}
+                                        onClick={this.handleClick.bind(this, 'logs', null)}
                                     >
                                         {'Logs'}
                                     </a>
@@ -105,7 +205,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('rate_settings')}
-                                        onClick={this.handleClick.bind(this, 'rate_settings')}
+                                        onClick={this.handleClick.bind(this, 'rate_settings', null)}
                                     >
                                         {'Rate Limit Settings'}
                                     </a>
@@ -114,7 +214,7 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('privacy_settings')}
-                                        onClick={this.handleClick.bind(this, 'privacy_settings')}
+                                        onClick={this.handleClick.bind(this, 'privacy_settings', null)}
                                     >
                                         {'Privacy Settings'}
                                     </a>
@@ -123,21 +223,50 @@ export default class AdminSidebar extends React.Component {
                                     <a
                                         href='#'
                                         className={this.isSelected('gitlab_settings')}
-                                        onClick={this.handleClick.bind(this, 'gitlab_settings')}
+                                        onClick={this.handleClick.bind(this, 'gitlab_settings', null)}
                                     >
                                         {'GitLab Settings'}
                                     </a>
                                 </li>
+                                 <li>
+                                    <h4>
+                                        <span className='icon fa fa-gear'></span>
+                                        <span>{'TEAMS (' + count + ')'}</span>
+                                        <span className='menu-icon--right'>
+                                            <a
+                                                href='#'
+                                                onClick={this.showTeamSelect}
+                                            >
+                                                <i className='fa fa-plus'></i>
+                                            </a>
+                                        </span>
+                                    </h4>
+                                </li>
+                                <li>
+                                    {teams}
+                                </li>
                             </ul>
                         </li>
                     </ul>
                 </div>
+
+                <SelectTeamModal
+                    teams={this.props.teams}
+                    show={this.state.showSelectModal}
+                    onModalSubmit={this.teamSelectedModal}
+                    onModalDismissed={this.teamSelectedModalDismissed}
+                />
             </div>
         );
     }
 }
 
 AdminSidebar.propTypes = {
+    teams: React.PropTypes.object,
+    selectedTeams: React.PropTypes.object,
+    removeSelectedTeam: React.PropTypes.func,
+    addSelectedTeam: React.PropTypes.func,
     selected: React.PropTypes.string,
+    selectedTeam: React.PropTypes.string,
     selectTab: React.PropTypes.func
 };
\ No newline at end of file
-- 
cgit v1.2.3-1-g7c22


From 985aebf86120188c2a14adfab39af7c4da3c1c9d Mon Sep 17 00:00:00 2001
From: =Corey Hulen <corey@hulen.com>
Date: Wed, 23 Sep 2015 15:16:48 -0700
Subject: Fixing state setting

---
 .../components/admin_console/admin_sidebar.jsx     | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'web/react/components/admin_console/admin_sidebar.jsx')

diff --git a/web/react/components/admin_console/admin_sidebar.jsx b/web/react/components/admin_console/admin_sidebar.jsx
index 375a6a8e9..cebb3ff20 100644
--- a/web/react/components/admin_console/admin_sidebar.jsx
+++ b/web/react/components/admin_console/admin_sidebar.jsx
@@ -192,15 +192,6 @@ export default class AdminSidebar extends React.Component {
                                         {'Log Settings'}
                                     </a>
                                 </li>
-                                <li>
-                                    <a
-                                        href='#'
-                                        className={this.isSelected('logs')}
-                                        onClick={this.handleClick.bind(this, 'logs', null)}
-                                    >
-                                        {'Logs'}
-                                    </a>
-                                </li>
                                 <li>
                                     <a
                                         href='#'
@@ -245,6 +236,21 @@ export default class AdminSidebar extends React.Component {
                                 <li>
                                     {teams}
                                 </li>
+                                <li>
+                                    <h4>
+                                        <span className='icon fa fa-gear'></span>
+                                        <span>{'OTHER'}</span>
+                                    </h4>
+                                </li>
+                                <li>
+                                    <a
+                                        href='#'
+                                        className={this.isSelected('logs')}
+                                        onClick={this.handleClick.bind(this, 'logs', null)}
+                                    >
+                                        {'Logs'}
+                                    </a>
+                                </li>
                             </ul>
                         </li>
                     </ul>
-- 
cgit v1.2.3-1-g7c22

