mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
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...)
This commit is contained in:
parent
f51808d914
commit
c95000866d
2 changed files with 32 additions and 15 deletions
|
@ -328,7 +328,6 @@ def search():
|
||||||
paste_size = []
|
paste_size = []
|
||||||
|
|
||||||
# Search filename
|
# Search filename
|
||||||
print r_serv_pasteName.smembers(q[0])
|
|
||||||
for path in r_serv_pasteName.smembers(q[0]):
|
for path in r_serv_pasteName.smembers(q[0]):
|
||||||
print path
|
print path
|
||||||
r.append(path)
|
r.append(path)
|
||||||
|
@ -351,7 +350,7 @@ def search():
|
||||||
from whoosh.qparser import QueryParser
|
from whoosh.qparser import QueryParser
|
||||||
with ix.searcher() as searcher:
|
with ix.searcher() as searcher:
|
||||||
query = QueryParser("content", ix.schema).parse(" ".join(q))
|
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:
|
for x in results:
|
||||||
r.append(x.items()[0][1])
|
r.append(x.items()[0][1])
|
||||||
paste = Paste.Paste(x.items()[0][1])
|
paste = Paste.Paste(x.items()[0][1])
|
||||||
|
@ -370,7 +369,7 @@ def get_more_search_result():
|
||||||
query = request.form['query']
|
query = request.form['query']
|
||||||
q = []
|
q = []
|
||||||
q.append(query)
|
q.append(query)
|
||||||
offset = request.form['offset']
|
offset = int(request.form['offset'])
|
||||||
|
|
||||||
path_array = []
|
path_array = []
|
||||||
preview_array = []
|
preview_array = []
|
||||||
|
@ -386,7 +385,7 @@ def get_more_search_result():
|
||||||
from whoosh.qparser import QueryParser
|
from whoosh.qparser import QueryParser
|
||||||
with ix.searcher() as searcher:
|
with ix.searcher() as searcher:
|
||||||
query = QueryParser("content", ix.schema).parse(" ".join(q))
|
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:
|
for x in results:
|
||||||
path_array.append(x.items()[0][1])
|
path_array.append(x.items()[0][1])
|
||||||
paste = Paste.Paste(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["preview_array"] = preview_array
|
||||||
to_return["date_array"] = date_array
|
to_return["date_array"] = date_array
|
||||||
to_return["size_array"] = size_array
|
to_return["size_array"] = size_array
|
||||||
|
if len(path_array) < 10: #pagelength
|
||||||
to_return["moreData"] = False
|
to_return["moreData"] = False
|
||||||
|
else:
|
||||||
|
to_return["moreData"] = True
|
||||||
|
|
||||||
return jsonify(to_return)
|
return jsonify(to_return)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,8 @@
|
||||||
</br>
|
</br>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<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 class="pull-right">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -130,12 +131,16 @@
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
console.log($('[data-toggle="tooltip"]'));
|
||||||
|
|
||||||
|
|
||||||
$("#button_show_path").hide();
|
$("#button_show_path").hide();
|
||||||
var search_table = $('#myTable').DataTable();
|
var search_table = $('#myTable').DataTable();
|
||||||
|
|
||||||
var prev_query = "{{ query }}";
|
var prev_query = "{{ query }}";
|
||||||
var offset = 1;
|
var offset = 2;
|
||||||
load_search_data(search_table, prev_query, offset);
|
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>
|
</script>
|
||||||
|
@ -145,25 +150,34 @@
|
||||||
// Loop to recover all the data from get_more_search_results
|
// Loop to recover all the data from get_more_search_results
|
||||||
// And add it dynamically top the dataTable
|
// And add it dynamically top the dataTable
|
||||||
|
|
||||||
function load_search_data(search_table, prev_query, offset) {
|
function load_search_data(init_num_of_elements_in_table, search_table, prev_query, offset) {
|
||||||
$.post( "{{ url_for('get_more_search_result') }}", { query: prev_query, offset: offset }).done(function( data ) {
|
var options = { query: prev_query, offset: offset };
|
||||||
console.log( "Data Loaded: " )
|
console.log(options);
|
||||||
console.log( data );
|
$.post( "{{ url_for('get_more_search_result') }}", options).done(function( data ) {
|
||||||
|
|
||||||
for(i=0; i<data.path_array.length; i++) {
|
for(i=0; i<data.path_array.length; i++) {
|
||||||
|
var curr_preview = data.preview_array[i].replace(/\"/g, "\'");
|
||||||
search_table.row.add( [
|
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>",
|
"<a target=\"_blank\" href=\"{{ url_for('showsavedpaste') }}?paste="+data.path_array[i]+"&num="+i+"\"> "+ data.path_array[i] +"</a>",
|
||||||
data.date_array[i],
|
data.date_array[i],
|
||||||
data.size_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 );
|
] ).draw( false );
|
||||||
}
|
}
|
||||||
|
$("#numberOfRes").text(parseInt($("#numberOfRes").text()) + data.path_array.length);
|
||||||
if (data.moreData == true)
|
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>
|
</script>
|
||||||
|
|
||||||
<!-- Dynamically update the modal -->
|
<!-- Dynamically update the modal -->
|
||||||
|
|
Loading…
Reference in a new issue