Skip to content

Commit

Permalink
REFACTORING: Memos rendered thanks to a list.
Browse files Browse the repository at this point in the history
One list replaces multiple queries required to show one memo (#40), related comments (#45), its groundings preview and leaves names (#47).
  • Loading branch information
christophe-lejeune committed Jan 7, 2017
1 parent bb56bce commit 80f5f59
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 212 deletions.
16 changes: 16 additions & 0 deletions _attachments/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ form {
#header {
margin-bottom: 0;
padding: 4px;
z-index: +1;
}

#menu>* {
Expand All @@ -38,6 +39,9 @@ form {
padding: 30px 0 0 0 ;
}

#content {
padding-bottom: 35px;
}

#memo>#content {
padding: 0 35px 0 21% ;
Expand All @@ -51,6 +55,11 @@ form {
padding: 0 5px 0 0;
}

.words .post p {
margin-top: 0px;
margin-bottom: 0px;
}

th {
vertical-align: top;
text-align: left;
Expand Down Expand Up @@ -92,6 +101,12 @@ div.post {
cursor: pointer;
}

#add-leaves {
position:absolute;
right: 36px;
top: 36px;
}

#show-leaves {
height: 36px;
line-height: 36px;
Expand Down Expand Up @@ -145,6 +160,7 @@ div.post {
margin: 40px 0 0 10px ;
}

.comment>.meta,
#contributors_add,
#readers_add,
#authorization {
Expand Down
4 changes: 3 additions & 1 deletion l10n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"i_sign-in": "Sign in",
"i_sign-out": "Sign out",
"i_sign-in_required": "You shouldn't be there",
"i_created": "Created by",
"i_contributors": "Modifiable by",
"i_readers": "Readable by",
"i_everyone": "everyone",
Expand Down Expand Up @@ -81,6 +82,7 @@
"i_sign-in": "S'identifier",
"i_sign-out": "Se déconnecter",
"i_sign-in_required": "Accès refusé",
"i_created": "Créé par",
"i_contributors": "Modifiable par",
"i_readers": "Lisible par",
"i_everyone": "tout le monde",
Expand Down Expand Up @@ -131,7 +133,7 @@
"storyline": "Résultats intermédiaires"
},
"i_content": {
"field": "Qu'ai je observé ?",
"field": "Que m'a-t-on dit ? Qu'ai je observé ?",
"coding": "Comment se définit tel processus, telle action ou telle activité ?",
"operational": "Que ne faut-il pas oublier de faire sur le terrain ?",
"theoretical": "Reformulation de la question de recherche, nouvelles questions théoriques que suscite l'analyse du matériau, propriété ou articulation à approfondir.",
Expand Down
150 changes: 150 additions & 0 deletions lists/memo.js
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);
}
13 changes: 9 additions & 4 deletions rewrites.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@
}
}, {
"method": "GET",
"from": "memo/:diary/:memo",
"to": "_show/memo/:memo"
"from": "memo/:diary/:memo",
"to": "_list/memo/memo",
"query": {
"startkey": [":memo"],
"endkey": [":memo", {}],
"include_docs": "true"
}
}, {
"from": "diagram/:diary/:diagram",
"to": "_show/diagram/:diagram"
Expand All @@ -69,10 +74,10 @@
"group_level": "2"
}
}, {
"from": "editable_memo/:memo",
"from": "editable_memo/:memo",
"to": "_show/editable_memo/:memo"
}, {
"from": "editable_text/:text",
"from": "editable_text/:text",
"to": "_show/editable_text/:text"
}, {
"from": "item/",
Expand Down
2 changes: 1 addition & 1 deletion shows/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function(o, req) {
return {
body: JSON.stringify({
service: 'Cassandre',
revision: '2.14.11.03',
revision: '3.17.01.07',
update_seq: req.info.update_seq
})
}
Expand Down
74 changes: 0 additions & 74 deletions shows/memo.js

This file was deleted.

Loading

2 comments on commit 80f5f59

@christophe-lejeune
Copy link
Member Author

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.

@christophe-lejeune
Copy link
Member Author

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

Please sign in to comment.