Commit b96ef986 authored by Elias's avatar Elias

restored annotations UI after API refactoring

parent e8590680
......@@ -27,13 +27,13 @@
border-bottom: none;
}
.miamlist {
.miamword {
color: black;
background-color: rgba(60, 118, 61, 0.5);
cursor: pointer;
}
.stoplist {
.stopword {
color: black;
background-color: rgba(169, 68, 66, 0.2);
cursor: pointer;
......
......@@ -93,10 +93,10 @@
$timeout(function() {
$scope.$apply(function() {
$scope.miamListId = _.invert($rootScope.lists)['MiamList'];
$scope.stopListId = _.invert($rootScope.lists)['StopList'];;
$scope.stopListId = _.invert($rootScope.lists)['StopList'];
if (angular.isObject(annotation)) {
$scope.level = angular.copy(annotation.level);
$scope.level = angular.copy(annotation.level || 'global');
$scope.category = $rootScope.lists[annotation.list_id].toLowerCase();
$scope.listId = angular.copy(annotation.list_id);
// used in onClick
......@@ -176,7 +176,7 @@
// action from the menu of an existing Ngram
$scope.selection_text.category = $rootScope.lists[listId].toLowerCase();
// TODO deprecated
$scope.selection_text.level = level;
$scope.selection_text.level = 'global';
// delete from the current list
NgramHttpService.delete({
'listId': $scope.selection_text.list_id,
......@@ -222,15 +222,15 @@
/*
* Replace the text by and html template
*/
function replaceTextByTemplate(text, annotation, template, pattern) {
function replaceTextByTemplate(text, annotation, template, pattern, lists) {
return text.replace(pattern, function(matched) {
var tpl = angular.element(template);
tpl.append(matched);
tpl.attr('title', annotation.tooltip_content);
tpl.attr('uuid', annotation.uuid);
if (annotation.category == 'miamlist') tpl.addClass("miamword");
if (annotation.category == 'stoplist' && annotation.level == 'local') tpl.addClass("stopword");
if ('MiamList' == lists[annotation.list_id]) tpl.addClass("miamword");
if ('StopList' == lists[annotation.list_id]) tpl.addClass("stopword");
//if (annotation.category == 'stoplist' && annotation.level == 'global') tpl.addClass("global-stopword");
return tpl.get(0).outerHTML;
......@@ -266,30 +266,32 @@
_.each(sortedSizeAnnotations, function (annotation) {
// TODO better split to manage two-words with minus sign
annotation.category = $rootScope.lists[annotation.list_id].toLowerCase();
var words = annotation.text.split(" ");
var pattern = new RegExp(startPattern + words.join(middlePattern) + endPattern, 'gmi');
var textRegexp = new RegExp("\\b"+annotation.text+"\\b", 'igm');
if (pattern.test(fullText) === true) {
fullText = replaceTextByTemplate(fullText, annotation, template, pattern);
fullText = replaceTextByTemplate(fullText, annotation, template, pattern, $rootScope.lists);
// TODO remove debug
counter++;
} else if (pattern.test(abstractText) === true) {
abstractText = replaceTextByTemplate(abstractText, annotation, template, pattern);
abstractText = replaceTextByTemplate(abstractText, annotation, template, pattern, $rootScope.lists);
counter++;
} else if (!textRegexp.test($rootScope.full_text) && !textRegexp.test($rootScope.abstract_text)) {
if (annotation.category == "stoplist" && annotation.level == 'local') {
if (annotation.category == "stoplist") {
// Deactivated stoplist for the moment
// if ($.inArray(annotation.uuid, $scope.extra_stoplist.map(function (item) {
// return item.uuid;
// })) == -1) {
extra_stoplist = lengthSort(extra_stoplist.concat(annotation), "text");
// return item.uuid;
// })) == -1) {
// extra_stoplist = lengthSort(extra_stoplist.concat(annotation), "text");
// }
} else if (annotation.category == "miamlist") {
// if ($.inArray(annotation.uuid, $scope.extra_miamlist.map(function (item) {
// return item.uuid;
// })) == -1) {
if ($.inArray(annotation.uuid, $scope.extra_miamlist.map(function (item) {
return item.uuid;
})) == -1) {
extra_miamlist = lengthSort(extra_miamlist.concat(annotation), "text");
// }
}
}
}
});
......@@ -313,7 +315,8 @@
$rootScope.annotations,
angular.copy($rootScope.full_text),
angular.copy($rootScope.abstract_text),
$rootScope);
$rootScope
);
console.log($rootScope.annotations.length);
console.log(counter);
......@@ -348,11 +351,11 @@
}
$scope.onMiamlistSubmit = function ($event) {
submitNewAnnotation($event, "#miamlist-input", "miamlist");
submitNewAnnotation($event, "#miamlist-input", _.invert($rootScope.lists)['MiamList']);
};
// TODO refactor
$scope.onStoplistSubmit = function ($event) {
submitNewAnnotation($event, "#stoplist-input", "stoplist");
submitNewAnnotation($event, "#stoplist-input", _.invert($rootScope.lists)['MiamList']);
};
$scope.numStopPages = function () {
if ($scope.extra_stoplist === undefined) return 0;
......
......@@ -23,14 +23,14 @@
<div class="container-fluid">
<div class="row-fluid main-panel" ng-controller="IntraTextController">
<div class="col-md-4 col-xs-4 tabbable words-panel">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Miamwords</a></li>
<li><a href="#tab2" data-toggle="tab">Local stopwords</a></li>
<ul class="nav nav-pills nav-justified">
<li class="active"><a href="#tab1" data-toggle="tab"><span class="glyphicon glyphicon-tags"></span>&nbsp;&nbsp;Miamwords</a></li>
<!--<li><a href="#tab2" data-toggle="tab">Local stopwords</a></li>-->
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<ul class="list-group words-list">
<div ng-if="extra_miamlist.length == 0" class="alert alert-info" role="alert">No extra-text miam-word yet</div>
<div ng-if="extra_miamlist.length == 0" class="alert alert-info" role="alert">No extra text miam-word yet</div>
<li ng-repeat="keyword in extra_miamlist | startFrom:currentMiamPage*pageSize | limitTo:pageSize" class="list-group-item">
<div ng-controller="ExtraAnnotationController" keyword-template class="keyword-container"></div>
......@@ -47,7 +47,7 @@
<button type="submit" class="btn btn-default btn-primary" ng-click="onMiamlistSubmit($event)">Add</button>
</div>
</div>
<div class="tab-pane" id="tab2">
<!--<div class="tab-pane" id="tab2">
<ul class="list-group words-list clearfix">
<div ng-if="extra_stoplist.length == 0" class="alert alert-info" role="alert">No extra-text stop-word yet</div>
<li ng-repeat="keyword in extra_stoplist | startFrom:currentStopPage*pageSize | limitTo:pageSize" class="list-group-item"><div ng-controller="ExtraAnnotationController" keyword-template></div></li>
......@@ -62,7 +62,7 @@
<input type="text" class="form-control" id="stoplist-input" ng-keypress="onStoplistSubmit($event)">
<button type="submit" class="btn btn-default" ng-click="onStoplistSubmit($event)">Exclude</button>
</div>
</div>
</div>-->
</div>
</div>
<div class="col-md-8 col-xs-8 text-panel" ng-controller="DocController" id="document">
......@@ -87,9 +87,13 @@
</ul>
</div>
<h4>Abstract</h4>
<p id="abstract-text" class="text-container"></p>
<h4>Article</h4>
<p id="full-text" class="text-container"></p>
<p id="abstract-text" class="text-container">
<div ng-if="abstract_text.length == 0" class="alert alert-info" role="alert">No abstract text</div>
</p>
<h4>Full Article</h4>
<p id="full-text" class="text-container">
<div ng-if="abstract_text.length == 0" class="alert alert-info" role="alert">No full text</div>
</p>
</div>
</div> <!-- end of the main row -->
</div>
......
......@@ -5,5 +5,5 @@ from annotations import views
urlpatterns = patterns('',
url(r'^document/(?P<doc_id>[0-9]+)$', views.Document.as_view()), # document view
url(r'^corpus/(?P<corpus_id>[0-9]+)/document/(?P<doc_id>[0-9]+)$', views.NgramList.as_view()), # the list associated with an ngram
url(r'^lists/(?P<list_id>[0-9]+)/ngrams/(?P<ngram_id>[0-9]+|new)?$', views.Ngram.as_view()), #
url(r'^lists/(?P<list_id>[0-9]+)/ngrams/(?P<ngram_id>[new0-9]+)$', views.NgramEdit.as_view()), #
)
......@@ -10,14 +10,13 @@ from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from rest_framework.exceptions import APIException
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from node.models import Node
from gargantext_web.db import *
from ngram.lists import listIds, listNgramIds, ngramList
import sqlalchemy
from sqlalchemy.orm import aliased
@login_required
def main(request, project_id, corpus_id, document_id):
......@@ -37,6 +36,8 @@ class NgramList(APIView):
def get(self, request, corpus_id, doc_id):
"""Get All for a doc id"""
corpus_id = int(corpus_id)
doc_id = int(doc_id)
lists = dict()
for list_type in ['MiamList', 'StopList']:
list_id = list()
......@@ -45,6 +46,8 @@ class NgramList(APIView):
# ngrams of list_id of corpus_id:
doc_ngram_list = listNgramIds(corpus_id=corpus_id, doc_id=doc_id, user_id=request.user.id)
doc_ngram_list = [(1, 'miam', 2, 1931), (2, 'stop', 2, 1932), (3, 'Potassium channels', 4, 1931)]
data = { '%s' % corpus_id : {
'%s' % doc_id : [
{
......@@ -59,15 +62,18 @@ class NgramList(APIView):
return Response(data)
class Ngram(APIView):
class NgramEdit(APIView):
"""
Actions on one Ngram in one list
"""
renderer_classes = (JSONRenderer,)
authentication_classes = (SessionAuthentication, BasicAuthentication)
def post(self, request, list_id, ngram_id):
"""
Add a ngram in a list
"""
import pudb; pu.db
ngram_dict = json.loads(request.POST.get('annotation'))
if ngram_id == 'new':
ngram_dict = json.loads(request.POST.get('annotation'))
......
......@@ -189,7 +189,6 @@ def ngrams2miam(user_id=None, corpus_id=None):
miam_id = listIds(typeList='MiamList', user_id=user_id, corpus_id=corpus_id)[0][0]
print(miam_id)
query = (session.query(
literal_column(str(miam_id)).label("node_id"),
Ngram.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