Commit 07086b67 authored by Romain Loth's avatar Romain Loth

annotations: add possibility to overhighlight a maplist term via route...

annotations: add possibility to overhighlight a maplist term via route projects/1/corpora/81/documents/83/focus=2677 where 2677 is the id of the term to highlight
parent 5aa72882
...@@ -28,6 +28,15 @@ ...@@ -28,6 +28,15 @@
cursor: pointer; cursor: pointer;
} }
.FOCUS {
color: black;
font-weight: bold;
/* yellow */
background-color: rgba(255, 224, 101, 1);
cursor: pointer;
}
.delete-keyword, .occurrences { .delete-keyword, .occurrences {
vertical-align: super; vertical-align: super;
font-size: 70%; font-size: 70%;
......
...@@ -23,10 +23,17 @@ ...@@ -23,10 +23,17 @@
* GET the document node and all its ngrams * GET the document node and all its ngrams
*/ */
window.annotationsApp.run(function ($rootScope) { window.annotationsApp.run(function ($rootScope) {
var path = window.location.pathname.match(/\/projects\/(.*)\/corpora\/(.*)\/documents\/(.*)\//); // ex: projects/1/corpora/2/documents/9/
// ex: projects/1/corpora/2/documents/9/focus=2677 (to highlight ngram 2677 more)
var path = window.location.pathname.match(/\/projects\/(.*)\/corpora\/(.*)\/documents\/(.*)\/(?:focus=([0-9,]+))?/);
$rootScope.projectId = path[1]; $rootScope.projectId = path[1];
$rootScope.corpusId = path[2]; $rootScope.corpusId = path[2];
$rootScope.docId = path[3]; $rootScope.docId = path[3];
$rootScope.focusNgram = path[4];
// debug
// console.log("==> $rootScope <==")
// console.log($rootScope)
}); });
})(window); })(window);
...@@ -375,7 +375,7 @@ ...@@ -375,7 +375,7 @@
/* /*
* Replace the any ad hoc anchor by an html template * Replace the any ad hoc anchor by an html template
*/ */
function replaceAnchorByTemplate(text, ngram, template, pattern) { function replaceAnchorByTemplate(text, ngram, template, pattern, cssclass) {
// exemple args: // exemple args:
// ============= // =============
...@@ -387,6 +387,7 @@ ...@@ -387,6 +387,7 @@
// ng-click='onClick($event)' // ng-click='onClick($event)'
// class='keyword-inline'></span>" // class='keyword-inline'></span>"
// pattern ---- RegExp(/#\(#MAINLIST-10007#\)#/gm) // pattern ---- RegExp(/#\(#MAINLIST-10007#\)#/gm)
// cssclass --- MAINLIST
return text.replace(pattern, function(matched) { return text.replace(pattern, function(matched) {
var tpl = angular.element(template); var tpl = angular.element(template);
...@@ -396,7 +397,7 @@ ...@@ -396,7 +397,7 @@
/* /*
* Add CSS class depending on the list the ngram is into * Add CSS class depending on the list the ngram is into
*/ */
tpl.addClass(ngram.listName); tpl.addClass(cssclass);
return tpl.get(0).outerHTML; return tpl.get(0).outerHTML;
}); });
} }
...@@ -424,9 +425,18 @@ ...@@ -424,9 +425,18 @@
} }
/* /*
* Match and replace Ngram into the text * Match and replace Ngram into the text
* =====================================
* main mechanism:
* @param annotations is the list of ngrams with their info
* @param textMapping is an object with text contents
* @param $rootScope (global) to check activeLists and list names
*
* add-on mechanism:
* @param focusNgram: an ngram_id to higlight more
* (it is assumed to be already in one of the active lists)
*/ */
function compileNgramsHtml(annotations, textMapping, $rootScope) { function compileNgramsHtml(annotations, textMapping, $rootScope, focusNgram) {
if ($rootScope.activeLists === undefined) return; if (typeof $rootScope.activeLists == "undefined") return;
if (_.keys($rootScope.activeLists).length === 0) return; if (_.keys($rootScope.activeLists).length === 0) return;
var templateBegin = "<span ng-controller='TextSelectionController' ng-click='onClick($event)' class='keyword-inline'>"; var templateBegin = "<span ng-controller='TextSelectionController' ng-click='onClick($event)' class='keyword-inline'>";
var templateEnd = "</span>"; var templateEnd = "</span>";
...@@ -534,8 +544,13 @@ ...@@ -534,8 +544,13 @@
// again exclude ngrams that are into inactive lists // again exclude ngrams that are into inactive lists
if ($rootScope.activeLists[annotation.list_id] === undefined) return; if ($rootScope.activeLists[annotation.list_id] === undefined) return;
// now used to setup css class // listName now used to setup css class
annotation.listName = $rootScope.lists[annotation.list_id]; var cssClass = $rootScope.lists[annotation.list_id];
// except if FOCUS
if (annotation.uuid == focusNgram) {
cssClass = "FOCUS"
}
// used as unique placeholder for str.replace // used as unique placeholder for str.replace
// (anchor avoids side effects of multiple replacements // (anchor avoids side effects of multiple replacements
...@@ -553,7 +568,8 @@ ...@@ -553,7 +568,8 @@
textContent, textContent,
annotation, annotation,
template, template,
anchorPattern); anchorPattern,
cssClass);
} }
}); });
}); });
...@@ -588,6 +604,9 @@ ...@@ -588,6 +604,9 @@
if ($rootScope.activeLists === undefined) return; if ($rootScope.activeLists === undefined) return;
if (_.keys($rootScope.activeLists).length === 0) return; if (_.keys($rootScope.activeLists).length === 0) return;
// console.log("$rootScope.annotations")
// console.log($rootScope.annotations)
// initialize ngramsInPanel // initialize ngramsInPanel
// ------------------------ // ------------------------
// $rootScope.ngramsInPanel = { // $rootScope.ngramsInPanel = {
...@@ -620,7 +639,8 @@ ...@@ -620,7 +639,8 @@
'#abstract-text': angular.copy($rootScope.abstract_text), '#abstract-text': angular.copy($rootScope.abstract_text),
'#title': angular.copy($rootScope.title) '#title': angular.copy($rootScope.title)
}, },
$rootScope $rootScope,
$rootScope.focusNgram // new: optional focus ngram
); );
// inject highlighted HTML // inject highlighted HTML
angular.forEach(result, function(html, eltId) { angular.forEach(result, function(html, eltId) {
......
...@@ -19,9 +19,11 @@ from gargantext.util.http import requires_auth ...@@ -19,9 +19,11 @@ from gargantext.util.http import requires_auth
from sqlalchemy.sql.expression import case from sqlalchemy.sql.expression import case
@requires_auth @requires_auth
def main(request, project_id, corpus_id, document_id): def main(request, project_id, corpus_id, document_id, optional_focus_ngram):
""" """
Full page view Full page view
NB: url params are NOT used here (angular has its own url regex in app.js)
""" """
return render_to_response('annotations/main.html', { return render_to_response('annotations/main.html', {
# TODO use reverse() # TODO use reverse()
...@@ -48,14 +50,14 @@ class NgramList(APIView): ...@@ -48,14 +50,14 @@ class NgramList(APIView):
corpus_id = int(corpus_id) corpus_id = int(corpus_id)
doc_id = int(doc_id) doc_id = int(doc_id)
# our results: ngrams for the corpus_id (ignoring doc_id for the moment) # our results: ngrams within a doc and a list + weights in the doc
doc_ngram_list = [] doc_ngram_list = []
doc_ngram_list_add = doc_ngram_list.append doc_ngram_list_add = doc_ngram_list.append
lists = {} lists = {}
corpus_nod = cache.Node[corpus_id] corpus_nod = cache.Node[corpus_id]
doc_nod = cache.Node[doc_id] doc_nod = cache.Node[doc_id]
scores_nod = corpus_nod.children(typename="OCCURRENCES").first() # scores_nod = corpus_nod.children(typename="OCCURRENCES").first()
groups_nod = corpus_nod.children(typename="GROUPLIST").first() groups_nod = corpus_nod.children(typename="GROUPLIST").first()
# synonyms sub table for outerjoins # synonyms sub table for outerjoins
......
...@@ -41,7 +41,7 @@ urlpatterns = [ url(r'^admin/' , admin.site.urls ) ...@@ -41,7 +41,7 @@ urlpatterns = [ url(r'^admin/' , admin.site.urls )
# Module Annotation # Module Annotation
# tempo: unchanged doc-annotations routes -- # tempo: unchanged doc-annotations routes --
, url(r'^annotations/', include( annotations_urls ) ) , url(r'^annotations/', include( annotations_urls ) )
, url(r'^projects/(\d+)/corpora/(\d+)/documents/(\d+)/$', annotations_main_view) , url(r'^projects/(\d+)/corpora/(\d+)/documents/(\d+)/(focus=[0-9,]+)?$', annotations_main_view)
# Module Scrapers (Moissonneurs in French) # Module Scrapers (Moissonneurs in French)
, url(r'^moissonneurs/' , include( moissonneurs.urls ) ) , url(r'^moissonneurs/' , include( moissonneurs.urls ) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment