blob: ad970d811c174dcd4837bbc67d02e1a8a7c14166 [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';
36
xuegao691e2b72019-08-16 11:07:24 +020037import { Route } from 'react-router-dom'
sebdet493c3832019-07-15 17:26:18 +020038import OpenLoopModal from './components/dialogs/OpenLoop/OpenLoopModal';
39import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal';
40import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal';
xuegaoe52d5722019-07-25 15:43:06 +020041import LoopProperties from './components/dialogs/LoopProperties';
42import UserInfo from './components/dialogs/UserInfo';
sebdet83ce0762019-08-02 14:53:59 +020043import LoopService from './api/LoopService';
sebdetf9e2cee2019-08-09 18:36:09 +020044import PerformAction from './components/dialogs/PerformActions';
45import RefreshStatus from './components/dialogs/RefreshStatus';
46import DeployLoop from './components/dialogs/DeployLoop';
xuegao0efeb6b2019-10-07 14:36:34 +020047import Alert from 'react-bootstrap/Alert';
sebdetc8d61302019-07-04 15:50:34 +020048
sebdetd0d65632019-08-26 05:47:01 -070049import { Link } from 'react-router-dom';
50
51const StyledMainDiv = styled.div`
52 background-color: ${props => props.theme.backgroundColor};
53`
54
sebdet4946e5b2019-07-10 12:32:36 +020055const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020056 vertical-align: middle;
57 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070058 font-size: 36px;
59 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020060`
sebdetd0d65632019-08-26 05:47:01 -070061
62const StyledRouterLink = styled(Link)`
63 color: ${props => props.theme.menuFontColor};
64 background-color: ${props => props.theme.backgroundColor};
65`
66
67const StyledLoginInfo = styled.a`
68 color: ${props => props.theme.menuFontColor};
69 background-color: ${props => props.theme.backgroundColor};
70`
71
sebdet4946e5b2019-07-10 12:32:36 +020072const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020073 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020074 overflow: hidden;
75 margin-left: 10px;
76 margin-right: 10px;
77 margin-bottom: 10px;
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};
82`
83
sebdet4946e5b2019-07-10 12:32:36 +020084const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020085 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
86 padding: 10px 10px;
87 color: ${props => props.theme.loopViewerHeaderFontColor};
88`
89
sebdet4946e5b2019-07-10 12:32:36 +020090const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020091 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
92 padding: 10px 10px;
93 color: ${props => (props.theme.loopViewerHeaderFontColor)};
94 height: 95%;
95`
96
sebdetc8d61302019-07-04 15:50:34 +020097export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020098
sebdet2dacb9b2019-07-17 13:48:44 +020099 static defaultLoopName="Empty (NO loop loaded yet)";
100
sebdet4946e5b2019-07-10 12:32:36 +0200101 state = {
102 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +0200103 loopName: LoopUI.defaultLoopName,
xuegao0efeb6b2019-10-07 14:36:34 +0200104 loopCache: new LoopCache({}),
105 showAlert: false
sebdet4946e5b2019-07-10 12:32:36 +0200106 };
xuegao7c7323d2019-07-09 11:52:20 +0200107
sebdet4946e5b2019-07-10 12:32:36 +0200108 constructor() {
109 super();
110 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700111 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200112 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200113 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200114 this.closeLoop = this.closeLoop.bind(this);
xuegao0efeb6b2019-10-07 14:36:34 +0200115 this.showAlert = this.showAlert.bind(this);
116 this.disableAlert = this.disableAlert.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200117 }
sebdet493c3832019-07-15 17:26:18 +0200118
sebdet2dacb9b2019-07-17 13:48:44 +0200119 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200120 this.getUser();
121 }
sebdet4946e5b2019-07-10 12:32:36 +0200122
123 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200124 UserService.login().then(user => {
125 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200126 });
127 }
sebdet687b8de2019-08-26 14:29:11 -0700128
129 logout() {
130 UserService.logout().then(user => {
131 this.setState({ userName: user });
132 window.location.reload();
133 });
134
135 }
sebdet493c3832019-07-15 17:26:18 +0200136
sebdetc8d61302019-07-04 15:50:34 +0200137 renderMenuNavBar() {
138 return (
xuegao691e2b72019-08-16 11:07:24 +0200139 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200140 );
141 }
sebdet4946e5b2019-07-10 12:32:36 +0200142
sebdetc8d61302019-07-04 15:50:34 +0200143 renderUserLoggedNavBar() {
144 return (
145 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700146 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
147 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
148 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200149 </Navbar.Text>
150 );
151 }
sebdet4946e5b2019-07-10 12:32:36 +0200152
sebdetc8d61302019-07-04 15:50:34 +0200153 renderLogoNavBar() {
154 return (
155 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200156 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200157 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200158 </Navbar.Brand>
159 );
160 }
sebdet4946e5b2019-07-10 12:32:36 +0200161
xuegao0efeb6b2019-10-07 14:36:34 +0200162 renderAlertBar() {
163 return (
164 <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible>
165 {this.state.showMessage}
166 </Alert>
167 );
168 }
169
sebdetc8d61302019-07-04 15:50:34 +0200170 renderNavBar() {
171 return (
sebdetd0d65632019-08-26 05:47:01 -0700172 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200173 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700174 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200175 {this.renderMenuNavBar()}
176 {this.renderUserLoggedNavBar()}
177 </Navbar>
178 );
sebdetc8d61302019-07-04 15:50:34 +0200179 }
sebdet493c3832019-07-15 17:26:18 +0200180
sebdetc8d61302019-07-04 15:50:34 +0200181 renderLoopViewHeader() {
182 return (
sebdet4946e5b2019-07-10 12:32:36 +0200183 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200184 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200185 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200186 );
187 }
sebdet493c3832019-07-15 17:26:18 +0200188
sebdetc8d61302019-07-04 15:50:34 +0200189 renderLoopViewBody() {
190 return (
sebdet4946e5b2019-07-10 12:32:36 +0200191 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200192 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200193 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200194 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200195 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200196 );
197 }
sebdet493c3832019-07-15 17:26:18 +0200198
xuegaoe52d5722019-07-25 15:43:06 +0200199 getLoopCache() {
200 return this.state.loopCache;
201
202 }
xuegao5fe750c2019-08-06 13:03:53 +0200203
sebdetc8d61302019-07-04 15:50:34 +0200204 renderLoopViewer() {
205 return (
sebdet4946e5b2019-07-10 12:32:36 +0200206 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200207 {this.renderLoopViewHeader()}
208 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200209 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200210 );
sebdetc8d61302019-07-04 15:50:34 +0200211 }
sebdet493c3832019-07-15 17:26:18 +0200212
213 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200214 this.setState({ loopCache: new LoopCache(loopJson) });
215 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200216 console.info(this.state.loopName+" loop loaded successfully");
217 }
xuegao5fe750c2019-08-06 13:03:53 +0200218
xuegao0efeb6b2019-10-07 14:36:34 +0200219 showAlert(message) {
220 this.setState ({ showAlert: true, showMessage:message });
221 }
222
223 disableAlert() {
224 this.setState ({ showAlert: false });
225 }
226
sebdet83ce0762019-08-02 14:53:59 +0200227 loadLoop(loopName) {
228 LoopService.getLoop(loopName).then(loop => {
229 console.debug("Updating loopCache");
230 this.updateLoopCache(loop);
231 });
sebdet493c3832019-07-15 17:26:18 +0200232 }
233
xuegao691e2b72019-08-16 11:07:24 +0200234 closeLoop() {
235 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
236 this.props.history.push('/');
237 }
sebdet687b8de2019-08-26 14:29:11 -0700238
239 render() {
sebdetc8d61302019-07-04 15:50:34 +0200240 return (
sebdetd0d65632019-08-26 05:47:01 -0700241 <StyledMainDiv id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200242 <Route path="/operationalPolicyModal"
xuegao0efeb6b2019-10-07 14:36:34 +0200243 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} />
sebdet83ce0762019-08-02 14:53:59 +0200244 <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}/>)} />
xuegaoe52d5722019-07-25 15:43:06 +0200247 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200248 <Route path="/closeLoop" render={this.closeLoop} />
xuegao0efeb6b2019-10-07 14:36:34 +0200249 <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}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700256 <Route path="/logout" render={this.logout} />
257 <GlobalClampStyle />
xuegao0efeb6b2019-10-07 14:36:34 +0200258 {this.renderAlertBar()}
sebdet8a02dd72019-07-31 17:11:11 +0200259 {this.renderNavBar()}
260 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700261 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200262 );
263 }
264}