Commit 9533d10a 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 ca339c4a
......@@ -28,6 +28,15 @@
cursor: pointer;
}
.FOCUS {
color: black;
font-weight: bold;
/* yellow */
background-color: rgba(255, 224, 101, 1);
cursor: pointer;
}
.delete-keyword, .occurrences {
vertical-align: super;
font-size: 70%;
......
......@@ -23,10 +23,17 @@
* GET the document node and all its ngrams
*/
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.corpusId = path[2];
$rootScope.docId = path[3];
$rootScope.focusNgram = path[4];
// debug
// console.log("==> $rootScope <==")
// console.log($rootScope)
});
})(window);
......@@ -375,7 +375,7 @@
/*
* 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:
// =============
......@@ -387,6 +387,7 @@
// ng-click='onClick($event)'
// class='keyword-inline'></span>"
// pattern ---- RegExp(/#\(#MAINLIST-10007#\)#/gm)
// cssclass --- MAINLIST
return text.replace(pattern, function(matched) {
var tpl = angular.element(template);
......@@ -396,7 +397,7 @@
/*
* Add CSS class depending on the list the ngram is into
*/
tpl.addClass(ngram.listName);
tpl.addClass(cssclass);
return tpl.get(0).outerHTML;
});
}
......@@ -424,9 +425,18 @@
}
/*
* 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) {
if ($rootScope.activeLists === undefined) return;
function compileNgramsHtml(annotations, textMapping, $rootScope, focusNgram) {
if (typeof $rootScope.activeLists == "undefined") return;
if (_.keys($rootScope.activeLists).length === 0) return;
var templateBegin = "<span ng-controller='TextSelectionController' ng-click='onClick($event)' class='keyword-inline'>";
var templateEnd = "</span>";
......@@ -534,8 +544,13 @@
// again exclude ngrams that are into inactive lists
if ($rootScope.activeLists[annotation.list_id] === undefined) return;
// now used to setup css class
annotation.listName = $rootScope.lists[annotation.list_id];
// listName now used to setup css class
var cssClass = $rootScope.lists[annotation.list_id];
// except if FOCUS
if (annotation.uuid == focusNgram) {
cssClass = "FOCUS"
}
// used as unique placeholder for str.replace
// (anchor avoids side effects of multiple replacements
......@@ -553,7 +568,8 @@
textContent,
annotation,
template,
anchorPattern);
anchorPattern,
cssClass);
}
});
});
......@@ -588,6 +604,9 @@
if ($rootScope.activeLists === undefined) return;
if (_.keys($rootScope.activeLists).length === 0) return;
// console.log("$rootScope.annotations")
// console.log($rootScope.annotations)
// initialize ngramsInPanel
// ------------------------
// $rootScope.ngramsInPanel = {
......@@ -620,7 +639,8 @@
'#abstract-text': angular.copy($rootScope.abstract_text),
'#title': angular.copy($rootScope.title)
},
$rootScope
$rootScope,
$rootScope.focusNgram // new: optional focus ngram
);
// inject highlighted HTML
angular.forEach(result, function(html, eltId) {
......
......@@ -19,9 +19,11 @@ from gargantext.util.http import requires_auth
from sqlalchemy.sql.expression import case
@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
NB: url params are NOT used here (angular has its own url regex in app.js)
"""
return render_to_response('annotations/main.html', {
# TODO use reverse()
......@@ -48,14 +50,14 @@ class NgramList(APIView):
corpus_id = int(corpus_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_add = doc_ngram_list.append
lists = {}
corpus_nod = cache.Node[corpus_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()
# synonyms sub table for outerjoins
......
......@@ -41,7 +41,7 @@ urlpatterns = [ url(r'^admin/' , admin.site.urls )
# Module Annotation
# tempo: unchanged doc-annotations routes --
, 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)
, 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