blob: 40ae1379c57cdada45beee89d40178106f1bbd55 [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';
sebdetc8d61302019-07-04 15:50:34 +020041
sebdet4946e5b2019-07-10 12:32:36 +020042const ProjectNameStyled = styled.a`
sebdetc8d61302019-07-04 15:50:34 +020043 vertical-align: middle;
44 padding-left: 30px;
45 font-size: 30px;
46
47`
sebdet4946e5b2019-07-10 12:32:36 +020048const LoopViewDivStyled = styled.div`
sebdet190227a2019-07-19 16:51:19 +020049 height: 100%;
sebdetc8d61302019-07-04 15:50:34 +020050 overflow: hidden;
51 margin-left: 10px;
52 margin-right: 10px;
53 margin-bottom: 10px;
54 color: ${props => props.theme.loopViewerFontColor};
55 background-color: ${props => props.theme.loopViewerBackgroundColor};
56 border: 1px solid transparent;
57 border-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
58`
59
sebdet4946e5b2019-07-10 12:32:36 +020060const LoopViewHeaderDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020061 background-color: ${props => props.theme.loopViewerHeaderBackgroundColor};
62 padding: 10px 10px;
63 color: ${props => props.theme.loopViewerHeaderFontColor};
64`
65
sebdet4946e5b2019-07-10 12:32:36 +020066const LoopViewBodyDivStyled = styled.div`
sebdetc8d61302019-07-04 15:50:34 +020067 background-color: ${props => (props.theme.loopViewerBackgroundColor)};
68 padding: 10px 10px;
69 color: ${props => (props.theme.loopViewerHeaderFontColor)};
70 height: 95%;
71`
72
sebdet4946e5b2019-07-10 12:32:36 +020073const LoopViewLoopNameSpanStyled = styled.span`
sebdetc8d61302019-07-04 15:50:34 +020074 font-weight: bold;
75 color: ${props => (props.theme.loopViewerHeaderFontColor)};
76 background-color: ${props => (props.theme.loopViewerHeaderBackgroundColor)};
77`
78
79export default class LoopUI extends React.Component {
sebdet493c3832019-07-15 17:26:18 +020080
sebdet2dacb9b2019-07-17 13:48:44 +020081 static defaultLoopName="Empty (NO loop loaded yet)";
82
sebdet4946e5b2019-07-10 12:32:36 +020083 state = {
84 userName: null,
sebdet2dacb9b2019-07-17 13:48:44 +020085 loopName: LoopUI.defaultLoopName,
sebdet493c3832019-07-15 17:26:18 +020086 loopCache: new LoopCache({}),
sebdet4946e5b2019-07-10 12:32:36 +020087 };
xuegao7c7323d2019-07-09 11:52:20 +020088
sebdet4946e5b2019-07-10 12:32:36 +020089 constructor() {
90 super();
91 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +020092 this.updateLoopCache = this.updateLoopCache.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 (
107 <MenuBar />
108 );
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
sebdetc8d61302019-07-04 15:50:34 +0200156 renderLoopViewer() {
157 return (
sebdet4946e5b2019-07-10 12:32:36 +0200158 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200159 {this.renderLoopViewHeader()}
160 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200161 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200162 );
sebdetc8d61302019-07-04 15:50:34 +0200163 }
sebdet493c3832019-07-15 17:26:18 +0200164
165 updateLoopCache(loopJson) {
166 this.setState({ loopCache: new LoopCache(loopJson) });
sebdet2dacb9b2019-07-17 13:48:44 +0200167 this.setState({ loopName: this.state.loopCache.getLoopName() });
sebdet493c3832019-07-15 17:26:18 +0200168 }
169
sebdetc8d61302019-07-04 15:50:34 +0200170 render() {
171 return (
sebdet4946e5b2019-07-10 12:32:36 +0200172 <div id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200173 <GlobalClampStyle />
174 {this.renderNavBar()}
175 {this.renderLoopViewer()}
176 <Route path="/operationalPolicyModal"
177 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
sebdet5f6c1782019-07-18 15:23:13 +0200178 <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
sebdet493c3832019-07-15 17:26:18 +0200179 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} updateLoopCacheFunction={this.updateLoopCache} />)} />
sebdet2dacb9b2019-07-17 13:48:44 +0200180 <Route path="/closeLoop" render={(routeProps) => (<Redirect to='/'/>)} />
sebdet493c3832019-07-15 17:26:18 +0200181 </div>
sebdetc8d61302019-07-04 15:50:34 +0200182 );
183 }
184}