This commit is contained in:
IDONTSUDO 2024-05-02 12:40:20 +03:00
parent f0ed478b36
commit 8bc943de2c
16 changed files with 252 additions and 134 deletions

View file

@ -1,6 +1,6 @@
import makeAutoObservable from "mobx-store-inheritance";
import { CoreThreeRepository, UserData } from "../../../core/repository/core_three_repository";
import { Object3D, Vector2, Vector3 } from "three";
import { CoreThreeRepository } from "../../../core/repository/core_three_repository";
import { Object3D, Vector2 } from "three";
import { HttpError } from "../../../core/repository/http_repository";
import { UiErrorState } from "../../../core/store/base_store";
import { UiBaseError } from "../../../core/model/ui_base_error";

View file

@ -5,6 +5,7 @@ import { CoreText, CoreTextType } from "../../core/ui/text/text";
import { ProcessStatus } from "../dataset/dataset_model";
import { IMenuItem } from "../dataset/card_dataset";
import type { MenuProps } from "antd";
import { match } from "ts-pattern";
export interface ISkillCardProps {
processStatus?: string;
@ -16,7 +17,9 @@ export interface ISkillCardProps {
continueOnClick?: (id: string) => void;
empty: boolean;
onEdit?: (id: string) => void;
epoch?: number;
onDelete?: (id: string) => void;
datasetName?: string;
}
export const SkillCard = (props: ISkillCardProps) => {
@ -34,7 +37,7 @@ export const SkillCard = (props: ISkillCardProps) => {
name: "Удалить",
},
];
const items: MenuProps["items"] = menu.map((el, index) => {
return {
key: String(index),
@ -58,92 +61,132 @@ export const SkillCard = (props: ISkillCardProps) => {
justifyContent: "space-between",
}}
>
{props.empty ? (
<div
onClick={() => {
if (props.empty && props.emptyOnClick) props.emptyOnClick();
}}
style={{ display: "flex", justifyContent: "center", alignItems: "center" }}
>
<Icon type="PlusCircle" />
</div>
) : (
<>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<CoreText text={props.name ?? ""} type={CoreTextType.medium} />
<Dropdown overlayStyle={{ backgroundColor: "rgba(243, 237, 247, 1)" }} menu={{ items }}>
<div>
<Icon type="Settings" />
</div>
</Dropdown>
</div>
<div style={{ height: 10 }} />
<div>
{props.processStatus === ProcessStatus.NONE ? (
<>
<CoreButton
text="старт"
onClick={() => {
if (props.startOnClick && props.id) props.startOnClick(props.id);
}}
/>
<div style={{ height: 10 }} />
<CoreButton
text="продолжить"
onClick={() => {
if (props.continueOnClick && props.id) props.continueOnClick(props.id);
}}
/>
</>
) : null}
{props.processStatus === ProcessStatus.END ? (
<>
<CoreButton
text="старт"
onClick={() => {
if (props.startOnClick && props.id) props.startOnClick(props.id);
}}
/>
<div style={{ height: 10 }} />
<CoreButton
text="продолжить"
onClick={() => {
if (props.continueOnClick && props.id) props.continueOnClick(props.id);
}}
/>
</>
) : null}
{props.processStatus === ProcessStatus.RUN ? (
<>
<CoreButton
onClick={() => {
// if (props.type.isEqual(CardDataSetType.COMPLETED) && props.onClickButton && props.id) {
// props.onClickButton(props.id);
}}
block={true}
text="Стоп"
/>
</>
) : null}
{props.processStatus === ProcessStatus.ERROR ? (
<CoreButton
{match(props.empty)
.with(true, () => (
<>
<div
onClick={() => {
if (props.empty && props.emptyOnClick) props.emptyOnClick();
}}
style={{ display: "flex", justifyContent: "center", alignItems: "center" }}
>
<Icon type="PlusCircle" />
</div>
</>
))
.with(false, () => (
<>
<>
<div
style={{
backgroundColor: "red",
display: "flex",
justifyContent: "space-between",
}}
onClick={() => {}}
filled={true}
text="Ошибка"
/>
) : null}
</div>
</>
)}
>
<div style={{ display: "flex", flexDirection: "column", margin: 10 }}>
<CoreText text={props.name ?? ""} type={CoreTextType.medium} />
<div style={{ height: 10 }} />
<CoreText text={"Количество эпох: " + props.epoch?.toString() ?? ""} type={CoreTextType.small} />
<CoreText text={"Датасет: " + props.datasetName ?? ""} type={CoreTextType.small} />
</div>
<div style={{ height: 10 }}>
<Dropdown overlayStyle={{ backgroundColor: "rgba(243, 237, 247, 1)" }} menu={{ items }}>
<div>
<Icon type="Settings" />
</div>
</Dropdown>
</div>
</div>
<div style={{ height: 10 }} />
<div>
{match(props.processStatus)
.with(ProcessStatus.END, () => (
<>
<CoreButton
text="дообучение"
onClick={() => {
if (props.startOnClick && props.id) props.startOnClick(props.id);
}}
/>
<CoreButton
text="заново"
onClick={() => {
if (props.startOnClick && props.id) props.startOnClick(props.id);
}}
/>
</>
))
.with(ProcessStatus.NONE, () => (
<>
<CoreButton
text="старт"
onClick={() => {
if (props.startOnClick && props.id) props.startOnClick(props.id);
}}
/>
</>
))
.otherwise(() => (
<></>
))}
</div>
</>
</>
))
.otherwise(() => (
<></>
))}
</div>
);
};
// {props.processStatus === ProcessStatus.NONE ? (
// <>
// <div style={{ height: 10 }} />
// <CoreButton
// text="продолжить"
// onClick={() => {
// if (props.continueOnClick && props.id) props.continueOnClick(props.id);
// }}
// />
// </>
// ) : null}
// {props.processStatus === ProcessStatus.END ? (
// <>
// <CoreButton
// text="старт"
// onClick={() => {
// if (props.startOnClick && props.id) props.startOnClick(props.id);
// }}
// />
// <div style={{ height: 10 }} />
// <CoreButton
// text="продолжить"
// onClick={() => {
// if (props.continueOnClick && props.id) props.continueOnClick(props.id);
// }}
// />
// </>
// ) : null}
// {props.processStatus === ProcessStatus.RUN ? (
// <>
// <CoreButton
// onClick={() => {
// // if (props.type.isEqual(CardDataSetType.COMPLETED) && props.onClickButton && props.id) {
// // props.onClickButton(props.id);
// }}
// block={true}
// text="Стоп"
// />
// </>
// ) : null}
// {props.processStatus === ProcessStatus.ERROR ? (
// <CoreButton
// style={{
// backgroundColor: "red",
// }}
// onClick={() => {}}
// filled={true}
// text="Ошибка"
// />
// ) : null}

View file

@ -1,10 +1,22 @@
import makeAutoObservable from "mobx-store-inheritance";
import { Result } from "../../core/helper/result";
import { ISkils } from "./skills_repository";
export class SkillModel {
constructor(public name: string, public datasetId: string, public project: string, public epoch: number) {
numberOfTrainedEpochs?: number;
constructor(
public name: string,
public datasetId: string,
public project: string,
public epoch: number,
numberOfTrainedEpochs?: number
) {
this.numberOfTrainedEpochs = numberOfTrainedEpochs;
makeAutoObservable(this);
}
static fromISkill(model: ISkils) {
return new SkillModel(model.name, model.datasetId._id, model.project._id, model.epoch, model.numberOfTrainedEpochs);
}
static empty() {
return new SkillModel("", "", "", 0);
}

View file

@ -8,9 +8,11 @@ export interface ISkils {
_id: string;
name: string;
processStatus: string;
epoch:number;
isFinished: boolean;
datasetId: any;
project: any;
numberOfTrainedEpochs:number;
__v: number;
}

View file

@ -48,12 +48,31 @@ export const SkillScreen = observer(() => {
}}
>
{store.skils?.map((el) => (
<SkillCard id={el._id} isFinished={el.isFinished} name={el.name} processStatus={el.processStatus} empty={false} startOnClick={(id) => store.execSkill(id)} continueOnClick={(id) => store.continueSkill(id)} />
<SkillCard
datasetName={el.datasetId.name}
id={el._id}
isFinished={el.isFinished}
name={el.name}
processStatus={el.processStatus}
empty={false}
epoch={el.numberOfTrainedEpochs}
startOnClick={(id) => store.execSkill(id)}
continueOnClick={(id) => store.continueSkill(id)}
onEdit={(id) => store.editSkill(id)}
/>
))}
<SkillCard empty={true} emptyOnClick={() => store.edtDrawer(DrawersSkill.NEW_SKILL, true)} />
</div>
}
/>
<Drawer
title={store.titleDrawer}
destroyOnClose={true}
onClose={() => store.edtDrawer(DrawersSkill.EDIT_SKILL, false)}
open={store.drawers.find((el) => el.name === DrawersSkill.EDIT_SKILL)?.status}
>
<CoreInput value={(store.skill.epoch ?? "").toString()} label={"добавить эпох"} />
</Drawer>
<Drawer
title={store.titleDrawer}
destroyOnClose={true}

View file

@ -11,9 +11,15 @@ import { SkillModel } from "./skill_model";
export enum DrawersSkill {
NEW_SKILL = "Новый навык",
EDIT_SKILL = "Редактировать навык",
}
export class SkillStore extends UiErrorState<HttpError> {
editSkill(id: string): void {
this.skill = SkillModel.fromISkill(this.getSkillById(id) as ISkils);
this.edtDrawer(DrawersSkill.EDIT_SKILL, true);
}
drawers: Drawer[];
skillsHttpRepository: SkillsHttpRepository;
skils?: ISkils[];
@ -66,17 +72,19 @@ export class SkillStore extends UiErrorState<HttpError> {
}
changeEpoch(epoch: number) {
this.skill.epoch = epoch;
}
saveSkill() {
this.skill.project = this.activeProjectId?.id ?? "";
this.skill.valid().fold(
async (model) => {
(await this.skillsHttpRepository.addNewSkill(model)).fold(
(s) => {
async (s) => {
message.success("Новый ");
this.skill = SkillModel.empty();
await this.mapOk("skils", this.skillsHttpRepository.getAllSkills());
},
(e) => message.error(e.message)
async (e) => message.error(e.message)
);
},
async (e) => message.error(e)