blob: 4b779dece324bdbe39c4525e78c73a9af942afde [file] [log] [blame]
xuegaoe52d5722019-07-25 15:43:06 +02001/*-
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
23import React from 'react'
24import Button from 'react-bootstrap/Button';
25import Modal from 'react-bootstrap/Modal';
26import Form from 'react-bootstrap/Form';
27import Row from 'react-bootstrap/Row';
28import Col from 'react-bootstrap/Col';
29import styled from 'styled-components';
30import UserService from '../../api/UserService';
31
32const ModalStyled = styled(Modal)`
33 background-color: transparent;
34`
35
sebdet4dc849f2019-11-15 17:49:42 +010036export default class UserInfoModal extends React.Component {
xuegaoe52d5722019-07-25 15:43:06 +020037
38 constructor(props, context) {
39 super(props, context);
40
41 this.handleClose = this.handleClose.bind(this);
sebdet76580072020-02-23 09:31:04 -080042 this.renderPermissions = this.renderPermissions.bind(this);
xuegaoe52d5722019-07-25 15:43:06 +020043 this.renderUserName = this.renderUserName.bind(this);
44 this.state = {
45 show: true,
sebdet687b8de2019-08-26 14:29:11 -070046 userInfo: {}
xuegaoe52d5722019-07-25 15:43:06 +020047 };
xuegaoe52d5722019-07-25 15:43:06 +020048 }
sebdet687b8de2019-08-26 14:29:11 -070049 componentWillMount() {
xuegaoe52d5722019-07-25 15:43:06 +020050 UserService.getUserInfo().then(userInfo => {
51 this.setState({ userInfo: userInfo })
52 });
53 }
sebdet687b8de2019-08-26 14:29:11 -070054
xuegaoe52d5722019-07-25 15:43:06 +020055 handleClose() {
56 this.props.history.push('/');
57 }
sebdet76580072020-02-23 09:31:04 -080058 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 }
xuegaoe52d5722019-07-25 15:43:06 +020068 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 (
sebdet687b8de2019-08-26 14:29:11 -070084 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
xuegaoe52d5722019-07-25 15:43:06 +020085 <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>
sebdet76580072020-02-23 09:31:04 -0800100 {this.renderPermissions()}
xuegaoe52d5722019-07-25 15:43:06 +0200101 </Col>
102 </Form.Group>
103 </Modal.Body>
104 <Modal.Footer>
sebdet8a02dd72019-07-31 17:11:11 +0200105 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
xuegaoe52d5722019-07-25 15:43:06 +0200106 </Modal.Footer>
107 </ModalStyled>
108 );
109 }
110}