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"; |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 37 | import LoopCache from '../../../api/LoopCache'; |
| 38 | import SvgGenerator from '../../loop_viewer/svg/SvgGenerator'; |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 39 | |
| 40 | const ModalStyled = styled(Modal)` |
| 41 | background-color: transparent; |
| 42 | ` |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 43 | |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 44 | const cellStyle = { border: '1px solid black' }; |
| 45 | const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; |
| 46 | const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; |
| 47 | |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 48 | export default class ViewLoopTemplatesModal extends React.Component { |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 49 | state = { |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 50 | show: true, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 51 | content: 'Please select a loop template to display it', |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 52 | selectedRow: -1, |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 53 | loopTemplatesData: [], |
| 54 | fakeLoopCacheWithTemplate: new LoopCache({}), |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 55 | loopTemplateColumnsDefinition: [ |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 56 | { title: "#", field: "index", render: rowData => rowData.tableData.id + 1, |
| 57 | cellStyle: cellStyle, |
| 58 | headerStyle: headerStyle |
| 59 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 60 | { title: "Template Name", field: "name", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 61 | cellStyle: cellStyle, |
| 62 | headerStyle: headerStyle |
| 63 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 64 | { title: "Service Model Name", field: "modelService.serviceDetails.name", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 65 | cellStyle: cellStyle, |
| 66 | headerStyle: headerStyle |
| 67 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 68 | { title: "Loop Type Allowed", field: "allowedLoopType", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 69 | cellStyle: cellStyle, |
| 70 | headerStyle: headerStyle |
| 71 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 72 | { title: "# Instances Allowed", field: "maximumInstancesAllowed", |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 73 | cellStyle: cellStyle, |
| 74 | headerStyle: headerStyle |
| 75 | }, |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 76 | { title: "Modified Date", field: "updatedDate", editable: 'never', |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 77 | 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 Humphrey | 083e5a2 | 2020-07-08 16:48:40 -0400 | [diff] [blame] | 95 | this.renderSvg = this.renderSvg.bind(this); |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 96 | this.getLoopTemplate = this.getLoopTemplate.bind(this); |
| 97 | this.getAllLoopTemplates(); |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 98 | } |
| 99 | |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 100 | getAllLoopTemplates() { |
| 101 | TemplateService.getAllLoopTemplates().then(templatesData => { |
Ted Humphrey | db90efc | 2020-07-29 18:59:12 -0400 | [diff] [blame] | 102 | // replace -1 in maximumInstancesAllowed with more meaningful 'No Limit' |
| 103 | for (let item in templatesData) { |
| 104 | if (templatesData[item].maximumInstancesAllowed === -1) { |
| 105 | templatesData[item].maximumInstancesAllowed = 'No Limit'; |
| 106 | } |
| 107 | } |
| 108 | this.setState({ loopTemplatesData: templatesData }) |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 109 | }); |
| 110 | } |
| 111 | |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 112 | getLoopTemplate(templateIdInDataArray) { |
| 113 | if (typeof templateIdInDataArray !== "undefined") { |
| 114 | this.setState({ fakeLoopCacheWithTemplate: |
| 115 | new LoopCache({ |
| 116 | "loopTemplate":this.state.loopTemplatesData[templateIdInDataArray], |
| 117 | "name": "fakeLoop" |
| 118 | }) |
| 119 | }) |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 120 | } else { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 121 | this.setState({ fakeLoopCacheWithTemplate: new LoopCache({}) }) |
| 122 | } |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 123 | } |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 124 | |
| 125 | handleClose() { |
| 126 | this.setState({ show: false }); |
| 127 | this.props.history.push('/') |
| 128 | } |
| 129 | |
Ted Humphrey | 083e5a2 | 2020-07-08 16:48:40 -0400 | [diff] [blame] | 130 | renderSvg() { |
| 131 | return( |
| 132 | <SvgGenerator loopCache={this.state.fakeLoopCacheWithTemplate} clickable={false} generatedFrom={SvgGenerator.GENERATED_FROM_TEMPLATE}/> |
| 133 | ) |
| 134 | } |
| 135 | |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 136 | render() { |
| 137 | return ( |
Ted Humphrey | df68db2 | 2020-04-16 17:36:17 +0000 | [diff] [blame] | 138 | <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] | 139 | <Modal.Header closeButton> |
| 140 | </Modal.Header> |
| 141 | <Modal.Body> |
| 142 | <MaterialTable |
| 143 | title={"View Blueprint MicroService Templates"} |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 144 | data={this.state.loopTemplatesData} |
sebdet | 3b7f669 | 2020-02-17 06:03:31 -0800 | [diff] [blame] | 145 | columns={this.state.loopTemplateColumnsDefinition} |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 146 | icons={this.state.tableIcons} |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 147 | onRowClick={(event, rowData) => {this.getLoopTemplate(rowData.tableData.id);this.setState({selectedRow: rowData.tableData.id})}} |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 148 | options={{ |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 149 | headerStyle:rowHeaderStyle, |
| 150 | rowStyle: rowData => ({ |
| 151 | backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF' |
| 152 | }) |
| 153 | }} |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 154 | /> |
Ted Humphrey | 083e5a2 | 2020-07-08 16:48:40 -0400 | [diff] [blame] | 155 | {this.renderSvg()} |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 156 | </Modal.Body> |
| 157 | <Modal.Footer> |
| 158 | <Button variant="secondary" onClick={this.handleClose}>Close</Button> |
| 159 | </Modal.Footer> |
drveerendra | 684057e | 2019-11-11 19:37:39 -0500 | [diff] [blame] | 160 | </ModalStyled> |
| 161 | ); |
| 162 | } |
| 163 | } |