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 | |
| 36 | export default class UserInfo extends React.Component { |
| 37 | |
| 38 | constructor(props, context) { |
| 39 | super(props, context); |
| 40 | |
| 41 | this.handleClose = this.handleClose.bind(this); |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 42 | this.renderReadTemplatePermission = this.renderReadTemplatePermission.bind(this); |
| 43 | this.renderReadModelPermission = this.renderReadModelPermission.bind(this); |
| 44 | this.renderReadToscaPermission = this.renderReadToscaPermission.bind(this); |
| 45 | this.renderUpdateTemplatePermission = this.renderUpdateTemplatePermission.bind(this); |
| 46 | this.renderUpdateModelPermission = this.renderUpdateModelPermission.bind(this); |
| 47 | this.renderUpdateToscaPermission = this.renderUpdateToscaPermission.bind(this); |
| 48 | this.renderUserName = this.renderUserName.bind(this); |
| 49 | this.state = { |
| 50 | show: true, |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 51 | userInfo: {} |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 52 | }; |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 53 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 54 | componentWillMount() { |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 55 | UserService.getUserInfo().then(userInfo => { |
| 56 | this.setState({ userInfo: userInfo }) |
| 57 | }); |
| 58 | } |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 59 | |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 60 | handleClose() { |
| 61 | this.props.history.push('/'); |
| 62 | } |
| 63 | renderReadTemplatePermission() { |
| 64 | if (this.state.userInfo["permissionReadTemplate"]) { |
| 65 | return <Form.Control plaintext readOnly defaultValue="Read Template" /> |
| 66 | } else { |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | renderReadModelPermission() { |
| 71 | if (this.state.userInfo["permissionReadCl"]) { |
| 72 | return <Form.Control plaintext readOnly defaultValue="Read Model" /> |
| 73 | } else { |
| 74 | return; |
| 75 | } |
| 76 | } |
| 77 | renderReadToscaPermission() { |
| 78 | if (this.state.userInfo["permissionReadTosca"]) { |
| 79 | return <Form.Control plaintext readOnly defaultValue="Read Tosca" /> |
| 80 | } else { |
| 81 | return; |
| 82 | } |
| 83 | } |
| 84 | renderUpdateTemplatePermission() { |
| 85 | if (this.state.userInfo["permissionUpdateTemplate"]) { |
| 86 | return <Form.Control plaintext readOnly defaultValue="Edit Template" /> |
| 87 | } else { |
| 88 | return; |
| 89 | } |
| 90 | } |
| 91 | renderUpdateModelPermission() { |
| 92 | if (this.state.userInfo["permissionUpdateCl"]) { |
| 93 | return <Form.Control plaintext readOnly defaultValue="Edit Model" /> |
| 94 | } else { |
| 95 | return; |
| 96 | } |
| 97 | } |
| 98 | renderUpdateToscaPermission() { |
| 99 | if (this.state.userInfo["permissionUpdateTosca"]) { |
| 100 | return <Form.Control plaintext readOnly defaultValue="Edit Tosca" /> |
| 101 | } else { |
| 102 | return; |
| 103 | } |
| 104 | } |
| 105 | renderUserName() { |
| 106 | if (this.state.userInfo["userName"]) { |
| 107 | return <Form.Control plaintext readOnly defaultValue={this.state.userInfo["userName"]} /> |
| 108 | } else { |
| 109 | return; |
| 110 | } |
| 111 | } |
| 112 | renderVersion() { |
| 113 | if (this.state.userInfo["cldsVersion"]) { |
| 114 | return <Form.Control plaintext readOnly defaultValue={this.state.userInfo["cldsVersion"]} /> |
| 115 | } else { |
| 116 | return; |
| 117 | } |
| 118 | } |
| 119 | render() { |
| 120 | return ( |
sebdet | 687b8de | 2019-08-26 14:29:11 -0700 | [diff] [blame] | 121 | <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 122 | <Modal.Header closeButton> |
| 123 | <Modal.Title>User Info</Modal.Title> |
| 124 | </Modal.Header> |
| 125 | <Modal.Body> |
| 126 | <Form.Group as={Row} controlId="userName"> |
| 127 | <Form.Label column sm="3">Current User:</Form.Label> |
| 128 | <Col>{this.renderUserName()}</Col> |
| 129 | </Form.Group> |
| 130 | <Form.Group as={Row} controlId="cldsVersion"> |
| 131 | <Form.Label column sm="3">CLDS Version:</Form.Label> |
| 132 | <Col>{this.renderVersion()}</Col> |
| 133 | </Form.Group> |
| 134 | <Form.Group as={Row} controlId="userPermissions"> |
| 135 | <Form.Label column sm="3">User Permissions:</Form.Label> |
| 136 | <Col> |
| 137 | {this.renderReadTemplatePermission()} |
| 138 | {this.renderReadModelPermission()} |
| 139 | {this.renderReadToscaPermission()} |
| 140 | {this.renderUpdateTemplatePermission()} |
| 141 | {this.renderUpdateModelPermission()} |
| 142 | {this.renderUpdateToscaPermission()} |
| 143 | </Col> |
| 144 | </Form.Group> |
| 145 | </Modal.Body> |
| 146 | <Modal.Footer> |
sebdet | 8a02dd7 | 2019-07-31 17:11:11 +0200 | [diff] [blame] | 147 | <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button> |
xuegao | e52d572 | 2019-07-25 15:43:06 +0200 | [diff] [blame] | 148 | </Modal.Footer> |
| 149 | </ModalStyled> |
| 150 | ); |
| 151 | } |
| 152 | } |