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.logout = this.logout.bind(this);
118 this.updateLoopCache = this.updateLoopCache.bind(this);
119 this.loadLoop = this.loadLoop.bind(this);
120 this.closeLoop = this.closeLoop.bind(this);
121 this.showSucAlert = this.showSucAlert.bind(this);
122 this.showFailAlert = this.showFailAlert.bind(this);
123 this.disableAlert = this.disableAlert.bind(this);
126 componentWillMount() {
131 UserService.login().then(user => {
132 this.setState({ userName: user })
137 UserService.logout().then(user => {
138 this.setState({ userName: user });
139 window.location.reload();
146 <MenuBar loopName={this.state.loopName}/>
150 renderUserLoggedNavBar() {
153 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
154 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
155 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
163 <img height="50px" width="234px" src={logo} alt="" />
164 <ProjectNameStyled>CLAMP</ProjectNameStyled>
172 <Alert variant="success" show={this.state.showSucAlert} onClose={this.disableAlert} dismissible>
173 {this.state.showMessage}
175 <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
176 {this.state.showMessage}
185 {this.renderLogoNavBar()}
186 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
187 {this.renderMenuNavBar()}
188 {this.renderUserLoggedNavBar()}
193 renderLoopViewHeader() {
195 <LoopViewHeaderDivStyled>
196 Loop Viewer - {this.state.loopName} - ({this.state.loopCache.getTemplateName()})
197 </LoopViewHeaderDivStyled>
201 renderLoopViewBody() {
203 <LoopViewBodyDivStyled>
204 <SvgGenerator loopCache={this.state.loopCache} clickable={true} generatedFrom={SvgGenerator.GENERATED_FROM_INSTANCE}/>
205 <LoopStatus loopCache={this.state.loopCache}/>
206 <LoopLogs loopCache={this.state.loopCache} />
207 </LoopViewBodyDivStyled>
212 return this.state.loopCache;
219 {this.renderLoopViewHeader()}
220 {this.renderLoopViewBody()}
225 updateLoopCache(loopJson) {
226 this.setState({ loopCache: new LoopCache(loopJson) });
227 this.setState({ loopName: this.state.loopCache.getLoopName() });
228 console.info(this.state.loopName+" loop loaded successfully");
231 showSucAlert(message) {
232 this.setState ({ showSucAlert: true, showMessage:message });
235 showFailAlert(message) {
236 this.setState ({ showFailAlert: true, showMessage:message });
240 this.setState ({ showSucAlert: false, showFailAlert: false });
244 LoopService.getLoop(loopName).then(loop => {
245 console.debug("Updating loopCache");
246 LoopActionService.refreshStatus(loopName).then(data => {
247 this.updateLoopCache(data);
248 this.props.history.push('/');
251 this.updateLoopCache(loop);
252 this.props.history.push('/');
258 this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
259 this.props.history.push('/');
264 <StyledMainDiv id="main_div">
265 <Route path="/uploadToscaPolicyModal" render={(routeProps) => (<UploadToscaPolicyModal {...routeProps} />)} />
266 <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} />
267 <Route path="/ViewLoopTemplatesModal" render={(routeProps) => (<ViewLoopTemplatesModal {...routeProps} />)} />
268 <Route path="/ManageDictionaries" render={(routeProps) => (<ManageDictionaries {...routeProps} />)} />
269 <Route path="/policyModal/:policyInstanceType/:policyName" render={(routeProps) => (<PolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
270 <Route path="/createLoop" render={(routeProps) => (<CreateLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
271 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
272 <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
273 <Route path="/modifyLoop" render={(routeProps) => (<ModifyLoopModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
275 <Route path="/userInfo" render={(routeProps) => (<UserInfoModal {...routeProps} />)} />
276 <Route path="/closeLoop" render={this.closeLoop} />
277 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
278 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
279 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
280 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
281 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
282 <Route path="/deploy" render={(routeProps) => (<DeployLoopModal {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
283 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showSucAlert={this.showSucAlert} showFailAlert={this.showFailAlert}/>)} />
284 <Route path="/logout" render={this.logout} />
286 {this.renderAlertBar()}
287 {this.renderNavBar()}
288 {this.renderLoopViewer()}