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_controller.jsx  | 84 ++++++++++++++++++++--
 1 file changed, 79 insertions(+), 5 deletions(-)

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

diff --git a/web/react/components/admin_console/admin_controller.jsx b/web/react/components/admin_console/admin_controller.jsx
index ce7d61ca9..25476251f 100644
--- a/web/react/components/admin_console/admin_controller.jsx
+++ b/web/react/components/admin_console/admin_controller.jsx
@@ -3,6 +3,7 @@
 
 var AdminSidebar = require('./admin_sidebar.jsx');
 var AdminStore = require('../../stores/admin_store.jsx');
+var TeamStore = require('../../stores/team_store.jsx');
 var AsyncClient = require('../../utils/async_client.jsx');
 var LoadingScreen = require('../loading_screen.jsx');
 
@@ -16,38 +17,104 @@ var GitLabSettingsTab = require('./gitlab_settings.jsx');
 var SqlSettingsTab = require('./sql_settings.jsx');
 var TeamSettingsTab = require('./team_settings.jsx');
 var ServiceSettingsTab = require('./service_settings.jsx');
+var TeamUsersTab = require('./team_users.jsx');
 
 export default class AdminController extends React.Component {
     constructor(props) {
         super(props);
 
         this.selectTab = this.selectTab.bind(this);
+        this.removeSelectedTeam = this.removeSelectedTeam.bind(this);
+        this.addSelectedTeam = this.addSelectedTeam.bind(this);
         this.onConfigListenerChange = this.onConfigListenerChange.bind(this);
+        this.onAllTeamsListenerChange = this.onAllTeamsListenerChange.bind(this);
+
+        var selectedTeams = AdminStore.getSelectedTeams();
+        if (selectedTeams == null) {
+            selectedTeams = {};
+            selectedTeams[TeamStore.getCurrentId()] = 'true';
+            AdminStore.saveSelectedTeams(selectedTeams);
+        }
 
         this.state = {
-            config: null,
-            selected: 'service_settings'
+            config: AdminStore.getConfig(),
+            teams: AdminStore.getAllTeams(),
+            selectedTeams,
+            selected: 'service_settings',
+            selectedTeam: null
         };
     }
 
     componentDidMount() {
         AdminStore.addConfigChangeListener(this.onConfigListenerChange);
         AsyncClient.getConfig();
+
+        AdminStore.addAllTeamsChangeListener(this.onAllTeamsListenerChange);
+        AsyncClient.getAllTeams();
     }
 
     componentWillUnmount() {
         AdminStore.removeConfigChangeListener(this.onConfigListenerChange);
+        AdminStore.removeAllTeamsChangeListener(this.onAllTeamsListenerChange);
     }
 
     onConfigListenerChange() {
         this.setState({
             config: AdminStore.getConfig(),
-            selected: this.state.selected
+            teams: AdminStore.getAllTeams(),
+            selectedTeams: AdminStore.getSelectedTeams(),
+            selected: this.state.selected,
+            selectedTeam: this.state.selectedTeam
         });
     }
 
-    selectTab(tab) {
-        this.setState({selected: tab});
+    onAllTeamsListenerChange() {
+        this.setState({
+            config: AdminStore.getConfig(),
+            teams: AdminStore.getAllTeams(),
+            selectedTeams: AdminStore.getSelectedTeams(),
+            selected: this.state.selected,
+            selectedTeam: this.state.selectedTeam
+
+        });
+    }
+
+    selectTab(tab, teamId) {
+        this.setState({
+            config: AdminStore.getConfig(),
+            teams: AdminStore.getAllTeams(),
+            selectedTeams: AdminStore.getSelectedTeams(),
+            selected: tab,
+            selectedTeam: teamId
+        });
+    }
+
+    removeSelectedTeam(teamId) {
+        var selectedTeams = AdminStore.getSelectedTeams();
+        Reflect.deleteProperty(selectedTeams, teamId);
+        AdminStore.saveSelectedTeams(selectedTeams);
+
+        this.setState({
+            config: AdminStore.getConfig(),
+            teams: AdminStore.getAllTeams(),
+            selectedTeams: AdminStore.getSelectedTeams(),
+            selected: this.state.selected,
+            selectedTeam: this.state.selectedTeam
+        });
+    }
+
+    addSelectedTeam(teamId) {
+        var selectedTeams = AdminStore.getSelectedTeams();
+        selectedTeams[teamId] = 'true';
+        AdminStore.saveSelectedTeams(selectedTeams);
+
+        this.setState({
+            config: AdminStore.getConfig(),
+            teams: AdminStore.getAllTeams(),
+            selectedTeams: AdminStore.getSelectedTeams(),
+            selected: this.state.selected,
+            selectedTeam: this.state.selectedTeam
+        });
     }
 
     render() {
@@ -74,6 +141,8 @@ export default class AdminController extends React.Component {
                 tab = <TeamSettingsTab config={this.state.config} />;
             } else if (this.state.selected === 'service_settings') {
                 tab = <ServiceSettingsTab config={this.state.config} />;
+            } else if (this.state.selected === 'team_users') {
+                tab = <TeamUsersTab team={this.state.teams[this.state.selectedTeam]} />;
             }
         }
 
@@ -85,7 +154,12 @@ export default class AdminController extends React.Component {
                 />
                 <AdminSidebar
                     selected={this.state.selected}
+                    selectedTeam={this.state.selectedTeam}
                     selectTab={this.selectTab}
+                    teams={this.state.teams}
+                    selectedTeams={this.state.selectedTeams}
+                    removeSelectedTeam={this.removeSelectedTeam}
+                    addSelectedTeam={this.addSelectedTeam}
                 />
                 <div className='inner__wrap channel__wrap'>
                     <div className='row header'>
-- 
cgit v1.2.3-1-g7c22

