Skip to content

Commit 018a0f2

Browse files
committed
wip
1 parent 583031d commit 018a0f2

2 files changed

Lines changed: 95 additions & 59 deletions

File tree

hwproj.front/src/components/Courses/StudentStats.tsx

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
2-
import {CourseViewModel, HomeworkViewModel, ResultString, StatisticsCourseMatesModel} from "../../api/";
2+
import {CourseViewModel, HomeworkViewModel, StatisticsCourseMatesModel} from "../../api/";
33
import {Table, TableBody, TableCell, TableContainer, TableHead, TableRow} from "@material-ui/core";
44
import StudentStatsCell from "../Tasks/StudentStatsCell";
5-
import {Alert, Button, Grid, MenuItem, Select, TextField} from "@mui/material";
6-
import apiSingleton from "../../api/ApiSingleton";
5+
import {Alert, Grid} from "@mui/material";
6+
import LoadStatsToGoogleDoc from "components/Solutions/LoadStatsToGoogleDoc";
77

88
interface IStudentStatsProps {
99
course: CourseViewModel;
@@ -15,17 +15,13 @@ interface IStudentStatsProps {
1515

1616
interface IStudentStatsState {
1717
searched: string
18-
googleDocUrl: string
19-
sheetTitles: ResultString | undefined
2018
}
2119

2220
class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsState> {
2321
constructor(props: IStudentStatsProps) {
2422
super(props);
2523
this.state = {
26-
searched: "",
27-
googleDocUrl: "",
28-
sheetTitles: undefined
24+
searched: ""
2925
}
3026

3127
// document.addEventListener('keydown', (event: KeyboardEvent) => {
@@ -45,17 +41,9 @@ class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsStat
4541
// })
4642
}
4743

48-
//TODO: throttling
49-
private handleGoogleDocUrlChange = async (value: string) => {
50-
const titles = value === ""
51-
? undefined
52-
: await apiSingleton.statisticsApi.apiStatisticsGetSheetTitlesPost({url: value})
53-
this.setState({googleDocUrl: value, sheetTitles: titles});
54-
}
55-
5644
public render() {
5745
const homeworks = this.props.homeworks.filter(h => h.tasks && h.tasks.length > 0)
58-
const {searched, googleDocUrl, sheetTitles} = this.state
46+
const {searched} = this.state
5947
const solutions = searched
6048
? this.props.solutions.filter(cm => (cm.surname + " " + cm.name).toLowerCase().includes(searched.toLowerCase()))
6149
: this.props.solutions
@@ -69,7 +57,8 @@ class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsStat
6957
return (
7058
<div>
7159
{searched &&
72-
<Alert style={{marginBottom: 5}} severity="info"><b>Студенты:</b> {searched.replaceAll(" ", "·")}
60+
<Alert style={{marginBottom: 5}}
61+
severity="info"><b>Студенты:</b> {searched.replaceAll(" ", "·")}
7362
</Alert>}
7463
<TableContainer style={{maxHeight: 600}}>
7564
<Table stickyHeader aria-label="sticky table">
@@ -133,48 +122,11 @@ class StudentStats extends React.Component<IStudentStatsProps, IStudentStatsStat
133122
</TableBody>
134123
</Table>
135124
</TableContainer>
136-
<Grid container spacing={1} style={{marginTop: 15}}>
137-
<Grid item>
138-
<Alert severity="info" variant={"standard"}>
139-
Для загрузки таблицы необходимо разрешить доступ на редактирование по ссылке для Google Docs
140-
страницы
141-
</Alert>
142-
</Grid>
143-
<Grid container item spacing={1} alignItems={"center"}>
144-
<Grid item>
145-
<TextField size={"small"} fullWidth label={"Ссылка на Google Docs"} value={googleDocUrl}
146-
onChange={event => {
147-
event.persist()
148-
this.handleGoogleDocUrlChange(event.target.value)
149-
}}/>
150-
</Grid>
151-
{sheetTitles && !sheetTitles.succeeded && <Grid item>
152-
<Alert severity="error">
153-
{sheetTitles!.errors![0]}
154-
</Alert>
155-
</Grid>}
156-
{sheetTitles && sheetTitles.value && sheetTitles.value.length > 0 && <Grid item>
157-
<Select
158-
size={"small"}
159-
id="demo-simple-select"
160-
label="Sheet"
161-
value={0}
162-
>
163-
{sheetTitles.value.map((title, i) => <MenuItem value={i}>{title}</MenuItem>)}
164-
</Select>
165-
</Grid>}
166-
{sheetTitles && sheetTitles.succeeded && <Grid item>
167-
<Button fullWidth
168-
variant="text"
169-
color="primary"
170-
type="button">
171-
Загрузить
172-
</Button>
173-
</Grid>}
174-
</Grid>
175-
</Grid>
125+
<div style={{marginTop: 15}}>
126+
<LoadStatsToGoogleDoc/>
127+
</div>
176128
</div>
177-
);
129+
)
178130
}
179131
}
180132

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React, {FC, useState} from "react";
2+
import {Alert, Button, Grid, MenuItem, Select, TextField} from "@mui/material";
3+
import {ResultString} from "../../api";
4+
import apiSingleton from "../../api/ApiSingleton";
5+
6+
interface LoadStatsToGoogleDocProps {
7+
}
8+
9+
interface LoadStatsToGoogleDocState {
10+
googleDocUrl: string,
11+
sheetTitles: ResultString | undefined,
12+
selectedSheet: number,
13+
isOpened: boolean
14+
}
15+
16+
const LoadStatsToGoogleDoc: FC<LoadStatsToGoogleDocProps> = (props) => {
17+
const [state, setState] = useState<LoadStatsToGoogleDocState>({
18+
selectedSheet: 0,
19+
isOpened: false,
20+
googleDocUrl: "",
21+
sheetTitles: undefined
22+
})
23+
24+
const {googleDocUrl, sheetTitles, isOpened, selectedSheet} = state
25+
26+
//TODO: throttling
27+
const handleGoogleDocUrlChange = async (value: string) => {
28+
const titles = value === ""
29+
? undefined
30+
: await apiSingleton.statisticsApi.apiStatisticsGetSheetTitlesPost({url: value})
31+
setState(prevState => ({...prevState, googleDocUrl: value, sheetTitles: titles}));
32+
}
33+
34+
return !isOpened
35+
? <Button variant="text" color="primary" type="button"
36+
onClick={() => setState(prevState => ({...prevState, isOpened: true}))}>
37+
Загрузить
38+
</Button>
39+
: <Grid container spacing={1} style={{marginTop: 15}}>
40+
<Grid item>
41+
<Alert severity="info" variant={"standard"}>
42+
Для загрузки таблицы необходимо разрешить доступ на редактирование по ссылке для Google Docs
43+
страницы
44+
</Alert>
45+
</Grid>
46+
<Grid container item spacing={1} alignItems={"center"}>
47+
<Grid item>
48+
<TextField size={"small"} fullWidth label={"Ссылка на Google Docs"} value={googleDocUrl}
49+
onChange={event => {
50+
event.persist()
51+
handleGoogleDocUrlChange(event.target.value)
52+
}}/>
53+
</Grid>
54+
{sheetTitles && !sheetTitles.succeeded && <Grid item>
55+
<Alert severity="error">
56+
{sheetTitles!.errors![0]}
57+
</Alert>
58+
</Grid>}
59+
{sheetTitles && sheetTitles.value && sheetTitles.value.length > 0 && <Grid item>
60+
<Select
61+
size={"small"}
62+
id="demo-simple-select"
63+
label="Sheet"
64+
value={selectedSheet}
65+
onChange={v => setState(prevState => ({...prevState, selectedSheet: +v.target.value}))}
66+
>
67+
{sheetTitles.value.map((title, i) => <MenuItem value={i}>{title}</MenuItem>)}
68+
</Select>
69+
</Grid>}
70+
{sheetTitles && sheetTitles.succeeded && <Grid item>
71+
<Button variant="text" color="primary" type="button">
72+
Загрузить
73+
</Button>
74+
</Grid>}
75+
{<Grid item>
76+
<Button variant="text" color="primary" type="button"
77+
onClick={() => setState(prevState => ({...prevState, isOpened: false}))}>
78+
Отмена
79+
</Button>
80+
</Grid>}
81+
</Grid>
82+
</Grid>
83+
}
84+
export default LoadStatsToGoogleDoc;

0 commit comments

Comments
 (0)