blob: 1273d87c03e196e2aefb87f298139139871beac7 [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);
xuegaoe52d5722019-07-25 15:43:06 +020042 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,
sebdet687b8de2019-08-26 14:29:11 -070051 userInfo: {}
xuegaoe52d5722019-07-25 15:43:06 +020052 };
xuegaoe52d5722019-07-25 15:43:06 +020053 }
sebdet687b8de2019-08-26 14:29:11 -070054 componentWillMount() {
xuegaoe52d5722019-07-25 15:43:06 +020055 UserService.getUserInfo().then(userInfo => {
56 this.setState({ userInfo: userInfo })
57 });
58 }
sebdet687b8de2019-08-26 14:29:11 -070059
xuegaoe52d5722019-07-25 15:43:06 +020060 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 (
sebdet687b8de2019-08-26 14:29:11 -0700121 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
xuegaoe52d5722019-07-25 15:43:06 +0200122 <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>
sebdet8a02dd72019-07-31 17:11:11 +0200147 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
xuegaoe52d5722019-07-25 15:43:06 +0200148 </Modal.Footer>
149 </ModalStyled>
150 );
151 }
152}