Skip to content

Commit

Permalink
Auto tagging button for Admin Problem
Browse files Browse the repository at this point in the history
  • Loading branch information
nvatuan committed Jul 1, 2023
1 parent 04fadd2 commit 062d4bc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/api/problem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const adminEditProblemDetails = ({shortname, data}) => {
const adminEditProblemDetailsForm = ({shortname, formData}) => {
return axiosFormClient.patch(`/problem/${shortname}/`, formData);
};
const adminTriggerProblemAutoTag = ({shortname}) => {
return axiosClient.post(`/problem/${shortname}/auto-tagging`,);
};

const adminGetProblemDetailsData = ({shortname}) => {
return axiosClient.get(`/problem/${shortname}/data/`);
};
Expand Down Expand Up @@ -77,6 +81,8 @@ const problemAPI = {

adminPostProblemFromZip,

adminTriggerProblemAutoTag,

adminGetProblemDetailsData,
adminGetProblemDetailsTest,

Expand Down
2 changes: 1 addition & 1 deletion src/components/Content/Content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Content extends React.Component {
<h5 className="">
phase <span className="code-markup">openBETA</span>
</h5>
<span className="code-markup">22年10月20日</span>
<span className="code-markup">23年06月25日</span>
</div>
</div>
<span className="subtext text-center">
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectMulti/ProblemTag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ProblemTagMultiSelect = (props) => {
return (
<>
<Select
{...props}
isMulti
cacheOptions
isLoading={isLoading}
Expand Down
38 changes: 36 additions & 2 deletions src/pages/admin/problem/_/GeneralDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import OrgMultiSelect from "components/SelectMulti/Org";
import ProblemTagMultiSelect from "components/SelectMulti/ProblemTag";
import {qmClarify} from "helpers/components";

import {AiOutlineTags} from 'react-icons/ai'

class GeneralDetails extends React.Component {
constructor(props) {
super(props);
this.state = {
data: this.props.data,
selectedPdf: null,
submitting: false,

shouldDisableTags: false,
};
}
componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -144,6 +148,26 @@ class GeneralDetails extends React.Component {
})
}

autoTagHandler(e) {
e.preventDefault()
let conf = window.confirm(
"Thao tác này sẽ tự động phân tích các mã nguồn đã AC để tự động gán tags cho bài toán. "+
"Việc tự động này có thể sẽ mất thời gian nên sẽ được thực hiện ngầm, và sẽ ghi "+
"đề lên các tags có sẵn của bài toán. Bạn có muốn tiếp tục?"
)
if (!conf) return;

problemAPI.adminTriggerProblemAutoTag({
shortname: this.props.shortname
}).then(_res => {
toast.success("Thành công. Xin hãy đợi trong giây lát.")
this.setState({shouldDisableTags: true})
}).catch(err => {
console.log(err)
toast.error("Có lỗi đã xảy ra.")
})
}

render() {
const {data} = this.state;
return (
Expand Down Expand Up @@ -257,11 +281,19 @@ class GeneralDetails extends React.Component {
<Form.Label column="sm" xl={12}>
Tags
</Form.Label>
<Col xl={12}>
<Col lg={10}>
<ProblemTagMultiSelect tags={data.tags}
isDisabled={this.state.shouldDisableTags}
onChange={newTags => this.setState({data: {...data, tags: newTags}})}
/>
</Col>
<Col lg={2}>
<Button className="btn-svg d-flex justify-content-center" variant="light"
onClick={e => this.autoTagHandler(e)}>
<span className="d-none d-md-inline">Auto</span>
<AiOutlineTags/>
</Button>
</Col>
</Row>
</Accordion.Body>
</Accordion.Item>
Expand Down Expand Up @@ -555,7 +587,9 @@ class GeneralDetails extends React.Component {
<Row>
<Col xl={10}></Col>
<Col className="justify-content-end">
<Button variant="dark" size="sm" type="submit" className="btn-svg">
<Button variant="dark" size="sm" type="submit" className="btn-svg"
disabled={this.state.shouldDisableTags}
>
<FaRegSave /> Save
</Button>
{this.state.submitting && (
Expand Down

0 comments on commit 062d4bc

Please sign in to comment.