Dynamic table in search now load all the data + fixed bugs where tooltip where not shown on other than the first page displayed and

tooltip interpret html (not supposed to...)
pull/95/head
Mokaddem 2016-10-28 14:21:08 +02:00
parent f51808d914
commit c95000866d
2 changed files with 32 additions and 15 deletions

View File

@ -328,7 +328,6 @@ def search():
paste_size = []
# Search filename
print r_serv_pasteName.smembers(q[0])
for path in r_serv_pasteName.smembers(q[0]):
print path
r.append(path)
@ -351,7 +350,7 @@ def search():
from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse(" ".join(q))
results = searcher.search_page(query, 1, pagelen=20)
results = searcher.search_page(query, 1, pagelen=10)
for x in results:
r.append(x.items()[0][1])
paste = Paste.Paste(x.items()[0][1])
@ -370,7 +369,7 @@ def get_more_search_result():
query = request.form['query']
q = []
q.append(query)
offset = request.form['offset']
offset = int(request.form['offset'])
path_array = []
preview_array = []
@ -386,7 +385,7 @@ def get_more_search_result():
from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse(" ".join(q))
results = searcher.search_page(query, offset, pagelen=20)
results = searcher.search_page(query, offset, pagelen=10)
for x in results:
path_array.append(x.items()[0][1])
paste = Paste.Paste(x.items()[0][1])
@ -402,7 +401,11 @@ def get_more_search_result():
to_return["preview_array"] = preview_array
to_return["date_array"] = date_array
to_return["size_array"] = size_array
to_return["moreData"] = False
if len(path_array) < 10: #pagelength
to_return["moreData"] = False
else:
to_return["moreData"] = True
return jsonify(to_return)

View File

@ -84,7 +84,8 @@
</br>
<div class="panel panel-default">
<div class="panel-heading">
<i class="glyphicon glyphicon-search"></i> {{ r|length }} Results for "<strong>{{ query }}</strong>"
<i class="glyphicon glyphicon-search"></i> <b id="numberOfRes">{{ r|length }}</b> Results for "<strong>{{ query }}</strong>
<img id="loading_gif_search" src="{{url_for('static', filename='image/loading.gif') }}" height="20" width="20" style="margin: 2px;">
<div class="pull-right">
</div>
@ -130,12 +131,16 @@
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
console.log($('[data-toggle="tooltip"]'));
$("#button_show_path").hide();
var search_table = $('#myTable').DataTable();
var prev_query = "{{ query }}";
var offset = 1;
load_search_data(search_table, prev_query, offset);
var offset = 2;
var init_num_of_elements_in_table = parseInt("{{ r|length }}"); // Comes from the file search
load_search_data(init_num_of_elements_in_table, search_table, prev_query, offset);
});
</script>
@ -145,25 +150,34 @@
// Loop to recover all the data from get_more_search_results
// And add it dynamically top the dataTable
function load_search_data(search_table, prev_query, offset) {
$.post( "{{ url_for('get_more_search_result') }}", { query: prev_query, offset: offset }).done(function( data ) {
console.log( "Data Loaded: " )
console.log( data );
function load_search_data(init_num_of_elements_in_table, search_table, prev_query, offset) {
var options = { query: prev_query, offset: offset };
console.log(options);
$.post( "{{ url_for('get_more_search_result') }}", options).done(function( data ) {
for(i=0; i<data.path_array.length; i++) {
var curr_preview = data.preview_array[i].replace(/\"/g, "\'");
search_table.row.add( [
i+offset,
init_num_of_elements_in_table+((offset-2))+i+1,
"<a target=\"_blank\" href=\"{{ url_for('showsavedpaste') }}?paste="+data.path_array[i]+"&num="+i+"\"> "+ data.path_array[i] +"</a>",
data.date_array[i],
data.size_array[i],
"<p><span class=\"glyphicon glyphicon-info-sign\" data-toggle=\"tooltip\" data-placement=\"left\" title=\""+data.preview_array[i]+"\"></span> <button type=\"button\" class=\"btn-link\" data-num=\""+i+"\" data-toggle=\"modal\" data-target=\"#mymodal\" data-url=\"{{ url_for('showsavedpaste') }}?paste=\""+data.path_array[i]+"\"&num=\""+i+"\" data-path=\""+data.path_array[i]+"\"><span class=\"fa fa-search-plus\"></span></button></p>"
"<p><span class=\"glyphicon glyphicon-info-sign\" data-toggle=\"tooltip\" data-placement=\"left\" title=\""+curr_preview+"\"></span> <button type=\"button\" class=\"btn-link\" data-num=\""+i+"\" data-toggle=\"modal\" data-target=\"#mymodal\" data-url=\"{{ url_for('showsavedpaste') }}?paste=\""+data.path_array[i]+"\"&num=\""+i+"\" data-path=\""+data.path_array[i]+"\"><span class=\"fa fa-search-plus\"></span></button></p>"
] ).draw( false );
}
$("#numberOfRes").text(parseInt($("#numberOfRes").text()) + data.path_array.length);
if (data.moreData == true)
load_search_data(prev_query, offset+i);
load_search_data(init_num_of_elements_in_table, search_table, prev_query, offset+10);
else {
$("#loading_gif_search").hide();
}
});
}
$('#myTable').on( 'page.dt', function () {
setTimeout(function(){ $('[data-toggle="tooltip"]').tooltip(); }, 300);
} );
</script>
<!-- Dynamically update the modal -->