Skip to content

Commit

Permalink
FEATURE: Coding interview fragments
Browse files Browse the repository at this point in the history
This (paragraph level) `code and retrieve` feature requires to modify 
the way memo are grounding are stored (#106).
  • Loading branch information
christophe-lejeune committed Jul 16, 2021
1 parent 22e6803 commit 39acf27
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 35 deletions.
8 changes: 7 additions & 1 deletion app/lists/editable_memo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ function(head, req){
break;
case ('G'):
if (row.doc) {
if (row.doc.body) {
if (row.value.preview) {
preview = [];
for (var p in row.value.preview) {
preview.push(row.value.preview[p].text);
}
preview = preview.join('\n \n---\n');
} else if (row.doc.body) {
var preview = row.doc.body.substr(0, 200);
} else {
if (row.doc.speeches) {
Expand Down
33 changes: 19 additions & 14 deletions app/lists/memo.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,33 @@ function(head, req) {
break;
case ('G'):
if (row.doc) {
var preview = null;
if (row.doc.body) preview = row.doc.body;
if (row.doc.speeches) preview = row.doc.speeches[0].text;
if (row.doc.negative) preview = row.doc.negative;
if (preview != null) preview = preview.substr(0, 200);
var ground_type = row.doc.type || 'transcript';
var ground_type = row.doc.type || 'transcript',
ground_path = '',
preview = null;
if (row.value.preview) {
preview = [];
for (var p in row.value.preview) {
preview.push('['+row.value.preview[p].text+']('+row.value._id+'#'+row.value.preview[p].anchor+')');
}
preview = preview.join('\n \n---\n');
} else {
if (row.doc.body) preview = row.doc.body;
if (row.doc.speeches) preview = row.doc.speeches[0].text;
if (row.doc.negative) preview = row.doc.negative;
if (preview != null) preview = preview.substr(0, 200);
}
switch (ground_type) {
case ('diagram'):
var ground_path = '../../diagram/'+diary+'/';
break;
case ('table'):
var ground_path = '../../table/'+diary+'/';
break;
case ('graph'):
var ground_path = '../../graph/'+diary+'/';
ground_path = '../../'+ground_type+'/'+diary+'/';
break;
default:
var ground_path = '';
}
ground_path += row.value._id;
if (row.value.anchor) ground_path += '#'+row.value.anchor;
data.groundings.push({
id: row.value._id,
href: ground_path + row.value._id,
href: ground_path,
type: ground_type,
preview: preview,
name: row.doc.name
Expand Down
4 changes: 3 additions & 1 deletion app/lists/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ function(head, req) {
});
if (row.value.type != 'statement')
for (i in row.value.groundings) {
var from = row.value.groundings[i];
if (typeof from._id === 'string') from = from._id;
data.edges.push({
'from': row.value.groundings[i],
'from': from,
'to': row.value.id,
'color': color
});
Expand Down
30 changes: 18 additions & 12 deletions app/templates/memo.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1><img src="{{>relpath}}style/{{type}}.svg"/> {{name}}</h1>
{{#timestamp}}
<div class="timestamp">{{timestamp}}</div>
{{/timestamp}}
<div class="post begin">
<div class="post">
{{#words}}<font>{{.}}</font>{{/words}}
{{#text}}{{text}}{{/text}}
</div>
Expand Down Expand Up @@ -224,6 +224,7 @@ <h1><img src="{{>relpath}}style/{{type}}.svg"/> {{name}}</h1>
trigrams = {},
leaf_type = leaf_id = resume = '',
anchor = 0,
options = [],
userids = [],
help = [];
help["field"] = {init: "{{{i18n.i_content.field}}}", next: "{{{i18n.i_next.field}}}"};
Expand Down Expand Up @@ -618,26 +619,31 @@ <h1><img src="{{>relpath}}style/{{type}}.svg"/> {{name}}</h1>
})

$('#remove_grounding').on('show.bs.modal', function (event) {
var options = [];
options = [];
$('#remove_grounding select').children("option").each(function(){
options.push($(this).val());
})
$('#groundings').children('li').each(function() {
var id = ($(this).attr('id')),
name = ($(this).find('a:first').text());
if (name.length > 45) name = name.substr(0,45)+'...';
if (options.indexOf(id) < 0)
$("#remove_grounding").find('select').append($('<option>', {
value: id,
title: ($(this).find('a:first').text()),
text: name
}));
addOptions(id, name);
$('#'+id).find('.preview a').each(function() {
var href = $(this).attr('href');
if (href.includes(id)) addOptions(href, '> '+$(this).text());
});
});
});

$(window).scroll(function(){
$('.post').removeClass("begin");
});
function addOptions(id, name) {
var shortname = name;
if (name.length > 45) shortname = name.substr(0,45)+'...';
if (options.indexOf(id) < 0)
$("#remove_grounding").find('select').append($('<option>', {
value: id,
title: name,
text: shortname
}));
}

function renameDiagram(id,name) {
$.ajax({
Expand Down
40 changes: 36 additions & 4 deletions app/updates/adapt_memo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,48 @@ function (doc, req) {
break;
case ('add_grounding'):
if (!doc.groundings) doc.groundings = [];
if (doc.groundings.indexOf(obj.value) == -1) doc.groundings.push(obj.value);
if (doc.type == 'coding' && obj.highlight) {
var highlight = obj.highlight;
var highlight = obj.highlight,
preview = {
'text': obj.highlight,
'anchor': obj.anchor
},
grounding = {
'_id': obj.value,
'preview': [preview]
};
if (obj.anchor > 0) highlight = '['+highlight+']('+obj.value+'#'+obj.anchor+')';
doc.body = doc.body + '\n \n>'+highlight+' \n \n';
var i = doc.groundings.map(function(g){
if (g._id) {return g._id} else return g;
}).indexOf(obj.value);
if (i > -1) {
if (doc.groundings[i].preview) {
doc.groundings[i].preview.push(preview);
} else {
doc.groundings.splice(i, 1, grounding);
}
} else {
doc.groundings.push(grounding);
}
} else {
if (doc.groundings.indexOf(obj.value) == -1) doc.groundings.push(obj.value);
}
break;
case ('remove_grounding'):
var i = doc.groundings.indexOf(obj.value);
if (i > -1) doc.groundings.splice(i, 1);
var arg = obj.value;
var [id, anchor] = obj.value.split('#');
var i = doc.groundings.map(function(g){
if (g._id) {return g._id} else return g;
}).indexOf(id);
if (arg.indexOf('#') > -1){
var j = doc.groundings[i].preview.map(function(p){
return p.anchor.toString();
}).indexOf(anchor);
if (i > -1 && j > -1) doc.groundings[i].preview.splice(j, 1)
} else {
if (i > -1) doc.groundings.splice(i, 1);
}
break;
}
return [doc, 'Memo updated']
Expand Down
1 change: 1 addition & 0 deletions app/views/leaves/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function(o) {
var diary = o.diary || o.corpus;
for (var g in o.groundings) {
var ground = o.groundings[g];
if (typeof ground._id === 'string') ground = ground._id;
var type = o.type || 'transcript';
emit([ground], {
id: o._id,
Expand Down
9 changes: 7 additions & 2 deletions app/views/memo/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ function(o) {
if (o.corpus)
emit([o._id, 'D'], {'_id': o.corpus});
for (var key in o.groundings) {
emit([o._id, 'G'], {'_id': o.groundings[key]});
emit([o.groundings[key], 'L']);
if (typeof o.groundings[key] === 'string' || o.groundings[key] instanceof String) {
emit([o._id, 'G'], {'_id': o.groundings[key]});
emit([o.groundings[key], 'L']);
} else {
emit([o._id, 'G'], o.groundings[key]);
emit([o.groundings[key]._id, 'L']);
}
}
if (o.commented)
emit([o.commented, 'M', o.date], {'_id': o.user, 'date': o.date, 'text': o.text, 'checked': o.checked, 'id': o._id});
Expand Down
4 changes: 3 additions & 1 deletion app/views/tasklist/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function(o) {
if (o.groundings && o.groundings.length < 1)
emit([diary, user, 'G', o.history[0].date], {'id': o._id, '_id': null, 'name': o.name});
if (o.groundings && o.groundings.length == 1)
emit([diary, user, 'G', o.history[0].date], {'id': o._id, '_id': o.groundings[0], 'name': o.name});
var gid = o.groundings[0];
if (typeof gid._id === 'string') gid = gid._id;
emit([diary, user, 'G', o.history[0].date], {'id': o._id, '_id': gid, 'name': o.name});
if (o.type == 'diagram' && o.groundings && o.groundings.length == 1)
emit([diary, user, 'A', o.history[0].date], {'id': o._id, '_id': o._id, 'name': o.name});
}
Expand Down

0 comments on commit 39acf27

Please sign in to comment.