-
Notifications
You must be signed in to change notification settings - Fork 0
/
umlFactory.js
144 lines (132 loc) · 4.6 KB
/
umlFactory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// umlFactory.js
const { translateSQLToERDType } = require('./utils/utils');
// Generic function to create a diagram
function createDiagram({ idType, parent, name, defaultDiagram = false }) {
return app.factory.createDiagram({
id: idType, // e.g., "UMLClassDiagram", "ERDClassDiagram"
parent: parent,
diagramInitializer: function (dgm) {
dgm.name = name; // Set the name of the diagram
dgm.defaultDiagram = defaultDiagram; // Set if it's the default diagram
}
});
}
// Generic function to create a model (e.g., UMLModel, ERDModel)
function createModel({ idType, parent, name }) {
return app.factory.createModel({
id: idType, // e.g., "UMLModel", "ERDModel"
parent: parent,
modelInitializer: function (model) {
model.name = name; // Set the name of the model
}
});
}
// Generic function to create a model and view, allowing one or many key-value pairs
function createModelAndView({ idType, parent, diagram, dictionary = {} }) {
return app.factory.createModelAndView({
id: idType, // e.g., "UMLClass" or "ERDEntity"
parent: parent,
diagram: diagram,
modelInitializer: function (elem) {
Object.entries(dictionary).forEach(([key, value]) => {
elem[key] = value;
});
}
});
}
function createDirectedModelAndView({ idType, parent, diagram, from, to, dictionary = {} }) {
return app.factory.createModelAndView({
id: idType, // e.g., "UMLClass" or "ERDEntity"
parent: parent,
diagram: diagram,
tailView: from,
headView: to,
tailModel: from.model,
headModel: to.model,
modelInitializer: function (elem) {
Object.entries(dictionary).forEach(([key, value]) => {
elem[key] = value;
});
}
});
}
// Generic function to create a model and view with a position, allowing one or many key-value pairs
function createPositionedModelAndView({ idType, parent, diagram, x1, y1, x2, y2, dictionary = {} }) {
return app.factory.createModelAndView({
id: idType,
parent: parent,
diagram: diagram,
x1: x1,
y1: y1,
x2: x2,
y2: y2,
modelInitializer: function (elem) {
Object.entries(dictionary).forEach(([key, value]) => {
elem[key] = value;
});
}
});
}
// Generic function to create a model and view with a position and directed connection, allowing one or many key-value pairs
function createPositionedDirectedModelAndView({ idType, parent, diagram, x1, y1, x2, y2, from, to, dictionary = {} }) {
return app.factory.createModelAndView({
id: idType,
parent: parent,
diagram: diagram,
x1: x1,
y1: y1,
x2: x2,
y2: y2,
tailView: from,
headView: to,
tailModel: from.model,
headModel: to.model,
modelInitializer: function (elem) {
Object.entries(dictionary).forEach(([key, value]) => {
elem[key] = value;
});
}
});
}
// Generic function to add elements (e.g., attributes, methods) to a UML class
function addClassElement(elemType, parent, field, inElements) {
app.factory.createModel({
id: elemType, // e.g., "UMLAttribute", "UMLOperation"
parent: parent,
field: field, // e.g., "attributes" or "operations"
modelInitializer: function (elem) {
elem.name = inElements.name;
elem.type = inElements.type || inElements.returnType;
elem.visibility = inElements.visibility;
}
});
}
// Generic function to add elements (columns) to an ERD entity
function addERDElement(elemType, parent, field, inElements) {
var keys = inElements.keys || [];
var properties = inElements.properties || {};
app.factory.createModel({
id: elemType,
parent: parent,
field: field,
modelInitializer: function (elem) {
elem.name = inElements.name;
elem.type = translateSQLToERDType(inElements.type);
elem.length = properties.length || '';
elem.primaryKey = keys.includes('PK');
elem.foreignKey = keys.includes('FK');
elem.unique = keys.includes('UK');
elem.nullable = properties.nullable || false;
}
});
}
module.exports = {
createDiagram,
createModel,
createModelAndView,
createDirectedModelAndView,
createPositionedModelAndView,
createPositionedDirectedModelAndView,
addClassElement,
addERDElement
};