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';
31 import LoopSvg from './components/loop_viewer/svg/LoopSvg';
32 import LoopLogs from './components/loop_viewer/logs/LoopLogs';
33 import LoopStatus from './components/loop_viewer/status/LoopStatus';
34 import UserService from './api/UserService';
35 import LoopCache from './api/LoopCache';
36 import LoopActionService from './api/LoopActionService';
38 import { Route } from 'react-router-dom'
39 import OpenLoopModal from './components/dialogs/OpenLoop/OpenLoopModal';
40 import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
41 import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
42 import LoopProperties from './components/dialogs/LoopProperties';
43 import UserInfo from './components/dialogs/UserInfo';
44 import LoopService from './api/LoopService';
45 import PerformAction from './components/dialogs/PerformActions';
46 import RefreshStatus from './components/dialogs/RefreshStatus';
47 import DeployLoop from './components/dialogs/DeployLoop';
48 import Alert from 'react-bootstrap/Alert';
50 import { Link } from 'react-router-dom';
52 const StyledMainDiv = styled.div`
53 background-color: ${props => props.theme.backgroundColor};
56 const ProjectNameStyled = styled.a`
57 vertical-align: middle;
63 const StyledRouterLink = styled(Link)`
64 color: ${props => props.theme.menuFontColor};
65 background-color: ${props => props.theme.backgroundColor};
68 const StyledLoginInfo = styled.a`
69 color: ${props => props.theme.menuFontColor};
70 background-color: ${props => props.theme.backgroundColor};
73 const LoopViewDivStyled = styled.div`
79 color: ${props => props.theme.loopViewerFontColor};
80 background-color: ${props => props.theme.loopViewerBackgroundColor};
81 border: 1px solid transparent;
82 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
85 const LoopViewHeaderDivStyled = styled.div`
86 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
88 color: ${props => props.theme.loopViewerHeaderFontColor};
91 const LoopViewBodyDivStyled = styled.div`
92 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
94 color: ${props => (props.theme.loopViewerHeaderFontColor)};
98 export default class LoopUI extends React.Component {
100 static defaultLoopName="Empty (NO loop loaded yet)";
104 loopName: LoopUI.defaultLoopName,
105 loopCache: new LoopCache({}),
111 this.getUser = this.getUser.bind(this);
112 this.logout = this.logout.bind(this);
113 this.updateLoopCache = this.updateLoopCache.bind(this);
114 this.loadLoop = this.loadLoop.bind(this);
115 this.closeLoop = this.closeLoop.bind(this);
116 this.showAlert = this.showAlert.bind(this);
117 this.disableAlert = this.disableAlert.bind(this);
120 componentWillMount() {
125 UserService.login().then(user => {
126 this.setState({ userName: user })
131 UserService.logout().then(user => {
132 this.setState({ userName: user });
133 window.location.reload();
140 <MenuBar loopName={this.state.loopName}/>
144 renderUserLoggedNavBar() {
147 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
148 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
149 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
157 <img height="50px" width="234px" src={logo} alt="" />
158 <ProjectNameStyled>CLAMP</ProjectNameStyled>
165 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
166 {this.state.showMessage}
174 {this.renderLogoNavBar()}
175 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
176 {this.renderMenuNavBar()}
177 {this.renderUserLoggedNavBar()}
182 renderLoopViewHeader() {
184 <LoopViewHeaderDivStyled>
185 Loop Viewer - {this.state.loopName}
186 </LoopViewHeaderDivStyled>
190 renderLoopViewBody() {
192 <LoopViewBodyDivStyled>
193 <LoopSvg loopCache={this.state.loopCache} />
194 <LoopStatus loopCache={this.state.loopCache}/>
195 <LoopLogs loopCache={this.state.loopCache} />
196 </LoopViewBodyDivStyled>
201 return this.state.loopCache;
208 {this.renderLoopViewHeader()}
209 {this.renderLoopViewBody()}
214 updateLoopCache(loopJson) {
215 this.setState({ loopCache: new LoopCache(loopJson) });
216 this.setState({ loopName: this.state.loopCache.getLoopName() });
217 console.info(this.state.loopName+" loop loaded successfully");
221 this.setState ({ showAlert: true, showMessage:message });
225 this.setState ({ showAlert: false });
229 LoopService.getLoop(loopName).then(loop => {
230 console.debug("Updating loopCache");
231 LoopActionService.refreshStatus(loopName).then(data => {
232 this.updateLoopCache(data);
233 this.props.history.push('/');
236 this.updateLoopCache(loop);
237 this.props.history.push('/');
243 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
244 this.props.history.push('/');
249 <StyledMainDiv id="main_div">
250 <Route path="/operationalPolicyModal"
251 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} />
252 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
253 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
254 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
255 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
256 <Route path="/closeLoop" render={this.closeLoop} />
257 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
258 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
259 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
260 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
261 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
262 <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
263 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
264 <Route path="/logout" render={this.logout} />
266 {this.renderAlertBar()}
267 {this.renderNavBar()}
268 {this.renderLoopViewer()}