Revert "BUG-410 -- update RIFT platform"
[osm/UI.git] / skyquake / plugins / launchpad / src / ssh_keys / sshKeys.jsx
1 /*
2  *
3  *   Copyright 2016 RIFT.IO Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18 import React, {Component} from 'react';
19 import DashboardCard from 'widgets/dashboard_card/dashboard_card.jsx'
20 import SshKeyCard from './sshKeyCard.jsx';
21 import SshKeyStore from './sshKeyStore.js';
22 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
23 import '../../node_modules/open-iconic/font/css/open-iconic.css';
24 // import 'style/base.scss';
25
26
27 class SshKeys extends Component {
28     constructor(props) {
29         super(props);
30         this.Store = this.props.flux.stores.hasOwnProperty('SshKeyStore') ? this.props.flux.stores.SshKeyStore : this.props.flux.createStore(SshKeyStore, 'SshKeyStore');
31         this.state = this.Store.getState();
32         this.Store.listen(this.handleUpdate);
33     }
34     componentWillMount() {
35         this.Store.getSshKey();
36     }
37     componentWillUnmount() {
38       this.Store.unlisten(this.handleUpdate);
39     }
40     handleUpdate = (state) => {
41         this.setState(state)
42     }
43     render() {
44         let self = this;
45         let Store = self.Store;
46         // return <div>test</div>
47         return (
48           <div className="sshKeyCards">
49             {
50               self.state.data && self.state.data.keys.map(function(k, i) {
51                 let sshKey = self.state.data.entities[k];
52                 return (
53                   <SshKeyCard key={i}  name={sshKey.name} value={sshKey.key}
54                   editMode={sshKey.isEditable}
55                   editKey= {Store.editSshKeyPair(sshKey.name)}
56                   updateSshKeyPair={Store.updateSshKeyPair}
57                   cancelEditSshKeyPair={Store.cancelEditSshKeyPair}
58                   saveEditSshKeyPair={Store.saveEditSshKeyPair}
59                   updateEditSshKeyPair={Store.updateEditSshKeyPair}
60                   deleteKey={Store.deleteSshKeyPair(sshKey.name)}
61                   />
62                 )
63               })
64             }
65             <SshKeyCard  name={this.state.newKey.name} value={ this.state.newKey.key}
66                   editMode={"create"}
67                   updateSshKeyPair={Store.updateNewKeyValue}
68                   saveEditSshKeyPair={Store.saveEditSshKeyPair}
69                   />
70           </div>
71         )
72   }
73 }
74
75 export default SkyquakeComponent(SshKeys);