Commit 750e7a46 authored by Elias's avatar Elias

Annotations Fixes : refreshDisplay, refactored onListSubmit into ngramlist.js...

Annotations Fixes : refreshDisplay, refactored onListSubmit into ngramlist.js and cleaned some unused dependencies
parent aa17ae8b
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
var annotationsAppDocument = angular.module('annotationsAppDocument', ['annotationsAppHttp']); var annotationsAppDocument = angular.module('annotationsAppDocument', ['annotationsAppHttp']);
annotationsAppDocument.controller('DocController', annotationsAppDocument.controller('DocController',
['$scope', '$rootScope', '$timeout', 'NgramListHttpService', 'DocumentHttpService', ['$scope', '$rootScope', '$timeout', 'NgramListHttpService', 'DocumentHttpService',
function ($scope, $rootScope, $timeout, NgramListHttpService, DocumentHttpService) { function ($scope, $rootScope, $timeout, NgramListHttpService, DocumentHttpService) {
......
...@@ -186,6 +186,7 @@ ...@@ -186,6 +186,7 @@
}, },
function(data) { function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()]; $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
}, },
function(data) { function(data) {
console.error("unable to get the list of ngrams"); console.error("unable to get the list of ngrams");
...@@ -214,6 +215,7 @@ ...@@ -214,6 +215,7 @@
}, },
function(data) { function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()]; $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
}, },
function(data) { function(data) {
console.error("unable to get the list of ngrams"); console.error("unable to get the list of ngrams");
...@@ -235,9 +237,8 @@ ...@@ -235,9 +237,8 @@
* Text highlighting controller * Text highlighting controller
*/ */
annotationsAppHighlight.controller('NGramHighlightController', annotationsAppHighlight.controller('NGramHighlightController',
['$scope', '$rootScope', '$compile', 'NgramHttpService', 'NgramListHttpService', ['$scope', '$rootScope', '$compile',
function ($scope, $rootScope, $compile, NgramHttpService, NgramListHttpService) { function ($scope, $rootScope, $compile) {
var counter = 0;
/* /*
* Replace the text by an html template for ngram keywords * Replace the text by an html template for ngram keywords
*/ */
...@@ -274,9 +275,6 @@ ...@@ -274,9 +275,6 @@
function compileNgramsHtml(annotations, textMapping, $rootScope) { function compileNgramsHtml(annotations, textMapping, $rootScope) {
if ($rootScope.activeLists === undefined) return; if ($rootScope.activeLists === undefined) return;
if (_.keys($rootScope.activeLists).length === 0) return; if (_.keys($rootScope.activeLists).length === 0) return;
// TODO remove this debug counter
counter = 0;
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 templateBeginRegexp = "<span ng-controller='TextSelectionController' ng-click='onClick\(\$event\)' class='keyword-inline'>"; var templateBeginRegexp = "<span ng-controller='TextSelectionController' ng-click='onClick\(\$event\)' class='keyword-inline'>";
...@@ -309,8 +307,6 @@ ...@@ -309,8 +307,6 @@
angular.forEach(textMapping, function(text, eltId) { angular.forEach(textMapping, function(text, eltId) {
if (pattern.test(text) === true) { if (pattern.test(text) === true) {
textMapping[eltId] = replaceTextByTemplate(text, annotation, template, pattern); textMapping[eltId] = replaceTextByTemplate(text, annotation, template, pattern);
// TODO remove debug
counter++;
isDisplayedIntraText = true; isDisplayedIntraText = true;
} }
}); });
...@@ -333,7 +329,7 @@ ...@@ -333,7 +329,7 @@
return textMapping; return textMapping;
} }
function refreshDisplay() { $rootScope.refreshDisplay = function() {
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;
...@@ -370,51 +366,9 @@ ...@@ -370,51 +366,9 @@
* Listen changes on the ngram data * Listen changes on the ngram data
*/ */
$rootScope.$watchCollection('activeLists', function (newValue, oldValue) { $rootScope.$watchCollection('activeLists', function (newValue, oldValue) {
refreshDisplay(); $rootScope.refreshDisplay();
}); });
/*
* Add a new NGram from the user input in the extra-text list
*/
$scope.onListSubmit = function ($event, listId) {
var inputEltId = "#"+ listId +"-input";
if ($event.keyCode !== undefined && $event.keyCode != 13) return;
var value = $(inputEltId).val().trim();
if (value === "") return;
NgramHttpService.post(
{
'listId': listId,
'ngramId': 'create'
},
{
'text': value
},
function(data) {
// on success
if (data) {
$(inputEltId).val("");
// Refresh the annotationss
NgramListHttpService.get(
{
'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
},
function(data) {
console.error("unable to get the list of ngrams");
}
);
}
}, function(data) {
// on error
$(inputEltId).parent().addClass("has-error");
console.error("error adding Ngram "+ value);
}
);
};
} }
]); ]);
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
* Controls one Ngram displayed in the flat lists (called "extra-text") * Controls one Ngram displayed in the flat lists (called "extra-text")
*/ */
annotationsAppNgramList.controller('NgramController', annotationsAppNgramList.controller('NgramController',
['$scope', '$rootScope', '$element', 'NgramHttpService', ['$scope', '$rootScope', 'NgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, $element, NgramHttpService) { function ($scope, $rootScope, NgramHttpService, NgramListHttpService) {
/* /*
* Click on the 'delete' cross button * Click on the 'delete' cross button
*/ */
...@@ -17,15 +17,22 @@ ...@@ -17,15 +17,22 @@
'listId': $scope.keyword.list_id, 'listId': $scope.keyword.list_id,
'ngramId': $scope.keyword.uuid 'ngramId': $scope.keyword.uuid
}, function(data) { }, function(data) {
$.each($rootScope.annotations, function(index, element) { // Refresh the annotationss
if (element.list_id == $scope.keyword.list_id && element.uuid == $scope.keyword.uuid) { NgramListHttpService.get(
$rootScope.annotations.splice(index, 1); {
return false; 'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to refresh the list of ngrams");
} }
}); );
}, function(data) { }, function(data) {
console.log(data); console.error("unable to remove the Ngram " + $scope.keyword.text);
console.error("unable to delete the Ngram " + $scope.keyword.uuid);
}); });
}; };
}]); }]);
...@@ -65,4 +72,56 @@ ...@@ -65,4 +72,56 @@
} }
}; };
}); });
/*
* new NGram from the user input
*/
annotationsAppNgramList.controller('NgramInputController',
['$scope', '$rootScope', '$element', 'NgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, $element, NgramHttpService, NgramListHttpService) {
/*
* Add a new NGram from the user input in the extra-text list
*/
$scope.onListSubmit = function ($event, listId) {
var inputEltId = "#"+ listId +"-input";
if ($event.keyCode !== undefined && $event.keyCode != 13) return;
var value = angular.element(inputEltId).val().trim();
if (value === "") return;
NgramHttpService.post(
{
'listId': listId,
'ngramId': 'create'
},
{
'text': value
},
function(data) {
// on success
if (data) {
angular.element(inputEltId).val("");
// Refresh the annotationss
NgramListHttpService.get(
{
'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to get the list of ngrams");
}
);
}
}, function(data) {
// on error
angular.element(inputEltId).parent().addClass("has-error");
console.error("error adding Ngram "+ value);
}
);
};
}]);
})(window); })(window);
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
</ul> </ul>
</nav> </nav>
<div class="form-group"> <div class="form-group" ng-controller="NgramInputController">
<input autosave="search" maxlength="240" placeholder="Add any text" type="text" class="form-control" id="{[{listId}]}-input" ng-keypress="onListSubmit($event, listId)"> <input autosave="search" maxlength="240" placeholder="Add any text" type="text" class="form-control" id="{[{listId}]}-input" ng-keypress="onListSubmit($event, listId)">
<button type="submit" class="form-control btn btn-default btn-primary" ng-click="onListSubmit($event, listId)">Add to {[{listName}]}</button> <button type="submit" class="form-control btn btn-default btn-primary" ng-click="onListSubmit($event, listId)">Add to {[{listName}]}</button>
</div> </div>
......
...@@ -103,6 +103,7 @@ def listNgramIds(list_id=None, typeList=None, ...@@ -103,6 +103,7 @@ def listNgramIds(list_id=None, typeList=None,
.group_by(Ngram.id, ListNgram.node_id) .group_by(Ngram.id, ListNgram.node_id)
) )
# FIXME this is only used to filter on 1 document
if doc_id is not None: if doc_id is not None:
Doc = aliased(Node) Doc = aliased(Node)
DocNgram = aliased(NodeNgram) DocNgram = aliased(NodeNgram)
......
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