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 CreateLoopModal from './components/dialogs/Loop/CreateLoopModal';
41 import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
42 import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal';
43 import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
44 import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
45 import PolicyModal from './components/dialogs/Policy/PolicyModal';
46 import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
47 import UserInfoModal from './components/dialogs/UserInfoModal';
48 import LoopService from './api/LoopService';
49 import UploadToscaPolicyModal from './components/dialogs/Tosca/UploadToscaPolicyModal';
50 import ViewToscaPolicyModal from './components/dialogs/Tosca/ViewToscaPolicyModal';
51 import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal';
52 import ManageDictionaries from './components/dialogs/ManageDictionaries/ManageDictionaries';
53 import PerformAction from './components/dialogs/PerformActions';
54 import RefreshStatus from './components/dialogs/RefreshStatus';
55 import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
56 import Alert from 'react-bootstrap/Alert';
58 import { Link } from 'react-router-dom';
60 const StyledMainDiv = styled.div`
61 background-color: ${props => props.theme.backgroundColor};
64 const ProjectNameStyled = styled.a`
65 vertical-align: middle;
71 const StyledRouterLink = styled(Link)`
72 color: ${props => props.theme.menuFontColor};
73 background-color: ${props => props.theme.backgroundColor};
76 const StyledLoginInfo = styled.a`
77 color: ${props => props.theme.menuFontColor};
78 background-color: ${props => props.theme.backgroundColor};
81 const LoopViewDivStyled = styled.div`
87 color: ${props => props.theme.loopViewerFontColor};
88 background-color: ${props => props.theme.loopViewerBackgroundColor};
89 border: 1px solid transparent;
90 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
93 const LoopViewHeaderDivStyled = styled.div`
94 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
96 color: ${props => props.theme.loopViewerHeaderFontColor};
99 const LoopViewBodyDivStyled = styled.div`
100 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
102 color: ${props => (props.theme.loopViewerHeaderFontColor)};
106 export default class LoopUI extends React.Component {
110 loopName: OnapConstants.defaultLoopName,
111 loopCache: new LoopCache({}),
118 this.getUser = this.getUser.bind(this);
119 this.logout = this.logout.bind(this);
120 this.updateLoopCache = this.updateLoopCache.bind(this);
121 this.loadLoop = this.loadLoop.bind(this);
122 this.closeLoop = this.closeLoop.bind(this);
123 this.showSucAlert = this.showSucAlert.bind(this);
124 this.showFailAlert = this.showFailAlert.bind(this);
125 this.disableAlert = this.disableAlert.bind(this);
128 componentWillMount() {
133 UserService.login().then(user => {
134 this.setState({ userName: user })
139 UserService.logout().then(user => {
140 this.setState({ userName: user });
141 window.location.reload();
148 <MenuBar loopName={this.state.loopName}/>
152 renderUserLoggedNavBar() {
155 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
156 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
157 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
165 <img height="50px" width="234px" src={logo} alt="" />
166 <ProjectNameStyled>CLAMP</ProjectNameStyled>
174 <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible>
175 {this.state.showMessage}
177 <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
178 {this.state.showMessage}
187 {this.renderLogoNavBar()}
188 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
189 {this.renderMenuNavBar()}
190 {this.renderUserLoggedNavBar()}
195 renderLoopViewHeader() {
197 <LoopViewHeaderDivStyled>
198 Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()})
199 </LoopViewHeaderDivStyled>
203 renderLoopViewBody() {
205 <LoopViewBodyDivStyled>
206 <LoopSvg loopCache={this.state.loopCache} />
207 <LoopStatus loopCache={this.state.loopCache}/>
208 <LoopLogs loopCache={this.state.loopCache} />
209 </LoopViewBodyDivStyled>
214 return this.state.loopCache;
221 {this.renderLoopViewHeader()}
222 {this.renderLoopViewBody()}
227 updateLoopCache(loopJson) {
228 this.setState({ loopCache: new LoopCache(loopJson) });
229 this.setState({ loopName: this.state.loopCache.getLoopName() });
230 console.info(this.state.loopName+" loop loaded successfully");
233 showSucAlert(message) {
234 this.setState ({ showSucAlert: true, showMessage:message });
237 showFailAlert(message) {
238 this.setState ({ showFailAlert: true, showMessage:message });
242 this.setState ({ showSucAlert: false, showFailAlert: false });
246 LoopService.getLoop(loopName).then(loop => {
247 console.debug("Updating loopCache");
248 LoopActionService.refreshStatus(loopName).then(data => {
249 this.updateLoopCache(data);
250 this.props.history.push('/');
253 this.updateLoopCache(loop);
254 this.props.history.push('/');
260 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
261 this.props.history.push('/');
266 <StyledMainDiv id="main_div">
267 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
268 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
269 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
270 <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} />
271 <Route path="/operationalPolicyModal"
272 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
273 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
274 <Route path="/configurationPolicyModal/:policyName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
275 <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
276 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
277 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
278 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
280 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
281 <Route path="/closeLoop" render={this.closeLoop} />
282 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
283 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
284 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
285 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
286 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
287 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
288 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
289 <Route path="/logout" render={this.logout} />
291 {this.renderAlertBar()}
292 {this.renderNavBar()}
293 {this.renderLoopViewer()}