blob: 18c444046ce2c96e71cf394f993fcca01965fb7f [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";
37
38const ModalStyled = styled(Modal)`
39 background-color: transparent;
40`
jingjincs3173d552020-03-04 09:11:10 +010041const LoopViewSvgDivStyled = styled.div`
42 overflow: hidden;
43 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
44 border-color: ${props => (props.theme.loopViewerHeaderColor)};
45 margin-left: auto;
46 margin-right:auto;
47 text-align: center;
48 margin-top: 20px;
drveerendra684057e2019-11-11 19:37:39 -050049`
jingjincs3173d552020-03-04 09:11:10 +010050const SvgContainerDivStyled = styled.div`
51 border: 1px solid;
52`
53
drveerendra684057e2019-11-11 19:37:39 -050054const cellStyle = { border: '1px solid black' };
55const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' };
56const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
57
sebdet3b7f6692020-02-17 06:03:31 -080058export default class ViewLoopTemplatesModal extends React.Component {
drveerendra684057e2019-11-11 19:37:39 -050059 state = {
jingjincs3173d552020-03-04 09:11:10 +010060 show: true,
sebdet3b7f6692020-02-17 06:03:31 -080061 content: 'Please select a loop template to display it',
drveerendra684057e2019-11-11 19:37:39 -050062 selectedRow: -1,
sebdet3b7f6692020-02-17 06:03:31 -080063 loopTemplateData: [],
64 loopTemplateColumnsDefinition: [
drveerendra684057e2019-11-11 19:37:39 -050065 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
66 cellStyle: cellStyle,
67 headerStyle: headerStyle
68 },
sebdet3b7f6692020-02-17 06:03:31 -080069 { title: "Template Name", field: "name",
drveerendra684057e2019-11-11 19:37:39 -050070 cellStyle: cellStyle,
71 headerStyle: headerStyle
72 },
sebdet3b7f6692020-02-17 06:03:31 -080073 { title: "Service Model Name", field: "modelService.serviceDetails.name",
drveerendra684057e2019-11-11 19:37:39 -050074 cellStyle: cellStyle,
75 headerStyle: headerStyle
76 },
sebdet3b7f6692020-02-17 06:03:31 -080077 { title: "Loop Type Allowed", field: "allowedLoopType",
drveerendra684057e2019-11-11 19:37:39 -050078 cellStyle: cellStyle,
79 headerStyle: headerStyle
80 },
sebdet3b7f6692020-02-17 06:03:31 -080081 { title: "# Instances Allowed", field: "maximumInstancesAllowed",
drveerendra684057e2019-11-11 19:37:39 -050082 cellStyle: cellStyle,
83 headerStyle: headerStyle
84 },
sebdet3b7f6692020-02-17 06:03:31 -080085 { title: "Modified Date", field: "updatedDate", editable: 'never',
drveerendra684057e2019-11-11 19:37:39 -050086 cellStyle: cellStyle,
87 headerStyle: headerStyle
88 }
89 ],
90 tableIcons: {
91 FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
92 LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
93 NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
94 PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
95 ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
96 Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
97 SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />)
98 }
99 };
100
101 constructor(props, context) {
102 super(props, context);
103 this.handleClose = this.handleClose.bind(this);
jingjincs3173d552020-03-04 09:11:10 +0100104 this.getBlueprintMicroServiceTemplate = this.getBlueprintMicroServiceTemplate.bind(this);
drveerendra684057e2019-11-11 19:37:39 -0500105 this.getBlueprintMicroServiceTemplates();
106 }
107
108 getBlueprintMicroServiceTemplates() {
sebdetaa486be2020-02-18 02:00:11 -0800109 TemplateService.getBlueprintMicroServiceTemplates().then(loopTemplateData => {
sebdet3b7f6692020-02-17 06:03:31 -0800110 this.setState({ loopTemplateData: loopTemplateData })
drveerendra684057e2019-11-11 19:37:39 -0500111 });
112 }
113
jingjincs3173d552020-03-04 09:11:10 +0100114 getBlueprintMicroServiceTemplate(templateName) {
115 if (typeof templateName !== "undefined") {
116 TemplateService.getBlueprintMicroServiceTemplate(templateName).then(svgXml => {
117 if (svgXml.length !== 0) {
118 this.setState({ content: svgXml })
119 } else {
120 this.setState({ content: 'Please select a loop template to view the details' })
121
122 }
123 });
124 } else {
125 this.setState({ content: 'Please select a loop template to view the details' })
126 }
127 }
drveerendra684057e2019-11-11 19:37:39 -0500128
129 handleClose() {
130 this.setState({ show: false });
131 this.props.history.push('/')
132 }
133
134 render() {
135 return (
jingjincs3173d552020-03-04 09:11:10 +0100136 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}>
137 <Modal.Header closeButton>
138 </Modal.Header>
139 <Modal.Body>
140 <MaterialTable
141 title={"View Blueprint MicroService Templates"}
142 data={this.state.loopTemplateData}
sebdet3b7f6692020-02-17 06:03:31 -0800143 columns={this.state.loopTemplateColumnsDefinition}
drveerendra684057e2019-11-11 19:37:39 -0500144 icons={this.state.tableIcons}
jingjincs3173d552020-03-04 09:11:10 +0100145 onRowClick={(event, rowData) => {this.getBlueprintMicroServiceTemplate(rowData.name);this.setState({selectedRow: rowData.tableData.id})}}
drveerendra684057e2019-11-11 19:37:39 -0500146 options={{
jingjincs3173d552020-03-04 09:11:10 +0100147 headerStyle:rowHeaderStyle,
148 rowStyle: rowData => ({
149 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
150 })
151 }}
152 />
153 <SvgContainerDivStyled>
154 <LoopViewSvgDivStyled dangerouslySetInnerHTML={{ __html: this.state.content }} value={this.state.content} >
155 </LoopViewSvgDivStyled>
156 </SvgContainerDivStyled>
157 </Modal.Body>
158 <Modal.Footer>
159 <Button variant="secondary" onClick={this.handleClose}>Close</Button>
160 </Modal.Footer>
drveerendra684057e2019-11-11 19:37:39 -0500161 </ModalStyled>
162 );
163 }
164 }