Added dynamic table sorting in search page. (Still need to add dependencies)

This commit is contained in:
Mokaddem 2016-07-07 16:38:00 +02:00
parent f1979f6dcb
commit 465244e1ce
3 changed files with 22 additions and 12 deletions

View file

@ -198,6 +198,9 @@ class Paste(object):
def _get_p_date(self):
return self.p_date
def _get_p_size(self):
return self.p_size
def _get_hash_lines(self, min=1, start=1, jump=10):
"""
Returning all the lines of the paste hashed.

View file

@ -76,6 +76,8 @@ def search():
q.append(query)
r = []
c = []
paste_date = []
paste_size = []
# Search
from whoosh import index
from whoosh.fields import Schema, TEXT, ID
@ -89,10 +91,13 @@ def search():
results = searcher.search(query, limit=None)
for x in results:
r.append(x.items()[0][1])
content = Paste.Paste(x.items()[0][1]).get_p_content().decode('utf8', 'ignore')
paste = Paste.Paste(x.items()[0][1])
content = paste.get_p_content().decode('utf8', 'ignore')
content_range = max_preview_char if len(content)>max_preview_char else len(content)-1
c.append(content[0:content_range])
return render_template("search.html", r=r, c=c, char_to_display=max_preview_modal)
paste_date.append(paste._get_p_date())
paste_size.append(paste._get_p_size())
return render_template("search.html", r=r, c=c, paste_date=paste_date, paste_size=paste_size, char_to_display=max_preview_modal)
@app.route("/")
def index():
@ -156,14 +161,6 @@ def getmoredata():
requested_path = request.args.get('paste', '')
paste = Paste.Paste(requested_path)
p_content = paste.get_p_content().decode('utf-8', 'ignore')
'''final_index = (index_prev+1)*max_preview_modal
if final_index > len(p_content)-1: # prevent out of bound
final_index = len(p_content)-1
'''
#to_return = p_content[index_prev*max_preview_modal:final_index]
#correct_index = len(p_content) if max_preview_modal > len(p_content) else max_preview_modal
#to_return = str(p_content[correct_index:])
to_return = p_content[max_preview_modal:]
return to_return

View file

@ -12,10 +12,14 @@
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dygraph_gallery.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.css') }}" rel="stylesheet" type="text/css" />
<!-- JS -->
<script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery-1.4.2.js') }}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.js') }}"></script>
<style>
.tooltip-inner {
text-align: left;
@ -81,6 +85,7 @@
<div class="row"> </div>
<div class="row">
<div class="col-lg-12">
</br>
<div class="panel panel-default">
<div class="panel-heading">
<i class="glyphicon glyphicon-search"></i> {{ r|length }} Results
@ -90,11 +95,13 @@
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<table class="table table-hover">
<table class="table table-striped table-bordered table-hover" id="myTable">
<thead>
<tr>
<th>#</th>
<th>Path</th>
<th style="max-width: 800px;">Path</th>
<th>Date</th>
<th>Size (Kb)</th>
<th>Action</th>
</tr>
</thead>
@ -105,6 +112,8 @@
<tr>
<td>{{ i + 1 }}</td>
<td><a target="_blank" href="{{ url_for('showsavedpaste') }}?paste={{ path }}"> {{ path }}</a></td>
<td>{{ paste_date[i] }}</td>
<td>{{ paste_size[i] }}</td>
<td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ prev_content }}"></span> <button type="button" class="btn-link" data-num="{{ i + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpaste') }}?paste={{ path }}&num={{ i+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td>
</tr>
{% set i = i + 1 %}
@ -127,6 +136,7 @@
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
$("#button_show_path").hide();
$('#myTable').dataTable();
});
</script>