Angularで作るER DIAGRAM TOOL – 第十一回 リレーションシップモーダルの作成と開く処理

First of all, we added an end point to H2 of Model last time,
I tried to create a connection,
Change it to open a modal without creating a connection.

(1) Creating a relationship modal


· Source_model is the source model and target_model is the destination model.
· Source_model_display_schema, target_model_display_schema is the column content to display.

For category has many books,
If you select a title for source_model_display_schema, you can choose a category title by pulldown when choosing a category.

For one-to-many, target_model_display_schema is unnecessary.

· Call dataService.addOneToManyRelation () or dataService.addManyToManyRelation () (not implemented yet) depending on relation_type.



· For now, add empty addOneToManyRelation () and addManyToManyRelation ()


· Import and register ModalRelationComponent

(2) Modify the processing after dropping the Model – H2 endpoint

First, modify the connection creation part to a modal call.


· Import of BsModalService, BsModalRef, ModalRelationComponent.
· DI of BsModalService
· Addition of member variable BsModalRef
Added option to addEndpoint

beforeDrop: (params) => {} — Occurred immediately after dropping the endpoint. Open a modal at this timing,
By return false, the subsequent processing (creation of connection) is canceled.

· The data to modally give is SourceModel and TargetModel. Because you can get the ID of SourceModel element and TargetModel element from param of beforeDrop,
We will implement the function to retrieve the model from the ID name of the element in the data class.


Implement getModelByElementH2Id ()

Now, by dragging and dropping the endPoint of model-h2, the relation modal opens.
※ Relation From modal to the other is not yet implemented.

Before implementing the relation modal destination, there is one remaining bug.
When deleting a model, endPoint will remain.


(3) Implement the function to delete the endPoint attached to the model when deleting the model


· Execute jsPlumbService.destroyModel () (unimplemented) on deletion (ngOnDestroy ())


· Implement destroyModel ()

Now, endPoint is automatically deleted when model is deleted.

Next time I will implement one-to-many relation creation.