xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 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 | |
sebdet | 4dc849f | 2019-11-15 17:49:42 +0100 | [diff] [blame] | 36 | export default class UserInfoModal extends React.Component { |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 37 | |
| 38 | constructor(props, context) { |
| 39 | super(props, context); |
| 40 | |
| 41 | this.handleClose = this.handleClose.bind(this); |
sebdet | 7658007 | 2020-02-23 09:31:04 -0800 | [diff] [blame] | 42 | this.renderPermissions = this.renderPermissions.bind(this); |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 43 | this.renderUserName = this.renderUserName.bind(this); |
| 44 | this.state = { |
| 45 | show: true, |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 46 | userInfo: {} |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 47 | }; |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 48 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 49 | componentWillMount() { |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 50 | UserService.getUserInfo().then(userInfo => { |
| 51 | this.setState({ userInfo: userInfo }) |
| 52 | }); |
| 53 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 54 | |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 55 | handleClose() { |
| 56 | this.props.history.push('/'); |
| 57 | } |
sebdet | 7658007 | 2020-02-23 09:31:04 -0800 | [diff] [blame] | 58 | renderPermissions() { |
| 59 | if (this.state.userInfo["allPermissions"]) { |
| 60 | var listOfPermissions = this.state.userInfo["allPermissions"].map(function(perm) { |
sebdet | 44fac5a | 2021-04-28 11:12:45 +0200 | [diff] [blame^] | 61 | return <Form.Control key={perm} plaintext readOnly defaultValue={perm} />; |
sebdet | 7658007 | 2020-02-23 09:31:04 -0800 | [diff] [blame] | 62 | }) |
| 63 | return listOfPermissions; |
| 64 | } else { |
| 65 | return; |
| 66 | } |
| 67 | } |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 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 ( |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 84 | <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 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> |
sebdet | 7658007 | 2020-02-23 09:31:04 -0800 | [diff] [blame] | 100 | {this.renderPermissions()} |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 101 | </Col> |
| 102 | </Form.Group> |
| 103 | </Modal.Body> |
| 104 | <Modal.Footer> |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 105 | <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 106 | </Modal.Footer> |
| 107 | </ModalStyled> |
| 108 | ); |
| 109 | } |
| 110 | } |