blob: fbfb4a78c32373da5b04daaca61793c1a6ec1487 [file] [log] [blame]
drveerendraf6b26252019-10-31 12:45:30 -04001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * 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';
sebdet81f5cab2019-11-06 11:40:46 +010029import TemplateMenuService from '../../../api/TemplateMenuService';
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`
sebdet81f5cab2019-11-06 11:40:46 +010042
drveerendraf6b26252019-10-31 12:45:30 -040043const vtmCellStyle = { border: '1px solid black' };
44const vtmHeaderStyle = { backgroundColor: '#ddd', border: '2px solid black' };
45const vtmRowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
46
sebdet81f5cab2019-11-06 11:40:46 +010047export default class ViewToscalModal extends React.Component {
drveerendraf6b26252019-10-31 12:45:30 -040048
49 state = {
50 show: true,
51 content: 'Please select Tosca model to view the details',
52 selectedRow: -1,
53 toscaNames: [],
54 toscaColumns: [
55 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
56 cellStyle: vtmCellStyle,
57 headerStyle: vtmHeaderStyle
58 },
59 { title: "Micro Service Name", field: "toscaModelName",
60 cellStyle: vtmCellStyle,
61 headerStyle: vtmHeaderStyle
62 },
63 { title: "PolicyType", field: "policyType",
64 cellStyle: vtmCellStyle,
65 headerStyle: vtmHeaderStyle
66 },
67 { title: "Version", field: "version",
68 cellStyle: vtmCellStyle,
69 headerStyle: vtmHeaderStyle
70 },
71 { title: "Uploaded By", field: "userId",
72 cellStyle: vtmCellStyle,
73 headerStyle: vtmHeaderStyle
74 },
75 { title: "Uploaded Date", field: "lastUpdatedDate", editable: 'never',
76 cellStyle: vtmCellStyle,
77 headerStyle: vtmHeaderStyle
78 }
79 ],
80 tableIcons: {
sebdet81f5cab2019-11-06 11:40:46 +010081 FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
82 LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
83 NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
84 PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
85 ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
86 Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
87 SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />)
drveerendraf6b26252019-10-31 12:45:30 -040088 }
89 };
90
91 constructor(props, context) {
92 super(props, context);
93 this.handleClose = this.handleClose.bind(this);
sebdet81f5cab2019-11-06 11:40:46 +010094 this.getToscaModels = this.getToscaModels.bind(this);
drveerendraf6b26252019-10-31 12:45:30 -040095 this.handleYamlContent = this.handleYamlContent.bind(this);
96 }
97
98 componentWillMount() {
sebdet81f5cab2019-11-06 11:40:46 +010099 this.getToscaModels();
drveerendraf6b26252019-10-31 12:45:30 -0400100 }
101
sebdet81f5cab2019-11-06 11:40:46 +0100102 getToscaModels() {
103 TemplateMenuService.getToscaModels().then(toscaNames => {
drveerendraf6b26252019-10-31 12:45:30 -0400104 this.setState({ toscaNames: toscaNames });
105 });
106 }
107
108 handleYamlContent(event) {
drveerendraf6b26252019-10-31 12:45:30 -0400109 this.setState({ content: event.target.value });
110 }
111
112 handleClose() {
113 this.setState({ show: false });
114 this.props.history.push('/');
115 }
116
117 render() {
118 return (
119 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}>
120 <Modal.Header closeButton>
121 <Modal.Title className="title">View Tosca Model</Modal.Title>
122 </Modal.Header>
123 <Modal.Body>
124 <MaterialTable
125 title={"View ToscaModel"}
126 data={this.state.toscaNames}
127 columns={this.state.toscaColumns}
128 icons={this.state.tableIcons}
129 onRowClick={(event, rowData) => {this.setState({content: rowData.toscaModelRevisions[0].toscaModelYaml, selectedRow: rowData.tableData.id})}}
130 options={{
131 headerStyle: vtmRowHeaderStyle,
132 rowStyle: rowData => ({
133 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
134 })
135 }}
136 />
sebdet81f5cab2019-11-06 11:40:46 +0100137 <div>
138 <textarea value={this.state.content} onChange={this.handleYamlContent}/>
139 </div>
drveerendraf6b26252019-10-31 12:45:30 -0400140 </Modal.Body>
141 <Modal.Footer>
142 <Button variant="secondary" onClick={this.handleClose}>Close</Button>
143 </Modal.Footer>
144 </ModalStyled>
145 );
146 }
147}