diff --git a/src/api/persistance/load.ts b/src/api/persistance/load.ts index 58d57c386..e593e55f0 100644 --- a/src/api/persistance/load.ts +++ b/src/api/persistance/load.ts @@ -7,14 +7,18 @@ export class Load { static async project(project: DProject) { const projectUrl = this.url + `projects/${project.id}`; - await Load.element(`${projectUrl}/metamodels`); - await Load.element(`${projectUrl}/models`); - await Load.element(`${projectUrl}/packages`); - await Load.element(`${projectUrl}/classes`); - await Load.element(`${projectUrl}/enumerators`); - await Load.element(`${projectUrl}/attributes`); - await Load.element(`${projectUrl}/references`); - await Load.element(`${projectUrl}/literals`); + await Promise.all([ + Load.element(`${projectUrl}/metamodels`), + Load.element(`${projectUrl}/models`), + Load.element(`${projectUrl}/packages`), + Load.element(`${projectUrl}/classes`), + Load.element(`${projectUrl}/enumerators`), + Load.element(`${projectUrl}/attributes`), + Load.element(`${projectUrl}/references`), + Load.element(`${projectUrl}/literals`), + Load.element(`${projectUrl}/objects`), + Load.element(`${projectUrl}/values`) + ]); CreateElementAction.new(project); } diff --git a/src/api/persistance/save.ts b/src/api/persistance/save.ts index e906c004c..617ee39f5 100644 --- a/src/api/persistance/save.ts +++ b/src/api/persistance/save.ts @@ -1,4 +1,4 @@ -import type {LProject, LModel, LPackage, LClass, LEnumerator, LAttribute, LReference, LEnumLiteral} from '../../joiner'; +import type {LProject, LModel, LPackage, LClass, LEnumerator, LAttribute, LReference, LEnumLiteral, LObject, LValue} from '../../joiner'; import {U} from '../../joiner'; import Fetch from '../fetch'; @@ -9,19 +9,24 @@ export class Save { await Fetch.post(this.url + 'projects', U.json(project)); const projectUrl = this.url + `projects/${project.id}`; - await Save.elements(`${projectUrl}/metamodels`, project.metamodels); - await Save.elements(`${projectUrl}/models`, project.models); - await Save.elements(`${projectUrl}/packages`, project.metamodels.flatMap(m => m.packages)); - await Save.elements(`${projectUrl}/classes`, project.metamodels.flatMap(m => m.classes)); - await Save.elements(`${projectUrl}/enumerators`, project.metamodels.flatMap(m => m.enumerators)); - // await Save.elements(`${projectUrl}/attributes`, project.metamodels.flatMap(m => m.attributes)); - await Save.elements(`${projectUrl}/references`, project.metamodels.flatMap(m => m.references)); - // await Save.elements(`${projectUrl}/literals`, project.metamodels.flatMap(m => m.literals)); + await Promise.all([ + Save.elements(`${projectUrl}/metamodels`, project.metamodels), + Save.elements(`${projectUrl}/models`, project.models), + Save.elements(`${projectUrl}/packages`, project.metamodels.flatMap(m => m.packages)), + Save.elements(`${projectUrl}/classes`, project.metamodels.flatMap(m => m.classes)), + Save.elements(`${projectUrl}/enumerators`, project.metamodels.flatMap(m => m.enumerators)), + Save.elements(`${projectUrl}/attributes`, project.metamodels.flatMap(m => m.attributes)), + Save.elements(`${projectUrl}/references`, project.metamodels.flatMap(m => m.references)), + Save.elements(`${projectUrl}/literals`, project.metamodels.flatMap(m => m.literals)), + Save.elements(`${projectUrl}/objects`, project.models.flatMap(m => m.objects)), + Save.elements(`${projectUrl}/values`, project.models.flatMap(m => m.values)) + ]); + // todo: fix metamodels.attributes, metamodels.literals and models.values (done without sub-checking) } - private static async elements(url: string, elements: (LModel|LPackage|LClass|LEnumerator|LAttribute|LReference|LEnumLiteral)[]): Promise { + private static async elements(url: string, elements: (LModel|LPackage|LClass|LEnumerator|LAttribute|LReference|LEnumLiteral|LObject|LValue)[]): Promise { + /* Override */ await Fetch.delete(url); - console.log('DEBUGGING', elements); for(let element of elements) await Fetch.post(url, U.json(element)); } diff --git a/src/model/logicWrapper/LModelElement.tsx b/src/model/logicWrapper/LModelElement.tsx index e9ac251ec..fc3916cd9 100644 --- a/src/model/logicWrapper/LModelElement.tsx +++ b/src/model/logicWrapper/LModelElement.tsx @@ -3270,6 +3270,7 @@ export class LModel = any, C extends Contex attributes!: LAttribute[]; references!: LReference[]; literals!: LEnumLiteral[]; + values!: LValue[]; allSubAnnotations!: LAnnotation[]; allSubPackages!: LPackage[]; allSubObjects!: LObject[]; @@ -3596,6 +3597,20 @@ export class LModel = any, C extends Contex protected get_getPackageByUri(context: Context): this["getPackageByUri"] { return (uri: string)=>context.proxyObject.allSubPackages.filter((p)=>p.uri === uri)[0]; } + + /* See src/api/persistance/save.ts */ + + protected get_attributes(context: Context): this['attributes'] { + return context.proxyObject.classes.flatMap(c => c.attributes); + } + + protected get_literals(context: Context): this['literals'] { + return context.proxyObject.enumerators.flatMap(e => e.literals); + } + + protected get_values(context: Context): this['values'] { + return context.proxyObject.objects.flatMap(o => o.features); + } } RuntimeAccessibleClass.set_extend(DNamedElement, DModel); RuntimeAccessibleClass.set_extend(LNamedElement, LModel);