Simplify the user management
[clamp.git] / ui-react / src / components / dialogs / UserInfoModal.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END============================================
19  * ===================================================================
20  *
21  */
22
23 import React from 'react'
24 import Button from 'react-bootstrap/Button';
25 import Modal from 'react-bootstrap/Modal';
26 import Form from 'react-bootstrap/Form';
27 import Row from 'react-bootstrap/Row';
28 import Col from 'react-bootstrap/Col';
29 import styled from 'styled-components';
30 import UserService from '../../api/UserService';
31
32 const ModalStyled = styled(Modal)`
33         background-color: transparent;
34 `
35
36 export default class UserInfoModal extends React.Component {
37
38         constructor(props, context) {
39                 super(props, context);
40
41                 this.handleClose = this.handleClose.bind(this);
42             this.renderPermissions = this.renderPermissions.bind(this);
43                 this.renderUserName = this.renderUserName.bind(this);
44                 this.state = {
45                         show: true,
46                         userInfo: {}
47                 };
48         }
49         componentWillMount() {
50                 UserService.getUserInfo().then(userInfo => {
51                         this.setState({ userInfo: userInfo })
52                 });
53         }
54
55         handleClose() {
56                         this.props.history.push('/');
57         }
58         renderPermissions() {
59           if (this.state.userInfo["allPermissions"]) {
60                 var listOfPermissions = this.state.userInfo["allPermissions"].map(function(perm) {
61                     return <Form.Control plaintext readOnly defaultValue={perm} />;
62                 })
63                     return listOfPermissions;
64                   } else {
65                     return;
66                   }
67         }
68         renderUserName() {
69                 if (this.state.userInfo["userName"]) {
70                         return <Form.Control plaintext readOnly defaultValue={this.state.userInfo["userName"]} />
71                 } else  {
72                         return;
73                 }
74         }
75         renderVersion() {
76                 if (this.state.userInfo["cldsVersion"]) {
77                         return <Form.Control plaintext readOnly defaultValue={this.state.userInfo["cldsVersion"]} />
78                 } else  {
79                         return;
80                 }
81         }
82         render() {
83                 return (
84                         <ModalStyled size="lg"  show={this.state.show} onHide={this.handleClose}>
85                                 <Modal.Header closeButton>
86                                         <Modal.Title>User Info</Modal.Title>
87                                 </Modal.Header>
88                                 <Modal.Body>
89                                         <Form.Group as={Row} controlId="userName">
90                                                 <Form.Label column sm="3">Current User:</Form.Label>
91                                                 <Col>{this.renderUserName()}</Col>
92                                         </Form.Group>
93                                         <Form.Group as={Row} controlId="cldsVersion">
94                                                 <Form.Label column sm="3">CLDS Version:</Form.Label>
95                                                 <Col>{this.renderVersion()}</Col>
96                                         </Form.Group>
97                                         <Form.Group as={Row} controlId="userPermissions">
98                                                 <Form.Label column sm="3">User Permissions:</Form.Label>
99                                                 <Col>
100                                                         {this.renderPermissions()}
101                                                 </Col>
102                                         </Form.Group>
103                                 </Modal.Body>
104                                 <Modal.Footer>
105                                         <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
106                                 </Modal.Footer>
107                         </ModalStyled>
108                 );
109         }
110 }