-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathedit.html
273 lines (244 loc) · 10.2 KB
/
edit.html
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="UML, TXT, Java">
<meta name="description" content="Convert TXT to UML">
<meta name="author" content="Matheus Gaudencio">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Modeligado - Text to UML</title>
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.css">
<link href="https://fonts.googleapis.com/css2?family=Russo+One&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.1/theme/eclipse.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/release/go.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js"></script>
<script src= "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.js"></script>
<script type="module">
import { init, create, ClickHistory } from "./gojs.js"
import { init as initSequence, load as createSequence } from "./sequence_diagram.js"
import { parse, exportPng, exportSvg, exportTxt, exportJava } from "./modeligado.js"
import { clickControl } from "./flow.js"
import { load, loadExample, save } from "./modeligado_storage.js"
const sequenceGraph = {
"class": "go.GraphLinksModel",
"nodeDataArray": [
{ "key": "Main", "text": "Main", "isGroup": true, "loc": "0 0", "duration": 20 },
],
"linkDataArray": [],
}
let autoUpdate = true
let myDiagram = null
let sequenceDiagram = null
let timeout = null
let errorDiv = null
let textArea = null
let codemirrorEditor = null
let trace = false
window.showTrace = function() {
if (trace) {
document.getElementById("traceButton").textContent = "☐ Trace"
codemirrorEditor.getWrapperElement().style['display'] = ""
document.getElementById("trace").style['display'] = "none"
trace = false
} else {
document.getElementById("traceButton").textContent = "☑ Trace"
codemirrorEditor.getWrapperElement().style['display'] = "none"
document.getElementById("trace").style['display'] = "flex"
document.getElementById("trace").style['flex-direction'] = "column"
trace = true
}
}
window.enableAutoUpdate = function() {
if (autoUpdate) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
document.getElementById("autoUpdateButton").textContent = "☐ Auto Update"
} else {
window.convert()
document.getElementById("autoUpdateButton").textContent = "☑ Auto Update"
}
autoUpdate = !autoUpdate
}
const convert = function() {
let text = codemirrorEditor.getValue()
let nodeName = []
let linkData = []
try {
let missingClasses = parse(text, nodeName, linkData)
nodeName.push(...missingClasses)
errorDiv.textContent = "No errors detected..."
} catch (err) {
errorDiv.textContent = err.message
return;
}
window.saveLocal()
create(myDiagram, nodeName, linkData)
}
window.convert = () => {convert(); saveLocal()}
window.saveLocal = () => save(codemirrorEditor.getValue())
window.loadExample = () => {codemirrorEditor.setValue(loadExample()); convert()}
window.load = () => {codemirrorEditor.setValue(load()); convert()}
window.exportPng = () => {exportPng(myDiagram, "uml.png")}
window.exportSvg = () => {exportSvg(myDiagram, "uml.svg")}
window.exportTxt = () => {exportTxt(codemirrorEditor.getValue(), "uml.txt")}
window.exportJava = () => {exportJava(codemirrorEditor.getValue(), 'project.zip')}
window.exportSvg = () => {exportSvg(myDiagram, "uml.svg")}
let clickHistory = new ClickHistory()
window.clickHistory = clickHistory
clickHistory.subscribe(() => {
let data = ""
let pos = 150
let time = 0
let keys = ["Main"]
const sequenceGraph = {
"class": "go.GraphLinksModel",
"nodeDataArray": [
{ "key": "Main", "text": "Main", "isGroup": true, "loc": "0 0", "duration": 20 },
],
"linkDataArray": [],
}
clickHistory.history.forEach((elem) => {
if(!keys.includes(elem[1].className)) {
sequenceGraph.nodeDataArray.push({
"key": elem[1].className,
"text": elem[1].className,
"isGroup": true,
"loc": `${pos} 0`,
"duration": 20,
})
keys.push(elem[1].className)
pos = pos + 150
}
})
for(let i = 0; i < clickHistory.history.length; i++) {
const isReturn = clickHistory.history[i][1].type === 'Retorno'
const origin = isReturn
? clickHistory.history[i][1].parameters[0].origin
: (i > 0
? (clickHistory.history.at(i - 1)[1].type === 'Retorno'
? (
clickHistory.history[i - 1][1].parameters[0].destination > -1
? clickHistory.history.at(clickHistory.history[i - 1][1].parameters[0].destination)[1].className
: 'Main'
)
: clickHistory.history.at(i - 1)[1].className
) : keys[0])
const destination = clickHistory.history.at(i)[1]
sequenceGraph.linkDataArray.push({
"from": origin,
"to": isReturn
? (
clickHistory.history[i][1].parameters[0].destination > -1
? clickHistory.history.at(clickHistory.history[i][1].parameters[0].destination)[1].className
: 'Main'
)
: (destination ? destination.className : 'Main'),
"text": isReturn ? 'Retorno' : destination.name,
"time": time
})
time = time + 1.5
}
clickHistory.history.forEach((hist, i) => {
const isReturn = clickHistory.history[i][1].type === 'Retorno'
const op = hist[0]
const h = hist[1]
let elem = h.className + "." + h.name
if (op == "method") {
if (h["name"] === h["className"]) { // constructor
elem += "()"
} else { // method
elem += "("
if (h.hasOwnProperty("parameters")) {
for (const p of h.parameters) {
elem += p.name + ": " + p.name + ", "
}
elem = elem.substring(0, elem.length - 2)
}
elem += ")"
}
}
data += "<div class=\"elem\">" +
"<button style=\"background-color: #E9E9E9; border-radius: 6px; padding: 4px;\" onClick=\"clickHistory.moveUp(" + i + ")\">UP</button> " +
"<button style=\"background-color: #E9E9E9; border-radius: 6px; padding: 4px;\" onClick=\"clickHistory.moveDown(" + i + ")\">DOWN</button> " +
"<button style=\"background-color: #E9E9E9; border-radius: 6px; padding: 4px;\" onClick=\"clickHistory.delete(" + i + ")\">DELETE</button> "
if (hist[0] === 'method' && !isReturn && !clickHistory.returneds.includes(i))
data += "<button style=\"background-color: #E9E9E9; border-radius: 6px; padding: 4px;\" onClick=\"clickHistory.returnFunction(" + i + ")\">RETORNAR</button> "
data += "<span>" + elem.replace(">", ">").replace("<", "<") + "</span>" + "</div>"
})
document.getElementById("traceInput").innerHTML = data
sequenceDiagram = createSequence(sequenceGraph)
})
window.initDiv = function() {
errorDiv = document.getElementById("error")
textArea = document.getElementById("text")
codemirrorEditor = CodeMirror.fromTextArea(textArea, {
value: loadExample(),
lineNumbers: true,
lineWrapping: true,
theme: "eclipse"
})
// making codemirror accessible to puppeteer
document.codemirrorEditor = codemirrorEditor;
codemirrorEditor.setValue(loadExample())
codemirrorEditor.on('change', (e) => {
if (!autoUpdate) {
return true;
}
if(timeout) {
clearTimeout(timeout);
timeout = null;
}
timeout = setTimeout(() => {
convert()
}, 2000)
})
myDiagram = init(document.getElementById("myDiagramDiv"), clickHistory)
sequenceDiagram = initSequence(sequenceGraph)
clickControl(document.getElementById("flowDiv"), clickHistory)
window.initDiv = undefined
window.load()
setTimeout(() => {
codemirrorEditor.refresh()
}, 1000)
}
</script>
</head>
<body onload="initDiv()">
<div class="flex-container">
<div class="flex-column">
<header>
<div class="top-header">
<span class="logo">modeligado</span>
</div>
<nav>
<div class="menu">
<button class="nav-button" id="autoUpdateButton" onClick="enableAutoUpdate()">☑ Auto Update</button>
<button class="nav-button" id="traceButton" onClick="showTrace()">☐ Trace</button>
<span id="error" class="error">No errors detected...</span>
</div>
<div class="menu">
<button class="nav-button" onClick="convert()">UML (F2)</button>
<button class="nav-button" onClick="exportTxt()">TXT</button>
<button class="nav-button" onClick="exportPng()">PNG</button>
<button class="nav-button" onClick="exportSvg()">SVG</button>
<button class="nav-button" onClick="exportJava()">Java</button>
<button class="nav-button" id="loadButton" onClick="loadExample()">Load Example</button>
</div>
</nav>
</header>
<main class="flex-row-content">
<textarea placeholder="Text UML here..." id="text" class="code col-1"></textarea>
<div hidden class="col-1" style="margin: 0.8rem;" id="trace">
<div class="row-1 trace" style="margin-bottom: 0.5rem;" id="traceInput"></div>
<div class="row-2 trace" id="sequenceDiagramDiv" class="flex-column col-2"></div>
</div>
<div id="myDiagramDiv" class="flex-column col-2"></div>
</main>
</div>
</div>
</body>
</html>