blob: adacbc8c6bbc2bc326beca10bb59bc83020d2b37 [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';
28import TemplateMenuService from '../../../api/TemplateMenuService';
29import 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`
41const TextModal = styled.textarea`
42margin-top: 20px;
43white-space:pre;
44background-color: ${props => props.theme.toscaTextareaBackgroundColor};;
45text-align: justify;
46font-size: ${props => props.theme.toscaTextareaFontSize};;
47width: 100%;
48height: 300px;
49`
50const cellStyle = { border: '1px solid black' };
51const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' };
52const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
53
54export default class ViewBlueprintMicroServiceTemplatesModal extends React.Component {
55 state = {
56 show: true,
57 content: 'Please select Blue print template to view the details',
58 selectedRow: -1,
59 bpTemplNames: [],
60 bpTemplColumns: [
61 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
62 cellStyle: cellStyle,
63 headerStyle: headerStyle
64 },
65 { title: "Template Name", field: "templateName",
66 cellStyle: cellStyle,
67 headerStyle: headerStyle
68 },
69 { title: "Policy Model", field: "templatePolicy[0].policyModelId",
70 cellStyle: cellStyle,
71 headerStyle: headerStyle
72 },
73 { title: "Template ID", field: "templateId",
74 cellStyle: cellStyle,
75 headerStyle: headerStyle
76 },
77 { title: "Uploaded By", field: "updatedBy",
78 cellStyle: cellStyle,
79 headerStyle: headerStyle
80 },
81 { title: "Uploaded Date", field: "timestamp", editable: 'never',
82 cellStyle: cellStyle,
83 headerStyle: headerStyle
84 }
85 ],
86 tableIcons: {
87 FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
88 LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
89 NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
90 PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
91 ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
92 Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
93 SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />)
94 }
95 };
96
97 constructor(props, context) {
98 super(props, context);
99 this.handleClose = this.handleClose.bind(this);
100 this.getBlueprintMicroServiceTemplates = this.getBlueprintMicroServiceTemplates.bind(this);
101 this.handleYamlContent = this.handleYamlContent.bind(this);
102 }
103
104 componentWillMount() {
105 this.getBlueprintMicroServiceTemplates();
106 }
107
108 getBlueprintMicroServiceTemplates() {
109 TemplateMenuService.getBlueprintMicroServiceTemplates().then(bpTemplNames => {
110 this.setState({ bpTemplNames: bpTemplNames })
111 });
112 }
113
114 handleYamlContent = event => {
115 this.setState({
116 content: event.target.value
117 });
118 }
119
120 handleClose() {
121 this.setState({ show: false });
122 this.props.history.push('/')
123 }
124
125 render() {
126 return (
127 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}>
128 <Modal.Header closeButton>
129 </Modal.Header>
130 <Modal.Body>
131 <MaterialTable
132 title={"View Blueprint MicroService Templates"}
133 data={this.state.bpTemplNames}
134 columns={this.state.bpTemplColumns}
135 icons={this.state.tableIcons}
136 onRowClick={(event, rowData) => {this.setState({content: rowData.templateYaml, selectedRow: rowData.tableData.id})}}
137 options={{
138 headerStyle:rowHeaderStyle,
139 rowStyle: rowData => ({
140 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
141 })
142 }}
143 />
144 <div>
145 <TextModal value={this.state.content} onChange={this.handleYamlContent} />
146 </div>
147 </Modal.Body>
148 <Modal.Footer>
149 <Button variant="secondary" onClick={this.handleClose}>Close</Button>
150 </Modal.Footer>
151 </ModalStyled>
152 );
153 }
154 }