Skip to content

Commit adee35e

Browse files
authored
Merge pull request #110 from doctorixx/master
Add JSON and Fix Latest push
2 parents 71b7b5a + de2b518 commit adee35e

8 files changed

Lines changed: 155 additions & 5 deletions

File tree

.github/workflows/build_on_release.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ jobs:
2121
- name: Pull images
2222
run: docker compose pull
2323

24+
- name: (Latest) Build images
25+
run: docker compose build
26+
27+
- name: (Latest) Push images
28+
run: docker compose push
29+
2430
- name: Extract release tag
2531
id: extract_tag
2632
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
27-
28-
- name: Build and push images
33+
34+
- name: (Release Tag) Build images
2935
run: docker compose build
3036

31-
- name: Build and push images
37+
- name: (Release Tag) Push images
3238
run: docker compose push
39+

FRONTEND_V2/src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {ChangePassword} from "./pages/shared/ChangePassword.jsx";
3434
import {AdminProblemsPageImportFromPolygon} from "./pages/admin/problems/AdminProblemsPageImportFromPolygon.jsx";
3535
import ChangeLanguagePage from "./pages/shared/ChangeLanguagePage.jsx";
3636
import RegisterPage from "./pages/shared/RegisterPage.jsx";
37+
import {AdminProblemsPageImportFromJSON} from "./pages/admin/problems/AdminProblemsPageImportFromJSON.jsx";
3738

3839
import("../node_modules/bootstrap/dist/js/bootstrap.min.js")
3940

