| author | gibus |
| Tue, 15 May 2012 11:16:46 +0200 | |
| changeset 432 | aad07a378d44 |
| parent 413 | 2479d33898dd |
| child 504 | b2e0186daa5b |
| permissions | -rw-r--r-- |
| 0 | 1 |
Db = function() { |
| 341 | 2 |
//initial comment db as objs (TREE LIKE MODEL : replies are included in comment.replies) |
3 |
this.comments = null; // current set of (filtered) comments |
|
4 |
this.allComments = null; // all server database comments |
|
| 0 | 5 |
|
| 341 | 6 |
// obj |
7 |
// keys : commentDbId as string |
|
8 |
// values : comment db as obj |
|
9 |
this.commentsByDbId = {}; |
|
10 |
this.allCommentsByDbId = {}; |
|
11 |
|
|
12 |
// dictionary (always contains all comments (no reply) whatever the filter |
|
13 |
// order key --> ordered array of comment ids (no reply) |
|
14 |
this.ordered_comment_ids = {}; // all server database comments |
|
15 |
|
|
| 0 | 16 |
} |
17 |
||
18 |
Db.prototype = { |
|
| 341 | 19 |
|
| 0 | 20 |
////////////////////////////// |
| 341 | 21 |
// CORE FUNCTIONS |
| 0 | 22 |
////////////////////////////// |
| 341 | 23 |
init : function() { |
24 |
// at first server side ordered comment by asc ids, replies by creation date : |
|
25 |
this.allComments = CY.JSON.parse(sv_comments) ; |
|
26 |
if (sv_read_only) { |
|
27 |
this.initToReadOnly() ; |
|
28 |
} |
|
29 |
|
|
30 |
this._computeAllCommentsByDbId() ; |
|
31 |
|
|
32 |
this._reorder() ; |
|
33 |
}, |
|
34 |
|
|
35 |
_del : function (arr, dic, id) { |
|
36 |
// first recursively remove all replies |
|
37 |
var comment = dic[id] ; |
|
38 |
|
|
39 |
for (var i = 0 ; i < comment.replies.length ; i++) { |
|
40 |
var rid = comment.replies[i].id ; |
|
41 |
this._del(comment.replies, dic, rid) ; |
|
42 |
i--; |
|
43 |
} |
|
44 |
|
|
45 |
for (var i = 0, ilen = arr.length ; i < ilen ; i++) { |
|
46 |
if (arr[i].id == id) { |
|
47 |
arr.splice(i, 1) ; |
|
48 |
delete dic[id] ; |
|
49 |
break ; |
|
50 |
} |
|
51 |
} |
|
52 |
}, |
|
| 0 | 53 |
|
| 341 | 54 |
del : function(comment) { |
55 |
var arr = (comment.reply_to_id == null) ? this.comments : this.commentsByDbId[comment.reply_to_id].replies ; |
|
56 |
this._del(arr, this.commentsByDbId, comment.id) ; |
|
57 |
arr = (comment.reply_to_id == null) ? this.allComments : this.allCommentsByDbId[comment.reply_to_id].replies ; |
|
58 |
this._del(arr, this.allCommentsByDbId, comment.id) ; |
|
59 |
|
|
60 |
this._reorder() ; |
|
61 |
|
|
62 |
}, |
|
63 |
|
|
64 |
// maintains the ordered lists |
|
65 |
_reorder : function() { |
|
66 |
|
|
67 |
// scope (order by start_wrapper, start_offset, end_wrapper, end_offset |
|
68 |
var a = [] ; |
|
69 |
|
|
70 |
for (var i = 0, ilen = this.allComments.length ; i < ilen ; i++) { |
|
71 |
|
|
72 |
var comment = this.allComments[i] ; |
|
73 |
var found = false ; |
|
| 0 | 74 |
|
| 341 | 75 |
for (var j = 0, jlen = a.length ; j < jlen ; j++) { |
76 |
|
|
77 |
var id = a[j] ; |
|
78 |
var comment2 = this.allCommentsByDbId[id] ; |
|
79 |
|
|
80 |
if ((comment.start_wrapper < comment2.start_wrapper) |
|
81 |
|| |
|
82 |
((comment.start_wrapper == comment2.start_wrapper) && (comment.start_offset < comment2.start_offset) ) |
|
83 |
|| |
|
84 |
((comment.start_wrapper == comment2.start_wrapper) && (comment.start_offset == comment2.start_offset) && (comment.end_wrapper < comment2.end_wrapper) ) |
|
85 |
|| |
|
86 |
((comment.start_wrapper == comment2.start_wrapper) && (comment.start_offset == comment2.start_offset) && (comment.end_wrapper == comment2.end_wrapper) && (comment.end_offset < comment2.end_offset) ) ) { |
|
87 |
a.splice(j, 0, comment.id) ; |
|
88 |
found = true ; |
|
89 |
break ; |
|
90 |
} |
|
91 |
} |
|
92 |
if (!found) { |
|
93 |
a.push(comment.id) ; |
|
94 |
} |
|
95 |
} |
|
96 |
this.ordered_comment_ids['scope'] = a ; |
|
97 |
|
|
98 |
// modified thread |
|
99 |
a = [] ; |
|
100 |
var mod = {} ; // we'll aggregate modification dates in this assoc array id --> latest modification |
|
101 |
|
|
102 |
for (var i = 0, ilen = this.allComments.length ; i < ilen ; i++) { |
|
103 |
|
|
104 |
var comment = this.allComments[i] ; |
|
105 |
var commentModif = comment.modified ; |
|
106 |
|
|
|
333
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
107 |
mod[comment.id] = this._latest_mod(comment); |
| 341 | 108 |
} |
109 |
|
|
110 |
for (var id in mod) { |
|
111 |
var numberId = this.allCommentsByDbId[id].id |
|
112 |
var found = false ; |
|
113 |
for (var i = 0, ilen = a.length ; i < ilen ; i++) { |
|
114 |
var id2 = a[i] ; |
|
115 |
|
|
116 |
if (mod[id] < mod[id2]) { |
|
117 |
a.splice(i, 0, numberId) ; |
|
118 |
found = true ; |
|
119 |
break ; |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
123 |
if (!found) { |
|
124 |
a.push(numberId) ; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
this.ordered_comment_ids['modif_thread'] = a ; |
|
129 |
}, |
|
| 0 | 130 |
|
|
333
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
131 |
// Finds recursively the last modification date of a thread. |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
132 |
_latest_mod : function(comment) { |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
133 |
var latest_mod = comment.modified; |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
134 |
for (var i=0; i<comment.replies.length; i++) { |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
135 |
var reply = comment.replies[i] ; |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
136 |
var reply_mod = this._latest_mod(reply); |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
137 |
if (reply_mod > latest_mod) |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
138 |
latest_mod = reply_mod; |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
139 |
} |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
140 |
return latest_mod; |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
141 |
}, |
|
f080de4cad76
Fix browsing by modifications, take into account every comment in a thread (instead of only the first two levels in each thread).
gibus
parents:
144
diff
changeset
|
142 |
|
| 341 | 143 |
// EDIT OR ADD CASE : when just added id is max and so both (comments and replies) initial id asc order remains |
144 |
_upd : function(arr, dic, c) { |
|
145 |
var found = false ; |
|
146 |
for (var i = 0, ilen = arr.length ; i < ilen ; i++) { |
|
147 |
if (arr[i].id == c.id) { // edit |
|
148 |
arr.splice(i, 1, c) ; |
|
149 |
found = true ; |
|
150 |
break ; |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
if (!found) { // add |
|
155 |
arr.push(c) ; |
|
156 |
} |
|
157 |
|
|
158 |
dic[c.id] = c ; |
|
159 |
}, |
|
| 0 | 160 |
|
| 341 | 161 |
// EDIT OR ADD CASE : when just added id is max and so both (comments and replies) initial id asc order respected |
162 |
upd : function(comment) { |
|
163 |
var arr = (comment.reply_to_id == null) ? this.allComments : this.allCommentsByDbId[comment.reply_to_id].replies ; |
|
164 |
this._upd(arr, this.allCommentsByDbId, comment) ; |
|
165 |
|
|
166 |
var cloneComment = CY.clone(comment) ; |
|
167 |
|
|
168 |
arr = (comment.reply_to_id == null) ? this.comments : this.commentsByDbId[comment.reply_to_id].replies ; |
|
169 |
this._upd(arr, this.commentsByDbId, cloneComment) ; |
|
170 |
|
|
171 |
this._reorder() ; |
|
172 |
|
|
173 |
}, |
|
| 0 | 174 |
|
| 341 | 175 |
// initializes this.comments |
176 |
// commentId is the result of a computeFilterResults call : no assumption can be made on the order of ids (!) |
|
177 |
// so we'll loop through allComments to carry order from allComments to comments |
|
178 |
initComments : function(commentIds) { |
|
179 |
this.comments = [] ; |
|
180 |
for (var i = 0, ilen = this.allComments.length ; i < ilen ; i++) { |
|
181 |
|
|
182 |
var index = CY.Array.indexOf(commentIds, this.allComments[i].id) ; |
|
183 |
if (index != -1) { |
|
184 |
|
|
185 |
var cloneComment = CY.clone(this.allComments[i]) ; |
|
186 |
|
|
187 |
this.comments.push(cloneComment) ; |
|
188 |
} |
|
189 |
} |
|
190 |
this._computeCommentsByDbId() ; |
|
191 |
}, |
|
| 0 | 192 |
|
| 341 | 193 |
_computeCommentsByDbId : function() { |
194 |
this.commentsByDbId = {} ; |
|
195 |
var flatComments = this.getThreads(this.comments) ; |
|
196 |
for ( var i = 0; i < flatComments.length; i++) |
|
197 |
this.commentsByDbId[flatComments[i].id] = flatComments[i]; |
|
198 |
}, |
|
199 |
|
|
200 |
_computeAllCommentsByDbId : function() { |
|
201 |
this.allCommentsByDbId = {} ; |
|
202 |
var flatComments = this.getThreads(this.allComments) ; |
|
203 |
for (var i = 0; i < flatComments.length; i++) |
|
204 |
this.allCommentsByDbId[flatComments[i].id] = flatComments[i]; |
|
205 |
}, |
|
206 |
|
|
207 |
// returns threads : |
|
208 |
// given an array [comment1, comment2, comment3], this function will return [comment1, comment1reply1, comment1reply1reply1, comment1reply1reply2, comment2, comment3, comment3reply1] |
|
209 |
//note : will return top parents ordered the way comments are |
|
210 |
getThreads : function(comments) { |
|
211 |
var ret = [] ; |
|
| 0 | 212 |
|
| 341 | 213 |
for (var i = 0 ; i < comments.length ; i++) { |
214 |
ret.push(comments[i]) ; |
|
215 |
if (comments[i].replies.length > 0) |
|
216 |
ret = ret.concat(this.getThreads(comments[i].replies)) ; |
|
217 |
} |
|
218 |
return ret ; |
|
219 |
}, |
|
220 |
_getPath : function(dic, comment) { |
|
221 |
var ret = [comment] ; |
|
222 |
|
|
223 |
var c = comment ; |
|
224 |
while (c.reply_to_id != null) { |
|
225 |
c = dic[c.reply_to_id] ; |
|
226 |
ret.push(c) ; |
|
227 |
} |
|
228 |
|
|
229 |
return ret ; |
|
230 |
}, |
|
231 |
// returns comments as array : [comment, ..., comment's top parent] |
|
232 |
getPath : function(comment) { |
|
233 |
return this._getPath(this.commentsByDbId, comment) ; |
|
234 |
}, |
|
235 |
// getCommentFromIComment ... |
|
236 |
getComment : function(dbId) { |
|
237 |
return this.commentsByDbId[dbId] ; |
|
238 |
}, |
|
239 |
|
|
240 |
getCommentByIdKey : function(id_key) { |
|
241 |
for (var id in this.commentsByDbId) { |
|
242 |
var comment = this.commentsByDbId[id] ; |
|
243 |
if (comment.id_key == id_key) { |
|
244 |
return comment ; |
|
245 |
} |
|
246 |
} |
|
247 |
return null ; |
|
248 |
}, |
|
249 |
|
|
250 |
isChild : function(commentDbId, parentDbId) { |
|
251 |
var comment = this.commentsByDbId[commentDbId] ; |
|
252 |
|
|
253 |
var isChild = (commentDbId == parentDbId) ; |
|
254 |
|
|
255 |
while ((!isChild) && (comment.reply_to_id != null)) { |
|
256 |
comment = this.commentsByDbId[comment.reply_to_id] ; |
|
257 |
isChild = (comment.id == parentDbId) ; ; |
|
258 |
} |
|
259 |
return isChild ; |
|
260 |
}, |
|
261 |
|
|
262 |
initToReadOnly : function(commentDbId, parentDbId) { |
|
263 |
for (var i = 0, ilen = this.allComments.length ; i < ilen ; i++) { |
|
264 |
var comment = this.allComments[i] ; |
|
265 |
for (var prop in comment) { |
|
266 |
if (0 == prop.indexOf("can_") && typeof comment[prop] === 'boolean') |
|
267 |
comment[prop] = false ; |
|
268 |
} |
|
269 |
} |
|
270 |
}, |
|
271 |
|
|
| 0 | 272 |
////////////////////////////// |
| 341 | 273 |
// BROWSING FUNCTIONS |
| 0 | 274 |
////////////////////////////// |
275 |
||
| 341 | 276 |
browsingIndex : function(dbId) { |
277 |
var indx = {} ; |
|
278 |
for (var order in this.ordered_comment_ids) { |
|
279 |
var inFilter = CY.Array.filter(this.ordered_comment_ids[order], function(id) {return (id in this.commentsByDbId);}, this) ; |
|
280 |
indx[order] = CY.Array.indexOf(inFilter, dbId ) ; |
|
281 |
} |
|
282 |
//indx['total'] = this.ordered_comment_ids['scope'].length |
|
283 |
return indx ; |
|
284 |
}, |
|
285 |
|
|
286 |
browse : function(order, whereto, dbId) { |
|
287 |
//var arr = this.ordered_comment_ids[gConf['defaultBrowsingOrder']] ; |
|
288 |
// CY.log(order) ; |
|
289 |
var arr = this.ordered_comment_ids[order] ; |
|
290 |
if (arr.length > 0) { |
|
291 |
|
|
292 |
var starti = -1 ; |
|
293 |
if ((whereto == 'prev') ||Â (whereto == 'next')) { |
|
294 |
|
|
295 |
for (var i = 0 ; i < arr.length ; i++) { |
|
296 |
var id = arr[i] ; |
|
297 |
if (id == dbId) { |
|
298 |
starti = (whereto == 'prev') ? i - 1 : i + 1 ; |
|
299 |
starti = (arr.length + starti) % arr.length ; // to guaranty a positive value |
|
300 |
break ; |
|
301 |
} |
|
302 |
} |
|
303 |
if (starti == -1) { |
|
304 |
CY.error("internal error in db browse (was called with a dbId that isn't among the filtered ones)") ; |
|
305 |
return null; |
|
306 |
} |
|
307 |
} |
|
308 |
if (whereto == 'last') { |
|
309 |
starti = arr.length - 1 ; |
|
310 |
} |
|
311 |
if (whereto == 'first') { |
|
312 |
starti = 0 ; |
|
313 |
} |
|
314 |
|
|
315 |
for (var i = starti, j = 0 ; (i >= 0) && (i < arr.length) ; j++ ) { |
|
316 |
var id = arr[i] ; |
|
317 |
if (id in this.commentsByDbId) // checking id is among the filtered ones |
|
318 |
return this.commentsByDbId[id] ; |
|
319 |
if ((whereto == 'prev') ||Â (whereto == 'last')) |
|
320 |
i = i - 1 ; |
|
321 |
else |
|
322 |
i = i + 1 ; |
|
323 |
i = (arr.length + i) % arr.length ; // to guaranty a positive value |
|
324 |
if (j > arr.length)// to prevent an infinite loop |
|
325 |
break ; |
|
326 |
} |
|
327 |
|
|
328 |
CY.error("internal error in db browse (could not find any filtered comment)") ; |
|
329 |
} |
|
330 |
return null; |
|
331 |
}, |
|
332 |
|
|
| 0 | 333 |
////////////////////////////// |
| 341 | 334 |
// FILTER FUNCTIONS |
| 0 | 335 |
////////////////////////////// |
| 341 | 336 |
|
337 |
//returns the list of commentIds satisfying the filter |
|
338 |
computeFilterResults : function(filterGETValues) { |
|
339 |
var filterData = {} ; |
|
340 |
if (filterGETValues) { |
|
341 |
for (key in filterGETValues) { |
|
342 |
if (key.indexOf('filter_') == 0) |
|
343 |
filterData[key.substr('filter_'.length)] = filterGETValues[key]; |
|
344 |
} |
|
345 |
} |
|
346 |
else { |
|
347 |
if (gLayout.isInFrame()) |
|
348 |
filterData = parent.f_getFrameFilterData() ; |
|
349 |
} |
|
| 0 | 350 |
|
| 341 | 351 |
var cWithNameIds = [] ; |
352 |
var rWithNameIds = [] ; |
|
353 |
var filterName = "" ; |
|
354 |
if ('name' in filterData) |
|
355 |
filterName = filterData['name'] ; |
|
356 |
this.filterByName(filterName, cWithNameIds, rWithNameIds) ; |
|
357 |
|
|
358 |
var cAfterDateIds = [] ; |
|
359 |
var rAfterDateIds = [] ; |
|
360 |
var filterDate = "" ; |
|
361 |
if ('date' in filterData) |
|
362 |
filterDate = filterData['date'] ; |
|
363 |
this.filterByDate(filterDate, cAfterDateIds, rAfterDateIds) ; |
|
| 0 | 364 |
|
| 341 | 365 |
var cWithTextIds = [] ; |
366 |
var rWithTextIds = [] ; |
|
367 |
var filterText = "" ; |
|
368 |
if ('text' in filterData) |
|
369 |
filterText = filterData['text'] ; |
|
370 |
this.filterByText(filterText, cWithTextIds, rWithTextIds) ; |
|
371 |
|
|
372 |
var cWithTagIds = [] ; |
|
373 |
var rWithTagIds = [] ; |
|
374 |
var filterTag = "" ; |
|
375 |
if ('tag' in filterData) |
|
376 |
filterTag = filterData['tag'] ; |
|
377 |
this.filterByTag(filterTag, cWithTagIds, rWithTagIds) ; |
|
378 |
|
|
379 |
var cWithStateIds = [] ; |
|
380 |
var rWithStateIds = [] ; |
|
381 |
var filterState = "" ; |
|
382 |
if ('state' in filterData) |
|
383 |
filterState = filterData['state'] ; |
|
384 |
this.filterByState(filterState, cWithStateIds, rWithStateIds) ; |
|
385 |
|
|
386 |
|
|
387 |
var commentIds = [] ; |
|
388 |
var replyIds = [] ; |
|
389 |
// find intersections |
|
390 |
for (var i = 0, ilen = cWithNameIds.length ; i < ilen ; i++) { |
|
391 |
var id = cWithNameIds[i] ; |
|
392 |
if ((CY.Array.indexOf(cAfterDateIds, id) != -1) && (CY.Array.indexOf(cWithTextIds,id) != -1) && (CY.Array.indexOf(cWithTagIds,id) != -1) && (CY.Array.indexOf(cWithStateIds,id) != -1)) { |
|
393 |
commentIds.push(id) ; |
|
394 |
} |
|
395 |
} |
|
396 |
|
|
397 |
for (var i = 0, ilen = rWithNameIds.length ; i < ilen ; i++) { |
|
398 |
var id = rWithNameIds[i] ; |
|
399 |
if ((CY.Array.indexOf(rAfterDateIds,id) != -1) && (CY.Array.indexOf(rWithTextIds,id) != -1) && (CY.Array.indexOf(rWithTagIds,id) != -1) && (CY.Array.indexOf(rWithStateIds,id) != -1)) { |
|
400 |
replyIds.push(id) ; |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
var nbReplies = replyIds.length, nbComments = commentIds.length ; |
|
405 |
var nbDiscussions = nbComments ; |
|
406 |
|
|
407 |
// look for comments to add because a reply satisfies the filter |
|
408 |
// CY.log('replyIds:') ; |
|
409 |
// CY.log(replyIds) ; |
|
410 |
// CY.log('this.allCommentsByDbId :');CY.A |
|
411 |
// CY.log(this.allCommentsByDbId); |
|
412 |
for (var i = 0, ilen = replyIds.length ; i < ilen ; i++) { |
|
413 |
var id = replyIds[i] ; |
|
414 |
var reply = this.allCommentsByDbId[id] ; |
|
415 |
var parents = this._getPath(this.allCommentsByDbId, reply) ; |
|
416 |
var topComment = parents[parents.length - 1] ; |
|
417 |
var id = topComment.id ; |
|
418 |
if (CY.Array.indexOf(commentIds,id) == -1) { |
|
419 |
commentIds.push(id) ; |
|
420 |
nbDiscussions++ ; |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
return {'commentIds': commentIds,'nbDiscussions':nbDiscussions, 'nbComments':nbComments, 'nbReplies':nbReplies} ; |
|
425 |
}, |
|
| 0 | 426 |
|
| 341 | 427 |
filterByText : function(text, cWithTextIds, rWithTextIds) { |
428 |
var re = new RegExp(text, "gi"); |
|
429 |
for (var id in this.allCommentsByDbId) { |
|
430 |
var comment = this.allCommentsByDbId[id] ; |
|
431 |
if (text == "" || re.exec(comment.title) != null || re.exec(comment.content) != null) { // search only in the comment (not the comment scope) for now |
|
432 |
if (comment.reply_to_id == null) |
|
433 |
cWithTextIds.push(comment.id); |
|
434 |
else |
|
435 |
rWithTextIds.push(comment.id) ; |
|
436 |
} |
|
437 |
} |
|
438 |
}, |
|
| 0 | 439 |
|
| 341 | 440 |
filterByName : function(name, cWithNameIds, rWithNameIds) { |
441 |
for (var id in this.allCommentsByDbId) { |
|
442 |
var comment = this.allCommentsByDbId[id] ; |
|
443 |
if (name == "" || comment.name == name) { // sensitive exact match for now |
|
444 |
if (comment.reply_to_id == null) |
|
445 |
cWithNameIds.push(comment.id); |
|
446 |
else |
|
447 |
rWithNameIds.push(comment.id) ; |
|
448 |
} |
|
449 |
} |
|
450 |
}, |
|
| 0 | 451 |
|
| 341 | 452 |
// warning : tags are case sensitive |
453 |
filterByTag : function(tag, cWithTagIds, rWithTagIds) { |
|
454 |
// cf ", ".join... in client.py |
|
| 413 | 455 |
var re0 = new RegExp("^" + tag + "$", ''); |
456 |
var re1 = new RegExp("^" + tag + ", ", ''); |
|
457 |
var re2 = new RegExp(", " + tag + ", ", ''); |
|
458 |
var re3 = new RegExp(", " + tag + "$", ''); |
|
| 341 | 459 |
for (var id in this.allCommentsByDbId) { |
460 |
var comment = this.allCommentsByDbId[id] ; |
|
| 413 | 461 |
if ((tag == "") || re0.exec(comment.tags) != null || re1.exec(comment.tags) != null || re2.exec(comment.tags) != null || re3.exec(comment.tags) != null) { // search only in the comment (not the comment scope) for now |
| 341 | 462 |
if (comment.reply_to_id == null) |
463 |
cWithTagIds.push(comment.id); |
|
464 |
else |
|
465 |
rWithTagIds.push(comment.id) ; |
|
466 |
} |
|
467 |
} |
|
468 |
}, |
|
| 0 | 469 |
|
| 341 | 470 |
filterByState : function(state, cWithStateIds, rWithStateIds) { |
471 |
for (var id in this.allCommentsByDbId) { |
|
472 |
var comment = this.allCommentsByDbId[id] ; |
|
473 |
if (state == "" || comment.state == state) { |
|
474 |
if (comment.reply_to_id == null) |
|
475 |
cWithStateIds.push(comment.id); |
|
476 |
else |
|
477 |
rWithStateIds.push(comment.id) ; |
|
478 |
} |
|
479 |
} |
|
480 |
}, |
|
| 0 | 481 |
|
| 341 | 482 |
filterByDate : function(date_str, cAfterDateIds, rAfterDateIds) { |
483 |
var date = (date_str == "") ? 0 : parseInt(date_str) ; |
|
484 |
for (var id in this.allCommentsByDbId) { |
|
485 |
var comment = this.allCommentsByDbId[id] ; |
|
486 |
if (comment.modified > date) { |
|
487 |
if (comment.reply_to_id == null) |
|
488 |
cAfterDateIds.push(comment.id); |
|
489 |
else |
|
490 |
rAfterDateIds.push(comment.id) ; |
|
491 |
} |
|
492 |
} |
|
493 |
}, |
|
494 |
// filterByDate : function(date_str, cAfterDateIds, rAfterDateIds) { |
|
495 |
// var date = (date_str == "") ? "" : Date.parseDate(date_str, sv_client_date_fmt).getTime() ; |
|
496 |
// for (var id in this.allCommentsByDbId) { |
|
497 |
// var comment = this.allCommentsByDbId[id] ; |
|
498 |
// // TODO : created should be the date not a string !! |
|
499 |
// var create_date = (date_str == "") ? "" : Date.parseDate(comment.created_str, sv_client_date_fmt).getTime() ; |
|
500 |
// if (date_str == "" || create_date > date) { |
|
501 |
// if (comment.reply_to_id == null) |
|
502 |
// cAfterDateIds.push(comment.id); |
|
503 |
// else |
|
504 |
// rAfterDateIds.push(comment.id) ; |
|
505 |
// } |
|
506 |
// } |
|
507 |
// }, |
|
508 |
|
|
| 0 | 509 |
////////////////////////////// |
| 341 | 510 |
// COUNT FUNCTIONS |
| 0 | 511 |
////////////////////////////// |
| 341 | 512 |
|
513 |
getCommentsAndRepliesCounts : function(all) { |
|
514 |
var cCount = 0 ; |
|
515 |
var rCount = 0 ; |
|
516 |
var arr = (all) ? this.allComments:this.comments; |
|
517 |
var flatComments = this.getThreads(arr) ; |
|
518 |
for ( var i = 0; i < flatComments.length; i++) { |
|
519 |
if (flatComments[i].reply_to_id == null) |
|
520 |
cCount++ ; |
|
521 |
else |
|
522 |
rCount++ ; |
|
523 |
} |
|
524 |
return [cCount, rCount] ; |
|
525 |
}, |
|
| 0 | 526 |
|
| 341 | 527 |
// counts both comments and comments |
528 |
getCommentsNb : function(all) { |
|
529 |
var arr = (all) ? this.allComments:this.comments; |
|
530 |
return this.getThreads(arr).length ; |
|
531 |
}, |
|
532 |
getFilteredCommentIdsAsString : function() { |
|
533 |
var ret = "" ; |
|
534 |
for (var id in this.commentsByDbId) |
|
535 |
ret = ret + id + "," ; |
|
536 |
return ret ; |
|
537 |
} |
|
| 0 | 538 |
} |
539 |
||
540 |