blob: a1aff3d61c7827d3c13774051711c3642b378538 [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
37import { Route } from 'react-router-dom'
38import 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`
sebdetc8d61302019-07-04 15:50:34 +020049 height: 90vh;
50 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
sebdet4946e5b2019-07-10 12:32:36 +020081 state = {
82 userName: null,
83 loopName: "Empty (NO loop loaded yet)",
sebdet493c3832019-07-15 17:26:18 +020084 loopCache: new LoopCache({}),
sebdet4946e5b2019-07-10 12:32:36 +020085 };
xuegao7c7323d2019-07-09 11:52:20 +020086
sebdet4946e5b2019-07-10 12:32:36 +020087 constructor() {
88 super();
89 this.getUser = this.getUser.bind(this);
sebdet493c3832019-07-15 17:26:18 +020090 this.updateLoopCache = this.updateLoopCache.bind(this);
sebdet4946e5b2019-07-10 12:32:36 +020091 }
sebdet493c3832019-07-15 17:26:18 +020092
93 componentDidMount() {
94 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 (
105 <MenuBar />
106 );
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>
sebdet493c3832019-07-15 17:26:18 +0200139 Loop Viewer - <LoopViewLoopNameSpanStyled id="loop_name">{this.state.loopName}</LoopViewLoopNameSpanStyled>
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} />
148 <LoopLogs />
149 <LoopStatus />
sebdet4946e5b2019-07-10 12:32:36 +0200150 </LoopViewBodyDivStyled>
sebdetc8d61302019-07-04 15:50:34 +0200151 );
152 }
sebdet493c3832019-07-15 17:26:18 +0200153
sebdetc8d61302019-07-04 15:50:34 +0200154 renderLoopViewer() {
155 return (
sebdet4946e5b2019-07-10 12:32:36 +0200156 <LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200157 {this.renderLoopViewHeader()}
158 {this.renderLoopViewBody()}
sebdet4946e5b2019-07-10 12:32:36 +0200159 </LoopViewDivStyled>
sebdet493c3832019-07-15 17:26:18 +0200160 );
sebdetc8d61302019-07-04 15:50:34 +0200161 }
sebdet493c3832019-07-15 17:26:18 +0200162
163 updateLoopCache(loopJson) {
164 this.setState({ loopCache: new LoopCache(loopJson) });
165 }
166
sebdetc8d61302019-07-04 15:50:34 +0200167 render() {
168 return (
sebdet4946e5b2019-07-10 12:32:36 +0200169 <div id="main_div">
sebdet493c3832019-07-15 17:26:18 +0200170 <GlobalClampStyle />
171 {this.renderNavBar()}
172 {this.renderLoopViewer()}
173 <Route path="/operationalPolicyModal"
174 render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
175 <Route path="/configurationPolicyModal" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.state.loopCache} />)} />
176 <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} updateLoopCacheFunction={this.updateLoopCache} />)} />
177 </div>
sebdetc8d61302019-07-04 15:50:34 +0200178 );
179 }
180}