Skip to content

Commit

Permalink
FEATURE: Grounding an existing memo in the current memo (#83)
Browse files Browse the repository at this point in the history
Up to now, if the user tried to create a memo with a name that already existed in the diary, he was prompted (though a dialog box) that a memo with that name already exists.

From now on, the platform suggests to ground the existing memo in the current one (through a one-click operation). The user is simply prompted (with no suggestion) if the grounding link already exists.
  • Loading branch information
christophe-lejeune committed Dec 6, 2019
1 parent ad82ba3 commit 165bd4d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/l10n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
"i_enter_memo_name": "Give a name to this memo",
"i_enter_graph_name": "Give a name to this diagram",
"i_memo_already_exists": "This memo name already exists",
"i_memo_already_linked": "A memo with this name is already grounded here",
"i_link_leaf": "Do you want to ground it here ?",
"i_my_diary": "My diary",
"i_my_research_question": "My research question",
"i_memos": "Memos",
Expand All @@ -108,6 +110,7 @@
"i_select_grounding": "Select a ground",
"i_groundings": "Grounded in",
"i_grounding": "Grounded in",
"i_ground": "Grounding here",
"i_comment": "Comment",
"i_enter_comment": "Enter your comment",
"i_memo": {
Expand Down Expand Up @@ -254,6 +257,8 @@
"i_enter_memo_name": "Donnez un nom à ce compte-rendu",
"i_enter_graph_name": "Donnez un nom à cette schématisation",
"i_memo_already_exists": "Un compte-rendu portant ce nom existe déjà",
"i_memo_already_linked": "Un compte-rendu portant ce nom est déjà ancré ici",
"i_link_leaf": "Voulez-vous l'ancrer ici ?",
"i_my_diary": "Mon journal de bord",
"i_my_research_question": "Ma question de recherche",
"i_memos": "Comptes-rendus",
Expand All @@ -268,6 +273,7 @@
"i_select_grounding": "Choisissez un ancrage",
"i_groundings": "Ancrages",
"i_grounding": "Ancrage",
"i_ground": "Ancrer",
"i_comment": "Commenter",
"i_enter_comment": "Saisissez un commentaire",
"i_memo": {
Expand Down
9 changes: 8 additions & 1 deletion app/lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ var shared = {
i = existing_memos.rows.map(function(e) { return e.value.name; }).indexOf(name);\
}\
if (i != -1) {\
alert('{{i18n.i_memo_already_exists}}');\
if(existing_memos.rows[i].value.groundings.indexOf('{{_id}}') != -1) {\
alert('{{i18n.i_memo_already_linked}}');\
} else {\
leaf_type = existing_memos.rows[i].value.type,\
leaf_id = existing_memos.rows[i].value.id;\
if (['diagram','graph','table'].indexOf(leaf_type) > -1) $('.linkLeaf').addClass('d-none');\
$('#existing_memo').modal('show');\
}\
} else {\
var data = {\
groundings: [grounding],\
Expand Down
40 changes: 37 additions & 3 deletions app/templates/memo.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ <h1><img src="../../style/{{type}}.svg"/> {{name}}</h1>
</div>
</div>
</div>
<div id="existing_memo" class="modal fade" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<p>{{i18n.i_memo_already_exists}}</p>
<p class="linkLeaf">{{i18n.i_link_leaf}}</p>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">{{i18n.i_cancel}}</button>
<button id="link_leaf" type="button" class="btn btn-secondary linkLeaf">{{i18n.i_ground}}</button>
</div>
</div>
</div>
</div>
</div>
<div id="modify_rights_dialog" class="modal fade" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand Down Expand Up @@ -180,8 +194,10 @@ <h1><img src="../../style/{{type}}.svg"/> {{name}}</h1>
{{>script}}
<script src="../../script/showdown.min.js"></script>
<script>
var metrics = {};
var trigrams = {};
var metrics = {},
trigrams = {},
leaf_type = '',
leaf_id = '';
$(document).ready(function() {
{{>render}}
moment.locale('{{locale}}');
Expand Down Expand Up @@ -210,7 +226,7 @@ <h1><img src="../../style/{{type}}.svg"/> {{name}}</h1>
document.getElementById('edit').disabled = true
}
$('main').append('<div class="toast" style="position: absolute; top: 1%; right: 3%;" role="alert">'
+ '<div class="toast-body alert-danger">'
+ '<div class="toast-body alert-warning">'
+ '<button type="button" class="close" data-dismiss="toast">×</button>'
+ $('#editing').text().replace(/\s+/g, " ") + '</div></div>');
$('.toast').toast({autohide: false});
Expand Down Expand Up @@ -428,6 +444,24 @@ <h1><img src="../../style/{{type}}.svg"/> {{name}}</h1>
create(type, '{{_id}}', $('#leave-name').val().trim());
});

$('#link_leaf').on('click', function() {
$.ajax({
url: '../../'+leaf_id,
type: "GET",
dataType: "json"
})
.then(function(leaf) {
if (leaf.groundings.indexOf('{{_id}}') == -1) leaf.groundings.push('{{_id}}');
$.ajax({
type: "PUT",
url: '../../'+leaf_id,
contentType: "application/json",
data: JSON.stringify(leaf),
success: reload
});
});
});

$('#add_grounding').on('show.bs.modal', function (event) {
$.ajax({
url: "../../memo_attribute/{{diary}}",
Expand Down

0 comments on commit 165bd4d

Please sign in to comment.