forked from DIT029Team08/SimulatorJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimationPage.html
248 lines (226 loc) · 10.2 KB
/
animationPage.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="public/styles/animationPage.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<title>Animation | DIT029 Simulator</title>
</head>
<body>
<header>
<nav>
<ul id="homeNav">
<li><a href="/index.html"><span class="glyphicon glyphicon-home" aria-hidden="true"></span></a></li>
<li><a href="#" id="restart" class="glyphicon glyphicon-play" aria-hidden="true"></a></li>
</ul>
<ul id="playNav">
<li><a href="#" id="SDbutton"><span aria-hidden="true">S</span></a></li>
<li><a href="#" id="CDbutton"><span aria-hidden="true">C</span></a></li>
<li><a href="#" id="DDbutton"><span aria-hidden="true">D</span></a></li>
</ul>
<ul id="helpNav">
<li><a onclick="newHelpWindow()" href="#"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a></li>
</ul>
</nav>
</header>
<main>
<div id="outputJSON">
<!--<svg width="20px" height="14" preserveAspectRatio="xMaxYMid slice" viewBox="0 0 1400 14">-->
<!--<polygon points="1400,7 1385,1 1390,6 0,6 0,8 1390,8 1385,13 1400,7 "></polygon></svg>-->
</div>
<div id="logAndChat">
<div class="logAndChatBox" id="log">
<ul id="logList"></ul>
</div>
<div class="logAndChatBox" id="chat">
<div id="nameFormArea">
<form id="nameForm">
<label>Enter username to chat</label>
<textarea id="nameTextArea"></textarea>
<button type="button" id="nameButton">Submit</button>
</form>
</div>
<div id="chatArea">
<div id="messagesBox"></div>
<textarea id="messageTextArea"></textarea>
<button type="button" id="messageButton">Send</button>
</div>
</div>
</div>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="public/js/inputFile.js"></script>
<script type="text/javascript" src="public/js/animator.js"></script>
<script type="text/javascript" src="public/js/help.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var objectIndex = 0;
var isSubmitter = false;
$(function() {
var socket = io.connect();
var $restart = $('#restart');
var $nameForm = $('#nameForm');
var $nameButton = $('#nameButton');
var $nameFormArea = $('#nameFormArea');
var $nameTextArea = $('#nameTextArea');
var $chatArea = $('#chatArea');
var $messagesBox = $('#messagesBox');
var $messageTextArea = $('#messageTextArea');
var $messageButton = $('#messageButton');
var $SDbutton = $('#SDbutton');
var $CDbutton = $('#CDbutton');
var $DDbutton = $('#DDbutton');
var stringJSON;
// Check the localstorage for files - removes unused buttons
if(localStorage.getItem('DD') !== null){
stringJSON = JSON.parse(localStorage.getItem('DD'));
}
else{
$DDbutton.remove();
}
if(localStorage.getItem('CD') !== null){
stringJSON = JSON.parse(localStorage.getItem('CD'));
}
else{
$CDbutton.remove();
}
if(localStorage.getItem('SD') !== null){
stringJSON = JSON.parse(localStorage.getItem('SD'));
}
else{
$SDbutton.remove();
}
$restart.click(function (e) {
$restart.removeClass('glyphicon glyphicon-play');
$restart.addClass('glyphicon glyphicon-repeat');
e.preventDefault();
isSubmitter = true;
socket.emit('begin animation', {animator: stringJSON});
});
$SDbutton.click(function (e) {
// Check if already loaded said diagram
if(stringJSON.type === 'sequence_diagram'){
}
else {
isSubmitter = true;
stringJSON = JSON.parse(localStorage.getItem('SD'));
socket.emit('begin animation', {animator: stringJSON});
}
});
$CDbutton.click(function (e) {
// Check if already loaded said diagram
if(stringJSON.type === 'class_diagram'){
}
else {
stringJSON = JSON.parse(localStorage.getItem('CD'));
socket.emit('begin animation', {animator: stringJSON});
}
});
$DDbutton.click(function (e) {
// Check if already loaded said diagram
if(stringJSON.type === 'deployment_diagram'){
// Do nothing
}
else {
stringJSON = JSON.parse(localStorage.getItem('DD'));
socket.emit('begin animation', {animator: stringJSON});
}
});
socket.on("begin animation", function (data, socketIds) {
console.log(data);
outputAnimation(data, socketIds);
});
$nameTextArea.keydown(function(event) {
if (event.keyCode === 13) {
event.preventDefault();
$nameButton.click();
}
});
$nameButton.click(function (e) {
e.preventDefault();
socket.emit('new user', $nameTextArea.val(), function (data) {
if (data && $nameTextArea.val() !== '') {
$nameFormArea.hide();
$chatArea.show();
}
});
$nameButton.val('');
});
$messageTextArea.keydown(function(event) {
if (event.keyCode === 13) {
event.preventDefault();
$messageButton.click();
}
});
$messageButton.click(function (e) {
e.preventDefault();
socket.emit('send message', $messageTextArea.val());
$messageTextArea.val('');
});
socket.on('new message', function(data){
$messagesBox.append('<div><strong>' + data.user + '</strong>: ' + data.msg + '</div>');
document.getElementById('messagesBox').scrollBy(0, document.getElementById('messagesBox').scrollHeight);
});
socket.on('arrow reply', function (data) {
if (objectIndex === 0) {
var stickyArr = document.getElementsByClassName("stickyDiv");
var stickyArrBig = document.getElementsByClassName("stickyDivBig");
if(stickyArr.length > 0) {
for (var i = 0; i < stickyArr.length; i++) {
if (socket.id === stickyArr[i].id) {
stickyArr[i].className += " blackProcess";
console.log("COLORING");
}
}
}
else if(stickyArrBig.length > 0){
for (var i = 0; i < stickyArrBig.length; i++) {
if (socket.id === stickyArrBig[i].id) {
stickyArrBig[i].className += " blackProcess";
console.log("COLORING");
}
}
}
}
console.log("ANIMATING ARROW");
// Arrow animation
if (objectArray[objectIndex].fromNode.x === objectArray[objectIndex].toNode.x) {
selfCallArrow(objectArray[objectIndex].fromNode, objectArray[objectIndex].toNode,
objectArray[objectIndex].messageToSend, objectArray[objectIndex].frameToAppend);
incrementLifeline(92);
}
else if (objectArray[objectIndex].fromNode.x > objectArray[objectIndex].toNode.x) {
arrowR2L(objectArray[objectIndex].fromNode, objectArray[objectIndex].toNode,
objectArray[objectIndex].messageToSend, objectArray[objectIndex].frameToAppend);
incrementLifeline(75);
}
else {
arrowL2R(objectArray[objectIndex].fromNode, objectArray[objectIndex].toNode,
objectArray[objectIndex].messageToSend, objectArray[objectIndex].frameToAppend);
incrementLifeline(75);
}
if (objectArray.length - 1 > objectIndex) {
objectIndex++;
}
else {
isSubmitter = false;
}
});
serverRequest = function serverRequest() {
if (isSubmitter) {
var $lifelineId = $('#' + objectArray[objectIndex].lifelineElement.id); // name of process is the id of lifeline
var lifeLineIdNoQuery = objectArray[objectIndex].lifelineElement.id;
var $processId = $lifelineId.parent().closest('div').attr('id'); // socketId is Id of process
socket.emit('arrow request', {socketId: socket.id});
}
};
window.onbeforeunload = function(e) {
socket.disconnect();
};
});
</script>
</body>
</html>