aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor/EditorStore.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-12 21:59:50 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-12 21:59:50 +0200
commita2a4696fdbd6440269d576aeba7b25b2ea40d9bf (patch)
tree5cbdf981a51a09fbe162e7748555d213ca518ff4 /subprojects/frontend/src/editor/EditorStore.ts
parentfix: avoid GLOP error message on stderr (diff)
downloadrefinery-a2a4696fdbd6440269d576aeba7b25b2ea40d9bf.tar.gz
refinery-a2a4696fdbd6440269d576aeba7b25b2ea40d9bf.tar.zst
refinery-a2a4696fdbd6440269d576aeba7b25b2ea40d9bf.zip
feat: connect model generator to UI
Diffstat (limited to 'subprojects/frontend/src/editor/EditorStore.ts')
-rw-r--r--subprojects/frontend/src/editor/EditorStore.ts85
1 files changed, 85 insertions, 0 deletions
diff --git a/subprojects/frontend/src/editor/EditorStore.ts b/subprojects/frontend/src/editor/EditorStore.ts
index b5989ad1..f9a9a7da 100644
--- a/subprojects/frontend/src/editor/EditorStore.ts
+++ b/subprojects/frontend/src/editor/EditorStore.ts
@@ -32,6 +32,7 @@ import type XtextClient from '../xtext/XtextClient';
32import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults'; 32import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults';
33 33
34import EditorErrors from './EditorErrors'; 34import EditorErrors from './EditorErrors';
35import GeneratedModelStore from './GeneratedModelStore';
35import LintPanelStore from './LintPanelStore'; 36import LintPanelStore from './LintPanelStore';
36import SearchPanelStore from './SearchPanelStore'; 37import SearchPanelStore from './SearchPanelStore';
37import createEditorState from './createEditorState'; 38import createEditorState from './createEditorState';
@@ -69,6 +70,10 @@ export default class EditorStore {
69 70
70 graph: GraphStore; 71 graph: GraphStore;
71 72
73 generatedModels = new Map<string, GeneratedModelStore>();
74
75 selectedGeneratedModel: string | undefined;
76
72 constructor(initialValue: string, pwaStore: PWAStore) { 77 constructor(initialValue: string, pwaStore: PWAStore) {
73 this.id = nanoid(); 78 this.id = nanoid();
74 this.state = createEditorState(initialValue, this); 79 this.state = createEditorState(initialValue, this);
@@ -307,4 +312,84 @@ export default class EditorStore {
307 this.delayedErrors.dispose(); 312 this.delayedErrors.dispose();
308 this.disposed = true; 313 this.disposed = true;
309 } 314 }
315
316 startModelGeneration(): void {
317 this.client
318 ?.startModelGeneration()
319 ?.catch((error) => log.error('Could not start model generation', error));
320 }
321
322 addGeneratedModel(uuid: string): void {
323 this.generatedModels.set(uuid, new GeneratedModelStore());
324 this.selectGeneratedModel(uuid);
325 }
326
327 cancelModelGeneration(): void {
328 this.client
329 ?.cancelModelGeneration()
330 ?.catch((error) => log.error('Could not start model generation', error));
331 }
332
333 selectGeneratedModel(uuid: string | undefined): void {
334 if (uuid === undefined) {
335 this.selectedGeneratedModel = uuid;
336 return;
337 }
338 if (this.generatedModels.has(uuid)) {
339 this.selectedGeneratedModel = uuid;
340 return;
341 }
342 this.selectedGeneratedModel = undefined;
343 }
344
345 deleteGeneratedModel(uuid: string | undefined): void {
346 if (uuid === undefined) {
347 return;
348 }
349 if (this.selectedGeneratedModel === uuid) {
350 let previous: string | undefined;
351 let found: string | undefined;
352 this.generatedModels.forEach((_value, key) => {
353 if (key === uuid) {
354 found = previous;
355 }
356 previous = key;
357 });
358 this.selectGeneratedModel(found);
359 }
360 const generatedModel = this.generatedModels.get(uuid);
361 if (generatedModel !== undefined && generatedModel.running) {
362 this.cancelModelGeneration();
363 }
364 this.generatedModels.delete(uuid);
365 }
366
367 modelGenerationCancelled(): void {
368 this.generatedModels.forEach((value) =>
369 value.setError('Model generation cancelled'),
370 );
371 }
372
373 setGeneratedModelMessage(uuid: string, message: string): void {
374 this.generatedModels.get(uuid)?.setMessage(message);
375 }
376
377 setGeneratedModelError(uuid: string, message: string): void {
378 this.generatedModels.get(uuid)?.setError(message);
379 }
380
381 setGeneratedModelSemantics(
382 uuid: string,
383 semantics: SemanticsSuccessResult,
384 ): void {
385 this.generatedModels.get(uuid)?.setSemantics(semantics);
386 }
387
388 get generating(): boolean {
389 let generating = false;
390 this.generatedModels.forEach((value) => {
391 generating = generating || value.running;
392 });
393 return generating;
394 }
310} 395}