Commit bdb6ac85 authored by Mathieu Rodic's avatar Mathieu Rodic

[BUGFIX] completed advanced chart

 - introduced a timer so data are not instantely reloaded
 - corpus list is made more compact
 - filters on metadata seem to be working properly
 - some fields are explicitely rejected for metadata filtering
parent a41833eb
......@@ -86,6 +86,7 @@ class NodeNgramsQueries(APIView):
'contains': lambda field, value: (field.contains(value)),
'doesnotcontain': lambda field, value: (not_(field.contains(value))),
'startswith': lambda field, value: (field.startswith(value)),
'endswith': lambda field, value: (field.endswith(value)),
}
_converters = {
......@@ -93,7 +94,7 @@ class NodeNgramsQueries(APIView):
'int': int,
'datetime': lambda x: x + '2000-01-01 00:00:00Z'[len(x):],
'text': str,
'str': str,
'string': str,
}
......@@ -219,7 +220,6 @@ class NodeNgramsQueries(APIView):
.filter(NH.hyperdata_id == hyperdata_id)
.filter(operator(NH_column, value))
)
# build result: prepare data
date_value_list = query_result.all()
if date_value_list:
......
......@@ -242,18 +242,46 @@ gargantext.controller('DatasetController', function($scope, $http) {
$.each($scope.corpora, function(c, corpus){
corpus.is_selected = false;
});
$scope.updateDataset();
$scope._updateHyperdataList(function() {
$scope.updateDataset();
});
};
$scope.corporaSelectAll = function() {
$.each($scope.corpora, function(c, corpus){
corpus.is_selected = true;
});
$scope.updateDataset();
$scope._updateHyperdataList(function() {
$scope.updateDataset();
});
};
// filters: metadata, according to the considered corpora
// filters: hyperdata, according to the considered corpora
$scope.hyperdataList = [];
$scope.updateHyperdataTimer = null;
$scope.setHyperdataList = function(hyperdataList) {
// add an empty item for each value
$.each(hyperdataList, function(h, hyperdata) {
if (hyperdata.values) {
hyperdata.values.unshift(undefined);
}
});
// do not keep the ones we are not interested into
var rejectedHyperdata = ['doi', 'volume', 'page'];
$scope.hyperdataList = [];
$.each(hyperdataList, function(h, hyperdata) {
if (rejectedHyperdata.indexOf(hyperdata.key) == -1) {
hyperdata.name = hyperdata.key.split('_')[0];
$scope.hyperdataList.push(hyperdata);
}
});
}
$scope.updateHyperdataList = function() {
if ($scope.updateHyperdataTimer) {
clearTimeout($scope.updateHyperdataTimer);
}
$scope.updateHyperdataTimer = setTimeout($scope._updateHyperdataList, 500);
};
$scope._updateHyperdataList = function(callback) {
var corpus_id_list = getSelectedCorporaIdList();
if (corpus_id_list && corpus_id_list.length) {
var url = '/api/hyperdata?corpus_id=';
......@@ -261,7 +289,10 @@ gargantext.controller('DatasetController', function($scope, $http) {
$scope.is_loading = true;
$http.get(url, {cache: true}).success(function(response){
$scope.is_loading = false;
$scope.hyperdataList = response.data;
$scope.setHyperdataList(response.data);
if (callback) {
callback();
}
});
} else {
$scope.hyperdataList = [];
......@@ -269,7 +300,14 @@ gargantext.controller('DatasetController', function($scope, $http) {
};
// update the dataset, according to the various filters applied to it
$scope.updateDatasetTimer = null;
$scope.updateDataset = function() {
if ($scope.updateDatasetTimer) {
clearTimeout($scope.updateDatasetTimer);
}
$scope.updateDatasetTimer = setTimeout($scope._updateDataset, 500);
};
$scope._updateDataset = function() {
// parameters
var parameters = {
'x': {
......@@ -296,6 +334,20 @@ gargantext.controller('DatasetController', function($scope, $http) {
})
console.log($scope.query_y.ngrams);
}
// filter: hyperdata
parameters.filter.hyperdata = [];
$.each($scope.hyperdataList, function(h, hyperdata) {
if ((hyperdata.values || hyperdata.operator) && hyperdata.value) {
if (hyperdata.values) {
hyperdata.operator = '=';
}
parameters.filter.hyperdata.push({
'key': hyperdata.key,
'operator': hyperdata.operator,
'value': hyperdata.value
});
}
});
// retrieve data
var url = '/api2/nodes/' + $scope.project_id + '/histories';
$scope.is_loading = true;
......
......@@ -53,8 +53,9 @@
li.dataset select {cursor: pointer; border: 0; padding: 0; }
ul.filters {list-style: none; margin: 0; padding: 0; margin-top: .25em;}
ul.filters>li {padding-top: .5em; margin-top: .5em; border-top: solid 1px rgba(0,0,0,.125);}
ul.filters>li>ul {list-style: none; padding-left: 0; }
ul.filters>li>ul label {font-weight: normal; cursor: pointer; }
ul.filters>li>ul {list-style: none; padding-left: 0; margin-top: .5em; }
ul.filters>li>ul>li.inline {width: 30%; display: inline-block; }
ul.filters>li>ul>li>label {font-weight: normal; cursor: pointer; }
ul.filters>li input[type=checkbox] {opacity: .8;}
</style>
......@@ -85,7 +86,7 @@
<button ng-click="corporaSelectNone()">select none</button>
...restrict to the following corpora:
<ul>
<li ng-repeat="corpus in corpora">
<li ng-repeat="corpus in corpora" class="inline">
<label>
<input type="checkbox" ng-model="corpus.is_selected" ng-change="updateHyperdataList();updateDataset()"/>
<span style="font-weight: {{ corpus.is_selected ? 'bold' : 'normal' }}">{{ corpus.name }}</span>
......@@ -104,12 +105,19 @@
<li>
<ul>
<li ng-repeat="hyperdata in hyperdataList">
...where the value of
<span ng-if="!hyperdata.operator">"{{ hyperdata.key }}"</span>
<strong ng-if="hyperdata.operator">{{ hyperdata.key }}</strong>
...where
<span ng-if="!hyperdata.operator &amp;&amp; (!hyperdata.values || !hyperdata.value)">"{{ hyperdata.name }}"</span>
<strong ng-if="hyperdata.operator || (hyperdata.values &amp;&amp; hyperdata.value)">{{ hyperdata.name }}</strong>
<span ng-if="hyperdata.values">
is
<select ng-model="hyperdata.value" ng-options="value for value in hyperdata.values" ng-change="updateDataset()"></select>
</span>
<span ng-if="!hyperdata.values">
<select ng-model="hyperdata.operator" ng-options="operator.key as operator.label for operator in operators[hyperdata.type]"></select>
<input type="text" ng-if="hyperdata.operator" ng-model="hyperdata.value" ng-change="updateDataset()" placeholder="type a value here..." />
</span>
<select ng-model="hyperdata.operator" ng-options="operator.key as operator.label for operator in operators[hyperdata.type]"></select>
<input type="text" ng-if="hyperdata.operator" ng-model="hyperdata.value" ng-change="updateDataset()" placeholder="type a value here..." />
</li>
</ul>
</li>
......
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