@@ -66,6 +67,7 @@ function App() {
6667
<Route path="/admin/problems" element={<AdminProblemsPage/>}/>
6768
<Route path="/admin/problems/create" element={<AdminProblemsPageCreate/>}/>
6869
<Route path="/admin/problems/import/polygon" element={<AdminProblemsPageImportFromPolygon/>}/>
70+
<Route path="/admin/problems/import/json" element={<AdminProblemsPageImportFromJSON/>}/>
6971
<Route path="/admin/problems/:probId/edit" element={<AdminProblemsPageEdit/>}/>
7072
<Route path="/admin/champs" element={<AdminChampsPage/>}/>
7173
<Route path="/admin/checkers" element={<AdminCheckersPage/>}/>

FRONTEND_V2/src/locales/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@
250250
"exampleOut": "Example output",
251251
"removeExample": "Remove example",
252252
"addExample": "Add example",
253-
"submit": "Submit"
253+
"submit": "Submit",
254+
"downloadAsFile": "Download as file",
255+
"importFromJSONFile": "Import from JSON",
256+
"uploadJadSONFile": "Upload json file",
257+
"addTask": "Add Task",
258+
"openOnPlatform": "Open task on platform"
254259
},
255260
"adminCheckers": {
256261
"checkers": "Checkers",

FRONTEND_V2/src/locales/ru.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@
250250
"exampleOut": "Выход примера",
251251
"removeExample": "Удалить пример",
252252
"addExample": "Добавить пример",
253-
"submit": "Отправить"
253+
"submit": "Отправить",
254+
"downloadAsFile": "Скачать файлом",
255+
"importFromJSONFile": "Импорт из JSON",
256+
"uploadJadSONFile": "Загрузить JSON",
257+
"addTask": "Добавить задачу",
258+
"openOnPlatform": "Открыть на платформе"
254259
},
255260
"adminCheckers": {
256261
"checkers": "Чекеры",

FRONTEND_V2/src/pages/admin/problems/AdminProblemsPage.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const AdminProblemsPage = () => {
6767
<div className='d-flex gap-2'>
6868
<Link to="/admin/problems/create" className="btn btn-success">{t('adminProblems.createProblem')}</Link>
6969
<Link to="/admin/problems/import/polygon" className="btn btn-info">{t('adminProblems.importFromPolygon')}</Link>
70+
<Link to="/admin/problems/import/json" className="btn btn-warning">{t('adminProblems.importFromJSONFile')}</Link>
7071
</div>
7172
</Card>
7273

FRONTEND_V2/src/pages/admin/problems/AdminProblemsPageEdit.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import constants from "../../../utils/consts.js";
1212
import {MasterForm} from "../../../components/forms/MasterForm.jsx";
1313
import {ProblemsForm} from "../../../components/form_impl/ProblemsForm.jsx";
1414
import {useTranslation} from 'react-i18next';
15+
import {downloadFile} from "../../../utils/download.js";
1516

1617
export const AdminProblemsPageEdit = () => {
1718

@@ -86,6 +87,10 @@ export const AdminProblemsPageEdit = () => {
8687
.then(() => navigate("/admin/problems"))
8788
};
8889

90+
const onDownloadBtnPressed = () => {
91+
downloadFile(`${data.id}-${data.name}-codebattles.json`,JSON.stringify(data))
92+
}
93+
8994
return (
9095
<>
9196
<UserLoginRequired/>
@@ -99,6 +104,7 @@ export const AdminProblemsPageEdit = () => {
99104
<Card>
100105
<div className="container mt-4">
101106
<h3>{t('adminProblems.editProblem')}</h3>
107+
<button className="btn btn-sm btn-info" onClick={onDownloadBtnPressed}>{t("adminProblems.downloadAsFile")}</button>
102108
<MasterForm form={form} onSubmit={onSubmit}>
103109
<ProblemsForm form={form} testsArray={testsArray} examplesArray={examplesArray}/>
104110
</MasterForm>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import BreadcrumbsElement from "../../../components/BreadcrumbsElement.jsx";
2+
import BreadcrumbsRoot from "../../../components/BreadcrumpsRoot.jsx";
3+
import UserLoginRequired from "../../../components/UserLoginRequired.jsx";
4+
import { AdminHeader } from "../../../components/AdminHeader.jsx";
5+
import Card from "../../../components/bootstrap/Card.jsx";
6+
import { useNavigate } from "react-router-dom";
7+
import { useForm } from "react-hook-form";
8+
import { useState } from "react";
9+
import { useTranslation } from "react-i18next";
10+
import { axiosInstance } from "../../../utils/settings.js";
11+
12+
export const AdminProblemsPageImportFromJSON = () => {
13+
const navigate = useNavigate();
14+
const { register, handleSubmit, reset } = useForm();
15+
16+
const [error, setError] = useState(false);
17+
const [done, setDone] = useState(false);
18+
19+
const [problemJSON, setProblemJSON] = useState(null);
20+
21+
const { t } = useTranslation();
22+
23+
const onSubmit = async (data) => {
24+
const file = data.jsonFile[0];
25+
if (!file) return;
26+
27+
try {
28+
// читаем json из файла
29+
const text = await file.text();
30+
const json = JSON.parse(text);
31+
32+
// отправляем на сервер
33+
const response = await axiosInstance.post("/api/problems", json);
34+
35+
// axiosInstance.post('/api/problems', sendData)
36+
// .then(() => navigate("/admin/champs"))
37+
38+
setProblemJSON(response.data);
39+
setError(false);
40+
setDone(true);
41+
} catch (e) {
42+
console.error(e);
43+
setError(true);
44+
setDone(false);
45+
}
46+
};
47+
48+
return (
49+
<>
50+
<UserLoginRequired />
51+
52+
<BreadcrumbsRoot>
53+
<BreadcrumbsElement name={t("adminProblems.problems")} url="/admin/problems" />
54+
<BreadcrumbsElement name={t("adminProblems.importFromPolygon")} />
55+
</BreadcrumbsRoot>
56+
57+
<AdminHeader />
58+
59+
<Card>
60+
<h2 className="mb-3">
61+
{t("adminProblems.importFromJSONFile")}
62+
</h2>
63+
<Card>
64+
<p>{t("adminProblems.uploadJadSONFile")}</p>
65+
</Card>
66+
<form onSubmit={handleSubmit(onSubmit)} className="mb-5">
67+
<div className="mb-3">
68+
<input
69+
type="file"
70+
accept=".json"
71+
{...register("jsonFile", { required: true })}
72+
className="form-control"
73+
/>
74+
</div>
75+
<div className="d-flex gap-2">
76+
<button type="submit" className="btn btn-primary">
77+
{t("adminProblems.addTask")}
78+
</button>
79+
<button
80+
type="button"
81+
onClick={() => {
82+
reset();
83+
setDone(false);
84+
setError(false);
85+
}}
86+
className="btn btn-outline-secondary"
87+
>
88+
{t("adminProblems.clear")}
89+
</button>
90+
</div>
91+
</form>
92+
{error && (
93+
<div className="alert alert-danger">
94+
{t("adminProblems.errorProcessingArchive")}
95+
</div>
96+
)}
97+
{done && (
98+
<>
99+
<div className="alert alert-success">
100+
{t("adminProblems.archiveProcessed", { name: problemJSON?.name })}
101+
</div>
102+
<button
103+
className="btn btn-primary"
104+
onClick={() => navigate(`/admin/problems/${problemJSON.id}/edit`)}
105+
>
106+
{t("adminProblems.openOnPlatform")}
107+
</button>
108+
</>
109+
)}
110+
</Card>
111+
</>
112+
);
113+
};

FRONTEND_V2/src/utils/download.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function downloadFile(filename, content, type = "text/plain") {
2+
const blob = new Blob([content], { type });
3+
const url = URL.createObjectURL(blob);
4+
5+
const a = document.createElement("a");
6+
a.href = url;
7+
a.download = filename;
8+
a.click();
9+
10+
URL.revokeObjectURL(url);
11+
}

0 commit comments

Comments
 (0)