blob: ff3c4445aa136b85bf02d1d91a5bbfc5793eb0b7 [file] [log] [blame]
sebdetc8d61302019-07-04 15:50:34 +02001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * reserved.
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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 * ===================================================================
21 *
22 */
23
24import React from 'react';
25import styled from 'styled-components';
sebdete44fdb12019-07-12 12:25:56 +020026import MenuBar from './components/menu/MenuBar';
sebdetc8d61302019-07-04 15:50:34 +020027import Navbar from 'react-bootstrap/Navbar';
28import logo from './logo.png';
sebdete44fdb12019-07-12 12:25:56 +020029import { GlobalClampStyle } from './theme/globalStyle.js';
sebdetc8d61302019-07-04 15:50:34 +020030
sebdet493c3832019-07-15 17:26:18 +020031import LoopSvg from './components/loop_viewer/svg/LoopSvg';
32import LoopLogs from './components/loop_viewer/logs/LoopLogs';
33import LoopStatus from './components/loop_viewer/status/LoopStatus';
sebdete44fdb12019-07-12 12:25:56 +020034import UserService from './api/UserService';
sebdet493c3832019-07-15 17:26:18 +020035import LoopCache from './api/LoopCache';
xuegaoac42c4b2019-10-09 16:12:37 +020036import LoopActionService from './api/LoopActionService';
sebdet493c3832019-07-15 17:26:18 +020037
xuegao691e2b72019-08-16 11:07:24 +020038import { Route } from 'react-router-dom'
sebdet493c3832019-07-15 17:26:18 +020039import OpenLoopModal from './components/dialogs/OpenLoop/OpenLoopModal';
40import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
41import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
xuegaoe52d5722019-07-25 15:43:06 +020042import LoopProperties from './components/dialogs/LoopProperties';
43import UserInfo from './components/dialogs/UserInfo';
sebdet83ce0762019-08-02 14:53:59 +020044import LoopService from './api/LoopService';
sebdetf9e2cee2019-08-09 18:36:09 +020045import PerformAction from './components/dialogs/PerformActions';
46import RefreshStatus from './components/dialogs/RefreshStatus';
47import DeployLoop from './components/dialogs/DeployLoop';
xuegao0efeb6b2019-10-07 14:36:34 +020048import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020049
sebdetd0d65632019-08-26 05:47:01 -070050import { Link } from 'react-router-dom';
51
52const StyledMainDiv = styled.div`
53 background-color: ${props => props.theme.backgroundColor};
54`
55
sebdet4946e5b2019-07-10 12:32:36 +020056const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020057 vertical-align: middle;
58 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070059 font-size: 36px;
60 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020061`
sebdetd0d65632019-08-26 05:47:01 -070062
63const StyledRouterLink = styled(Link)`
64 color: ${props => props.theme.menuFontColor};
65 background-color: ${props => props.theme.backgroundColor};
66`
67
68const StyledLoginInfo = styled.a`
69 color: ${props => props.theme.menuFontColor};
70 background-color: ${props => props.theme.backgroundColor};
71`
72
sebdet4946e5b2019-07-10 12:32:36 +020073const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020074 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020075 overflow: hidden;
76 margin-left: 10px;
77 margin-right: 10px;
78 margin-bottom: 10px;
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};
83`
84
sebdet4946e5b2019-07-10 12:32:36 +020085const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020086 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
87 padding: 10px 10px;
88 color: ${props => props.theme.loopViewerHeaderFontColor};
89`
90
sebdet4946e5b2019-07-10 12:32:36 +020091const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020092 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
93 padding: 10px 10px;
94 color: ${props => (props.theme.loopViewerHeaderFontColor)};
95 height: 95%;
96`
97
sebdetc8d61302019-07-04 15:50:34 +020098export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020099
sebdet2dacb9b2019-07-17 13:48:44 +0200100 static defaultLoopName="Empty (NO loop loaded yet)";
101
sebdet4946e5b2019-07-10 12:32:36 +0200102 state = {
103 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +0200104 loopName: LoopUI.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200105 loopCache: new LoopCache({}),
106 showAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200107 };
xuegao7c7323d2019-07-09 11:52:20 +0200108
sebdet4946e5b2019-07-10 12:32:36 +0200109 constructor() {
110 super();
111 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700112 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200113 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200114 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200115 this.closeLoop = this.closeLoop.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200116 this.showAlert = this.showAlert.bind(this);
117 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200118 }
sebdet493c3832019-07-15 17:26:18 +0200119
sebdet2dacb9b2019-07-17 13:48:44 +0200120 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200121 this.getUser();
122 }
sebdet4946e5b2019-07-10 12:32:36 +0200123
124 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200125 UserService.login().then(user => {
126 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200127 });
128 }
sebdet687b8de2019-08-26 14:29:11 -0700129
130 logout() {
131 UserService.logout().then(user => {
132 this.setState({ userName: user });
133 window.location.reload();
134 });
135
136 }
sebdet493c3832019-07-15 17:26:18 +0200137
sebdetc8d61302019-07-04 15:50:34 +0200138 renderMenuNavBar() {
139 return (
xuegao691e2b72019-08-16 11:07:24 +0200140 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200141 );
142 }
sebdet4946e5b2019-07-10 12:32:36 +0200143
sebdetc8d61302019-07-04 15:50:34 +0200144 renderUserLoggedNavBar() {
145 return (
146 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700147 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
148 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
149 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200150 </Navbar.Text>
151 );
152 }
sebdet4946e5b2019-07-10 12:32:36 +0200153
sebdetc8d61302019-07-04 15:50:34 +0200154 renderLogoNavBar() {
155 return (
156 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200157 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200158 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200159 </Navbar.Brand>
160 );
161 }
sebdet4946e5b2019-07-10 12:32:36 +0200162
xuegao0efeb6b2019-10-07 14:36:34 +0200163 renderAlertBar() {
164 return (
165 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
166 {this.state.showMessage}
167 </Alert>
168 );
169 }
170
sebdetc8d61302019-07-04 15:50:34 +0200171 renderNavBar() {
172 return (
sebdetd0d65632019-08-26 05:47:01 -0700173 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200174 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700175 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200176 {this.renderMenuNavBar()}
177 {this.renderUserLoggedNavBar()}
178 </Navbar>
179 );
sebdetc8d61302019-07-04 15:50:34 +0200180 }
sebdet493c3832019-07-15 17:26:18 +0200181
sebdetc8d61302019-07-04 15:50:34 +0200182 renderLoopViewHeader() {
183 return (
sebdet4946e5b2019-07-10 12:32:36 +0200184 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200185 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200186 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200187 );
188 }
sebdet493c3832019-07-15 17:26:18 +0200189
sebdetc8d61302019-07-04 15:50:34 +0200190 renderLoopViewBody() {
191 return (
sebdet4946e5b2019-07-10 12:32:36 +0200192 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200193 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200194 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200195 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200196 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200197 );
198 }
sebdet493c3832019-07-15 17:26:18 +0200199
xuegaoe52d5722019-07-25 15:43:06 +0200200 getLoopCache() {
201 return this.state.loopCache;
202
203 }
xuegao5fe750c2019-08-06 13:03:53 +0200204
sebdetc8d61302019-07-04 15:50:34 +0200205 renderLoopViewer() {
206 return (
sebdet4946e5b2019-07-10 12:32:36 +0200207 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200208 {this.renderLoopViewHeader()}
209 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200210 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200211 );
sebdetc8d61302019-07-04 15:50:34 +0200212 }
sebdet493c3832019-07-15 17:26:18 +0200213
214 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200215 this.setState({ loopCache: new LoopCache(loopJson) });
216 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200217 console.info(this.state.loopName+" loop loaded successfully");
218 }
xuegao5fe750c2019-08-06 13:03:53 +0200219
xuegao0efeb6b2019-10-07 14:36:34 +0200220 showAlert(message) {
221 this.setState ({ showAlert: true, showMessage:message });
222 }
223
224 disableAlert() {
225 this.setState ({ showAlert: false });
226 }
227
sebdet83ce0762019-08-02 14:53:59 +0200228 loadLoop(loopName) {
229 LoopService.getLoop(loopName).then(loop => {
230 console.debug("Updating loopCache");
xuegaoac42c4b2019-10-09 16:12:37 +0200231 LoopActionService.refreshStatus(loopName).then(data => {
232 this.updateLoopCache(data);
233 this.props.history.push('/');
234 })
235 .catch(error => {
236 this.updateLoopCache(loop);
237 this.props.history.push('/');
238 });
sebdet83ce0762019-08-02 14:53:59 +0200239 });
sebdet493c3832019-07-15 17:26:18 +0200240 }
241
xuegao691e2b72019-08-16 11:07:24 +0200242 closeLoop() {
243 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
244 this.props.history.push('/');
245 }
sebdet687b8de2019-08-26 14:29:11 -0700246
247 render() {
sebdetc8d61302019-07-04 15:50:34 +0200248 return (
sebdetd0d65632019-08-26 05:47:01 -0700249 <StyledMainDiv id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200250 <Route path="/operationalPolicyModal"
xuegao0efeb6b2019-10-07 14:36:34 +0200251 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} />
sebdet83ce0762019-08-02 14:53:59 +0200252 <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}/>)} />
xuegaoe52d5722019-07-25 15:43:06 +0200255 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200256 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200257 <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}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700264 <Route path="/logout" render={this.logout} />
265 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200266 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200267 {this.renderNavBar()}
268 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700269 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200270 );
271 }
272}