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 OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
42 import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
43 import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
44 import UserInfoModal from './components/dialogs/UserInfoModal';
45 import LoopService from './api/LoopService';
46 import UploadToscaPolicyModal from './components/dialogs/Tosca/UploadToscaPolicyModal';
47 import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
48 import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal';
49 import PerformAction from './components/dialogs/PerformActions';
50 import RefreshStatus from './components/dialogs/RefreshStatus';
51 import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
52 import Alert from 'react-bootstrap/Alert';
54 import { Link } from 'react-router-dom';
56 const StyledMainDiv = styled.div`
57 background-color: ${props => props.theme.backgroundColor};
60 const ProjectNameStyled = styled.a`
61 vertical-align: middle;
67 const StyledRouterLink = styled(Link)`
68 color: ${props => props.theme.menuFontColor};
69 background-color: ${props => props.theme.backgroundColor};
72 const StyledLoginInfo = styled.a`
73 color: ${props => props.theme.menuFontColor};
74 background-color: ${props => props.theme.backgroundColor};
77 const LoopViewDivStyled = styled.div`
83 color: ${props => props.theme.loopViewerFontColor};
84 background-color: ${props => props.theme.loopViewerBackgroundColor};
85 border: 1px solid transparent;
86 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
89 const LoopViewHeaderDivStyled = styled.div`
90 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
92 color: ${props => props.theme.loopViewerHeaderFontColor};
95 const LoopViewBodyDivStyled = styled.div`
96 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
98 color: ${props => (props.theme.loopViewerHeaderFontColor)};
102 export default class LoopUI extends React.Component {
106 loopName: OnapConstants.defaultLoopName,
107 loopCache: new LoopCache({}),
113 this.getUser = this.getUser.bind(this);
114 this.logout = this.logout.bind(this);
115 this.updateLoopCache = this.updateLoopCache.bind(this);
116 this.loadLoop = this.loadLoop.bind(this);
117 this.closeLoop = this.closeLoop.bind(this);
118 this.showAlert = this.showAlert.bind(this);
119 this.disableAlert = this.disableAlert.bind(this);
122 componentWillMount() {
127 UserService.login().then(user => {
128 this.setState({ userName: user })
133 UserService.logout().then(user => {
134 this.setState({ userName: user });
135 window.location.reload();
142 <MenuBar loopName={this.state.loopName}/>
146 renderUserLoggedNavBar() {
149 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
150 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
151 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
159 <img height="50px" width="234px" src={logo} alt="" />
160 <ProjectNameStyled>CLAMP</ProjectNameStyled>
167 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
168 {this.state.showMessage}
176 {this.renderLogoNavBar()}
177 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
178 {this.renderMenuNavBar()}
179 {this.renderUserLoggedNavBar()}
184 renderLoopViewHeader() {
186 <LoopViewHeaderDivStyled>
187 Loop Viewer - {this.state.loopName}
188 </LoopViewHeaderDivStyled>
192 renderLoopViewBody() {
194 <LoopViewBodyDivStyled>
195 <LoopSvg loopCache={this.state.loopCache} />
196 <LoopStatus loopCache={this.state.loopCache}/>
197 <LoopLogs loopCache={this.state.loopCache} />
198 </LoopViewBodyDivStyled>
203 return this.state.loopCache;
210 {this.renderLoopViewHeader()}
211 {this.renderLoopViewBody()}
216 updateLoopCache(loopJson) {
217 this.setState({ loopCache: new LoopCache(loopJson) });
218 this.setState({ loopName: this.state.loopCache.getLoopName() });
219 console.info(this.state.loopName+" loop loaded successfully");
223 this.setState ({ showAlert: true, showMessage:message });
227 this.setState ({ showAlert: false });
231 LoopService.getLoop(loopName).then(loop => {
232 console.debug("Updating loopCache");
233 LoopActionService.refreshStatus(loopName).then(data => {
234 this.updateLoopCache(data);
235 this.props.history.push('/');
238 this.updateLoopCache(loop);
239 this.props.history.push('/');
245 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
246 this.props.history.push('/');
251 <StyledMainDiv id="main_div">
252 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
253 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
254 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
255 <Route path="/operationalPolicyModal"
256 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
257 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
258 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
259 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
260 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
261 <Route path="/closeLoop" render={this.closeLoop} />
262 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
263 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
264 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
265 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
266 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
267 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
268 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
269 <Route path="/logout" render={this.logout} />
271 {this.renderAlertBar()}
272 {this.renderNavBar()}
273 {this.renderLoopViewer()}