From f29620cf969cfdb8b6779ae19ecf61dc42be4503 Mon Sep 17 00:00:00 2001
From: Mokaddem
Date: Wed, 6 Jul 2016 16:54:27 +0200
Subject: [PATCH] Added load more content in search modal preview. Works fine
but may duplicate content (need to fix).
---
var/www/Flask_server.py | 15 ++++++++++++++-
var/www/templates/search.html | 24 +++++++++++++++++++++++-
var/www/templates/show_saved_paste.html | 4 ++--
3 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py
index a9a03fa8..e87864a9 100755
--- a/var/www/Flask_server.py
+++ b/var/www/Flask_server.py
@@ -23,7 +23,7 @@ cfg.read(configfile)
max_preview_char = int(cfg.get("Flask", "max_preview_char"))
max_preview_modal = int(cfg.get("Flask", "max_preview_modal"))
-
+index_prev = 0 # used if the user want to load more paste content
# REDIS #
r_serv = redis.StrictRedis(
@@ -148,6 +148,19 @@ def showpreviewpaste():
p_content = paste.get_p_content()[0:max_preview_modal].decode('utf-8', 'ignore')
return render_template("show_saved_paste.html", date=p_date, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content)
+@app.route("/getmoredata/")
+def getmoredata():
+ requested_path = request.args.get('paste', '')
+ index_prev = int(request.args.get('index', ''))
+ 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]
+ return to_return
if __name__ == "__main__":
app.run(host='0.0.0.0', port=7000, threaded=True)
diff --git a/var/www/templates/search.html b/var/www/templates/search.html
index 1feef403..218bf606 100644
--- a/var/www/templates/search.html
+++ b/var/www/templates/search.html
@@ -135,17 +135,39 @@ $(document).ready(function(){
// On click, get html content from url and update the corresponding modal
$("[data-toggle='modal']").on("click", function (event) {
event.preventDefault();
- var modal=$(this)
+ var modal=$(this);
var url = " {{ url_for('showpreviewpaste') }}?paste=" + $(this).attr('data-path') + "&num=" + $(this).attr('data-num');
$.get(url, function (data) {
$("#mymodalbody").html(data);
+
+ var button = '';
+ $("#mymodalbody").children(".panel-default").append(button);
+
$("#button_show_path").attr('href', $(modal).attr('data-url'));
$("#button_show_path").show('fast');
+
+ var index_preview = 0 // used for load more preview
+
+ // On load more content click, replace paste content
+ $("#load-more-button").on("click", function (event) {
+ $.get("{{ url_for('getmoredata') }}"+"?paste="+$(modal).attr('data-path')+"&index="+index_preview, function(data, status){
+ index_preview++;
+ console.log($("#mymodalbody").find("#panel-body"));
+ var new_content = $(''+data+'
').hide();
+ $("#mymodalbody").find("#panel-body").append(new_content);
+ new_content.show('fast');
+ });
+ });
+
});
});
+
+ // When the modal goes out, refresh it to normal content
$("#mymodal").on('hidden.bs.modal', function () {
$("#mymodalbody").html("