blob: 6500805201a6c3ea1bc966d6a7c00bab34833d58 [file] [log] [blame]
drveerendraf6b26252019-10-31 12:45:30 -04001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
ash742683a83e2a2020-01-31 15:40:15 +00005 * Copyright (C) 2020 AT&T Intellectual Property. All rights
drveerendraf6b26252019-10-31 12:45:30 -04006 * reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 *
22 */
23
24import React, { forwardRef } from 'react'
25import MaterialTable from "material-table";
26import Button from 'react-bootstrap/Button';
27import Modal from 'react-bootstrap/Modal';
28import styled from 'styled-components';
sebdetaa486be2020-02-18 02:00:11 -080029import PolicyToscaService from '../../../api/PolicyToscaService';
drveerendraf6b26252019-10-31 12:45:30 -040030import ArrowUpward from '@material-ui/icons/ArrowUpward';
31import ChevronLeft from '@material-ui/icons/ChevronLeft';
32import ChevronRight from '@material-ui/icons/ChevronRight';
33import Clear from '@material-ui/icons/Clear';
34import FirstPage from '@material-ui/icons/FirstPage';
35import LastPage from '@material-ui/icons/LastPage';
36import Search from '@material-ui/icons/Search';
37
38
39const ModalStyled = styled(Modal)`
40 background-color: transparent;
41`
drveerendra684057e2019-11-11 19:37:39 -050042const TextModal = styled.textarea`
43 margin-top: 20px;
44 white-space:pre;
45 background-color: ${props => props.theme.toscaTextareaBackgroundColor};
46 text-align: justify;
47 font-size: ${props => props.theme.toscaTextareaFontSize};
48 width: 100%;
49 height: 300px;
50`
51const cellStyle = { border: '1px solid black' };
52const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' };
53const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
sebdet81f5cab2019-11-06 11:40:46 +010054
drveerendra684057e2019-11-11 19:37:39 -050055export default class ViewToscalPolicyModal extends React.Component {
drveerendraf6b26252019-10-31 12:45:30 -040056
57 state = {
58 show: true,
59 content: 'Please select Tosca model to view the details',
60 selectedRow: -1,
ash742683a83e2a2020-01-31 15:40:15 +000061 toscaPolicyModelNames: [],
drveerendraf6b26252019-10-31 12:45:30 -040062 toscaColumns: [
63 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
drveerendra684057e2019-11-11 19:37:39 -050064 cellStyle: cellStyle,
65 headerStyle: headerStyle
drveerendraf6b26252019-10-31 12:45:30 -040066 },
ash742683a83e2a2020-01-31 15:40:15 +000067 { title: "Policy Model Type", field: "policyModelType",
drveerendra684057e2019-11-11 19:37:39 -050068 cellStyle: cellStyle,
69 headerStyle: headerStyle
drveerendraf6b26252019-10-31 12:45:30 -040070 },
ash742683a83e2a2020-01-31 15:40:15 +000071 { title: "Policy Acronym", field: "policyAcronym",
drveerendra684057e2019-11-11 19:37:39 -050072 cellStyle: cellStyle,
73 headerStyle: headerStyle
drveerendraf6b26252019-10-31 12:45:30 -040074 },
ash742683a83e2a2020-01-31 15:40:15 +000075 { title: "Version", field: "version",
drveerendra684057e2019-11-11 19:37:39 -050076 cellStyle: cellStyle,
77 headerStyle: headerStyle
drveerendraf6b26252019-10-31 12:45:30 -040078 },
ash742683a83e2a2020-01-31 15:40:15 +000079 { title: "Uploaded By", field: "updatedBy",
drveerendra684057e2019-11-11 19:37:39 -050080 cellStyle: cellStyle,
81 headerStyle: headerStyle
drveerendraf6b26252019-10-31 12:45:30 -040082 },
ash742683a83e2a2020-01-31 15:40:15 +000083 { title: "Uploaded Date", field: "updatedDate", editable: 'never',
drveerendra684057e2019-11-11 19:37:39 -050084 cellStyle: cellStyle,
85 headerStyle: headerStyle
drveerendraf6b26252019-10-31 12:45:30 -040086 }
87 ],
88 tableIcons: {
sebdet81f5cab2019-11-06 11:40:46 +010089 FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
90 LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
91 NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
92 PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
93 ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
94 Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
95 SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />)
drveerendraf6b26252019-10-31 12:45:30 -040096 }
97 };
98
99 constructor(props, context) {
100 super(props, context);
101 this.handleClose = this.handleClose.bind(this);
drveerendra684057e2019-11-11 19:37:39 -0500102 this.getPolicyToscaModels = this.getToscaPolicyModels.bind(this);
drveerendraf6b26252019-10-31 12:45:30 -0400103 this.handleYamlContent = this.handleYamlContent.bind(this);
ash742683a83e2a2020-01-31 15:40:15 +0000104 this.getToscaPolicyModelYaml = this.getToscaPolicyModelYaml.bind(this);
drveerendraf6b26252019-10-31 12:45:30 -0400105 }
106
107 componentWillMount() {
drveerendra684057e2019-11-11 19:37:39 -0500108 this.getToscaPolicyModels();
drveerendraf6b26252019-10-31 12:45:30 -0400109 }
110
drveerendra684057e2019-11-11 19:37:39 -0500111 getToscaPolicyModels() {
sebdetaa486be2020-02-18 02:00:11 -0800112 PolicyToscaService.getToscaPolicyModels().then(toscaPolicyModelNames => {
ash742683a83e2a2020-01-31 15:40:15 +0000113 this.setState({ toscaPolicyModelNames: toscaPolicyModelNames });
drveerendraf6b26252019-10-31 12:45:30 -0400114 });
115 }
116
sebdetaa486be2020-02-18 02:00:11 -0800117 getToscaPolicyModelYaml(policyModelType, policyModelVersion) {
ash742683a83e2a2020-01-31 15:40:15 +0000118 if (typeof policyModelType !== "undefined") {
sebdetaa486be2020-02-18 02:00:11 -0800119 PolicyToscaService.getToscaPolicyModelYaml(policyModelType, policyModelVersion).then(toscaYaml => {
ash742683a83e2a2020-01-31 15:40:15 +0000120 if (toscaYaml.length !== 0) {
121 this.setState({content: toscaYaml})
122 } else {
123 this.setState({ content: 'Please select Tosca model to view the details' })
124 }
125 });
126 } else {
127 this.setState({ content: 'Please select Tosca model to view the details' })
128 }
129 }
130
drveerendraf6b26252019-10-31 12:45:30 -0400131 handleYamlContent(event) {
drveerendraf6b26252019-10-31 12:45:30 -0400132 this.setState({ content: event.target.value });
133 }
134
135 handleClose() {
136 this.setState({ show: false });
137 this.props.history.push('/');
138 }
139
140 render() {
141 return (
142 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}>
143 <Modal.Header closeButton>
drveerendraf6b26252019-10-31 12:45:30 -0400144 </Modal.Header>
145 <Modal.Body>
146 <MaterialTable
drveerendra684057e2019-11-11 19:37:39 -0500147 title={"View Tosca Policy Models"}
ash742683a83e2a2020-01-31 15:40:15 +0000148 data={this.state.toscaPolicyModelNames}
drveerendraf6b26252019-10-31 12:45:30 -0400149 columns={this.state.toscaColumns}
150 icons={this.state.tableIcons}
sebdetaa486be2020-02-18 02:00:11 -0800151 onRowClick={(event, rowData) => {this.getToscaPolicyModelYaml(rowData.policyModelType,rowData.version);this.setState({selectedRow: rowData.tableData.id})}}
drveerendraf6b26252019-10-31 12:45:30 -0400152 options={{
drveerendra684057e2019-11-11 19:37:39 -0500153 headerStyle: rowHeaderStyle,
drveerendraf6b26252019-10-31 12:45:30 -0400154 rowStyle: rowData => ({
155 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
156 })
157 }}
158 />
sebdet81f5cab2019-11-06 11:40:46 +0100159 <div>
drveerendra684057e2019-11-11 19:37:39 -0500160 <TextModal value={this.state.content} onChange={this.handleYamlContent}/>
sebdet81f5cab2019-11-06 11:40:46 +0100161 </div>
drveerendraf6b26252019-10-31 12:45:30 -0400162 </Modal.Body>
163 <Modal.Footer>
164 <Button variant="secondary" onClick={this.handleClose}>Close</Button>
165 </Modal.Footer>
166 </ModalStyled>
167 );
168 }
169}