mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-06 07:04:45 +09:00
1 parent
25e4acae64
commit
ff997cae94
11 files changed
+326
-4
No files matched your search
@@ -47,6 +47,7 @@ const SelectCard = memo(({
|
||||
stylesProps,
|
||||
action,
|
||||
actions,
|
||||
cardActionsProps,
|
||||
icon,
|
||||
title,
|
||||
subheader,
|
||||
@@ -131,7 +132,7 @@ const SelectCard = memo(({
|
||||
|
||||
{/* CARD ACTIONS */}
|
||||
{actions?.length > 0 && (
|
||||
<CardActions>
|
||||
<CardActions {...cardActionsProps}>
|
||||
{actions?.map(action => <Action key={action?.cy} {...action} />)}
|
||||
</CardActions>
|
||||
)}
|
||||
@@ -158,6 +159,10 @@ SelectCard.propTypes = {
|
||||
cy: PropTypes.string
|
||||
})
|
||||
),
|
||||
cardActionsProps: PropTypes.shape({
|
||||
className: PropTypes.string,
|
||||
style: PropTypes.object
|
||||
}),
|
||||
icon: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.object
|
||||
@@ -197,6 +202,7 @@ SelectCard.defaultProps = {
|
||||
stylesProps: undefined,
|
||||
action: undefined,
|
||||
actions: undefined,
|
||||
cardActionsProps: undefined,
|
||||
icon: undefined,
|
||||
title: undefined,
|
||||
subheader: undefined,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { CardContent } from '@material-ui/core'
|
||||
import SelectCard from 'client/components/Cards/SelectCard'
|
||||
|
||||
const WidgetCard = React.memo(({ value }) => {
|
||||
const { title, widget, actions } = value
|
||||
|
||||
return (
|
||||
<SelectCard
|
||||
actions={actions}
|
||||
cardActionsProps={{ style: { justifyContent: 'center' } }}
|
||||
title={title}
|
||||
cardHeaderProps={{
|
||||
titleTypographyProps: {
|
||||
variant: 'h4',
|
||||
style: { textAlign: 'center' }
|
||||
}
|
||||
}}
|
||||
>
|
||||
<CardContent>{widget}</CardContent>
|
||||
</SelectCard>
|
||||
)
|
||||
})
|
||||
|
||||
WidgetCard.propTypes = {
|
||||
value: PropTypes.shape({
|
||||
icon: PropTypes.node,
|
||||
title: PropTypes.string,
|
||||
subtitle: PropTypes.string,
|
||||
widget: PropTypes.node,
|
||||
actions: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.object.isRequired,
|
||||
cy: PropTypes.string
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
WidgetCard.defaultProps = {
|
||||
value: {
|
||||
icon: undefined,
|
||||
title: undefined,
|
||||
subtitle: undefined,
|
||||
widget: undefined,
|
||||
actions: []
|
||||
}
|
||||
}
|
||||
|
||||
WidgetCard.displayName = 'WidgetCard'
|
||||
|
||||
export default WidgetCard
|
||||
@@ -1,3 +1,4 @@
|
||||
import WidgetCard from 'client/components/Cards/WidgetCard'
|
||||
import ClusterCard from 'client/components/Cards/ClusterCard'
|
||||
import DatastoreCard from 'client/components/Cards/DatastoreCard'
|
||||
import HostCard from 'client/components/Cards/HostCard'
|
||||
@@ -14,6 +15,7 @@ import ProvisionCard from 'client/components/Cards/ProvisionCard'
|
||||
import LocationCard from 'client/components/Cards/LocationCard'
|
||||
|
||||
export {
|
||||
WidgetCard,
|
||||
ClusterCard,
|
||||
DatastoreCard,
|
||||
HostCard,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { Typography } from '@material-ui/core'
|
||||
|
||||
const Count = ({ start, number, duration, ...props }) => {
|
||||
const [count, setCount] = React.useState('0')
|
||||
|
||||
React.useEffect(() => {
|
||||
const end = parseInt(String(number).substring(0, 3))
|
||||
|
||||
if (start === end) return
|
||||
|
||||
const totalMilSecDur = parseInt(duration)
|
||||
const incrementTime = (totalMilSecDur / end) * 1000
|
||||
|
||||
const timer = setInterval(() => {
|
||||
start += 1
|
||||
setCount(String(start) + number.substring(3))
|
||||
if (start === end) clearInterval(timer)
|
||||
}, incrementTime)
|
||||
|
||||
return () => clearInterval(timer)
|
||||
}, [start, number, duration])
|
||||
|
||||
return <Typography {...props}>{count}</Typography>
|
||||
}
|
||||
|
||||
Count.propTypes = {
|
||||
start: PropTypes.number,
|
||||
number: PropTypes.string,
|
||||
duration: PropTypes.string,
|
||||
component: PropTypes.elementType
|
||||
}
|
||||
|
||||
Count.defaultProps = {
|
||||
start: 0,
|
||||
number: '0',
|
||||
duration: '1',
|
||||
component: 'span'
|
||||
}
|
||||
|
||||
Count.displayName = 'Count'
|
||||
|
||||
export default Count
|
||||
@@ -0,0 +1,74 @@
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { makeStyles, Box, CircularProgress } from '@material-ui/core'
|
||||
import Count from 'client/components/Count'
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
circle: { stroke: ({ color }) => `${color} !important` }
|
||||
}))
|
||||
|
||||
const Circle = React.memo(({ color }) => {
|
||||
const classes = useStyles({ color })
|
||||
const [progress, setProgress] = React.useState(0)
|
||||
|
||||
React.useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
setProgress(prevProgress => {
|
||||
const nextProgress = prevProgress + 5
|
||||
if (nextProgress === 100) clearInterval(timer)
|
||||
return nextProgress
|
||||
})
|
||||
}, 50)
|
||||
|
||||
return () => clearInterval(timer)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<CircularProgress
|
||||
classes={{ circle: classes.circle }}
|
||||
size={150}
|
||||
thickness={5}
|
||||
value={progress}
|
||||
variant='determinate'
|
||||
/>
|
||||
)
|
||||
}, (prev, next) => prev.color === next.color)
|
||||
|
||||
Circle.propTypes = { color: PropTypes.string }
|
||||
Circle.defaultProps = { color: 'primary' }
|
||||
Circle.displayName = 'Circle'
|
||||
|
||||
// -------------------------------------
|
||||
// WIDGET
|
||||
// -------------------------------------
|
||||
|
||||
const SimpleCircle = React.memo(({ label, color }) => (
|
||||
<Box position='relative' display='inline-flex' width={1}>
|
||||
<Box display='flex' flexDirection='column' alignItems='center' width={1}>
|
||||
<Circle color={color} />
|
||||
</Box>
|
||||
<Box top={0} left={0} bottom={0} right={0}
|
||||
position='absolute'
|
||||
display='flex'
|
||||
alignItems='center'
|
||||
justifyContent='center'
|
||||
>
|
||||
<Count number={label} variant='h4' component='div' color='textSecondary' />
|
||||
</Box>
|
||||
</Box>
|
||||
), (prev, next) => prev.label === next.label)
|
||||
|
||||
SimpleCircle.propTypes = {
|
||||
label: PropTypes.string,
|
||||
color: PropTypes.string
|
||||
}
|
||||
|
||||
SimpleCircle.defaultProps = {
|
||||
label: undefined,
|
||||
color: 'primary'
|
||||
}
|
||||
|
||||
SimpleCircle.displayName = 'SimpleCircle'
|
||||
|
||||
export default SimpleCircle
|
||||
@@ -0,0 +1,45 @@
|
||||
import * as React from 'react'
|
||||
import { useHistory } from 'react-router'
|
||||
|
||||
import { ViewList, Add } from '@material-ui/icons'
|
||||
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import Circle from 'client/components/Widgets/SimpleCircle'
|
||||
|
||||
import { PATH } from 'client/router/provision'
|
||||
import { T } from 'client/constants'
|
||||
|
||||
const cy = 'dashboard-widget-total-providers'
|
||||
const title = T.Providers
|
||||
|
||||
const WidgetTotalProviders = () => {
|
||||
const history = useHistory()
|
||||
const { providers, getProviders } = useProvision()
|
||||
const { fetchRequest } = useFetch(getProviders)
|
||||
|
||||
React.useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
const actions = React.useMemo(() => [
|
||||
{
|
||||
handleClick: () => history.push(PATH.PROVIDERS.LIST),
|
||||
icon: <ViewList />,
|
||||
cy: `${cy}-gotolist`
|
||||
},
|
||||
{
|
||||
handleClick: () => history.push(PATH.PROVIDERS.CREATE),
|
||||
icon: <Add color='primary' />,
|
||||
cy: `${cy}-create`
|
||||
}
|
||||
], [history])
|
||||
|
||||
const widget = React.useMemo(() => (
|
||||
<Circle label={`${providers?.length}`} color='#49457b' />
|
||||
), [providers?.length])
|
||||
|
||||
return { cy, title, actions, widget }
|
||||
}
|
||||
|
||||
WidgetTotalProviders.displayName = 'WidgetTotalProviders'
|
||||
|
||||
export default WidgetTotalProviders
|
||||
@@ -0,0 +1,45 @@
|
||||
import * as React from 'react'
|
||||
import { useHistory } from 'react-router'
|
||||
|
||||
import { ViewList, Add } from '@material-ui/icons'
|
||||
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import Circle from 'client/components/Widgets/SimpleCircle'
|
||||
|
||||
import { PATH } from 'client/router/provision'
|
||||
import { T } from 'client/constants'
|
||||
|
||||
const cy = 'dashboard-widget-total-provisions'
|
||||
const title = T.Provisions
|
||||
|
||||
const WidgetTotalProvisions = () => {
|
||||
const history = useHistory()
|
||||
const { provisions, getProvisions } = useProvision()
|
||||
const { fetchRequest } = useFetch(getProvisions)
|
||||
|
||||
React.useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
const actions = React.useMemo(() => [
|
||||
{
|
||||
handleClick: () => history.push(PATH.PROVISIONS.LIST),
|
||||
icon: <ViewList />,
|
||||
cy: `${cy}-gotolist`
|
||||
},
|
||||
{
|
||||
handleClick: () => history.push(PATH.PROVISIONS.CREATE),
|
||||
icon: <Add color='primary' />,
|
||||
cy: `${cy}-create`
|
||||
}
|
||||
], [history])
|
||||
|
||||
const widget = React.useMemo(() => (
|
||||
<Circle label={`${provisions?.length}`} color='#49457b' />
|
||||
), [provisions?.length])
|
||||
|
||||
return { cy, title, actions, widget }
|
||||
}
|
||||
|
||||
WidgetTotalProvisions.displayName = 'WidgetTotalProvisions'
|
||||
|
||||
export default WidgetTotalProvisions
|
||||
@@ -0,0 +1,44 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { Box, Container, Typography } from '@material-ui/core'
|
||||
|
||||
import { ListCards } from 'client/components/List'
|
||||
import { WidgetCard } from 'client/components/Cards'
|
||||
import WidgetTotalProviders from 'client/components/Widgets/WidgetTotalProviders'
|
||||
import WidgetTotalProvisions from 'client/components/Widgets/WidgetTotalProvisions'
|
||||
|
||||
import dashboardStyles from 'client/containers/Dashboard/Provision/styles'
|
||||
import { Tr } from 'client/components/HOC/Translate'
|
||||
import { T } from 'client/constants'
|
||||
|
||||
function Dashboard () {
|
||||
const classes = dashboardStyles()
|
||||
const widgets = [
|
||||
WidgetTotalProviders(),
|
||||
WidgetTotalProvisions()
|
||||
]
|
||||
|
||||
return (
|
||||
<Container disableGutters>
|
||||
<Box p={3}>
|
||||
<Typography
|
||||
variant="h2"
|
||||
className={classes.title}
|
||||
data-cy="dashboard-title"
|
||||
>
|
||||
{Tr(T.Dashboard)}
|
||||
</Typography>
|
||||
<Box py={3}>
|
||||
<ListCards
|
||||
list={widgets}
|
||||
keyProp='cy'
|
||||
CardComponent={WidgetCard}
|
||||
breakpoints={{ xs: 12, sm: 6 }}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export default Dashboard
|
||||
@@ -0,0 +1,6 @@
|
||||
import { makeStyles } from '@material-ui/core'
|
||||
|
||||
export default makeStyles(theme => ({
|
||||
root: {},
|
||||
title: { color: theme.palette.common.black }
|
||||
}))
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* 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 */
|
||||
@@ -13,7 +13,7 @@
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react'
|
||||
import * as React from 'react'
|
||||
|
||||
import { Box, Typography } from '@material-ui/core'
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from '@material-ui/icons'
|
||||
|
||||
import Login from 'client/containers/Login'
|
||||
import Dashboard from 'client/containers/Dashboard'
|
||||
import Dashboard from 'client/containers/Dashboard/Provision'
|
||||
import Settings from 'client/containers/Settings'
|
||||
|
||||
import Providers from 'client/containers/Providers'
|
||||
|
||||
Reference in new issue
Block a user