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