diff --git a/frontend/src/components/blocks/common/factory.tsx b/frontend/src/components/blocks/common/factory.tsx index cc804af6..f0414036 100644 --- a/frontend/src/components/blocks/common/factory.tsx +++ b/frontend/src/components/blocks/common/factory.tsx @@ -3,7 +3,7 @@ import { LinkModel, NodeModel, PortModel } from "@projectstorm/react-diagrams"; import { DefaultPortModel } from "@projectstorm/react-diagrams-defaults"; import { RightAngleLinkModel } from "@projectstorm/react-diagrams-routing"; import { PortTypes, ProjectInfo } from '../../../core/constants'; -import { ProjectDesign } from '../../../core/serialiser/interfaces'; +import { Dependency, ProjectDesign } from '../../../core/serialiser/interfaces'; import createCodeDialog from '../../dialogs/code-block-dialog'; import createConstantDialog from "../../dialogs/constant-block-dialog"; import createIODialog from '../../dialogs/input-output-block-dialog'; @@ -156,10 +156,13 @@ export const loadPackage = (jsonModel: any) => { const model = jsonModel.editor; const design = jsonModel.design as ProjectDesign; const info = jsonModel.package as ProjectInfo; + const dependencies = jsonModel.dependencies as Dependency; + return new PackageBlockModel({ model: model, design: design, - info: info + info: info, + dependencies: dependencies }); } diff --git a/frontend/src/components/blocks/package/package-model.ts b/frontend/src/components/blocks/package/package-model.ts index bd654e99..eba65a03 100644 --- a/frontend/src/components/blocks/package/package-model.ts +++ b/frontend/src/components/blocks/package/package-model.ts @@ -1,7 +1,7 @@ import BaseModel from "../common/base-model"; import { NodeModelGenerics, PortModelAlignment } from "@projectstorm/react-diagrams"; import { BaseModelOptions, DeserializeEvent } from '@projectstorm/react-canvas-core'; -import { ProjectDesign } from "../../../core/serialiser/interfaces"; +import { Dependency, ProjectDesign } from "../../../core/serialiser/interfaces"; import { createPortModel } from "../common/factory"; import { PortTypes, ProjectInfo } from "../../../core/constants"; @@ -19,6 +19,7 @@ export interface PackageBlockModelOptions extends BaseModelOptions { design: ProjectDesign; model: any; info: ProjectInfo; + dependencies: Dependency; } /** @@ -31,6 +32,7 @@ export class PackageBlockModel extends BaseModel { - console.log("node",node,node.getType()) if (node instanceof BaseModel) { - const block = { + const block: Block = { id: node.getID(), type: node.getType(), data: node.getData(), @@ -92,22 +88,23 @@ function getBlocksAndDependencies(model: DiagramModel) { x: node.getPosition().x, y: node.getPosition().y } - } - // If a node is of Package type then its included in Dependencies + }; + if (node instanceof PackageBlockModel) { - // The type is changed to a random string because a single package can be used multiple times - // with its own parameters and data. So making it a unique ID prevents any interference of data. - block.type = makeid(40); - // Add the design and package info of the package blocks under dependencies + const packageBlockModel = node as PackageBlockModel; + block.type = makeid(40); // Generate a unique identifier for the dependency + + // Add the package information, design, and nested dependencies to the dependencies object dependencies[block.type] = { package: node.info, - design: node.design + design: node.design, + dependencies: node.dependencies } - } + blocks.push(block); } - }) - + }); + // Return the blocks and dependencies as an object return { blocks: blocks, dependencies: dependencies }; -} \ No newline at end of file +} diff --git a/frontend/src/core/serialiser/interfaces.ts b/frontend/src/core/serialiser/interfaces.ts index b1bc1188..c516b521 100644 --- a/frontend/src/core/serialiser/interfaces.ts +++ b/frontend/src/core/serialiser/interfaces.ts @@ -67,6 +67,7 @@ export interface ProjectDesign { export interface Dependency { // Meta info about project (model) package: ProjectInfo; - // Data about blocks and connections. + // Data about blocks, connections and nested dependency. design: ProjectDesign; + dependencies: Dependency; } \ No newline at end of file