2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 import React, { forwardRef } from 'react'
25 import Button from 'react-bootstrap/Button';
26 import Modal from 'react-bootstrap/Modal';
27 import styled from 'styled-components';
28 import TemplateService from '../../../api/TemplateService';
29 import ArrowUpward from '@material-ui/icons/ArrowUpward';
30 import ChevronLeft from '@material-ui/icons/ChevronLeft';
31 import ChevronRight from '@material-ui/icons/ChevronRight';
32 import Clear from '@material-ui/icons/Clear';
33 import FirstPage from '@material-ui/icons/FirstPage';
34 import LastPage from '@material-ui/icons/LastPage';
35 import Search from '@material-ui/icons/Search';
36 import MaterialTable from "material-table";
38 const ModalStyled = styled(Modal)`
39 background-color: transparent;
41 const LoopViewSvgDivStyled = styled.div`
43 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
44 border-color: ${props => (props.theme.loopViewerHeaderColor)};
50 const SvgContainerDivStyled = styled.div`
54 const cellStyle = { border: '1px solid black' };
55 const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' };
56 const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
58 export default class ViewLoopTemplatesModal extends React.Component {
61 content: 'Please select a loop template to display it',
64 loopTemplateColumnsDefinition: [
65 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
67 headerStyle: headerStyle
69 { title: "Template Name", field: "name",
71 headerStyle: headerStyle
73 { title: "Service Model Name", field: "modelService.serviceDetails.name",
75 headerStyle: headerStyle
77 { title: "Loop Type Allowed", field: "allowedLoopType",
79 headerStyle: headerStyle
81 { title: "# Instances Allowed", field: "maximumInstancesAllowed",
83 headerStyle: headerStyle
85 { title: "Modified Date", field: "updatedDate", editable: 'never',
87 headerStyle: headerStyle
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} />)
101 constructor(props, context) {
102 super(props, context);
103 this.handleClose = this.handleClose.bind(this);
104 this.getBlueprintMicroServiceTemplate = this.getBlueprintMicroServiceTemplate.bind(this);
105 this.getBlueprintMicroServiceTemplates();
108 getBlueprintMicroServiceTemplates() {
109 TemplateService.getBlueprintMicroServiceTemplates().then(loopTemplateData => {
110 this.setState({ loopTemplateData: loopTemplateData })
114 getBlueprintMicroServiceTemplate(templateName) {
115 if (typeof templateName !== "undefined") {
116 TemplateService.getBlueprintMicroServiceTemplateSvg(templateName).then(svgXml => {
117 if (svgXml.length !== 0) {
118 this.setState({ content: svgXml })
120 this.setState({ content: 'Please select a loop template to view the details' })
125 this.setState({ content: 'Please select a loop template to view the details' })
130 this.setState({ show: false });
131 this.props.history.push('/')
136 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}>
137 <Modal.Header closeButton>
141 title={"View Blueprint MicroService Templates"}
142 data={this.state.loopTemplateData}
143 columns={this.state.loopTemplateColumnsDefinition}
144 icons={this.state.tableIcons}
145 onRowClick={(event, rowData) => {this.getBlueprintMicroServiceTemplate(rowData.name);this.setState({selectedRow: rowData.tableData.id})}}
147 headerStyle:rowHeaderStyle,
148 rowStyle: rowData => ({
149 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
153 <SvgContainerDivStyled>
154 <LoopViewSvgDivStyled dangerouslySetInnerHTML={{ __html: this.state.content }} value={this.state.content} >
155 </LoopViewSvgDivStyled>
156 </SvgContainerDivStyled>
159 <Button variant="secondary" onClick={this.handleClose}>Close</Button>