aboutsummaryrefslogtreecommitdiffstats
path: root/gui-clamp/ui-react/src/LoopUI.js
blob: e593a087946988bfa1feafc0438aaa4f8bd93fcc (plain)
1
2
3
4
5
6
7
8
9
10
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
distribution_type: 'container'
container_release_tag: '2.0.1'
project: 'policy-drools-applications'
log_dir: 'policy-drools-applications-maven-docker-stage-master/1463'
ref: ae6de5e3577295ec0e61a5714ffbf10321f38944
containers:
    - name: 'policy-pdpd-cl'
      version: '2.0.1-20231018T1619'
n223'>223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

import React from 'react';
import styled from 'styled-components';
import MenuBar from './components/menu/MenuBar';
import Navbar from 'react-bootstrap/Navbar';
import logo from './logo.png';
import { GlobalClampStyle } from './theme/globalStyle.js';
import OnapConstants from './utils/OnapConstants';

import SvgGenerator from './components/loop_viewer/svg/SvgGenerator';
import LoopLogs from './components/loop_viewer/logs/LoopLogs';
import LoopStatus from './components/loop_viewer/status/LoopStatus';
import UserService from './api/UserService';
import LoopCache from './api/LoopCache';
import LoopActionService from './api/LoopActionService';

import { Route } from 'react-router-dom'
import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal';
import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal';
import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal';
import PolicyModal from './components/dialogs/Policy/PolicyModal';
import ViewAllPolicies from './components/dialogs/Policy/ViewAllPolicies';
import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal';
import UserInfoModal from './components/dialogs/UserInfoModal';
import LoopService from './api/LoopService';
import ViewLoopTemplatesModal from './components/dialogs/Tosca/ViewLoopTemplatesModal';
import ManageDictionaries from './components/dialogs/ManageDictionaries/ManageDictionaries';
import PerformAction from './components/dialogs/PerformActions';
import RefreshStatus from './components/dialogs/RefreshStatus';
import DeployLoopModal from './components/dialogs/Loop/DeployLoopModal';
import Alert from 'react-bootstrap/Alert';
import Spinner from 'react-bootstrap/Spinner';

import { Link } from 'react-router-dom';
import ReadAndConvertYaml from "./components/dialogs/ControlLoop/ReadAndConvertYaml";
import MonitorInstantiation from "./components/dialogs/ControlLoop/MonitorInstantiation";
import GetLocalToscaFileForUpload from "./components/dialogs/ControlLoop/GetLocalToscaFileForUpload";
import CommissioningModal from "./components/dialogs/ControlLoop/CommissioningModal";
import InstancePropertiesModal from "./components/dialogs/ControlLoop/InstancePropertiesModal";
import ChangeOrderStateModal from "./components/dialogs/ControlLoop/ChangeOrderStateModal";
import InstantiationManagementModal from "./components/dialogs/ControlLoop/InstantiationManagementModal";

const StyledMainDiv = styled.div`
  background-color: ${ props => props.theme.backgroundColor };
`

const StyledSpinnerDiv = styled.div`
  justify-content: center !important;
  display: flex !important;
`;

const ProjectNameStyled = styled.a`
  vertical-align: middle;
  padding-left: 30px;
  font-size: 36px;
  font-weight: bold;
`

const StyledRouterLink = styled(Link)`
  color: ${ props => props.theme.menuFontColor };
  background-color: ${ props => props.theme.backgroundColor };
`

const StyledLoginInfo = styled.a`
  color: ${ props => props.theme.menuFontColor };
  background-color: ${ props => props.theme.backgroundColor };
`

const LoopViewDivStyled = styled.div`
  height: 100%;
  overflow: hidden;
  margin-left: 10px;
  margin-right: 10px;
  margin-bottom: 10px;
  color: ${ props => props.theme.loopViewerFontColor };
  background-color: ${ props => props.theme.loopViewerBackgroundColor };
  border: 1px solid transparent;
  border-color: ${ props => props.theme.loopViewerHeaderBackgroundColor };
`

const LoopViewHeaderDivStyled = styled.div`
  background-color: ${ props => props.theme.loopViewerHeaderBackgroundColor };
  padding: 10px 10px;
  color: ${ props => props.theme.loopViewerHeaderFontColor };
`

