2016-10-28 14:55:56 +00:00
< img id = "loading_gif_browse" src = "{{url_for('static', filename='image/loading.gif') }}" heigt = "20" width = "20" style = "margin: 2px; {{ finished }}" >
< table class = "table table-striped table-bordered table-hover" id = "myTable_{{ moduleName }}" >
2016-08-08 07:17:44 +00:00
< thead >
< tr >
< th > #< / th >
< th style = "max-width: 800px;" > Path< / th >
< th > Date< / th >
< th > # of lines< / th >
< th > Action< / th >
< / tr >
< / thead >
< tbody >
{% set i = 0 %}
{% for path in all_path %}
< tr >
< td > {{ i + 1 }}< / td >
< td > < a target = "_blank" href = "{{ url_for('showsavedpaste') }}?paste={{path}}&num={{i+1}}" > {{ path }}< / a > < / td >
< td > {{ paste_date[i] }}< / td >
< td > {{ paste_linenum[i] }}< / td >
< td > < p > < span class = "glyphicon glyphicon-info-sign" data-toggle = "tooltip" data-placement = "left" title = "{{ content[i] }} " > < / 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 %}
{% endfor %}
< / tbody >
< / table >
< / br >
< / br >
2016-10-28 14:55:56 +00:00
< script >
function deploy_source() {
if(typeof(EventSource) !== "undefined" & & typeof(source) !== "") {
var source = new EventSource("{{ url_for('getImportantPasteByModule') }}"+"?moduleName="+moduleName);
source.onmessage = function(event) {
var feed = jQuery.parseJSON( event.data );
var curr_numElem = parseInt($("#myTable_"+moduleName).attr('data-numElem'));
if (feed.index > curr_numElem & feed.module == moduleName) { // Avoid doubling the pastes
2016-11-10 08:28:55 +00:00
// Add the row to the table
2016-10-28 14:55:56 +00:00
search_table.row.add( [
feed.index,
"< a target = \"_blank\" href = \"{{ url_for ( ' showsavedpaste ' ) } } ? paste = "+feed.path+" & num = "+feed.index+" \ " > "+ feed.path +"< / a > ",
feed.date,
feed.linenum,
2016-11-10 09:30:29 +00:00
"< p > < span class = \"glyphicon glyphicon-info-sign \ " data-toggle = \"tooltip\" data-placement = \"left\" title = \""+feed.content+"\" > < / span > < button type = \"button\" class = \"btn-link\" data-num = \""+feed.index+"\" data-toggle = \"modal\" data-target = \"#mymodal\" data-url = \"{{ url_for ( ' showsavedpaste ' ) } } ? paste = "+feed.path+" & num = "+feed.index+" \ " data-path = \""+feed.path+"\" > < span class = \"fa fa-search-plus \ " > < / span > < / button > < / p > "
2016-10-28 14:55:56 +00:00
] ).draw( false );
$("#myTable_"+moduleName).attr('data-numElem', curr_numElem+1);
if(feed.finished) {
$("#loading_gif_browse").hide();
}
}
};
} else {
console.log("Sorry, your browser does not support server-sent events...");
}
}
< / script >
2016-08-08 07:17:44 +00:00
< script >
2016-10-28 14:55:56 +00:00
var moduleName = "{{ moduleName }}";
var search_table;
$("#myTable_"+moduleName).attr('data-numElem', "{{ all_path|length }}");
2016-08-08 07:17:44 +00:00
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
2016-10-28 14:55:56 +00:00
search_table = $('#myTable_'+moduleName).DataTable({ "order": [[ 2, "desc" ]] });
deploy_source();
2016-08-08 07:17:44 +00:00
});
< / script >
<!-- Dynamically update the modal -->
< script type = "text/javascript" >
// static data
var alert_message = '< div class = "alert alert-info alert-dismissable" > < button type = "button" class = "close" data-dismiss = "alert" aria-hidden = "true" > × < / button > < strong > No more data.< / strong > Full paste displayed.< / div > ';
var complete_paste = null;
var char_to_display = {{ char_to_display }};
var start_index = 0;
// On click, get html content from url and update the corresponding modal
2016-08-09 10:30:40 +00:00
$("[data-toggle='modal']").on("click.openmodal", function (event) {
2016-08-08 07:17:44 +00:00
event.preventDefault();
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 center-block" data-url = "' + $(modal).attr('data-path') +'" data-toggle = "tooltip" data-placement = "bottom" title = "Load more content" > < span class = "glyphicon glyphicon-download" > < / span > < / button > ');
button.tooltip();
$("#mymodalbody").children(".panel-default").append(button);
$("#button_show_path").attr('href', $(modal).attr('data-url'));
$("#button_show_path").show('fast');
$("#loading-gif-modal").css("visibility", "hidden"); // Hide the loading GIF
if ($("[data-initsize]").attr('data-initsize') < char_to_display ) { / / All the content is displayed
nothing_to_display();
}
// On click, donwload all paste's content
$("#load-more-button").on("click", function (event) {
if (complete_paste == null) { //Donwload only once
$.get("{{ url_for('getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){
complete_paste = data;
update_preview();
});
} else {
update_preview();
}
});
});
});
// When the modal goes out, refresh it to normal content
$("#mymodal").on('hidden.bs.modal', function () {
$("#mymodalbody").html("< p > Loading paste information...< / p > ");
var loading_gif = "< img id = 'loading-gif-modal' class = 'img-center' src = \"{{url_for('static', filename = 'image/loading.gif' ) } } \ " height = '26' width = '26' style = 'margin: 4px;' > ";
$("#mymodalbody").append(loading_gif); // Show the loading GIF
$("#button_show_path").attr('href', '');
$("#button_show_path").hide();
complete_paste = null;
start_index = 0;
});
// Update the paste preview in the modal
function update_preview() {
if (start_index + char_to_display > complete_paste.length-1){ // end of paste reached
var final_index = complete_paste.length-1;
var flag_stop = true;
} else {
var final_index = start_index + char_to_display;
}
if (final_index != start_index){ // still have data to display
2016-08-23 07:08:17 +00:00
// Append the new content using text() and not append (XSS)
$("#mymodalbody").find("#paste-holder").text($("#mymodalbody").find("#paste-holder").text()+complete_paste.substring(start_index+1, final_index+1));
2016-08-08 07:17:44 +00:00
start_index = final_index;
if (flag_stop)
nothing_to_display();
} else {
nothing_to_display();
}
}
// Update the modal when there is no more data
function nothing_to_display() {
var new_content = $(alert_message).hide();
$("#mymodalbody").find("#panel-body").append(new_content);
new_content.show('fast');
$("#load-more-button").hide();
}
2016-08-09 10:30:40 +00:00
// Use to bind the button with the new displayed data
// (The bind do not happens if the dataTable is in tabs and the clicked data is in another page)
2016-11-10 08:28:55 +00:00
search_table.on( 'draw.dt', function () {
// Bind tooltip each time we draw a new page
$('[data-toggle="tooltip"]').tooltip();
2016-08-09 10:30:40 +00:00
// On click, get html content from url and update the corresponding modal
$("[data-toggle='modal']").unbind('click.openmodal').on("click.openmodal", function (event) {
event.preventDefault();
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 center-block" data-url = "' + $(modal).attr('data-path') +'" data-toggle = "tooltip" data-placement = "bottom" title = "Load more content" > < span class = "glyphicon glyphicon-download" > < / span > < / button > ');
button.tooltip();
$("#mymodalbody").children(".panel-default").append(button);
$("#button_show_path").attr('href', $(modal).attr('data-url'));
$("#button_show_path").show('fast');
$("#loading-gif-modal").css("visibility", "hidden"); // Hide the loading GIF
if ($("[data-initsize]").attr('data-initsize') < char_to_display ) { / / All the content is displayed
nothing_to_display();
}
// On click, donwload all paste's content
$("#load-more-button").on("click", function (event) {
if (complete_paste == null) { //Donwload only once
$.get("{{ url_for('getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){
complete_paste = data;
update_preview();
});
} else {
update_preview();
}
});
});
});
} );
2016-08-08 07:17:44 +00:00
< / script >