blob: c7080a2b62516ad2ca9c3205438d248621db1440 [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
sebdet2dacb9b2019-07-17 13:48:44 +020037import { Route, Redirect } 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';
xuegao5fe750c2019-08-06 13:03:53 +020044import PerformAction from './components/menu/PerformActions';
45import RefreshStatus from './components/menu/RefreshStatus';
sebdetc8d61302019-07-04 15:50:34 +020046
sebdet4946e5b2019-07-10 12:32:36 +020047const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020048 vertical-align: middle;
49 padding-left: 30px;
50 font-size: 30px;
51
52`
sebdet4946e5b2019-07-10 12:32:36 +020053const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020054 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020055 overflow: hidden;
56 margin-left: 10px;
57 margin-right: 10px;
58 margin-bottom: 10px;
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};
63`
64
sebdet4946e5b2019-07-10 12:32:36 +020065const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020066 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
67 padding: 10px 10px;
68 color: ${props => props.theme.loopViewerHeaderFontColor};
69`
70
sebdet4946e5b2019-07-10 12:32:36 +020071const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020072 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
73 padding: 10px 10px;
74 color: ${props => (props.theme.loopViewerHeaderFontColor)};
75 height: 95%;
76`
77
sebdetc8d61302019-07-04 15:50:34 +020078export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020079
sebdet2dacb9b2019-07-17 13:48:44 +020080 static defaultLoopName="Empty (NO loop loaded yet)";
81
sebdet4946e5b2019-07-10 12:32:36 +020082 state = {
83 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +020084 loopName: LoopUI.defaultLoopName,
xuegao5fe750c2019-08-06 13:03:53 +020085 loopCache: new LoopCache({})
sebdet4946e5b2019-07-10 12:32:36 +020086 };
xuegao7c7323d2019-07-09 11:52:20 +020087
sebdet4946e5b2019-07-10 12:32:36 +020088 constructor() {
89 super();
90 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +020091 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +020092 this.loadLoop = this.loadLoop.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +020093 }
sebdet493c3832019-07-15 17:26:18 +020094
sebdet2dacb9b2019-07-17 13:48:44 +020095 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +020096 this.getUser();
97 }
sebdet4946e5b2019-07-10 12:32:36 +020098
99 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200100 UserService.login().then(user => {
101 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200102 });
103 }
sebdet493c3832019-07-15 17:26:18 +0200104
sebdetc8d61302019-07-04 15:50:34 +0200105 renderMenuNavBar() {
106 return (
xuegao5fe750c2019-08-06 13:03:53 +0200107 <MenuBar/>
sebdetc8d61302019-07-04 15:50:34 +0200108 );
109 }
sebdet4946e5b2019-07-10 12:32:36 +0200110
sebdetc8d61302019-07-04 15:50:34 +0200111 renderUserLoggedNavBar() {
112 return (
113 <Navbar.Text>
sebdet4946e5b2019-07-10 12:32:36 +0200114 Signed in as: <a href="/login">{this.state.userName}</a>
sebdetc8d61302019-07-04 15:50:34 +0200115 </Navbar.Text>
116 );
117 }
sebdet4946e5b2019-07-10 12:32:36 +0200118
sebdetc8d61302019-07-04 15:50:34 +0200119 renderLogoNavBar() {
120 return (
121 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200122 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200123 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200124 </Navbar.Brand>
125 );
126 }
sebdet4946e5b2019-07-10 12:32:36 +0200127
sebdetc8d61302019-07-04 15:50:34 +0200128 renderNavBar() {
129 return (
sebdet493c3832019-07-15 17:26:18 +0200130 <Navbar expand="lg">
131 {this.renderLogoNavBar()}
132 {this.renderMenuNavBar()}
133 {this.renderUserLoggedNavBar()}
134 </Navbar>
135 );
sebdetc8d61302019-07-04 15:50:34 +0200136 }
sebdet493c3832019-07-15 17:26:18 +0200137
sebdetc8d61302019-07-04 15:50:34 +0200138 renderLoopViewHeader() {
139 return (
sebdet4946e5b2019-07-10 12:32:36 +0200140 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200141 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200142 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200143 );
144 }
sebdet493c3832019-07-15 17:26:18 +0200145
sebdetc8d61302019-07-04 15:50:34 +0200146 renderLoopViewBody() {
147 return (
sebdet4946e5b2019-07-10 12:32:36 +0200148 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200149 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200150 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200151 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200152 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200153 );
154 }
sebdet493c3832019-07-15 17:26:18 +0200155
xuegaoe52d5722019-07-25 15:43:06 +0200156 getLoopCache() {
157 return this.state.loopCache;
158
159 }
xuegao5fe750c2019-08-06 13:03:53 +0200160
sebdetc8d61302019-07-04 15:50:34 +0200161 renderLoopViewer() {
162 return (
sebdet4946e5b2019-07-10 12:32:36 +0200163 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200164 {this.renderLoopViewHeader()}
165 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200166 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200167 );
sebdetc8d61302019-07-04 15:50:34 +0200168 }
sebdet493c3832019-07-15 17:26:18 +0200169
170 updateLoopCache(loopJson) {
171 this.setState({ loopCache: new LoopCache(loopJson) });
sebdet2dacb9b2019-07-17 13:48:44 +0200172 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200173 console.info(this.state.loopName+" loop loaded successfully");
174 }
xuegao5fe750c2019-08-06 13:03:53 +0200175
sebdet83ce0762019-08-02 14:53:59 +0200176 loadLoop(loopName) {
177 LoopService.getLoop(loopName).then(loop => {
178 console.debug("Updating loopCache");
179 this.updateLoopCache(loop);
180 });
sebdet493c3832019-07-15 17:26:18 +0200181 }
182
sebdetc8d61302019-07-04 15:50:34 +0200183 render() {
184 return (
sebdet8a02dd72019-07-31 17:11:11 +0200185 <div id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200186 <Route path="/operationalPolicyModal"
sebdet83ce0762019-08-02 14:53:59 +0200187 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}/>)} />
xuegaoe52d5722019-07-25 15:43:06 +0200191 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
sebdet2dacb9b2019-07-17 13:48:44 +0200192 <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} />
xuegao5fe750c2019-08-06 13:03:53 +0200193 <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}/>)} />
sebdet8a02dd72019-07-31 17:11:11 +0200199 <GlobalClampStyle />
200 {this.renderNavBar()}
201 {this.renderLoopViewer()}
202 </div>
sebdetc8d61302019-07-04 15:50:34 +0200203 );
204 }
205}