const LoopViewBodyDivStyled = styled.div`
  background-color: ${ props => (props.theme.loopViewerBackgroundColor) };
  padding: 10px 10px;
  color: ${ props => (props.theme.loopViewerHeaderFontColor) };
  height: 95%;
`

export default class LoopUI extends React.Component {

  state = {
    userName: null,
    loopName: OnapConstants.defaultLoopName,
    loopCache: new LoopCache({}),
    showSucAlert: false,
    showFailAlert: false,
    busyLoadingCount: 0
  };

  constructor() {
    super();
    this.getUser = this.getUser.bind(this);
    this.updateLoopCache = this.updateLoopCache.bind(this);
    this.loadLoop = this.loadLoop.bind(this);
    this.closeLoop = this.closeLoop.bind(this);
    this.showSucAlert = this.showSucAlert.bind(this);
    this.showFailAlert = this.showFailAlert.bind(this);
    this.disableAlert = this.disableAlert.bind(this);
    this.setBusyLoading = this.setBusyLoading.bind(this);
    this.clearBusyLoading = this.clearBusyLoading.bind(this);
    this.isBusyLoading = this.isBusyLoading.bind(this);
    this.renderGlobalStyle = this.renderGlobalStyle.bind(this);
    this.renderSvg = this.renderSvg.bind(this);
  }

  componentWillMount() {
    this.getUser();
  }

  getUser() {
    UserService.login().then(user => {
      this.setState({ userName: user })
    });
  }

  renderMenuNavBar() {
    return (
      <MenuBar loopName={ this.state.loopName }/>
    );
  }

  renderUserLoggedNavBar() {
    return (
      <Navbar.Text>
        <StyledLoginInfo>Signed in as: </StyledLoginInfo>
        <StyledRouterLink to="/userInfo">{ this.state.userName }</StyledRouterLink>
      </Navbar.Text>
    );
  }

  renderLogoNavBar() {
    return (
      <Navbar.Brand>
        <img height="50px" width="234px" src={ logo } alt=""/>
        <ProjectNameStyled>CLAMP</ProjectNameStyled>
      </Navbar.Brand>
    );
  }

  renderAlertBar() {
    return (
      <div>
        <Alert variant="success" show={ this.state.showSucAlert } onClose={ this.disableAlert } dismissible>
          { this.state.showMessage }
        </Alert>
        <Alert variant="danger" show={ this.state.showFailAlert } onClose={ this.disableAlert } dismissible>
          { this.state.showMessage }
        </Alert>
      </div>
    );
  }

  renderNavBar() {
    return (
      <Navbar>
        { this.renderLogoNavBar() }
        <Navbar.Toggle aria-controls="responsive-navbar-nav"/>
        { this.renderMenuNavBar() }
        { this.renderUserLoggedNavBar() }
      </Navbar>
    );
  }

  renderLoopViewHeader() {
    return (
      <LoopViewHeaderDivStyled>
        Loop Viewer - { this.state.loopName } - ({ this.state.loopCache.getTemplateName() })
      </LoopViewHeaderDivStyled>
    );
  }

  renderSvg() {
    return (
      <SvgGenerator loopCache={ this.state.loopCache } clickable={ true } generatedFrom={ SvgGenerator.GENERATED_FROM_INSTANCE } isBusyLoading={ this.isBusyLoading }/>
    )
  }

  renderLoopViewBody() {
    return (
      <LoopViewBodyDivStyled>
        { this.renderSvg() }
        <LoopStatus loopCache={ this.state.loopCache }/>
        <LoopLogs loopCache={ this.state.loopCache }/>
      </LoopViewBodyDivStyled>
    );
  }

  getLoopCache() {
    return this.state.loopCache;

  }

  renderLoopViewer() {
    return (
      <LoopViewDivStyled>
        { this.renderLoopViewHeader() }
        { this.renderLoopViewBody() }
      </LoopViewDivStyled>
    );
  }

  updateLoopCache(loopJson) {

    // If call with an empty object for loopJson, this is a reset to empty
    // from someplace like PerformActions for the case where we are "deleting"
    // a Control Loop model. Set the loopName to the default.

    if (loopJson === null) {
      this.setState({ loopName: OnapConstants.defaultLoopName });
      this.setState({ loopCache: new LoopCache({}) });
    } else {
      this.setState({ loopCache: new LoopCache(loopJson) });
      this.setState({ loopName: this.state.loopCache.getLoopName() });
    }
    console.info(this.state.loopName + " loop loaded successfully");
  }

  showSucAlert(message) {
    this.setState({ showSucAlert: true, showMessage: message });
  }

  showFailAlert(message) {
    this.setState({ showFailAlert: true, showMessage: message });
  }

  disableAlert() {
    this.setState({ showSucAlert: false, showFailAlert: false });
  }

  loadLoop(loopName) {
    this.setBusyLoading();
    LoopService.getLoop(loopName).then(loop => {
      console.debug("Updating loopCache");
      LoopActionService.refreshStatus(loopName).then(data => {
        this.updateLoopCache(data);
        this.clearBusyLoading();
        this.props.history.push('/');
      })
        .catch(error => {
          this.updateLoopCache(loop);
          this.clearBusyLoading();
          this.props.history.push('/');
        });
    });
  }

  setBusyLoading() {
    this.setState((state, props) => ({ busyLoadingCount: ++state.busyLoadingCount }));
  }

  clearBusyLoading() {
    this.setState((state, props) => ({ busyLoadingCount: --state.busyLoadingCount }));
  }

  isBusyLoading() {
    if (this.state.busyLoadingCount === 0) {
      return false;
    } else {
      return true;
    }
  }

  closeLoop() {
    this.setState({ loopCache: new LoopCache({}), loopName: OnapConstants.defaultLoopName });
    this.props.history.push('/');
  }

  renderRoutes() {
    return (
      <React.Fragment>
        <Route path="/readToscaTemplate" render={ (routeProps) => (<ReadAndConvertYaml { ...routeProps } />) }/>
        <Route path="/uploadToscaFile" render={ (routeProps) => (<GetLocalToscaFileForUpload { ...routeProps } />) }/>
        <Route path="/getJsonSchema" render={ (routeProps) => (<CommissioningModal { ...routeProps } />) }/>
        <Route path="/viewLoopTemplatesModal" render={ (routeProps) => (<ViewLoopTemplatesModal { ...routeProps } />) }/>
        <Route path="/manageDictionaries" render={ (routeProps) => (<ManageDictionaries { ...routeProps } />) }/>
        <Route path="/viewAllPolicies" render={ (routeProps) => (<ViewAllPolicies { ...routeProps } />) }/>
        <Route path="/policyModal/:policyInstanceType/:policyName" render={ (routeProps) => (<PolicyModal { ...routeProps }
                                                                                                          loopCache={ this.getLoopCache() }
                                                                                                          loadLoopFunction={ this.loadLoop }/>) }
        />
        <Route path="/createLoop" render={ (routeProps) => (<CreateLoopModal { ...routeProps }
                                                                             loadLoopFunction={ this.loadLoop }/>) }
        />
        <Route path="/openLoop" render={ (routeProps) => (<OpenLoopModal { ...routeProps }
                                                                         loadLoopFunction={ this.loadLoop }/>) }
        />
        <Route path="/loopProperties" render={ (routeProps) => (<LoopPropertiesModal { ...routeProps }
                                                                                     loopCache={ this.getLoopCache() }
                                                                                     loadLoopFunction={ this.loadLoop }/>) }
        />
        <Route path="/modifyLoop" render={ (routeProps) => (<ModifyLoopModal { ...routeProps }
                                                                             loopCache={ this.getLoopCache() }
                                                                             loadLoopFunction={ this.loadLoop }/>) }
        />

        <Route path="/userInfo" render={ (routeProps) => (<UserInfoModal { ...routeProps } />) }/>
        <Route path="/closeLoop" render={ this.closeLoop }/>

        <Route path="/submit" render={ (routeProps) => (<PerformAction { ...routeProps }
                                                                       loopAction="submit"
                                                                       loopCache={ this.getLoopCache() }
                                                                       updateLoopFunction={ this.updateLoopCache }
                                                                       showSucAlert={ this.showSucAlert }
                                                                       showFailAlert={ this.showFailAlert }
                                                                       setBusyLoading={ this.setBusyLoading }
                                                                       clearBusyLoading={ this.clearBusyLoading }/>) }
        />
        <Route path="/stop" render={ (routeProps) => (<PerformAction { ...routeProps }
                                                                     loopAction="stop"
                                                                     loopCache={ this.getLoopCache() }
                                                                     updateLoopFunction={ this.updateLoopCache }
                                                                     showSucAlert={ this.showSucAlert }
                                                                     showFailAlert={ this.showFailAlert }
                                                                     setBusyLoading={ this.setBusyLoading }
                                                                     clearBusyLoading={ this.clearBusyLoading }/>) }
        />
        <Route path="/restart" render={ (routeProps) => (<PerformAction { ...routeProps }
                                                                        loopAction="restart"
                                                                        loopCache={ this.getLoopCache() }
                                                                        updateLoopFunction={ this.updateLoopCache }
                                                                        showSucAlert={ this.showSucAlert }
                                                                        showFailAlert={ this.showFailAlert }
                                                                        setBusyLoading={ this.setBusyLoading }
                                                                        clearBusyLoading={ this.clearBusyLoading }/>) }
        />
        <Route path="/delete" render={ (routeProps) => (<PerformAction { ...routeProps }
                                                                       loopAction="delete"
                                                                       loopCache={ this.getLoopCache() }
                                                                       updateLoopFunction={ this.updateLoopCache }
                                                                       showSucAlert={ this.showSucAlert }
                                                                       showFailAlert={ this.showFailAlert }
                                                                       setBusyLoading={ this.setBusyLoading }
                                                                       clearBusyLoading={ this.clearBusyLoading }/>) }
        />
        <Route path="/undeploy" render={ (routeProps) => (<PerformAction { ...routeProps }
                                                                         loopAction="undeploy"
                                                                         loopCache={ this.getLoopCache() }
                                                                         updateLoopFunction={ this.updateLoopCache }
                                                                         showSucAlert={ this.showSucAlert }
                                                                         showFailAlert={ this.showFailAlert }
                                                                         setBusyLoading={ this.setBusyLoading }
                                                                         clearBusyLoading={ this.clearBusyLoading }/>) }
        />
        <Route path="/deploy" render={ (routeProps) => (<DeployLoopModal { ...routeProps }
                                                                         loopCache={ this.getLoopCache() }
                                                                         updateLoopFunction={ this.updateLoopCache }
                                                                         showSucAlert={ this.showSucAlert }
                                                                         showFailAlert={ this.showFailAlert }/>) }
        />
        <Route path="/refreshStatus" render={ (routeProps) => (<RefreshStatus { ...routeProps }
                                                                              loopCache={ this.getLoopCache() }
                                                                              updateLoopFunction={ this.updateLoopCache }
                                                                              showSucAlert={ this.showSucAlert }
                                                                              showFailAlert={ this.showFailAlert }/>) }
        />
        <Route path="/monitorInstantiation" render={ (routeProps) => (<MonitorInstantiation { ...routeProps } />) }/>
        <Route path="/instantiationManagement" render={ (routeProps) => (<InstantiationManagementModal { ...routeProps } />) }/>
        <Route path="/editControlLoopInstanceProperties" render={ (routeProps) => (<InstancePropertiesModal { ...routeProps } />) }/>
        <Route path="/changeOrderState" render={ (routeProps) => (<ChangeOrderStateModal { ...routeProps } />) }/>
      </React.Fragment>
    );
  }

  renderGlobalStyle() {
    return (
      <GlobalClampStyle/>
    );
  };


  renderSpinner() {
    if (this.isBusyLoading()) {
      return (
        <StyledSpinnerDiv>
          <Spinner animation="border" role="status">
            <span className="sr-only">Loading...</span>
          </Spinner>
        </StyledSpinnerDiv>
      );
    } else {
      return (<div></div>);
    }
  }

  render() {
    return (
      <StyledMainDiv id="main_div">
        { this.renderGlobalStyle() }
        { this.renderRoutes() }
        { this.renderSpinner() }
        { this.renderAlertBar() }
        { this.renderNavBar() }
        { this.renderLoopViewer() }
      </StyledMainDiv>
    );
  }
}