blob: b6dd0cb075f6f4418033e89fda700a002c69e721 [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';
sebdetc8d61302019-07-04 15:50:34 +020047
sebdetd0d65632019-08-26 05:47:01 -070048import { Link } from 'react-router-dom';
49
50const StyledMainDiv = styled.div`
51 background-color: ${props => props.theme.backgroundColor};
52`
53
sebdet4946e5b2019-07-10 12:32:36 +020054const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020055 vertical-align: middle;
56 padding-left: 30px;
sebdetd0d65632019-08-26 05:47:01 -070057 font-size: 36px;
58 font-weight: bold;
sebdetc8d61302019-07-04 15:50:34 +020059`
sebdetd0d65632019-08-26 05:47:01 -070060
61const StyledRouterLink = styled(Link)`
62 color: ${props => props.theme.menuFontColor};
63 background-color: ${props => props.theme.backgroundColor};
64`
65
66const StyledLoginInfo = styled.a`
67 color: ${props => props.theme.menuFontColor};
68 background-color: ${props => props.theme.backgroundColor};
69`
70
sebdet4946e5b2019-07-10 12:32:36 +020071const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020072 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020073 overflow: hidden;
74 margin-left: 10px;
75 margin-right: 10px;
76 margin-bottom: 10px;
77 color: ${props => props.theme.loopViewerFontColor};
78 background-color: ${props => props.theme.loopViewerBackgroundColor};
79 border: 1px solid transparent;
80 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
81`
82
sebdet4946e5b2019-07-10 12:32:36 +020083const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020084 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
85 padding: 10px 10px;
86 color: ${props => props.theme.loopViewerHeaderFontColor};
87`
88
sebdet4946e5b2019-07-10 12:32:36 +020089const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020090 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
91 padding: 10px 10px;
92 color: ${props => (props.theme.loopViewerHeaderFontColor)};
93 height: 95%;
94`
95
sebdetc8d61302019-07-04 15:50:34 +020096export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020097
sebdet2dacb9b2019-07-17 13:48:44 +020098 static defaultLoopName="Empty (NO loop loaded yet)";
99
sebdet4946e5b2019-07-10 12:32:36 +0200100 state = {
101 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +0200102 loopName: LoopUI.defaultLoopName,
xuegao5fe750c2019-08-06 13:03:53 +0200103 loopCache: new LoopCache({})
sebdet4946e5b2019-07-10 12:32:36 +0200104 };
xuegao7c7323d2019-07-09 11:52:20 +0200105
sebdet4946e5b2019-07-10 12:32:36 +0200106 constructor() {
107 super();
108 this.getUser = this.getUser.bind(this);
sebdet687b8de2019-08-26 14:29:11 -0700109 this.logout = this.logout.bind(this);
sebdet493c3832019-07-15 17:26:18 +0200110 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +0200111 this.loadLoop = this.loadLoop.bind(this);
xuegao691e2b72019-08-16 11:07:24 +0200112 this.closeLoop = this.closeLoop.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +0200113 }
sebdet493c3832019-07-15 17:26:18 +0200114
sebdet2dacb9b2019-07-17 13:48:44 +0200115 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +0200116 this.getUser();
117 }
sebdet4946e5b2019-07-10 12:32:36 +0200118
119 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200120 UserService.login().then(user => {
121 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200122 });
123 }
sebdet687b8de2019-08-26 14:29:11 -0700124
125 logout() {
126 UserService.logout().then(user => {
127 this.setState({ userName: user });
128 window.location.reload();
129 });
130
131 }
sebdet493c3832019-07-15 17:26:18 +0200132
sebdetc8d61302019-07-04 15:50:34 +0200133 renderMenuNavBar() {
134 return (
xuegao691e2b72019-08-16 11:07:24 +0200135 <MenuBar loopName={this.state.loopName}/>
sebdetc8d61302019-07-04 15:50:34 +0200136 );
137 }
sebdet4946e5b2019-07-10 12:32:36 +0200138
sebdetc8d61302019-07-04 15:50:34 +0200139 renderUserLoggedNavBar() {
140 return (
141 <Navbar.Text>
sebdetd0d65632019-08-26 05:47:01 -0700142 <StyledLoginInfo>Signed in as: </StyledLoginInfo>
143 <StyledRouterLink to="/userInfo">{this.state.userName}</StyledRouterLink>
144 <StyledRouterLink to="/logout/"> (logout)</StyledRouterLink>
sebdetc8d61302019-07-04 15:50:34 +0200145 </Navbar.Text>
146 );
147 }
sebdet4946e5b2019-07-10 12:32:36 +0200148
sebdetc8d61302019-07-04 15:50:34 +0200149 renderLogoNavBar() {
150 return (
151 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200152 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200153 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200154 </Navbar.Brand>
155 );
156 }
sebdet4946e5b2019-07-10 12:32:36 +0200157
sebdetc8d61302019-07-04 15:50:34 +0200158 renderNavBar() {
159 return (
sebdetd0d65632019-08-26 05:47:01 -0700160 <Navbar >
sebdet493c3832019-07-15 17:26:18 +0200161 {this.renderLogoNavBar()}
sebdetd0d65632019-08-26 05:47:01 -0700162 <Navbar.Toggle aria-controls="responsive-navbar-nav" />
sebdet493c3832019-07-15 17:26:18 +0200163 {this.renderMenuNavBar()}
164 {this.renderUserLoggedNavBar()}
165 </Navbar>
166 );
sebdetc8d61302019-07-04 15:50:34 +0200167 }
sebdet493c3832019-07-15 17:26:18 +0200168
sebdetc8d61302019-07-04 15:50:34 +0200169 renderLoopViewHeader() {
170 return (
sebdet4946e5b2019-07-10 12:32:36 +0200171 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200172 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200173 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200174 );
175 }
sebdet493c3832019-07-15 17:26:18 +0200176
sebdetc8d61302019-07-04 15:50:34 +0200177 renderLoopViewBody() {
178 return (
sebdet4946e5b2019-07-10 12:32:36 +0200179 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200180 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200181 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200182 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200183 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200184 );
185 }
sebdet493c3832019-07-15 17:26:18 +0200186
xuegaoe52d5722019-07-25 15:43:06 +0200187 getLoopCache() {
188 return this.state.loopCache;
189
190 }
xuegao5fe750c2019-08-06 13:03:53 +0200191
sebdetc8d61302019-07-04 15:50:34 +0200192 renderLoopViewer() {
193 return (
sebdet4946e5b2019-07-10 12:32:36 +0200194 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200195 {this.renderLoopViewHeader()}
196 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200197 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200198 );
sebdetc8d61302019-07-04 15:50:34 +0200199 }
sebdet493c3832019-07-15 17:26:18 +0200200
201 updateLoopCache(loopJson) {
xuegao52432d62019-10-04 16:11:22 +0200202 this.setState({ loopCache: new LoopCache(loopJson) });
203 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200204 console.info(this.state.loopName+" loop loaded successfully");
205 }
xuegao5fe750c2019-08-06 13:03:53 +0200206
sebdet83ce0762019-08-02 14:53:59 +0200207 loadLoop(loopName) {
208 LoopService.getLoop(loopName).then(loop => {
209 console.debug("Updating loopCache");
210 this.updateLoopCache(loop);
211 });
sebdet493c3832019-07-15 17:26:18 +0200212 }
213
xuegao691e2b72019-08-16 11:07:24 +0200214 closeLoop() {
215 this.setState({ loopCache: new LoopCache({}), loopName: LoopUI.defaultLoopName });
216 this.props.history.push('/');
217 }
sebdet687b8de2019-08-26 14:29:11 -0700218
219 render() {
sebdetc8d61302019-07-04 15:50:34 +0200220 return (
sebdetd0d65632019-08-26 05:47:01 -0700221 <StyledMainDiv id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200222 <Route path="/operationalPolicyModal"
sebdet83ce0762019-08-02 14:53:59 +0200223 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
224 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
225 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
226 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
xuegaoe52d5722019-07-25 15:43:06 +0200227 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
xuegao691e2b72019-08-16 11:07:24 +0200228 <Route path="/closeLoop" render={this.closeLoop} />
xuegao5fe750c2019-08-06 13:03:53 +0200229 <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
230 <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
231 <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
232 <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
233 <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
xuegao691e2b72019-08-16 11:07:24 +0200234 <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
xuegao5fe750c2019-08-06 13:03:53 +0200235 <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} />
sebdet687b8de2019-08-26 14:29:11 -0700236 <Route path="/logout" render={this.logout} />
237 <GlobalClampStyle />
sebdet8a02dd72019-07-31 17:11:11 +0200238 {this.renderNavBar()}
239 {this.renderLoopViewer()}
sebdetd0d65632019-08-26 05:47:01 -0700240 </StyledMainDiv>
sebdetc8d61302019-07-04 15:50:34 +0200241 );
242 }
243}