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, Redirect } 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/menu/PerformActions';
45 import RefreshStatus from './components/menu/RefreshStatus';
47 const ProjectNameStyled = styled.a`
48 vertical-align: middle;
53 const LoopViewDivStyled = styled.div`
59 color: ${props => props.theme.loopViewerFontColor};
60 background-color: ${props => props.theme.loopViewerBackgroundColor};
61 border: 1px solid transparent;
62 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
65 const LoopViewHeaderDivStyled = styled.div`
66 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
68 color: ${props => props.theme.loopViewerHeaderFontColor};
71 const LoopViewBodyDivStyled = styled.div`
72 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
74 color: ${props => (props.theme.loopViewerHeaderFontColor)};
78 export default class LoopUI extends React.Component {
80 static defaultLoopName="Empty (NO loop loaded yet)";
84 loopName: LoopUI.defaultLoopName,
85 loopCache: new LoopCache({})
90 this.getUser = this.getUser.bind(this);
91 this.updateLoopCache = this.updateLoopCache.bind(this);
92 this.loadLoop = this.loadLoop.bind(this);
95 componentWillMount() {
100 UserService.login().then(user => {
101 this.setState({ userName: user })
111 renderUserLoggedNavBar() {
114 Signed in as: <a href="/login">{this.state.userName}</a>
122 <img height="50px" width="234px" src={logo} alt="" />
123 <ProjectNameStyled>CLAMP</ProjectNameStyled>
131 {this.renderLogoNavBar()}
132 {this.renderMenuNavBar()}
133 {this.renderUserLoggedNavBar()}
138 renderLoopViewHeader() {
140 <LoopViewHeaderDivStyled>
141 Loop Viewer - {this.state.loopName}
142 </LoopViewHeaderDivStyled>
146 renderLoopViewBody() {
148 <LoopViewBodyDivStyled>
149 <LoopSvg loopCache={this.state.loopCache} />
150 <LoopStatus loopCache={this.state.loopCache}/>
151 <LoopLogs loopCache={this.state.loopCache} />
152 </LoopViewBodyDivStyled>
157 return this.state.loopCache;
164 {this.renderLoopViewHeader()}
165 {this.renderLoopViewBody()}
170 updateLoopCache(loopJson) {
171 this.setState({ loopCache: new LoopCache(loopJson) });
172 this.setState({ loopName: this.state.loopCache.getLoopName() });
173 console.info(this.state.loopName+" loop loaded successfully");
177 LoopService.getLoop(loopName).then(loop => {
178 console.debug("Updating loopCache");
179 this.updateLoopCache(loop);
186 <Route path="/operationalPolicyModal"
187 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
188 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
189 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
190 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
191 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
192 <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} />
193 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
194 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
195 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
196 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
197 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
198 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
200 {this.renderNavBar()}
201 {this.renderLoopViewer()}