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 from 'react';
25 import styled from 'styled-components';
26 import MenuBar from './components/menu/MenuBar';
27 import Navbar from 'react-bootstrap/Navbar';
28 import logo from './logo.png';
29 import { GlobalClampStyle } from './theme/globalStyle.js';
30 import OnapConstants from './utils/OnapConstants';
32 import SvgGenerator from './components/loop_viewer/svg/SvgGenerator';
33 import LoopLogs from './components/loop_viewer/logs/LoopLogs';
34 import LoopStatus from './components/loop_viewer/status/LoopStatus';
35 import UserService from './api/UserService';
36 import LoopCache from './api/LoopCache';
37 import LoopActionService from './api/LoopActionService';
39 import { Route } from 'react-router-dom'
40 import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal';
41 import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
42 import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal';
43 import PolicyModal from './components/dialogs/Policy/PolicyModal';
44 import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
45 import UserInfoModal from './components/dialogs/UserInfoModal';
46 import LoopService from './api/LoopService';
47 import UploadToscaPolicyModal from './components/dialogs/Tosca/UploadToscaPolicyModal';
48 import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
49 import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal';
50 import ManageDictionaries from './components/dialogs/ManageDictionaries/ManageDictionaries';
51 import PerformAction from './components/dialogs/PerformActions';
52 import RefreshStatus from './components/dialogs/RefreshStatus';
53 import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
54 import Alert from 'react-bootstrap/Alert';
56 import { Link } from 'react-router-dom';
58 const StyledMainDiv = styled.div`
59 background-color: ${props => props.theme.backgroundColor};
62 const ProjectNameStyled = styled.a`
63 vertical-align: middle;
69 const StyledRouterLink = styled(Link)`
70 color: ${props => props.theme.menuFontColor};
71 background-color: ${props => props.theme.backgroundColor};
74 const StyledLoginInfo = styled.a`
75 color: ${props => props.theme.menuFontColor};
76 background-color: ${props => props.theme.backgroundColor};
79 const LoopViewDivStyled = styled.div`
85 color: ${props => props.theme.loopViewerFontColor};
86 background-color: ${props => props.theme.loopViewerBackgroundColor};
87 border: 1px solid transparent;
88 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
91 const LoopViewHeaderDivStyled = styled.div`
92 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
94 color: ${props => props.theme.loopViewerHeaderFontColor};
97 const LoopViewBodyDivStyled = styled.div`
98 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
100 color: ${props => (props.theme.loopViewerHeaderFontColor)};
104 export default class LoopUI extends React.Component {
108 loopName: OnapConstants.defaultLoopName,
109 loopCache: new LoopCache({}),
116 this.getUser = this.getUser.bind(this);
117 this.updateLoopCache = this.updateLoopCache.bind(this);
118 this.loadLoop = this.loadLoop.bind(this);
119 this.closeLoop = this.closeLoop.bind(this);
120 this.showSucAlert = this.showSucAlert.bind(this);
121 this.showFailAlert = this.showFailAlert.bind(this);
122 this.disableAlert = this.disableAlert.bind(this);
125 componentWillMount() {
130 UserService.login().then(user => {
131 this.setState({ userName: user })
137 <MenuBar loopName={this.state.loopName}/>
141 renderUserLoggedNavBar() {
144 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
145 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
153 <img height="50px" width="234px" src={logo} alt="" />
154 <ProjectNameStyled>CLAMP</ProjectNameStyled>
162 <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible>
163 {this.state.showMessage}
165 <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
166 {this.state.showMessage}
175 {this.renderLogoNavBar()}
176 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
177 {this.renderMenuNavBar()}
178 {this.renderUserLoggedNavBar()}
183 renderLoopViewHeader() {
185 <LoopViewHeaderDivStyled>
186 Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()})
187 </LoopViewHeaderDivStyled>
191 renderLoopViewBody() {
193 <LoopViewBodyDivStyled>
194 <SvgGenerator loopCache={this.state.loopCache} clickable={true} generatedFrom={SvgGenerator.GENERATED_FROM_INSTANCE}/>
195 <LoopStatus loopCache={this.state.loopCache}/>
196 <LoopLogs loopCache={this.state.loopCache} />
197 </LoopViewBodyDivStyled>
202 return this.state.loopCache;
209 {this.renderLoopViewHeader()}
210 {this.renderLoopViewBody()}
215 updateLoopCache(loopJson) {
216 this.setState({ loopCache: new LoopCache(loopJson) });
217 this.setState({ loopName: this.state.loopCache.getLoopName() });
218 console.info(this.state.loopName+" loop loaded successfully");
221 showSucAlert(message) {
222 this.setState ({ showSucAlert: true, showMessage:message });
225 showFailAlert(message) {
226 this.setState ({ showFailAlert: true, showMessage:message });
230 this.setState ({ showSucAlert: false, showFailAlert: false });
234 LoopService.getLoop(loopName).then(loop => {
235 console.debug("Updating loopCache");
236 LoopActionService.refreshStatus(loopName).then(data => {
237 this.updateLoopCache(data);
238 this.props.history.push('/');
241 this.updateLoopCache(loop);
242 this.props.history.push('/');
248 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
249 this.props.history.push('/');
254 <StyledMainDiv id="main_div">
255 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
256 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
257 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
258 <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} />
259 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
260 <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
261 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
262 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
263 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
265 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
266 <Route path="/closeLoop" render={this.closeLoop} />
267 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
268 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
269 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
270 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
271 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
272 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
273 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
275 {this.renderAlertBar()}
276 {this.renderNavBar()}
277 {this.renderLoopViewer()}