-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_log.js
279 lines (262 loc) · 7.68 KB
/
ui_log.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
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
274
275
276
277
278
279
require(['domReady'], function (domReady) {
domReady(function () {
var scrollElem = document.getElementById('layer0');
scrollElem.addEventListener('scroll', function(){
if (/#log/.test(location.hash) || location.hash==='') {
if (this.scrollHeight - this.scrollTop === this.clientHeight) {
show_next();
}
}
});
});
});
var ui_log = {
};
nbElements = 100;
offsetElements = 0;
var retrieved_nodes = [];
//var scrollElem = document.body;
//var scrollElem = window;
var tableelem;
function show_log(){
offsetElements = 0;
var container = document.querySelector('#contents');
container.innerHTML = '';
tableelem = table();
container.appendChild(tableelem);
show_next();
}
/*
window.addEventListener('scroll', function(){
if (/#log/.test(location.hash) || location.hash==='') {
if (document.body.scrollHeight - document.body.scrollTop === document.body.clientHeight) {
show_next();
}
}
});
*/
function show_next(){
damas.search_mongo({'time': {$exists:true}, 'comment':{$exists:true}}, {"time":-1},nbElements,offsetElements, function(res){
damas.read(res.ids, function(nodes){
retrieved_nodes = retrieved_nodes.concat(nodes);
tablebody(tableelem, nodes);
offsetElements += nbElements;
});
});
}
function expand_events( id, current_event_id, out ){
damas.search_mongo({'#parent': id }, {"time":1},100, 0, function(res){
damas.read(res.ids, function(children){
for(var i=0; i< children.length; i++){
var n = children[i];
var tr = tablerow(n, true);
tr.classList.add('history');
if (n._id === current_event_id) {
out.style.display= 'none';
tr.classList.add('clicked');
}
td_time = tr.querySelector('td.time');
td_time.addEventListener('click', function(e){
out.style.display= 'table-row';
var trnext = out.nextElementSibling;
while(trnext) {
if(trnext.classList.contains('last')) {
trnext.remove();
break;
}
trnext.remove();
trnext = out.nextElementSibling;
}
});
if (i === 0) {
tr.classList.add('last');
}
if (i === children.length - 1) {
tr.classList.add('first');
}
out.parentNode.insertBefore(tr, out.nextSibling);
}
});
});
}
function table() {
var table = document.createElement('table');
var thead = document.createElement('thead');
var th1 = document.createElement('th');
var th2 = document.createElement('th');
//var th3 = document.createElement('th');
var th4 = document.createElement('th');
table.classList.add('log');
th1.classList.add('time');
th4.classList.add('file');
//th3.classList.add('size');
th2.classList.add('comment');
th1.innerHTML = 'time ▴';
th4.innerHTML = 'file';
//th3.innerHTML = 'size';
th2.innerHTML = 'comment';
table.appendChild(thead);
thead.appendChild(th1);
thead.appendChild(th2);
//thead.appendChild(th3);
thead.appendChild(th4);
return table;
}
function tablebody(container, nodes) {
var tbody = null;
for (var i=0; i<nodes.length; i++) {
if (i === 0){
tbody = document.createElement('tbody');
tbody.appendChild(tablerow(nodes[i]));
container.appendChild(tbody);
continue;
}
if (nodes[i].comment === nodes[i-1].comment) {
var trow = tablerow(nodes[i]);
trow.querySelector('td.comment').remove();
tbody.firstChild.querySelector('td.comment').rowSpan += 1;
if (nodes[i].time === nodes[i-1].time) {
trow.querySelector('td.time').innerHTML= '';
}
tbody.appendChild(trow);
}
else {
tbody = document.createElement('tbody');
tbody.appendChild(tablerow(nodes[i]));
container.appendChild(tbody);
}
}
}
/*
* @param noclickontimebool is an optional boolean
*/
function tablerow(node, noclickontimebool) {
var tr = document.createElement('tr');
var td1 = document.createElement('td');
//var td3 = document.createElement('td');
var td4 = document.createElement('td');
var td2 = document.createElement('td');
//var td5 = document.createElement('td');
td1.classList.add('time');
td4.classList.add('comment');
//td3.classList.add('size');
td2.classList.add('file');
//td5.classList.add('buttons');
var time = new Date(parseInt(node.time));
td1.style.width = '18ex';
td1.innerHTML= html_time(new Date(parseInt(node.time)));
var file = node.file || node['#parent'] || node._id;
if (file) {
td2.appendChild(human_filename_href(file));
/*
// here we want to know if we are in the zombillenium case or in the white fang case
if ( (node['#parent'] && !node.file) || ( node.synced_online && node.synced_online > node.time )) {
td2.appendChild(human_filename_href(file));
}
else {
td2.innerHTML = human_filename_txt(file);
}
*/
}
td2.setAttribute('style', node.style);
//td3.innerHTML = human_size( node.file_size || node.bytes || node.size || node.source_size);
td4.innerHTML = '<'+node.author+'> '+node.comment.replace(/\n/g,'<br/>');
tr.appendChild(td1);
//tr.appendChild(td3);
tr.appendChild(td4);
tr.appendChild(td2);
//tr.appendChild(td5);
//var td5span0 = document.createElement('span');
//var td5span1 = document.createElement('span');
//td5span1.classList.add('delete');
//td5span1.innerHTML = 'x';
//td5.appendChild(td5span1);
/*
td5span1.addEventListener('click', function(e){
e.stopPropagation();
if (confirm('Delete '+node._id+' ?')) {
damas.delete(node._id);
}
});
*/
if (noclickontimebool!==true) {
td1.addEventListener('click', function(e){
//if (node['#parent']) {
//expand_events(node['#parent'], e.target.parentNode.querySelector('.children'));
expand_events(node['#parent'], node._id, e.target.parentNode);
//}
//else {
//expand_events(node._id, e.target.parentNode.querySelector('.children'));
//expand_events(node._id, e.target.parentNode);
//}
});
}
if (require.specified('ui_editor')) {
tr.addEventListener('click', function(){
initEditor(node);
});
}
tr.setAttribute('title', JSON_tooltip(node));
td1.setAttribute('title', time);
//td3.setAttribute('title', node.file_size || node.bytes || node.size || node.source_size);
//td5span0.setAttribute('title', 'edit');
//td5span1.setAttribute('title', 'delete');
return tr;
}
/*
(function (root, factory) {
if (typeof define === 'function' && define.amd) { // AMD
define(['../socket.io/socket.io'], factory);
} else if (typeof module === 'object' && module.exports) { // Node
module.exports = factory(require('socket.io-client'));
} else { // Browser globals
root.returnExports = factory(root.io);
}
}(this, function (io) {
if (typeof window !== 'undefined') {
var address = location.protocol + '//' + location.host;
var socket = io.connect(address, { path: '/socket.io' });
window.addEventListener('beforeunload', function (event) {
socket.close();
});
} else {
// Suppose a local Socket.io server over TLS
var address = 'wss://0.0.0.0:8443';
var socket = io.connect(address, {
path: '/socket.io',
rejectUnauthorized: false
});
}
socket.on('connect', function () {
console.log('Connected to the Socket server ' + address);
});
socket.on('disconnect', function (reason) {
console.log('Disconnected: ' + reason);
});
socket.on('create', function (nodes) {
console.log(nodes.length + ' nodes created');
console.log(nodes);
var tbody = document.querySelector('tbody');
nodes.forEach(function(node){
if (node.time === undefined || node['#parent'] !== undefined ) {
return;
}
var tr = tablerow(node);
tr.style.opacity = '0';
tbody.insertBefore(tr, tbody.firstChild);
setTimeout(function() {
tr.style.opacity = '1';
}, 1);
});
});
socket.on('update', function (nodes) {
console.log(nodes.length + ' nodes updated');
console.log(nodes);
});
socket.on('remove', function (nodes) {
console.log(nodes.length + ' nodes removed');
console.log(nodes);
});
return socket;
}));
*/