drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 1 | /*- |
| 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 | |
| 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'; |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 28 | import TemplateService from '../../../api/TemplateService'; |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 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"; |
| 37 | |
| 38 | const ModalStyled = styled(Modal)` |
| 39 | background-color: transparent; |
| 40 | ` |
Ted Humphrey | df68db2 | 2020-04-16 17:36:17 +0000 | [diff] [blame^] | 41 | const LoopViewSvgDivStyled = styled.svg` |
| 42 | overflow-x: scroll; |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 43 | background-color: ${props => (props.theme.loopViewerBackgroundColor)}; |
| 44 | border-color: ${props => (props.theme.loopViewerHeaderColor)}; |
Ted Humphrey | df68db2 | 2020-04-16 17:36:17 +0000 | [diff] [blame^] | 45 | margin-top: 3em; |
| 46 | margin-left: 2em; |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 47 | margin-right:auto; |
| 48 | text-align: center; |
Ted Humphrey | df68db2 | 2020-04-16 17:36:17 +0000 | [diff] [blame^] | 49 | height: 100%; |
| 50 | width: 100%; |
| 51 | display: flex; |
| 52 | flex-direction: row; |
| 53 | align-items: center; |
| 54 | |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 55 | ` |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 56 | const SvgContainerDivStyled = styled.div` |
Ted Humphrey | df68db2 | 2020-04-16 17:36:17 +0000 | [diff] [blame^] | 57 | display: flex; |
| 58 | align-items: center; |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 59 | border: 1px solid; |
| 60 | ` |
| 61 | |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 62 | const cellStyle = { border: '1px solid black' }; |
| 63 | const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; |
| 64 | const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; |
| 65 | |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 66 | export default class ViewLoopTemplatesModal extends React.Component { |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 67 | state = { |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 68 | show: true, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 69 | content: 'Please select a loop template to display it', |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 70 | selectedRow: -1, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 71 | loopTemplateData: [], |
| 72 | loopTemplateColumnsDefinition: [ |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 73 | { title: "#", field: "index", render: rowData => rowData.tableData.id + 1, |
| 74 | cellStyle: cellStyle, |
| 75 | headerStyle: headerStyle |
| 76 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 77 | { title: "Template Name", field: "name", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 78 | cellStyle: cellStyle, |
| 79 | headerStyle: headerStyle |
| 80 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 81 | { title: "Service Model Name", field: "modelService.serviceDetails.name", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 82 | cellStyle: cellStyle, |
| 83 | headerStyle: headerStyle |
| 84 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 85 | { title: "Loop Type Allowed", field: "allowedLoopType", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 86 | cellStyle: cellStyle, |
| 87 | headerStyle: headerStyle |
| 88 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 89 | { title: "# Instances Allowed", field: "maximumInstancesAllowed", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 90 | cellStyle: cellStyle, |
| 91 | headerStyle: headerStyle |
| 92 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 93 | { title: "Modified Date", field: "updatedDate", editable: 'never', |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 94 | cellStyle: cellStyle, |
| 95 | headerStyle: headerStyle |
| 96 | } |
| 97 | ], |
| 98 | tableIcons: { |
| 99 | FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />), |
| 100 | LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />), |
| 101 | NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 102 | PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />), |
| 103 | ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
| 104 | Search: forwardRef((props, ref) => <Search {...props} ref={ref} />), |
| 105 | SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />) |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | constructor(props, context) { |
| 110 | super(props, context); |
| 111 | this.handleClose = this.handleClose.bind(this); |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 112 | this.getBlueprintMicroServiceTemplate = this.getBlueprintMicroServiceTemplate.bind(this); |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 113 | this.getBlueprintMicroServiceTemplates(); |
| 114 | } |
| 115 | |
| 116 | getBlueprintMicroServiceTemplates() { |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 117 | TemplateService.getBlueprintMicroServiceTemplates().then(loopTemplateData => { |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 118 | this.setState({ loopTemplateData: loopTemplateData }) |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 119 | }); |
| 120 | } |
| 121 | |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 122 | getBlueprintMicroServiceTemplate(templateName) { |
| 123 | if (typeof templateName !== "undefined") { |
sebdet | 8424215 | 2020-04-02 15:31:34 +0200 | [diff] [blame] | 124 | TemplateService.getBlueprintMicroServiceTemplateSvg(templateName).then(svgXml => { |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 125 | if (svgXml.length !== 0) { |
| 126 | this.setState({ content: svgXml }) |
| 127 | } else { |
| 128 | this.setState({ content: 'Please select a loop template to view the details' }) |
| 129 | |
| 130 | } |
| 131 | }); |
| 132 | } else { |
| 133 | this.setState({ content: 'Please select a loop template to view the details' }) |
| 134 | } |
| 135 | } |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 136 | |
| 137 | handleClose() { |
| 138 | this.setState({ show: false }); |
| 139 | this.props.history.push('/') |
| 140 | } |
| 141 | |
| 142 | render() { |
| 143 | return ( |
Ted Humphrey | df68db2 | 2020-04-16 17:36:17 +0000 | [diff] [blame^] | 144 | <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false}> |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 145 | <Modal.Header closeButton> |
| 146 | </Modal.Header> |
| 147 | <Modal.Body> |
| 148 | <MaterialTable |
| 149 | title={"View Blueprint MicroService Templates"} |
| 150 | data={this.state.loopTemplateData} |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 151 | columns={this.state.loopTemplateColumnsDefinition} |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 152 | icons={this.state.tableIcons} |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 153 | onRowClick={(event, rowData) => {this.getBlueprintMicroServiceTemplate(rowData.name);this.setState({selectedRow: rowData.tableData.id})}} |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 154 | options={{ |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 155 | headerStyle:rowHeaderStyle, |
| 156 | rowStyle: rowData => ({ |
| 157 | backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF' |
| 158 | }) |
| 159 | }} |
| 160 | /> |
| 161 | <SvgContainerDivStyled> |
| 162 | <LoopViewSvgDivStyled dangerouslySetInnerHTML={{ __html: this.state.content }} value={this.state.content} > |
| 163 | </LoopViewSvgDivStyled> |
| 164 | </SvgContainerDivStyled> |
| 165 | </Modal.Body> |
| 166 | <Modal.Footer> |
| 167 | <Button variant="secondary" onClick={this.handleClose}>Close</Button> |
| 168 | </Modal.Footer> |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 169 | </ModalStyled> |
| 170 | ); |
| 171 | } |
| 172 | } |