71456fe9b5249fc9024068c114a2f3db860ca0bf
[osm/riftware.git] /
1 /*
2  *    Copyright 2016 RIFT.IO Inc
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 /*
18  * 
19  *
20  */
21
22 import React from 'react';
23 import AppHeader from '../../components/header/header.jsx';
24 import ConfigAgentAccount from './configAgentAccount.jsx';
25 import ConfigAgentAccountStore from './configAgentAccountStore';
26 import AccountSidebar from '../account_sidebar/accountSidebar.jsx';
27
28 export default class LaunchpadConfigAgentAccount extends React.Component {
29     constructor(props) {
30         super(props);
31         this.state = ConfigAgentAccountStore.getState();
32         ConfigAgentAccountStore.getCatalog();
33         ConfigAgentAccountStore.listen(this.updateState);
34         if(this.props.edit) {
35             ConfigAgentAccountStore.getConfigAgentAccount(window.location.hash.split('/')[4])
36         } else {
37             this.state.isLoading = false;
38         }
39     }
40     updateState = (state) => {
41         this.setState(state);
42     }
43     loadComposer = () => {
44       let API_SERVER = rw.getSearchParams(window.location).api_server;
45       let auth = window.sessionStorage.getItem("auth");
46       let mgmtDomainName = window.location.hash.split('/')[2];
47         window.location.replace('//' + window.location.hostname + ':9000/index.html?api_server=' + API_SERVER + '&upload_server=' + window.location.protocol + '//' + window.location.hostname + '&clearLocalStorage' + '&mgmt_domain_name=' + mgmtDomainName + '&auth=' + auth);
48     }
49     render() {
50         let html;
51         let body;
52         let title = "Launchpad: Add Config Agent Account";
53         let mgmtDomainName = window.location.hash.split('/')[2];
54         if (this.props.edit) {
55             title = "Launchpad: Edit Config Agent Account";
56         }
57         let navItems = [{
58                 name: 'DASHBOARD',
59                 href: '#/launchpad/' + mgmtDomainName
60             },{
61                  name: 'CATALOG(' + this.state.descriptorCount + ')',
62                 'onClick': this.loadComposer
63             },
64             {
65                 name: 'Accounts'
66             }
67         ];
68         if (this.props.isDashboard) {
69             body = (<div>Edit or Create New Accounts</div>);
70         } else {
71              body = <ConfigAgentAccount {...this.props} />
72         }
73         html = (<div>
74                   <AppHeader title={title} nav={navItems} isLoading={this.state.isLoading} />
75                     <div className="flex">
76                       <AccountSidebar/>
77                       {body}
78                     </div>
79               </div>);
80         return html;
81     }
82 }