blob: 643b32d145346a45881fd7d8d05adc28163c1cb7 [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';
sebdetc8d61302019-07-04 15:50:34 +020044
sebdet4946e5b2019-07-10 12:32:36 +020045const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020046 vertical-align: middle;
47 padding-left: 30px;
48 font-size: 30px;
49
50`
sebdet4946e5b2019-07-10 12:32:36 +020051const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020052 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020053 overflow: hidden;
54 margin-left: 10px;
55 margin-right: 10px;
56 margin-bottom: 10px;
57 color: ${props => props.theme.loopViewerFontColor};
58 background-color: ${props => props.theme.loopViewerBackgroundColor};
59 border: 1px solid transparent;
60 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
61`
62
sebdet4946e5b2019-07-10 12:32:36 +020063const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020064 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
65 padding: 10px 10px;
66 color: ${props => props.theme.loopViewerHeaderFontColor};
67`
68
sebdet4946e5b2019-07-10 12:32:36 +020069const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020070 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
71 padding: 10px 10px;
72 color: ${props => (props.theme.loopViewerHeaderFontColor)};
73 height: 95%;
74`
75
sebdetc8d61302019-07-04 15:50:34 +020076export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020077
sebdet2dacb9b2019-07-17 13:48:44 +020078 static defaultLoopName="Empty (NO loop loaded yet)";
79
sebdet4946e5b2019-07-10 12:32:36 +020080 state = {
81 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +020082 loopName: LoopUI.defaultLoopName,
sebdet493c3832019-07-15 17:26:18 +020083 loopCache: new LoopCache({}),
sebdet4946e5b2019-07-10 12:32:36 +020084 };
xuegao7c7323d2019-07-09 11:52:20 +020085
sebdet4946e5b2019-07-10 12:32:36 +020086 constructor() {
87 super();
88 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +020089 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet83ce0762019-08-02 14:53:59 +020090 this.loadLoop = this.loadLoop.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +020091 }
sebdet493c3832019-07-15 17:26:18 +020092
sebdet2dacb9b2019-07-17 13:48:44 +020093 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +020094 this.getUser();
95 }
sebdet4946e5b2019-07-10 12:32:36 +020096
97 getUser() {
sebdet493c3832019-07-15 17:26:18 +020098 UserService.login().then(user => {
99 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200100 });
101 }
sebdet493c3832019-07-15 17:26:18 +0200102
sebdetc8d61302019-07-04 15:50:34 +0200103 renderMenuNavBar() {
104 return (
xuegaoe52d5722019-07-25 15:43:06 +0200105 <MenuBar loopCache={this.state.loopCache}/>
sebdetc8d61302019-07-04 15:50:34 +0200106 );
107 }
sebdet4946e5b2019-07-10 12:32:36 +0200108
sebdetc8d61302019-07-04 15:50:34 +0200109 renderUserLoggedNavBar() {
110 return (
111 <Navbar.Text>
sebdet4946e5b2019-07-10 12:32:36 +0200112 Signed in as: <a href="/login">{this.state.userName}</a>
sebdetc8d61302019-07-04 15:50:34 +0200113 </Navbar.Text>
114 );
115 }
sebdet4946e5b2019-07-10 12:32:36 +0200116
sebdetc8d61302019-07-04 15:50:34 +0200117 renderLogoNavBar() {
118 return (
119 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200120 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200121 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200122 </Navbar.Brand>
123 );
124 }
sebdet4946e5b2019-07-10 12:32:36 +0200125
sebdetc8d61302019-07-04 15:50:34 +0200126 renderNavBar() {
127 return (
sebdet493c3832019-07-15 17:26:18 +0200128 <Navbar expand="lg">
129 {this.renderLogoNavBar()}
130 {this.renderMenuNavBar()}
131 {this.renderUserLoggedNavBar()}
132 </Navbar>
133 );
sebdetc8d61302019-07-04 15:50:34 +0200134 }
sebdet493c3832019-07-15 17:26:18 +0200135
sebdetc8d61302019-07-04 15:50:34 +0200136 renderLoopViewHeader() {
137 return (
sebdet4946e5b2019-07-10 12:32:36 +0200138 <LoopViewHeaderDivStyled>
sebdet190227a2019-07-19 16:51:19 +0200139 Loop Viewer - {this.state.loopName}
sebdet4946e5b2019-07-10 12:32:36 +0200140 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200141 );
142 }
sebdet493c3832019-07-15 17:26:18 +0200143
sebdetc8d61302019-07-04 15:50:34 +0200144 renderLoopViewBody() {
145 return (
sebdet4946e5b2019-07-10 12:32:36 +0200146 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200147 <LoopSvg loopCache={this.state.loopCache} />
sebdet190227a2019-07-19 16:51:19 +0200148 <LoopStatus loopCache={this.state.loopCache}/>
sebdetc1ccc542019-07-19 09:50:33 +0200149 <LoopLogs loopCache={this.state.loopCache} />
sebdet4946e5b2019-07-10 12:32:36 +0200150 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200151 );
152 }
sebdet493c3832019-07-15 17:26:18 +0200153
xuegaoe52d5722019-07-25 15:43:06 +0200154 getLoopCache() {
155 return this.state.loopCache;
156
157 }
sebdetc8d61302019-07-04 15:50:34 +0200158 renderLoopViewer() {
159 return (
sebdet4946e5b2019-07-10 12:32:36 +0200160 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200161 {this.renderLoopViewHeader()}
162 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200163 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200164 );
sebdetc8d61302019-07-04 15:50:34 +0200165 }
sebdet493c3832019-07-15 17:26:18 +0200166
167 updateLoopCache(loopJson) {
168 this.setState({ loopCache: new LoopCache(loopJson) });
sebdet2dacb9b2019-07-17 13:48:44 +0200169 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet83ce0762019-08-02 14:53:59 +0200170 console.info(this.state.loopName+" loop loaded successfully");
171 }
172
173 loadLoop(loopName) {
174 LoopService.getLoop(loopName).then(loop => {
175 console.debug("Updating loopCache");
176 this.updateLoopCache(loop);
177 });
sebdet493c3832019-07-15 17:26:18 +0200178 }
179
sebdetc8d61302019-07-04 15:50:34 +0200180 render() {
181 return (
sebdet8a02dd72019-07-31 17:11:11 +0200182 <div id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200183 <Route path="/operationalPolicyModal"
sebdet83ce0762019-08-02 14:53:59 +0200184 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
185 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
186 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} />
187 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} />
xuegaoe52d5722019-07-25 15:43:06 +0200188 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
sebdet2dacb9b2019-07-17 13:48:44 +0200189 <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} />
sebdet8a02dd72019-07-31 17:11:11 +0200190 <GlobalClampStyle />
191 {this.renderNavBar()}
192 {this.renderLoopViewer()}
193 </div>
sebdetc8d61302019-07-04 15:50:34 +0200194 );
195 }
196}