blob: 342f43dae8513a91e3a1d6a31da263816204fdab [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';
sebdetc8d61302019-07-04 15:50:34 +020043
sebdet4946e5b2019-07-10 12:32:36 +020044const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020045 vertical-align: middle;
46 padding-left: 30px;
47 font-size: 30px;
48
49`
sebdet4946e5b2019-07-10 12:32:36 +020050const LoopViewDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020051 height: 90vh;
52 overflow: hidden;
53 margin-left: 10px;
54 margin-right: 10px;
55 margin-bottom: 10px;
56 color: ${props => props.theme.loopViewerFontColor};
57 background-color: ${props => props.theme.loopViewerBackgroundColor};
58 border: 1px solid transparent;
59 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
60`
61
sebdet4946e5b2019-07-10 12:32:36 +020062const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020063 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
64 padding: 10px 10px;
65 color: ${props => props.theme.loopViewerHeaderFontColor};
66`
67
sebdet4946e5b2019-07-10 12:32:36 +020068const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020069 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
70 padding: 10px 10px;
71 color: ${props => (props.theme.loopViewerHeaderFontColor)};
72 height: 95%;
73`
74
sebdet4946e5b2019-07-10 12:32:36 +020075const LoopViewLoopNameSpanStyled = styled.span`
sebdetc8d61302019-07-04 15:50:34 +020076 font-weight: bold;
77 color: ${props => (props.theme.loopViewerHeaderFontColor)};
78 background-color: ${props => (props.theme.loopViewerHeaderBackgroundColor)};
79`
80
81export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020082
sebdet2dacb9b2019-07-17 13:48:44 +020083 static defaultLoopName="Empty (NO loop loaded yet)";
84
sebdet4946e5b2019-07-10 12:32:36 +020085 state = {
86 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +020087 loopName: LoopUI.defaultLoopName,
sebdet493c3832019-07-15 17:26:18 +020088 loopCache: new LoopCache({}),
sebdet4946e5b2019-07-10 12:32:36 +020089 };
xuegao7c7323d2019-07-09 11:52:20 +020090
sebdet4946e5b2019-07-10 12:32:36 +020091 constructor() {
92 super();
93 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +020094 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +020095 }
sebdet493c3832019-07-15 17:26:18 +020096
sebdet2dacb9b2019-07-17 13:48:44 +020097 componentWillMount() {
sebdet493c3832019-07-15 17:26:18 +020098 this.getUser();
99 }
sebdet4946e5b2019-07-10 12:32:36 +0200100
101 getUser() {
sebdet493c3832019-07-15 17:26:18 +0200102 UserService.login().then(user => {
103 this.setState({ userName: user })
sebdet4946e5b2019-07-10 12:32:36 +0200104 });
105 }
sebdet493c3832019-07-15 17:26:18 +0200106
sebdetc8d61302019-07-04 15:50:34 +0200107 renderMenuNavBar() {
108 return (
xuegaoe52d5722019-07-25 15:43:06 +0200109 <MenuBar loopCache={this.state.loopCache}/>
sebdetc8d61302019-07-04 15:50:34 +0200110 );
111 }
sebdet4946e5b2019-07-10 12:32:36 +0200112
sebdetc8d61302019-07-04 15:50:34 +0200113 renderUserLoggedNavBar() {
114 return (
115 <Navbar.Text>
sebdet4946e5b2019-07-10 12:32:36 +0200116 Signed in as: <a href="/login">{this.state.userName}</a>
sebdetc8d61302019-07-04 15:50:34 +0200117 </Navbar.Text>
118 );
119 }
sebdet4946e5b2019-07-10 12:32:36 +0200120
sebdetc8d61302019-07-04 15:50:34 +0200121 renderLogoNavBar() {
122 return (
123 <Navbar.Brand>
sebdet493c3832019-07-15 17:26:18 +0200124 <img height="50px" width="234px" src={logo} alt="" />
sebdet4946e5b2019-07-10 12:32:36 +0200125 <ProjectNameStyled>CLAMP</ProjectNameStyled>
sebdetc8d61302019-07-04 15:50:34 +0200126 </Navbar.Brand>
127 );
128 }
sebdet4946e5b2019-07-10 12:32:36 +0200129
sebdetc8d61302019-07-04 15:50:34 +0200130 renderNavBar() {
131 return (
sebdet493c3832019-07-15 17:26:18 +0200132 <Navbar expand="lg">
133 {this.renderLogoNavBar()}
134 {this.renderMenuNavBar()}
135 {this.renderUserLoggedNavBar()}
136 </Navbar>
137 );
sebdetc8d61302019-07-04 15:50:34 +0200138 }
sebdet493c3832019-07-15 17:26:18 +0200139
sebdetc8d61302019-07-04 15:50:34 +0200140 renderLoopViewHeader() {
141 return (
sebdet4946e5b2019-07-10 12:32:36 +0200142 <LoopViewHeaderDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200143 Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled>
sebdet4946e5b2019-07-10 12:32:36 +0200144 </LoopViewHeaderDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200145 );
146 }
sebdet493c3832019-07-15 17:26:18 +0200147
sebdetc8d61302019-07-04 15:50:34 +0200148 renderLoopViewBody() {
149 return (
sebdet4946e5b2019-07-10 12:32:36 +0200150 <LoopViewBodyDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200151 <LoopSvg loopCache={this.state.loopCache} />
sebdetc1ccc542019-07-19 09:50:33 +0200152 <LoopLogs loopCache={this.state.loopCache} />
sebdet493c3832019-07-15 17:26:18 +0200153 <LoopStatus />
sebdet4946e5b2019-07-10 12:32:36 +0200154 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200155 );
156 }
sebdet493c3832019-07-15 17:26:18 +0200157
xuegaoe52d5722019-07-25 15:43:06 +0200158 getLoopCache() {
159 return this.state.loopCache;
160
161 }
sebdetc8d61302019-07-04 15:50:34 +0200162 renderLoopViewer() {
163 return (
sebdet4946e5b2019-07-10 12:32:36 +0200164 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200165 {this.renderLoopViewHeader()}
166 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200167 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200168 );
sebdetc8d61302019-07-04 15:50:34 +0200169 }
sebdet493c3832019-07-15 17:26:18 +0200170
171 updateLoopCache(loopJson) {
172 this.setState({ loopCache: new LoopCache(loopJson) });
sebdet2dacb9b2019-07-17 13:48:44 +0200173 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet493c3832019-07-15 17:26:18 +0200174 }
175
sebdetc8d61302019-07-04 15:50:34 +0200176 render() {
177 return (
sebdet4946e5b2019-07-10 12:32:36 +0200178 <div id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200179 <GlobalClampStyle />
180 {this.renderNavBar()}
181 {this.renderLoopViewer()}
182 <Route path="/operationalPolicyModal"
183 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
sebdet5f6c1782019-07-18 15:23:13 +0200184 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
sebdet493c3832019-07-15 17:26:18 +0200185 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} updateLoopCacheFunction={this.updateLoopCache} />)} />
xuegaoe52d5722019-07-25 15:43:06 +0200186 <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} />)} />
187 <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} />
sebdet2dacb9b2019-07-17 13:48:44 +0200188 <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} />
sebdet493c3832019-07-15 17:26:18 +0200189 </div>
sebdetc8d61302019-07-04 15:50:34 +0200190 );
191 }
192}