-
Notifications
You must be signed in to change notification settings - Fork 0
/
whiteboardController.js
55 lines (42 loc) · 1.7 KB
/
whiteboardController.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
var connect = require('express/node_modules/connect');
var utils = require('./utilities.js');
var interval;
var whiteboardController = function whiteboardController(activityLog) {
this.edit = function edit(request, response) {
var alias = request.body.alias;
var edit = request.body.edit;
if (utils.isAvailable([ alias, edit ]) == false) {
utils.statusResponse(400, response);
return;
}
utils.emptyResponse(response);
alias = connect.utils.escape(alias);
var entry = { type: 'edit-whiteboard', alias: alias, edit: edit };
activityLog.addEntry(entry);
};
this.clear = function clear(request, response) {
var alias = request.body.alias;
if (utils.isAvailable([ alias ]) == false) {
utils.statusResponse(400, response);
return;
}
utils.emptyResponse(response);
alias = connect.utils.escape(alias);
var entry = { type: 'clear-whiteboard', alias: alias };
removeAllWhiteboardEntries();
activityLog.addEntry(entry);
};
var removeAllWhiteboardEntries = function removeAllWhiteboardEntries() {
var entries = activityLog.findAllEntries();
for (i = entries.length - 1; i >= 0; i--) {
if (isWhiteboardEntry(entries[i])) {
activityLog.removeEntry(i);
}
}
};
var isWhiteboardEntry = function isWhiteboardEntry(entry) {
return entry.type == 'edit-whiteboard' ||
entry.type == 'clear-whiteboard';
};
};
module.exports = whiteboardController;