Commit 0228bef5 authored by delanoe's avatar delanoe

Merge remote-tracking branch 'origin/romain-refactoring' into refactoring-merge

parents 6c2b5ea4 82663596
......@@ -228,22 +228,22 @@ class EuropressParser(Parser):
# 2) we parse the retrieved datestring into a formal date
try:
hyperdata['publication_date'] = dateparser.parse(
the_date = dateparser.parse(
date_str.strip(),
languages=[doc_language],
date_formats=['%d %B %Y','%B %d, %Y']
)
# print("RES POSTPROC:",hyperdata['publication_date'])
except:
hyperdata['publication_date'] = timezone.now().strftime("%Y-%m-%d %H:%M:%S")
the_date = timezone.now()
hyperdata['publication_date'] = the_date.strftime("%Y-%m-%d %H:%M:%S")
# print("RES POSTPROC:",hyperdata['publication_date'])
# infos dérivées
hyperdata['publication_year'] = hyperdata['publication_date'].strftime('%Y')
hyperdata['publication_month'] = hyperdata['publication_date'].strftime('%m')
hyperdata['publication_day'] = hyperdata['publication_date'].strftime('%d')
hyperdata['publication_year'] = the_date.strftime('%Y')
hyperdata['publication_month'] = the_date.strftime('%m')
hyperdata['publication_day'] = the_date.strftime('%d')
# RUBRIQUE
......
......@@ -4,7 +4,7 @@ anyjson==0.3.3
billiard==3.3.0.22 # multiprocessing fork
celery==3.1.20
chardet==2.3.0
dateparser==0.3.2
dateparser==0.3.5
Django==1.9.2
django-celery==3.1.17
django-pgfields==1.4.4
......
......@@ -26,6 +26,10 @@ th a {
min-width: 20em;
}
#doubleSearch {
min-width: 25em;
}
.dynatable-search {
margin-left: 2em;
font-size: 16px;
......
......@@ -435,11 +435,14 @@ function Main_test( Data , SearchFilter ) {
},
features: {
pushState: false,
// prevent default title search which can't do title vs abstract
search: false,
// sort: false //i need to fix the sorting function... the current one just sucks
},
// inputs: {
// queries: $('#searchAB')
// },
inputs: {
// our own search which differentiates title vs abstract queries
queries: $('#doubleSearch')
},
writers: {
_rowWriter: ulWriter
// _cellWriter: customCellWriter
......@@ -454,26 +457,53 @@ function Main_test( Data , SearchFilter ) {
$(".dynatable-record-count").insertAfter(".imadiv")
$(".dynatable-pagination-links").insertAfter(".imadiv")
// make filter checkboxes appear in the right place (ie after search box)
$("#filter_search").html( $("#filter_search").html().replace('selected="selected"') );
$("#"+SearchFilter).attr( "selected" , "selected" )
var the_content = $("#filter_search").html();
$(""+the_content).insertAfter("#dynatable-query-search-my-ajax-table")
// $('#searchAB').click( function() {
// if($(this).is(':checked')) {
// console.log( "Do stuff")
// $("#dynatable-query-search-my-ajax-table").keyup(function (e) {
// if (e.keyCode == 13) {
// console.log("Do stuff: Just pressed ENTER")
// }
// })
// }
// });
// MyTable.data('dynatable').settings.inputs.queries = { $('#searchAB') }
// .insertAfter("#dynatable-query-search-my-ajax-table")
$(""+the_content).insertAfter("#doubleSearch")
// binds a custom filter to our 'doubleSearch' via dynatable.queries.functions
MyTable.data('dynatable').queries
.functions['doubleSearch'] = function(record,searchString) {
// NB searchString == $("#doubleSearch").val()
// by default we always decide to search in the title
matchInTexts = [record.title]
// if box is checked we'll also search in the abstracts
if ($("#searchAB").is(':checked')) {
matchInTexts.push(record.hyperdata.abstract)
}
// inspired from the default cf. dynatable.queries.functions['search']
var contains = false;
for (i in matchInTexts) {
matchInText = matchInTexts[i]
contains = (
matchInText.toLowerCase().indexOf(
searchString.toLowerCase()
) !== -1
)
if (contains) { break; } else { continue; }
}
return contains;
}
MyTable.data('dynatable').process
// re-apply search function on click
$('#searchAB').click( function() {
MyTable.data('dynatable').process();
});
// re-apply search function on ENTER
$("#doubleSearch").keyup(function (e) {
if (e.keyCode == 13) {
MyTable.data('dynatable').process();
}
})
return "OK"
}
......
......@@ -206,7 +206,7 @@
};
processAll = function(skipPushState) {
if( $("#multiple_selection").length>0 )
$("#multiple_selection")[0].checked = false;
......@@ -1177,51 +1177,9 @@
}
}
// collect all records that return true for query
if($('input[name=searchAB]:checked').length==0) {
settings.dataset.records = $.map(settings.dataset.records, function(record) {
return _this.functions[query](record, value) ? record : null;
});
} else {
var pageurl = window.location.href.split("/")
var cid;
for(var i in pageurl) {
if(pageurl[i]=="corpus") {
cid=parseInt(i);
break;
}
}
var corpus_id = pageurl[cid+1];
var search_api = window.location.origin+"/v1.0/nodes/"+corpus_id+"/children/ids?limit="+(settings.dataset.records.length)+"&contain="+encodeURI(value.toLowerCase())
var coincidences_ = []
$.ajax({
type: "GET",
url: search_api,
dataType: "json",
async: false,
success : function(data, textStatus, jqXHR) {
var results_ = {}
if(data.pagination.total>0) {
for(var i in data.data) {
results_[data.data[i].id]=true
}
for(var i in settings.dataset.records) {
if( results_[settings.dataset.records[i].id] ) {
coincidences_.push( settings.dataset.records[i] )
}
}
}
},
error: function(exception) {
console.log("error in abstracts-API:");
console.log(exception)
console.log(" - - - -- - - -")
}
})
console.log( "abstracts-API: "+coincidences_.length)
settings.dataset.records = coincidences_
}
settings.dataset.records = $.map(settings.dataset.records, function(record) {
return _this.functions[query](record, value) ? record : null;
});
}
}
settings.dataset.queryRecordCount = obj.records.count();
......
......@@ -61,6 +61,14 @@
<p id="corpusdisplayer" onclick='Final_UpdateTable("click")' class="btn btn-primary btn-lg" style="width:200px; margin:0 auto; display:block;">Titles</h2></p>
</a>
</h4>
<!-- search box with custom function in Docs_dyna_chart_and_tables.js -->
<div class="pull-left" style="margin-top:1.85em; font-size: 16px;">
Search:
<input type="search" id="doubleSearch"/>
</div>
</div>
<div id="collapseOne" class="panel-collapse collapse no-transition" role="tabpanel">
<div class="panel-body">
......@@ -78,6 +86,7 @@
<div id="filter_search" style="visibility:hidden">
<span style="font-size:70%;">
<!-- Used by the #doubleSearch associated function -->
<input title="Search in Titles" id="searchTI" name="searchTI" type="checkbox" checked onclick="return false">TI&nbsp;
<input title="Search in Abstracts" id="searchAB" name="searchAB" type="checkbox">AB
</span>&nbsp;&nbsp;
......@@ -90,7 +99,10 @@
<!-- </optgroup> -->
<!-- <optgroup label="Duplicates"> -->
<!-- <option value="filter_doi">By DOI</option> -->
<option id="filter_dupl-titles" value="filter_dupl-titles">Duplicates by Title</option>
<!-- TODO
<option id="filter_dupl-titles" value="filter_dupl-titles">Duplicates by Title</option> -->
<!-- </optgroup> -->
</select>
......
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