-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTORING: Memos rendered thanks to a list.
One list replaces multiple queries required to show one memo (#40), related comments (#45), its groundings preview and leaves names (#47).
- Loading branch information
1 parent
bb56bce
commit 80f5f59
Showing
8 changed files
with
293 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
function(head, req) { | ||
// !json templates.memo | ||
// !code lib/mustache.js | ||
// !code l10n/l10n.js | ||
start({"headers":{"Content-Type":"text/html;charset=utf-8"}}); | ||
|
||
const ALPHA = /[a-zàâçéêèëïîôöüùû0æœ0-9]+|[^a-zàâçéêèëïîôöüùûæœ0-9]+/gi; | ||
const SPACES = /^ +$/; | ||
var fullnames = []; | ||
|
||
while (row = getRow()) { | ||
switch (row.key[1]) { | ||
case ('C'): | ||
var id = row.value._id; | ||
var fullname = id; | ||
data.contributors.push(id); | ||
if (row.doc) fullname = row.doc.fullname; | ||
if (row.doc && !fullnames[id]) fullnames[id] = fullname; | ||
data.contributors_fullnames.push(fullname); | ||
break; | ||
case ('D'): | ||
if (row.doc) data.diary_name = row.doc.diary_name; | ||
break; | ||
case ('R'): | ||
var id = row.value._id; | ||
var fullname = id; | ||
data.readers.push(id); | ||
if (row.doc) fullname = row.doc.fullname; | ||
if (row.doc && !fullnames[id]) fullnames[id] = fullname; | ||
data.readers_fullnames.push(fullname); | ||
break; | ||
case ('M'): | ||
var user = row.value._id; | ||
if (row.doc && !fullnames[user]) fullnames[user] = row.doc.fullname; | ||
if (row.doc) user = row.doc.fullname; | ||
data.comments.push({ | ||
user: user, | ||
date: row.value.date, | ||
text: row.value.text | ||
}); | ||
break; | ||
case ('H'): | ||
var user = row.value._id; | ||
if (row.doc && !fullnames[user]) fullnames[user] = row.doc.fullname; | ||
if (row.doc) user = row.doc.fullname; | ||
data.date = user+', '+row.value.date; | ||
break; | ||
case ('G'): | ||
if (row.doc) { | ||
if (row.doc.body) { | ||
var preview = row.doc.body.substr(0, 200).replace("\s", ' '); | ||
} else { | ||
if (row.doc.speeches) { | ||
var preview = row.doc.speeches[0].text.substr(0, 200) || ' '; | ||
} else { | ||
var preview = ' '; | ||
} | ||
} | ||
var ground_type = row.doc.type || 'field'; | ||
switch (ground_type) { | ||
case ('diagram'): | ||
var ground_path = '../../diagram/'+diary+'/'; | ||
break; | ||
case ('graph'): | ||
var ground_path = '../../graph/'+diary+'/'; | ||
break; | ||
default: | ||
var ground_path = ''; | ||
} | ||
data.groundings.push({ | ||
id: '#' + row.value._id, | ||
href: ground_path + row.value._id, | ||
type: ground_type, | ||
preview: preview, | ||
name: row.doc.name | ||
}); | ||
} | ||
break; | ||
case ('L'): | ||
var type = row.doc.type || 'field'; | ||
var id = row.doc._id; | ||
var href = row.doc._id; | ||
var name = row.doc.name || '...'; | ||
if (type === 'diagram') href = '../../diagram/'+diary+'/'+href; | ||
data.leaves.push({ | ||
href: href, | ||
id: id, | ||
name: name, | ||
type: type | ||
}); | ||
break; | ||
default: | ||
// if (row.doc.draft) { | ||
// return { | ||
// "code": 302, | ||
// "headers":{ "Location": '../../editable_text/' + row.doc.corpus +'/'+ row.doc._id } | ||
// }; | ||
// } | ||
var username = req.userCtx.name; | ||
var type = row.doc.type || 'field'; | ||
var diary = row.doc.diary || row.doc.corpus; | ||
var data = { | ||
i18n: localized(), | ||
_id: row.doc._id, | ||
_rev: row.doc._rev, | ||
authorized: !row.doc.readers || row.doc.readers.indexOf(username)>-1 || row.doc.contributors && row.doc.contributors.indexOf(username)>-1 || req.userCtx.roles.indexOf("_admin")>-1, | ||
body: [], | ||
contributors: [], | ||
contributors_fullnames: [], | ||
comments: [], | ||
date: row.doc.date, | ||
diary: diary, | ||
groundings: [], | ||
peer: req.peer, | ||
leaves: [], | ||
logged: username, | ||
logged_fullname: username, | ||
name: row.doc.name, | ||
readers: [], | ||
readers_fullnames: [], | ||
roles: req.userCtx.roles, | ||
type: type | ||
} | ||
if (row.doc.body) { | ||
var content = { | ||
text: row.doc.body | ||
}; | ||
data.body.push(content); | ||
} else { | ||
for each (var s in row.doc.speeches) { | ||
var content = { | ||
actor: s.actor, | ||
timestamp: s.timestamp, | ||
words: [] | ||
}; | ||
for each (var w in s.text.match(ALPHA)) { | ||
if (w.match(SPACES) && content.words.length>0) { | ||
w = content.words.pop() + w; | ||
} | ||
content.words.push(w); | ||
} | ||
data.body.push(content); | ||
} | ||
} | ||
break; | ||
} | ||
if (fullnames[username]) data.logged_fullname = fullnames[username]; | ||
} | ||
return Mustache.to_html(templates.memo, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
80f5f59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit makes necessary to refactor feature #48.
80f5f59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nedded refactoring is provided by commit a3c495d