trigger screen
This commit is contained in:
parent
fbcfba3948
commit
d10a829882
30 changed files with 19101 additions and 26 deletions
80
ui/src/features/trigger/presentation/logic/trigger_store.ts
Normal file
80
ui/src/features/trigger/presentation/logic/trigger_store.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
import { makeAutoObservable } from "mobx";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { TriggerType } from "../../model/trigger_model";
|
||||
import { TriggerRepository } from "../../data/trigger_repository";
|
||||
import { TriggerViewModel } from "../../model/trigger_form_view_model";
|
||||
|
||||
class TriggerStore {
|
||||
constructor(repository: TriggerRepository) {
|
||||
this.triggerType = TriggerType.FILE;
|
||||
this.repository = repository;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
triggerType: TriggerType;
|
||||
codeTriggerValue = "";
|
||||
triggers: TriggerViewModel[] = [];
|
||||
|
||||
repository: TriggerRepository;
|
||||
|
||||
deleteItem(id: string): void {
|
||||
this.triggers = this.triggers.filter((el) => el.id !== id);
|
||||
console.log(id);
|
||||
}
|
||||
|
||||
getTriggerType = (): boolean => {
|
||||
return this.triggerType === TriggerType.FILE;
|
||||
};
|
||||
setTriggerType = (): void => {
|
||||
this.triggers = [];
|
||||
if (this.triggerType === TriggerType.FILE) {
|
||||
this.triggerType = TriggerType.PROCESS;
|
||||
return;
|
||||
}
|
||||
this.triggerType = TriggerType.FILE;
|
||||
};
|
||||
getTriggerDescription = (): string => {
|
||||
return this.triggerType === TriggerType.FILE
|
||||
? TriggerType.FILE
|
||||
: TriggerType.PROCESS;
|
||||
};
|
||||
pushTrigger = (value: string, type: TriggerType): void => {
|
||||
console.log(value);
|
||||
this.triggers.push({
|
||||
value: value,
|
||||
id: uuidv4(),
|
||||
type: type,
|
||||
});
|
||||
};
|
||||
|
||||
writeNewTrigger(v: string | undefined): void {
|
||||
if (v === undefined) {
|
||||
throw new Error("Editor Value is undefined");
|
||||
}
|
||||
this.codeTriggerValue = v;
|
||||
}
|
||||
clearTriggerCode(): void {
|
||||
this.codeTriggerValue = "";
|
||||
}
|
||||
saveCode(): void {
|
||||
if (this.codeTriggerValue !== "") {
|
||||
this.triggers.push({
|
||||
id: uuidv4(),
|
||||
value: this.codeTriggerValue,
|
||||
type: TriggerType.PROCESS,
|
||||
});
|
||||
|
||||
this.codeTriggerValue = "";
|
||||
}
|
||||
}
|
||||
async saveResult(): Promise<void> {
|
||||
await this.repository.save({
|
||||
type: this.getTriggerDescription(),
|
||||
value: this.triggers.map((el) => {
|
||||
return el.value;
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const triggerStore = new TriggerStore(new TriggerRepository());
|
Loading…
Add table
Add a link
Reference in a new issue