-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): home dashboard with stats
- Loading branch information
Showing
12 changed files
with
167 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable import/no-anonymous-default-export */ | ||
import * as React from 'react'; | ||
import Card from '@mui/material/Card'; | ||
import CardHeader from '@mui/material/CardHeader'; | ||
import Grid from '@mui/material/Grid'; | ||
import Box from '@mui/material/Box'; | ||
import Skeleton from '@mui/material/Skeleton'; | ||
import { TbUser, TbSeeding, TbTree, TbPlant2 } from 'react-icons/tb'; | ||
import { HttpClient } from './configs/HttpClient'; | ||
import { BASE_URL } from './configs/BaseUrl'; | ||
|
||
export default class Dashboard extends React.Component { | ||
state = { | ||
loading: true, | ||
stats: {} | ||
}; | ||
|
||
componentDidMount() { | ||
HttpClient(`${BASE_URL}/stats/global`).then(res => { | ||
this.setState({ stats: JSON.parse(res.body), loading: false }) | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<> | ||
<Box component="span" sx={{ p: 5 }}> | ||
<Grid container spacing={2}> | ||
<Grid item xs={3}> | ||
<Card sx={{ minWidth: 275 }} variant="outlined"> | ||
<CardHeader | ||
avatar={<TbUser />} | ||
title="Users" | ||
subheader={this.state.loading ? <Skeleton /> : this.state?.stats?.estimatedCount?.users}></CardHeader> | ||
</Card> | ||
</Grid> | ||
<Grid item xs={3}> | ||
<Card sx={{ minWidth: 275 }} variant="outlined"> | ||
<CardHeader | ||
avatar={<TbTree />} | ||
title="Plants" | ||
subheader={this.state.loading ? <Skeleton /> : this.state?.stats?.estimatedCount?.plants}></CardHeader> | ||
</Card> | ||
</Grid> | ||
<Grid item xs={3}> | ||
<Card sx={{ minWidth: 275 }} variant="outlined"> | ||
<CardHeader | ||
avatar={<TbSeeding />} | ||
title="Varieties" | ||
subheader={this.state.loading ? <Skeleton /> : this.state?.stats?.estimatedCount?.varieties}></CardHeader> | ||
</Card> | ||
</Grid> | ||
<Grid item xs={3}> | ||
<Card sx={{ minWidth: 275 }} variant="outlined"> | ||
<CardHeader | ||
avatar={<TbPlant2 />} | ||
title="Floors" | ||
subheader={this.state.loading ? <Skeleton /> : this.state?.stats?.estimatedCount?.floors}></CardHeader> | ||
</Card> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/src/controllers/stats/models/stats.global.response.body.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class StatsGlobalCountResponseBody { | ||
@ApiProperty() | ||
users: number; | ||
|
||
@ApiProperty() | ||
plants: number; | ||
|
||
@ApiProperty() | ||
varieties: number; | ||
|
||
@ApiProperty() | ||
floors: number; | ||
} | ||
|
||
export class StatsGlobalResponseBody { | ||
@ApiProperty({ type: StatsGlobalCountResponseBody }) | ||
estimatedCount: StatsGlobalCountResponseBody; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; | ||
import { ApiResponse } from '@nestjs/swagger'; | ||
import { VarietiesService } from '../../entities/varieties/varieties.service'; | ||
import { UsersService } from '../../users/users.service'; | ||
import { PlantsService } from '../../entities/plants/plants.service'; | ||
import { FloorsService } from '../../entities/floors/floors.service'; | ||
import { StatsGlobalResponseBody } from './models/stats.global.response.body'; | ||
|
||
@ApiBearerAuth() | ||
@ApiTags('Stats') | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
@ApiResponse({ status: 429, description: 'Too Many Requests' }) | ||
@Controller('stats') | ||
export class StatsController { | ||
constructor( | ||
private usersService: UsersService, | ||
private plantsService: PlantsService, | ||
private varietiesService: VarietiesService, | ||
private floorsService: FloorsService, | ||
) {} | ||
|
||
@Get('global') | ||
@ApiResponse({ status: 200, type: StatsGlobalResponseBody }) | ||
async getGlobal(): Promise<StatsGlobalResponseBody> { | ||
return { | ||
estimatedCount: { | ||
users: await this.usersService.count(), | ||
plants: await this.plantsService.count(), | ||
varieties: await this.varietiesService.count(), | ||
floors: await this.floorsService.count(), | ||
}, | ||
}; | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
core/src/entities/favorites/models/favorite.variety.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters