From c95000866db2ab371d7ad02f8932c2d06e1c562b Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Fri, 28 Oct 2016 14:21:08 +0200 Subject: [PATCH] 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...) --- var/www/Flask_server.py | 13 ++++++++----- var/www/templates/search.html | 34 ++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 73306ac6..a193fc16 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -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) diff --git a/var/www/templates/search.html b/var/www/templates/search.html index b984ecdc..b1f8cbab 100644 --- a/var/www/templates/search.html +++ b/var/www/templates/search.html @@ -84,7 +84,8 @@
- {{ r|length }} Results for "{{ query }}" + {{ r|length }} Results for "{{ query }} +
@@ -130,12 +131,16 @@ @@ -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[i] +"", data.date_array[i], data.size_array[i], - "

" + "

" ] ).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); + } ); +