Commit b067717e authored by Romain Loth's avatar Romain Loth

docs view: duplicates by title

parent 6d095f1c
...@@ -157,6 +157,7 @@ var MyTable; ...@@ -157,6 +157,7 @@ var MyTable;
var RecDict={}; var RecDict={};
var AjaxRecords = [] var AjaxRecords = []
var Garbage = {} var Garbage = {}
var countByTitles = {} // useful for title duplicates
function getRecord(rec_id) { function getRecord(rec_id) {
return MyTable.data('dynatable').settings.dataset.originalRecords[rec_id]; return MyTable.data('dynatable').settings.dataset.originalRecords[rec_id];
...@@ -263,7 +264,7 @@ function ulWriter(rowIndex, record, columns, cellWriter) { ...@@ -263,7 +264,7 @@ function ulWriter(rowIndex, record, columns, cellWriter) {
} }
function Main_test( Data , SearchFilter ) { function Main_test(Data) {
var DistributionDict = {} var DistributionDict = {}
for(var i in DistributionDict) for(var i in DistributionDict)
...@@ -441,7 +442,7 @@ function Main_test( Data , SearchFilter ) { ...@@ -441,7 +442,7 @@ function Main_test( Data , SearchFilter ) {
}, },
inputs: { inputs: {
// our own search which differentiates title vs abstract queries // our own search which differentiates title vs abstract queries
queries: $('#doubleSearch') queries: $('#doubleSearch, #dupFilter')
}, },
writers: { writers: {
_rowWriter: ulWriter _rowWriter: ulWriter
...@@ -457,23 +458,20 @@ function Main_test( Data , SearchFilter ) { ...@@ -457,23 +458,20 @@ function Main_test( Data , SearchFilter ) {
$(".dynatable-record-count").insertAfter(".imadiv") $(".dynatable-record-count").insertAfter(".imadiv")
$(".dynatable-pagination-links").insertAfter(".imadiv") $(".dynatable-pagination-links").insertAfter(".imadiv")
// make filter checkboxes appear in the right place (ie after search box) // binds a custom filter to our 'doubleSearch' via dynatable.queries.functions
$("#filter_search").html( $("#filter_search").html().replace('selected="selected"') );
$("#"+SearchFilter).attr( "selected" , "selected" )
var the_content = $("#filter_search").html();
$(""+the_content).insertAfter("#doubleSearch")
// binds a custom filter to our 'doubleSearch' via dynatable.queries.functions
MyTable.data('dynatable').queries MyTable.data('dynatable').queries
.functions['doubleSearch'] = function(record,searchString) { .functions['doubleSearch'] = function(record,searchString) {
// global context
doAbstractsSearch = $("#searchAB").is(':checked')
// NB searchString == $("#doubleSearch").val() // NB searchString == $("#doubleSearch").val()
// by default we always decide to search in the title // by default we always decide to search in the title
matchInTexts = [record.title] matchInTexts = [record.title]
// if box is checked we'll also search in the abstracts // if box is checked we'll also search in the abstracts
if ($("#searchAB").is(':checked')) { if (doAbstractsSearch) {
if (typeof record.hyperdata.abstract !== 'undefined') { if (typeof record.hyperdata.abstract !== 'undefined') {
matchInTexts.push(record.hyperdata.abstract) matchInTexts.push(record.hyperdata.abstract)
} }
...@@ -492,6 +490,18 @@ function Main_test( Data , SearchFilter ) { ...@@ -492,6 +490,18 @@ function Main_test( Data , SearchFilter ) {
} }
return contains; return contains;
} }
MyTable.data('dynatable').process();
// also append another bound filter for duplicates
MyTable.data('dynatable').queries
.functions['dupFilter'] = function(record,selected) {
return (selected == 'filter_all')||(countByTitles[record.title] > 1)
}
// and set this filter's initial status to 'filter_all'
MyTable.data('dynatable').settings.dataset.queries['dupFilter'] = 'filter_all'
MyTable.data('dynatable').process();
MyTable.data('dynatable').process MyTable.data('dynatable').process
...@@ -510,50 +520,6 @@ function Main_test( Data , SearchFilter ) { ...@@ -510,50 +520,6 @@ function Main_test( Data , SearchFilter ) {
return "OK" return "OK"
} }
function SearchFilters( elem ) {
var MODE = elem.value;
if( MODE == "filter_all") {
var result = Main_test(AjaxRecords , MODE)
console.log( result )
}
if( MODE == "filter_dupl-titles") {
var getDupl_API = "/api/nodes/" + corpus_id + "/children/duplicates?keys=title&limit=9999"
$.ajax({
url: getDupl_API,
success: function(data) {
bisarray = data.data
for(var i in bisarray) {
titlebis = bisarray[i].values
BIS_dict[titlebis[0]] = true;
}
var Duplicates = []
for(var r in AjaxRecords) {
if ( BIS_dict[AjaxRecords[r].title] )
Duplicates.push( AjaxRecords[r] )
}
var result = Main_test(Duplicates , MODE)
console.log( result )
MyTable.data('dynatable').sorts.clear();
MyTable.data('dynatable').sorts.add('title', 1) // 1=ASCENDING,
MyTable.data('dynatable').process();
}
});
}
}
$("#corpusdisplayer").hide() $("#corpusdisplayer").hide()
// FIRST portion of code to be EXECUTED: // FIRST portion of code to be EXECUTED:
// (3) Get records and hyperdata for paginator // (3) Get records and hyperdata for paginator
...@@ -572,11 +538,20 @@ $.ajax({ ...@@ -572,11 +538,20 @@ $.ajax({
record.date = get_node_date(record); record.date = get_node_date(record);
record.del = false; record.del = false;
}); });
// initialize CountByTitle census
for (var i in data.records) { for (var i in data.records) {
ourTitle = data.records[i]['title'] ;
if (countByTitles.hasOwnProperty(ourTitle)) {
countByTitles[ourTitle] ++ ;
}
else {
countByTitles[ourTitle] = 1 ;
}
} }
AjaxRecords = data.records; // backup-ing in global variable! AjaxRecords = data.records; // backup-ing in global variable!
var result = Main_test(data.records , "filter_all") var result = Main_test(data.records)
$("#corpusdisplayer").show() $("#corpusdisplayer").show()
$("#content_loader").remove() $("#content_loader").remove()
......
...@@ -66,6 +66,15 @@ ...@@ -66,6 +66,15 @@
<div class="pull-left" style="margin-top:1.85em; font-size: 16px;"> <div class="pull-left" style="margin-top:1.85em; font-size: 16px;">
Search: Search:
<input type="search" id="doubleSearch"/> <input type="search" id="doubleSearch"/>
<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;
<select id="dupFilter" name="dupFilter">
<option value="filter_all">All</option>
<option value="filter_dupl">Duplicates by Title</option>
</select>
</div> </div>
...@@ -83,32 +92,6 @@ ...@@ -83,32 +92,6 @@
</div> </div>
</div> </div>
<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;
<select id="example-single-optgroups" onchange="SearchFilters(this);">
<!-- <optgroup label=""> -->
<option id="filter_all" value="filter_all">All</option>
<!-- <option id="filter_title" value="filter_title">Title</option> -->
<!-- <option id="filter_date" value="filter_date">Date</option> -->
<!-- </optgroup> -->
<!-- <optgroup label="Duplicates"> -->
<!-- <option value="filter_doi">By DOI</option> -->
<!-- TODO
<option id="filter_dupl-titles" value="filter_dupl-titles">Duplicates by Title</option> -->
<!-- </optgroup> -->
</select>
</div>
</div>
<script type="text/javascript" src="{% static "js/jquery/jquery.min.js" %}"></script> <script type="text/javascript" src="{% static "js/jquery/jquery.min.js" %}"></script>
<script src="{% static "js/bootstrap/bootstrap.min.js" %}"></script> <script src="{% static "js/bootstrap/bootstrap.min.js" %}"></script>
<!-- here goes import script js/bootstrap/bootstrap-multiselect.js, mais ca marche pas--> <!-- here goes import script js/bootstrap/bootstrap-multiselect.js, mais ca marche pas-->
...@@ -117,6 +100,4 @@ ...@@ -117,6 +100,4 @@
<!-- custom-lib for dynatable.js and dc.js --> <!-- custom-lib for dynatable.js and dc.js -->
<script type="text/javascript" src="{% static "js/gargantext/Docs_dyna_chart_and_table.js" %}"></script> <script type="text/javascript" src="{% static "js/gargantext/Docs_dyna_chart_and_table.js" %}"></script>
{% endblock %} {% endblock %}
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