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';
37 import { Route } from 'react-router-dom'
38 import OpenLoopModal from './components/dialogs/OpenLoop/OpenLoopModal';
39 import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
40 import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
41 import LoopProperties from './components/dialogs/LoopProperties';
42 import UserInfo from './components/dialogs/UserInfo';
43 import LoopService from './api/LoopService';
44 import PerformAction from './components/dialogs/PerformActions';
45 import RefreshStatus from './components/dialogs/RefreshStatus';
46 import DeployLoop from './components/dialogs/DeployLoop';
47 import Alert from 'react-bootstrap/Alert';
49 import { Link } from 'react-router-dom';
51 const StyledMainDiv = styled.div`
52 background-color: ${props => props.theme.backgroundColor};
55 const ProjectNameStyled = styled.a`
56 vertical-align: middle;
62 const StyledRouterLink = styled(Link)`
63 color: ${props => props.theme.menuFontColor};
64 background-color: ${props => props.theme.backgroundColor};
67 const StyledLoginInfo = styled.a`
68 color: ${props => props.theme.menuFontColor};
69 background-color: ${props => props.theme.backgroundColor};
72 const LoopViewDivStyled = styled.div`
78 color: ${props => props.theme.loopViewerFontColor};
79 background-color: ${props => props.theme.loopViewerBackgroundColor};
80 border: 1px solid transparent;
81 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
84 const LoopViewHeaderDivStyled = styled.div`
85 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
87 color: ${props => props.theme.loopViewerHeaderFontColor};
90 const LoopViewBodyDivStyled = styled.div`
91 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
93 color: ${props => (props.theme.loopViewerHeaderFontColor)};
97 export default class LoopUI extends React.Component {
99 static defaultLoopName="Empty (NO loop loaded yet)";
103 loopName: LoopUI.defaultLoopName,
104 loopCache: new LoopCache({}),
110 this.getUser = this.getUser.bind(this);
111 this.logout = this.logout.bind(this);
112 this.updateLoopCache = this.updateLoopCache.bind(this);
113 this.loadLoop = this.loadLoop.bind(this);
114 this.closeLoop = this.closeLoop.bind(this);
115 this.showAlert = this.showAlert.bind(this);
116 this.disableAlert = this.disableAlert.bind(this);
119 componentWillMount() {
124 UserService.login().then(user => {
125 this.setState({ userName: user })
130 UserService.logout().then(user => {
131 this.setState({ userName: user });
132 window.location.reload();
139 <MenuBar loopName={this.state.loopName}/>
143 renderUserLoggedNavBar() {
146 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
147 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
148 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
156 <img height="50px" width="234px" src={logo} alt="" />
157 <ProjectNameStyled>CLAMP</ProjectNameStyled>
164 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
165 {this.state.showMessage}
173 {this.renderLogoNavBar()}
174 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
175 {this.renderMenuNavBar()}
176 {this.renderUserLoggedNavBar()}
181 renderLoopViewHeader() {
183 <LoopViewHeaderDivStyled>
184 Loop Viewer - {this.state.loopName}
185 </LoopViewHeaderDivStyled>
189 renderLoopViewBody() {
191 <LoopViewBodyDivStyled>
192 <LoopSvg loopCache={this.state.loopCache} />
193 <LoopStatus loopCache={this.state.loopCache}/>
194 <LoopLogs loopCache={this.state.loopCache} />
195 </LoopViewBodyDivStyled>
200 return this.state.loopCache;
207 {this.renderLoopViewHeader()}
208 {this.renderLoopViewBody()}
213 updateLoopCache(loopJson) {
214 this.setState({ loopCache: new LoopCache(loopJson) });
215 this.setState({ loopName: this.state.loopCache.getLoopName() });
216 console.info(this.state.loopName+" loop loaded successfully");
220 this.setState ({ showAlert: true, showMessage:message });
224 this.setState ({ showAlert: false });
228 LoopService.getLoop(loopName).then(loop => {
229 console.debug("Updating loopCache");
230 this.updateLoopCache(loop);
235 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
236 this.props.history.push('/');
241 <StyledMainDiv id="main_div">
242 <Route path="/operationalPolicyModal"
243 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} />
244 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
245 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
246 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
247 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
248 <Route path="/closeLoop" render={this.closeLoop} />
249 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
250 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
251 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
252 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
253 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
254 <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
255 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} />
256 <Route path="/logout" render={this.logout} />
258 {this.renderAlertBar()}
259 {this.renderNavBar()}
260 {this.renderLoopViewer()}