Skip to content

Commit 9486193

Browse files
committed
remove file name field for stats downloading, generate file name instead
1 parent 5547a67 commit 9486193

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

hwproj.front/src/components/Solutions/DownloadStats.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { FC, useState } from "react";
2-
import { Button, DialogActions, DialogContent, Grid, TextField } from "@mui/material";
2+
import { Button, DialogActions, DialogContent, Grid } from "@mui/material";
33
import apiSingleton from "../../api/ApiSingleton";
44
import { LoadingButton } from "@mui/lab";
5+
import Utils from "@/services/Utils";
56

67
interface DownloadStatsProps {
78
courseId: number | undefined
@@ -10,14 +11,15 @@ interface DownloadStatsProps {
1011
}
1112

1213
const DownloadStats: FC<DownloadStatsProps> = (props: DownloadStatsProps) => {
13-
const [fileName, setFileName] = useState<string>("")
1414
const [loading, setLoading] = useState<boolean>(false)
1515

1616
const handleFileDownloading = () => {
17+
const statsDatetime = Utils.toStringForFileName(new Date())
1718
setLoading(true)
1819
apiSingleton.statisticsApi.statisticsGetFile(props.courseId, props.userId, "Лист 1")
1920
.then((response) => response.blob())
2021
.then((blob) => {
22+
const fileName = `StatsReport_${statsDatetime}`
2123
const url = window.URL.createObjectURL(new Blob([blob]));
2224
const link = document.createElement("a");
2325
link.href = url;
@@ -31,20 +33,8 @@ const DownloadStats: FC<DownloadStatsProps> = (props: DownloadStatsProps) => {
3133

3234
return (
3335
<DialogContent>
34-
<DialogActions style={{ padding: 0, marginTop: 6 }}>
36+
<DialogActions style={{ padding: 0 }}>
3537
<Grid item>
36-
<TextField
37-
fullWidth
38-
size="small"
39-
label="Название файла"
40-
value={fileName}
41-
onChange={event => {
42-
event.persist();
43-
setFileName(event.target.value);
44-
}}
45-
/>
46-
</Grid>
47-
<Grid>
4838
<LoadingButton
4939
variant="text"
5040
color="primary"
@@ -55,7 +45,7 @@ const DownloadStats: FC<DownloadStatsProps> = (props: DownloadStatsProps) => {
5545
Скачать
5646
</LoadingButton>
5747
</Grid>
58-
<Grid>
48+
<Grid item>
5949
<Button variant="text" color="inherit" type="button"
6050
onClick={props.onCancellation}>
6151
Отмена

hwproj.front/src/services/Utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ export default class Utils {
2121
':' + pad(date.getSeconds())
2222
}
2323

24+
static toStringForFileName(date: Date | undefined) {
25+
if (date == null) return undefined
26+
27+
const pad = (num: number) => (num < 10 ? '0' : '') + num
28+
29+
return date.getFullYear() +
30+
'-' + pad(date.getMonth() + 1) +
31+
'-' + pad(date.getDate()) +
32+
'_' + pad(date.getHours()) +
33+
'-' + pad(date.getMinutes())
34+
}
35+
2436
static pluralizeDateTime(milliseconds: number) {
2537
const diffHours = milliseconds / (1000 * 60 * 60)
2638
const diffHoursInt = Math.trunc(diffHours)

0 commit comments

Comments
 (0)