mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 00:28:22 +00:00
Added load more content in search modal preview. Works fine but may duplicate content (need to fix).
This commit is contained in:
parent
3345124219
commit
f29620cf96
3 changed files with 39 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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 = '<button type="button" id="load-more-button" class="btn btn-info btn-xs pull-left" data-url="' + $(modal).attr('data-path') +'" data-toggle="tooltip" data-placement="bottom" title="Load more content"><span class="glyphicon glyphicon-download"></span></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 = $('<p><xmp>'+data+'</xmp></p>').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("<p>Loading paste information...</p>");
|
||||
$("#button_show_path").attr('href', '');
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</html>
|
||||
|
|
|
@ -41,9 +41,9 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="panel-body" id="panel-body">
|
||||
<h4> Content: </h4>
|
||||
<p id="paste_content"> <xmp> {{ content }} </xmp> </p>
|
||||
<p> <xmp> {{ content }} </xmp> </p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue