diff --git a/myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js b/myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js new file mode 100644 index 00000000..f9c11e97 --- /dev/null +++ b/myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js @@ -0,0 +1,166 @@ +import React, { createRef, Fragment, useState, useEffect } from 'react'; +import { + Breadcrumb, + BreadcrumbItem, + Card, + CardBody, + Col, + CustomInput, + Form, + FormGroup, + Label, + Row, + Spinner, +} from 'reactstrap'; +import RealtimeChart from './RealtimeChart'; +import { getCookieValue, createCookie } from '../../../helpers/utils'; +import withRedirect from '../../../hoc/withRedirect'; +import { withTranslation } from 'react-i18next'; +import uuid from 'uuid/v1'; +import { toast } from 'react-toastify'; +import { APIBaseURL } from '../../../config'; + + +const SvgSystem = ({ setRedirect, setRedirectUrl, t }) => { + + useEffect(() => { + let is_logged_in = getCookieValue('is_logged_in'); + let user_name = getCookieValue('user_name'); + let user_display_name = getCookieValue('user_display_name'); + let user_uuid = getCookieValue('user_uuid'); + let token = getCookieValue('token'); + if (is_logged_in === null || !is_logged_in) { + setRedirectUrl(`/authentication/basic/login`); + setRedirect(true); + } else { + //update expires time of cookies + createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); + createCookie('user_name', user_name, 1000 * 60 * 60 * 8); + createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); + createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); + createCookie('token', token, 1000 * 60 * 60 * 8); + } + }); + let table = createRef(); + // State + // Query Parameters + const [distributionSystemList, setSvgSystemList] = useState([]); + const [selectedSvgSystemName, setSelectedSvgSystemName] = useState(undefined); + const [selectedSvgSystemID, setSelectedSvgSystemID] = useState(undefined); + + //Results + const [images, setImages] = useState([]); + const [spinnerHidden, setSpinnerHidden] = useState(false); + + useEffect(() => { + let isResponseOK = false; + fetch(APIBaseURL + '/distributionsystems', { + method: 'GET', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: null, + + }).then(response => { + console.log(response); + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }).then(json => { + console.log(json); + if (isResponseOK) { + // rename keys + json = JSON.parse(JSON.stringify(json).split('"id":').join('"value":').split('"name":').join('"label":')); + + console.log(json); + setSvgSystemList(json); + setSelectedSvgSystemID([json[0]].map(o => o.value)); + setSelectedSvgSystemName([json[0]].map(o => o.label)); + + let images = {}; + json.forEach((currentValue, index) => { + images[currentValue['value']] = {__html: currentValue['svg']} + }); + setImages(images); + setSpinnerHidden(true); + } else { + toast.error(json.description); + } + }).catch(err => { + console.log(err); + }); + + }, []); + + const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; + + let onSvgSystemChange = (event) => { + setSelectedSvgSystemID(event.target.value); + distributionSystemList.forEach((currentItem, index) => { + if (currentItem['value'] === event.target.value) { + setSelectedSvgSystemName(currentItem['label']); + } + }); + + } + + + return ( + +
+ + {t('Auxiliary System')}{t('Distribution System')} + +
+ + +
+ + + + + + {distributionSystemList.map((distributionSystem, index) => ( + + ))} + + + + + +

+
+ +
+
+
+
+ + + + + + + +
+ + + + + ); +}; + +export default withTranslation()(withRedirect(SvgSystem)); diff --git a/myems-web/src/config.js b/myems-web/src/config.js index 942799f5..5f7ab368 100644 --- a/myems-web/src/config.js +++ b/myems-web/src/config.js @@ -1,8 +1,8 @@ export const version = '1.9.0'; export const navbarBreakPoint = 'xl'; // Vertical navbar breakpoint export const topNavbarBreakpoint = 'lg'; -//export const APIBaseURL = 'http://127.0.0.1:8000'; -export const APIBaseURL = window.location.protocol+"//"+window.location.hostname+":"+window.location.port+"/api"; +export const APIBaseURL = 'http://127.0.0.1:8000'; +// export const APIBaseURL = window.location.protocol+"//"+window.location.hostname+":"+window.location.port+"/api"; export const settings = { isFluid: true, isRTL: false, diff --git a/myems-web/src/layouts/MyEMSRoutes.js b/myems-web/src/layouts/MyEMSRoutes.js index 23f38bfb..6ab4fa13 100644 --- a/myems-web/src/layouts/MyEMSRoutes.js +++ b/myems-web/src/layouts/MyEMSRoutes.js @@ -196,6 +196,7 @@ import AdvancedReporting from '../components/MyEMS/AdvancedReporting/AdvancedRep import KnowledgeBase from '../components/MyEMS/KnowledgeBase/KnowledgeBase'; // Notification import Notification from '../components/MyEMS/Notification/Notification'; +import SvgSystem from '../components/MyEMS/AuxiliarySystem/SvgSystem'; // const InboxRoutes = ({ match: { url } }) => ( // @@ -422,6 +423,7 @@ const MyEMSRoutes = () => ( {/*Auxiliary System*/} + {/*FDD*/} diff --git a/myems-web/src/routes.js b/myems-web/src/routes.js index 61795c27..ee8e238b 100644 --- a/myems-web/src/routes.js +++ b/myems-web/src/routes.js @@ -443,7 +443,8 @@ export const auxiliarySystemRoutes = { icon: 'chart-pie', children: [ { to: '/auxiliarysystem/energyflowdiagram', name: 'Energy Flow Diagram' }, - { to: '/auxiliarysystem/distributionsystem', name: 'Distribution System' } + { to: '/auxiliarysystem/distributionsystem', name: 'Distribution System' }, + { to: '/auxiliarysystem/svgsystem', name: 'Svg System' } ] };