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 LoopSvg from './components/loop_viewer/svg/LoopSvg';
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 OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
41 import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal';
42 import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
43 import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
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 PerformAction from './components/dialogs/PerformActions';
51 import RefreshStatus from './components/dialogs/RefreshStatus';
52 import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
53 import Alert from 'react-bootstrap/Alert';
55 import { Link } from 'react-router-dom';
57 const StyledMainDiv = styled.div`
58 background-color: ${props => props.theme.backgroundColor};
61 const ProjectNameStyled = styled.a`
62 vertical-align: middle;
68 const StyledRouterLink = styled(Link)`
69 color: ${props => props.theme.menuFontColor};
70 background-color: ${props => props.theme.backgroundColor};
73 const StyledLoginInfo = styled.a`
74 color: ${props => props.theme.menuFontColor};
75 background-color: ${props => props.theme.backgroundColor};
78 const LoopViewDivStyled = styled.div`
84 color: ${props => props.theme.loopViewerFontColor};
85 background-color: ${props => props.theme.loopViewerBackgroundColor};
86 border: 1px solid transparent;
87 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
90 const LoopViewHeaderDivStyled = styled.div`
91 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
93 color: ${props => props.theme.loopViewerHeaderFontColor};
96 const LoopViewBodyDivStyled = styled.div`
97 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
99 color: ${props => (props.theme.loopViewerHeaderFontColor)};
103 export default class LoopUI extends React.Component {
107 loopName: OnapConstants.defaultLoopName,
108 loopCache: new LoopCache({}),
114 this.getUser = this.getUser.bind(this);
115 this.logout = this.logout.bind(this);
116 this.updateLoopCache = this.updateLoopCache.bind(this);
117 this.loadLoop = this.loadLoop.bind(this);
118 this.closeLoop = this.closeLoop.bind(this);
119 this.showAlert = this.showAlert.bind(this);
120 this.disableAlert = this.disableAlert.bind(this);
123 componentWillMount() {
128 UserService.login().then(user => {
129 this.setState({ userName: user })
134 UserService.logout().then(user => {
135 this.setState({ userName: user });
136 window.location.reload();
143 <MenuBar loopName={this.state.loopName}/>
147 renderUserLoggedNavBar() {
150 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
151 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
152 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
160 <img height="50px" width="234px" src={logo} alt="" />
161 <ProjectNameStyled>CLAMP</ProjectNameStyled>
168 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
169 {this.state.showMessage}
177 {this.renderLogoNavBar()}
178 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
179 {this.renderMenuNavBar()}
180 {this.renderUserLoggedNavBar()}
185 renderLoopViewHeader() {
187 <LoopViewHeaderDivStyled>
188 Loop Viewer - {this.state.loopName}
189 </LoopViewHeaderDivStyled>
193 renderLoopViewBody() {
195 <LoopViewBodyDivStyled>
196 <LoopSvg loopCache={this.state.loopCache} />
197 <LoopStatus loopCache={this.state.loopCache}/>
198 <LoopLogs loopCache={this.state.loopCache} />
199 </LoopViewBodyDivStyled>
204 return this.state.loopCache;
211 {this.renderLoopViewHeader()}
212 {this.renderLoopViewBody()}
217 updateLoopCache(loopJson) {
218 this.setState({ loopCache: new LoopCache(loopJson) });
219 this.setState({ loopName: this.state.loopCache.getLoopName() });
220 console.info(this.state.loopName+" loop loaded successfully");
224 this.setState ({ showAlert: true, showMessage:message });
228 this.setState ({ showAlert: false });
232 LoopService.getLoop(loopName).then(loop => {
233 console.debug("Updating loopCache");
234 LoopActionService.refreshStatus(loopName).then(data => {
235 this.updateLoopCache(data);
236 this.props.history.push('/');
239 this.updateLoopCache(loop);
240 this.props.history.push('/');
246 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
247 this.props.history.push('/');
252 <StyledMainDiv id="main_div">
253 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
254 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
255 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
256 <Route path="/operationalPolicyModal"
257 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
258 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
259 <Route path="/configurationPolicyModal/:policyName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
260 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
261 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
262 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
264 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
265 <Route path="/closeLoop" render={this.closeLoop} />
266 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
267 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
268 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
269 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
270 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
271 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
272 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
273 <Route path="/logout" render={this.logout} />
275 {this.renderAlertBar()}
276 {this.renderNavBar()}
277 {this.renderLoopViewer()}