Commit 25d76875 authored by delanoe's avatar delanoe

Merge branch 'romain-refactoring' into refactoring

parents 06d0a25a ff1b1634
...@@ -10,10 +10,14 @@ ...@@ -10,10 +10,14 @@
$scope.activeListsChange = function() { $scope.activeListsChange = function() {
var selected = $('.selectpicker option:selected').val(); var selected = $('.selectpicker option:selected').val();
var newActive = {}; var newActive = {};
$('.selectpicker option:selected').each(function(item, value) { $('.selectpicker option:selected').each(function(item, opt) {
var id = value.id.split("---", 2)[1]; // ex opt:
newActive[id] = value.value; // <option id="list---748" value="MAINLIST">MAINLIST</option>
var id = opt.id.split("---", 2)[1];
newActive[id] = opt.value;
}); });
// ex: {745: "MAINLIST", 748: "MAPLIST"}
$rootScope.activeLists = newActive; $rootScope.activeLists = newActive;
}; };
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
.MAPLIST { .MAPLIST {
color: black; color: black;
/* green */ /* green */
background-color: rgba(60, 118, 61, .7); background-color: rgba(23, 255, 189, .7);
/* background-color: rgba(60, 118, 61, .7); */
cursor: pointer; cursor: pointer;
} }
......
...@@ -441,15 +441,12 @@ ...@@ -441,15 +441,12 @@
var middlePattern = " "; var middlePattern = " ";
var endPattern = "(?:<\/span>)*)\\b"; var endPattern = "(?:<\/span>)*)\\b";
console.log("highlight annotations length: " + annotations.length) // hash of flags filled in first pass loop : (== did annotation i match ?)
var isDisplayedIntraText = {};
var sortedSizeAnnotations = lengthSort(annotations, "text"), console.log("highlight annotations length: " + annotations.length)
extraNgramList = angular.copy($rootScope.extraNgramList);
// reinitialize an empty list var sortedSizeAnnotations = lengthSort(annotations, "text")
extraNgramList = angular.forEach(extraNgramList, function(name, id) {
extraNgramList[id] = [];
});
// rl: £dbg counters // rl: £dbg counters
var i = 0 ; var i = 0 ;
...@@ -506,6 +503,9 @@ ...@@ -506,6 +503,9 @@
var nbMatches = matches ? eltLongtext.match(myPattern).length : 0 var nbMatches = matches ? eltLongtext.match(myPattern).length : 0
if (nbMatches > 0) { if (nbMatches > 0) {
k += nbMatches ; k += nbMatches ;
// remember that this annotation.text matched
isDisplayedIntraText[annotation.uuid] = annotation
l ++ ; l ++ ;
// ------------------------------------------------------------ // ------------------------------------------------------------
// ICI we update each time // ICI we update each time
...@@ -549,81 +549,72 @@ ...@@ -549,81 +549,72 @@
// highlight anchors as html spans // highlight anchors as html spans
// ------------------------------- // -------------------------------
angular.forEach(textMapping, function(text, eltId) { angular.forEach(textMapping, function(textContent, eltId) {
// console.log(anchorPattern) // console.log(anchorPattern)
if(text) { if(textContent) {
textMapping[eltId] = replaceAnchorByTemplate( textMapping[eltId] = replaceAnchorByTemplate(
text, textContent,
annotation, annotation,
template, template,
anchorPattern); anchorPattern);
} }
}); });
// rloth: for now let's show *all* ngrams of the active list
// in the left side
extraNgramList[annotation.list_id] = extraNgramList[annotation.list_id].concat(annotation);
}); });
// let's show just the ngrams that matched
// in the left side
var sortedDisplayedKeys = Object.keys(isDisplayedIntraText).sort()
// sorts on ngram_id
// new update ngramsInPanel
angular.forEach(sortedDisplayedKeys, function(id) {
var the_annot = isDisplayedIntraText[id] ;
var the_list_id = the_annot.list_id ;
$rootScope.ngramsInPanel[the_list_id].push(the_annot)
});
// debug
//console.warn("$rootScope.ngramsInPanel :")
//console.warn($rootScope.ngramsInPanel)
// update extraNgramList
$rootScope.extraNgramList = angular.forEach(extraNgramList, function(name, id) {
extraNgramList[id] = lengthSort(extraNgramList[id], 'text');
});
// return the object of element ID with the corresponding HTML // return the object of element ID with the corresponding HTML
return textMapping; return textMapping;
} }
/*
* main refresh
*/
$rootScope.refreshDisplay = function() { $rootScope.refreshDisplay = function() {
console.log("annotations.highlight.refreshDisplay()") console.log("annotations.highlight.refreshDisplay()")
if ($rootScope.annotations === undefined) return; if ($rootScope.annotations === undefined) return;
if ($rootScope.activeLists === undefined) return; if ($rootScope.activeLists === undefined) return;
if (_.keys($rootScope.activeLists).length === 0) return; if (_.keys($rootScope.activeLists).length === 0) return;
// initialize extraNgramList // initialize ngramsInPanel
var extraNgramList = {}; // ------------------------
$rootScope.extraNgramList = angular.forEach($rootScope.activeLists, function(name, id) { // $rootScope.ngramsInPanel = {
this[id] = []; // activelist1_id : [
}, extraNgramList); // annotation_a,
$rootScope.extraNgramList = extraNgramList; // annotation_b,
// annotation_c
// ] ,
// activelist2_id : [
// annotation_x,
// annotation_y,
// annotation_z
// ] ,
// ....
// }
//
var ngramsInPanel = {};
$rootScope.ngramsInPanel = angular.forEach($rootScope.activeLists, function(name, list_id) {
this[list_id] = [];
}, ngramsInPanel);
$rootScope.ngramsInPanel = ngramsInPanel;
/* /*
* Transform text into HTML with higlighted ngrams * Transform text into HTML with higlighted ngrams via compileNgramsHtml
*/ */
var result = compileNgramsHtml( var result = compileNgramsHtml(
$rootScope.annotations, $rootScope.annotations,
...@@ -643,6 +634,8 @@ ...@@ -643,6 +634,8 @@
angular.element(elt).replaceWith($compile(elt)($rootScope.$new(true))); angular.element(elt).replaceWith($compile(elt)($rootScope.$new(true)));
}); });
} }
/* /*
* Listen changes on the ngram data * Listen changes on the ngram data
*/ */
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
// (then used for left-side flatlist AND inline annots) // (then used for left-side flatlist AND inline annots)
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()]; $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo} // TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup = // $rootScope.lookup =
$rootScope.refreshDisplay(); $rootScope.refreshDisplay();
}, },
function(data) { function(data) {
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
annotationsAppNgramList.controller('NgramListPaginationController', annotationsAppNgramList.controller('NgramListPaginationController',
['$scope', '$rootScope', function ($scope, $rootScope) { ['$scope', '$rootScope', function ($scope, $rootScope) {
$rootScope.$watchCollection('extraNgramList', function (newValue, oldValue) { $rootScope.$watchCollection('ngramsInPanel', function (newValue, oldValue) {
$scope.currentListPage = 0; $scope.currentListPage = 0;
$scope.pageSize = 15; $scope.pageSize = 15;
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
}; };
$scope.totalListPages = function(listId) { $scope.totalListPages = function(listId) {
if ($rootScope.extraNgramList[listId] === undefined) return 0; if ($rootScope.ngramsInPanel[listId] === undefined) return 0;
return Math.ceil($rootScope.extraNgramList[listId].length / $scope.pageSize); return Math.ceil($rootScope.ngramsInPanel[listId].length / $scope.pageSize);
}; };
}); });
}]); }]);
...@@ -93,12 +93,12 @@ ...@@ -93,12 +93,12 @@
var value = angular.element(inputEltId).val().trim(); var value = angular.element(inputEltId).val().trim();
if (value === "") return; if (value === "") return;
// £TEST locally check if already in annotations NodeNgrams ------ // £TEST locally check if already in annotations NodeNgrams ------
// $rootScope.annotations = array of ngram objects like: // $rootScope.annotations = array of ngram objects like:
// {"list_id":805,"occurrences":2,"uuid":9386,"text":"petit échantillon"} // {"list_id":805,"occurrences":2,"uuid":9386,"text":"petit échantillon"}
console.log('looking for "' + value + '" in list:' + listId) console.log('looking for "' + value + '" in list:' + listId)
var already_in_list = false ; var already_in_list = false ;
angular.forEach($rootScope.annotations, function(annot,i) { angular.forEach($rootScope.annotations, function(annot,i) {
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
); );
if (already_in_list) { return ; } if (already_in_list) { return ; }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// will check if there's a preexisting ngramId for this value // will check if there's a preexisting ngramId for this value
// TODO: if maplist => also add to miam // TODO: if maplist => also add to miam
NgramHttpService.post( NgramHttpService.post(
...@@ -136,11 +136,11 @@ ...@@ -136,11 +136,11 @@
}, },
function(data) { function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()]; $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo} // TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup = // $rootScope.lookup =
$rootScope.refreshDisplay(); $rootScope.refreshDisplay();
}, },
function(data) { function(data) {
......
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div ng-controller="NgramListPaginationController" ng-repeat="(listId, listName) in activeLists" ng-class="{active: $first == true}" class="tab-pane" id="tab-{[{listId}]}"> <div ng-controller="NgramListPaginationController" ng-repeat="(listId, listName) in activeLists" ng-class="{active: $first == true}" class="tab-pane" id="tab-{[{listId}]}">
<div ng-if="extraNgramList[listId].length == 0" class="alert alert-info" role="alert"> <div ng-if="ngramsInPanel[listId].length == 0" class="alert alert-info" role="alert">
Input any keyword you want to link to this article and the list named '{[{listName}]}' Input any keyword you want to link to this article and the list named '{[{listName}]}'
</div> </div>
<ul class="list-group words-list clearfix"> <ul class="list-group words-list clearfix">
<li ng-repeat="keyword in extraNgramList[listId] | startFrom:currentListPage * pageSize | limitTo:pageSize" class="keyword-group-item"> <li ng-repeat="keyword in ngramsInPanel[listId] | startFrom:currentListPage * pageSize | limitTo:pageSize" class="keyword-group-item">
<div ng-controller="NgramController" keyword-template class="keyword-container"></div> <div ng-controller="NgramController" keyword-template class="keyword-container"></div>
</li> </li>
</ul> </ul>
......
...@@ -14,7 +14,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica ...@@ -14,7 +14,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica
# 2016-03-24: refactoring, new paths # 2016-03-24: refactoring, new paths
from gargantext.models.ngrams import Node, NodeNgram, Ngram from gargantext.models.ngrams import Node, NodeNgram, Ngram
from gargantext.util.db import session from gargantext.util.db import session, aliased
from gargantext.util.db_cache import cache from gargantext.util.db_cache import cache
from gargantext.util.http import requires_auth from gargantext.util.http import requires_auth
...@@ -47,16 +47,25 @@ class NgramList(APIView): ...@@ -47,16 +47,25 @@ class NgramList(APIView):
doc_ngram_list = [] doc_ngram_list = []
lists = {} lists = {}
corpus_nod = cache.Node[corpus_id]
doc_nod = cache.Node[doc_id]
scores_nod = corpus_nod.children(typename="OCCURRENCES").first()
for list_type in ['MAINLIST', 'MAPLIST', 'STOPLIST']: for list_type in ['MAINLIST', 'MAPLIST', 'STOPLIST']:
corpus_nod = cache.Node[corpus_id]
list_nod = corpus_nod.children(typename=list_type).first() list_nod = corpus_nod.children(typename=list_type).first()
list_id = list_nod.id list_id = list_nod.id
lists["%s" % list_id] = list_type lists["%s" % list_id] = list_type
ListsTable = aliased(NodeNgram)
# doc_nod.ngrams iff we just need the occurrences in the doc (otherwise do manually)
q = doc_nod.ngrams.join(ListsTable).filter(ListsTable.node_id == list_id)
# add to results # add to results
doc_ngram_list += [(obj.id, obj.terms, w, list_id) for (w,obj) in list_nod.ngrams.all()] doc_ngram_list += [(obj.id, obj.terms, w, list_id) for (w,obj) in q.all()]
print("annotations.views.NgramList.doc_ngram_list: ", doc_ngram_list) # debug
# print("annotations.views.NgramList.doc_ngram_list: ", doc_ngram_list)
data = { '%s' % corpus_id : { data = { '%s' % corpus_id : {
'%s' % doc_id : '%s' % doc_id :
[ [
......
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