/** * ============LICENSE_START======================================================================== * ONAP : ccsdk feature sdnr wt odlux * ================================================================================================= * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. All rights reserved. * ================================================================================================= * 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. * ============LICENSE_END========================================================================== */ import * as React from 'react'; import MuiDialogTitle from '@material-ui/core/DialogTitle'; import { AppBar, Dialog, DialogContent, IconButton, Tab, Tabs, TextField, Typography } from '@material-ui/core'; import CloseIcon from '@material-ui/icons/Close'; import { withStyles, WithStyles, createStyles, Theme, makeStyles } from '@material-ui/core/styles'; import StadokSite from '../../model/stadokSite'; import { LatLonToDMS } from '../../utils/mapUtils'; import DenseTable from '../../components/denseTable'; import { requestRest } from '../../../../../framework/src/services/restService'; import { OrderToDisplay, StadokOrder } from '../../model/stadokOrder'; import { CSSProperties } from '@material-ui/core/styles/withStyles'; import { SITEDOC_URL } from '../../config'; type props = { site: StadokSite; onClose(): void; open:boolean }; const styles = (theme: Theme) => createStyles({ root: { margin: 0, padding: theme.spacing(2), }, closeButton: { position: 'absolute', right: theme.spacing(1), top: theme.spacing(1), color: theme.palette.grey[500], }, }); const useStyles = makeStyles({ largeImage:{cursor:'pointer', width:300}, smallImage:{cursor:'pointer', width: 50, marginTop:'10px', marginLeft:'10px'} }); const StadokDetailsPopup: React.FunctionComponent = (props) => { const classes = useStyles(); const [open, setOpen] = React.useState(props.open); const [value, setValue] = React.useState("devices"); const [orders, setOrders] = React.useState(null); const DialogTitle = withStyles(styles)((props: any) => { const { children, classes, onClose, ...other } = props; return ( {children} {onClose ? ( ) : null} ); }); const getContacts = (site: StadokSite) =>{ const contacts = []; if(site.createdBy){ contacts.push({h: "Site Creator",col1: site.createdBy.firstName, col2: site.createdBy.lastName, col3: site.createdBy.email, col4: site.createdBy.telephoneNumber }); } if(site.contacts.manager){ contacts.push({h: "Manager",col1: site.contacts.manager.firstName, col2: site.contacts.manager.lastName, col3: site.contacts.manager.email, col4: site.contacts.manager.telephoneNumber }); } if(site.contacts.owner){ contacts.push({h: "Owner",col1: site.contacts.owner.firstName, col2: site.contacts.owner.lastName, col3: site.contacts.owner.email, col4: site.contacts.owner.telephoneNumber }); } return contacts; } const onClose = () =>{ // setOpen(false); props.onClose() } //todo: use a set 'panelId' -> which values are allowed const onHandleTabChange = (event: React.ChangeEvent<{}>, newValue: string) => { setValue(newValue); } console.log(props.site) const contacts = getContacts(props.site); const orderUrl=`${SITEDOC_URL}/site/${props.site.siteId}/orders`; if(orders==null){ requestRest(orderUrl,{ method: "GET"}).then(result =>{ if(result){ const orderList = result.map(order =>{ return OrderToDisplay.parse(order); }); setOrders(orderList); }else{ setOrders([]); } }); } const createOrderInfo = () => { if (orders === null) { return (
Loading orders
) } else if (orders.length === 0) { return (
No orders available
) } else { return } } const displayImages = () => { if (props.site.images.length === 1) { return stadokImage(props.site.siteId, props.site.images[0],"large") } else { return <> { stadokImage(props.site.siteId, props.site.images[0], "large") }
{ props.site.images.length<=9 ? props.site.images.slice(1, props.site.images.length).map(image => stadokImage(props.site.siteId, image, "small") ) : <> { props.site.images.slice(1, 9).map(image => stadokImage(props.site.siteId, image, "small") ) } }
} } const stadokImage = (siteId: string, imagename: string, size: 'large' | 'small') => { const url = `${SITEDOC_URL}/site/${siteId}/files/${imagename}`; const className = size === "small" ? classes.smallImage : classes.largeImage; return window.open(url)} /> } return ( {props.site.siteId}
{ props.site.type !== undefined && props.site.type.length > 0 && } { value == "devices" && (props.site.devices?.length>0 ? :
No devices available
) } { value == "contacts" && (contacts.length>0 ? :
No contacts available
) } { value == "safteyInfo" && (props.site.safteyNotices.length>0 ? :
No saftey notices applicable
) } { value == "logs" && (props.site.logs.length>0 ? :
No activity log available
) } { value ==="orders" && createOrderInfo() }
{ props.site.images.length == 0 ? No images available : displayImages() }
) } export default StadokDetailsPopup;