blob: 10473944f65f7587c261ffd80c0320af8c805072 [file] [log] [blame]
drveerendra684057e2019-11-11 19:37:39 -05001/*-
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 Button from 'react-bootstrap/Button';
26import Modal from 'react-bootstrap/Modal';
27import styled from 'styled-components';
sebdetaa486be2020-02-18 02:00:11 -080028import TemplateService from '../../../api/TemplateService';
drveerendra684057e2019-11-11 19:37:39 -050029import ArrowUpward from '@material-ui/icons/ArrowUpward';
30import ChevronLeft from '@material-ui/icons/ChevronLeft';
31import ChevronRight from '@material-ui/icons/ChevronRight';
32import Clear from '@material-ui/icons/Clear';
33import FirstPage from '@material-ui/icons/FirstPage';
34import LastPage from '@material-ui/icons/LastPage';
35import Search from '@material-ui/icons/Search';
36import MaterialTable from "material-table";
sebdetc0ec0fc2020-05-18 12:31:11 +020037import LoopCache from '../../../api/LoopCache';
38import SvgGenerator from '../../loop_viewer/svg/SvgGenerator';
drveerendra684057e2019-11-11 19:37:39 -050039
40const ModalStyled = styled(Modal)`
41 background-color: transparent;
42`
jingjincs3173d552020-03-04 09:11:10 +010043
drveerendra684057e2019-11-11 19:37:39 -050044const cellStyle = { border: '1px solid black' };
45const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' };
46const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
47
sebdet3b7f6692020-02-17 06:03:31 -080048export default class ViewLoopTemplatesModal extends React.Component {
drveerendra684057e2019-11-11 19:37:39 -050049 state = {
jingjincs3173d552020-03-04 09:11:10 +010050 show: true,
sebdet3b7f6692020-02-17 06:03:31 -080051 content: 'Please select a loop template to display it',
drveerendra684057e2019-11-11 19:37:39 -050052 selectedRow: -1,
sebdetc0ec0fc2020-05-18 12:31:11 +020053 loopTemplatesData: [],
54 fakeLoopCacheWithTemplate: new LoopCache({}),
sebdet3b7f6692020-02-17 06:03:31 -080055 loopTemplateColumnsDefinition: [
drveerendra684057e2019-11-11 19:37:39 -050056 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
57 cellStyle: cellStyle,
58 headerStyle: headerStyle
59 },
sebdet3b7f6692020-02-17 06:03:31 -080060 { title: "Template Name", field: "name",
drveerendra684057e2019-11-11 19:37:39 -050061 cellStyle: cellStyle,
62 headerStyle: headerStyle
63 },
sebdet3b7f6692020-02-17 06:03:31 -080064 { title: "Service Model Name", field: "modelService.serviceDetails.name",
drveerendra684057e2019-11-11 19:37:39 -050065 cellStyle: cellStyle,
66 headerStyle: headerStyle
67 },
sebdet3b7f6692020-02-17 06:03:31 -080068 { title: "Loop Type Allowed", field: "allowedLoopType",
drveerendra684057e2019-11-11 19:37:39 -050069 cellStyle: cellStyle,
70 headerStyle: headerStyle
71 },
sebdet3b7f6692020-02-17 06:03:31 -080072 { title: "# Instances Allowed", field: "maximumInstancesAllowed",
drveerendra684057e2019-11-11 19:37:39 -050073 cellStyle: cellStyle,
74 headerStyle: headerStyle
75 },
sebdet3b7f6692020-02-17 06:03:31 -080076 { title: "Modified Date", field: "updatedDate", editable: 'never',
drveerendra684057e2019-11-11 19:37:39 -050077 cellStyle: cellStyle,
78 headerStyle: headerStyle
79 }
80 ],
81 tableIcons: {
82 FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
83 LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
84 NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
85 PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
86 ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
87 Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
88 SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />)
89 }
90 };
91
92 constructor(props, context) {
93 super(props, context);
94 this.handleClose = this.handleClose.bind(this);
Ted Humphrey083e5a22020-07-08 16:48:40 -040095 this.renderSvg = this.renderSvg.bind(this);
sebdetc0ec0fc2020-05-18 12:31:11 +020096 this.getLoopTemplate = this.getLoopTemplate.bind(this);
97 this.getAllLoopTemplates();
drveerendra684057e2019-11-11 19:37:39 -050098 }
99
sebdetc0ec0fc2020-05-18 12:31:11 +0200100 getAllLoopTemplates() {
101 TemplateService.getAllLoopTemplates().then(templatesData => {
102 this.setState({ loopTemplatesData: templatesData })
drveerendra684057e2019-11-11 19:37:39 -0500103 });
104 }
105
sebdetc0ec0fc2020-05-18 12:31:11 +0200106 getLoopTemplate(templateIdInDataArray) {
107 if (typeof templateIdInDataArray !== "undefined") {
108 this.setState({ fakeLoopCacheWithTemplate:
109 new LoopCache({
110 "loopTemplate":this.state.loopTemplatesData[templateIdInDataArray],
111 "name": "fakeLoop"
112 })
113 })
jingjincs3173d552020-03-04 09:11:10 +0100114 } else {
sebdetc0ec0fc2020-05-18 12:31:11 +0200115 this.setState({ fakeLoopCacheWithTemplate: new LoopCache({}) })
116 }
jingjincs3173d552020-03-04 09:11:10 +0100117 }
drveerendra684057e2019-11-11 19:37:39 -0500118
119 handleClose() {
120 this.setState({ show: false });
121 this.props.history.push('/')
122 }
123
Ted Humphrey083e5a22020-07-08 16:48:40 -0400124 renderSvg() {
125 return(
126 <SvgGenerator loopCache={this.state.fakeLoopCacheWithTemplate} clickable={false} generatedFrom={SvgGenerator.GENERATED_FROM_TEMPLATE}/>
127 )
128 }
129
drveerendra684057e2019-11-11 19:37:39 -0500130 render() {
131 return (
Ted Humphreydf68db22020-04-16 17:36:17 +0000132 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false}>
jingjincs3173d552020-03-04 09:11:10 +0100133 <Modal.Header closeButton>
134 </Modal.Header>
135 <Modal.Body>
136 <MaterialTable
137 title={"View Blueprint MicroService Templates"}
sebdetc0ec0fc2020-05-18 12:31:11 +0200138 data={this.state.loopTemplatesData}
sebdet3b7f6692020-02-17 06:03:31 -0800139 columns={this.state.loopTemplateColumnsDefinition}
drveerendra684057e2019-11-11 19:37:39 -0500140 icons={this.state.tableIcons}
sebdetc0ec0fc2020-05-18 12:31:11 +0200141 onRowClick={(event, rowData) => {this.getLoopTemplate(rowData.tableData.id);this.setState({selectedRow: rowData.tableData.id})}}
drveerendra684057e2019-11-11 19:37:39 -0500142 options={{
jingjincs3173d552020-03-04 09:11:10 +0100143 headerStyle:rowHeaderStyle,
144 rowStyle: rowData => ({
145 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
146 })
147 }}
sebdetc0ec0fc2020-05-18 12:31:11 +0200148 />
Ted Humphrey083e5a22020-07-08 16:48:40 -0400149 {this.renderSvg()}
jingjincs3173d552020-03-04 09:11:10 +0100150 </Modal.Body>
151 <Modal.Footer>
152 <Button variant="secondary" onClick={this.handleClose}>Close</Button>
153 </Modal.Footer>
drveerendra684057e2019-11-11 19:37:39 -0500154 </ModalStyled>
155 );
156 }
157 }