mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
Added event source for getImportantPaste
This commit is contained in:
parent
c95000866d
commit
acdd1367a3
3 changed files with 75 additions and 6 deletions
|
@ -78,6 +78,28 @@ def event_stream():
|
||||||
if msg['type'] == 'pmessage' and level != "DEBUG":
|
if msg['type'] == 'pmessage' and level != "DEBUG":
|
||||||
yield 'data: %s\n\n' % json.dumps(msg)
|
yield 'data: %s\n\n' % json.dumps(msg)
|
||||||
|
|
||||||
|
def event_stream_getImportantPasteByModule(module_name):
|
||||||
|
index = 0
|
||||||
|
all_pastes_list = getPastebyType(r_serv_db, module_name)
|
||||||
|
for path in all_pastes_list:
|
||||||
|
index += 1
|
||||||
|
paste = Paste.Paste(path)
|
||||||
|
content = paste.get_p_content().decode('utf8', 'ignore')
|
||||||
|
content_range = max_preview_char if len(content)>max_preview_char else len(content)-1
|
||||||
|
curr_date = str(paste._get_p_date())
|
||||||
|
curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:]
|
||||||
|
data = {}
|
||||||
|
data["module"] = module_name
|
||||||
|
data["index"] = index
|
||||||
|
data["path"] = path
|
||||||
|
data["content"] = content[0:content_range]
|
||||||
|
data["linenum"] = paste.get_lines_info()[0]
|
||||||
|
data["date"] = curr_date
|
||||||
|
data["char_to_display"] = max_preview_modal
|
||||||
|
data["finished"] = True if index == len(all_pastes_list) else False
|
||||||
|
print index
|
||||||
|
yield 'data: %s\n\n' % json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
def get_queues(r):
|
def get_queues(r):
|
||||||
# We may want to put the llen in a pipeline to do only one query.
|
# We may want to put the llen in a pipeline to do only one query.
|
||||||
|
@ -452,8 +474,9 @@ def importantPasteByModule():
|
||||||
paste_date = []
|
paste_date = []
|
||||||
paste_linenum = []
|
paste_linenum = []
|
||||||
all_path = []
|
all_path = []
|
||||||
|
allPastes = getPastebyType(r_serv_db, module_name)
|
||||||
|
|
||||||
for path in getPastebyType(r_serv_db, module_name):
|
for path in allPastes[0:10]:
|
||||||
all_path.append(path)
|
all_path.append(path)
|
||||||
paste = Paste.Paste(path)
|
paste = Paste.Paste(path)
|
||||||
content = paste.get_p_content().decode('utf8', 'ignore')
|
content = paste.get_p_content().decode('utf8', 'ignore')
|
||||||
|
@ -464,7 +487,17 @@ def importantPasteByModule():
|
||||||
paste_date.append(curr_date)
|
paste_date.append(curr_date)
|
||||||
paste_linenum.append(paste.get_lines_info()[0])
|
paste_linenum.append(paste.get_lines_info()[0])
|
||||||
|
|
||||||
return render_template("important_paste_by_module.html", all_path=all_path, content=all_content, paste_date=paste_date, paste_linenum=paste_linenum, char_to_display=max_preview_modal)
|
if len(allPastes) > 10:
|
||||||
|
finished = ""
|
||||||
|
else:
|
||||||
|
finished = "display: none;"
|
||||||
|
|
||||||
|
return render_template("important_paste_by_module.html", moduleName=module_name, all_path=all_path, content=all_content, paste_date=paste_date, paste_linenum=paste_linenum, char_to_display=max_preview_modal, finished=finished)
|
||||||
|
|
||||||
|
@app.route("/_getImportantPasteByModule")
|
||||||
|
def getImportantPasteByModule():
|
||||||
|
module_name = request.args.get('moduleName')
|
||||||
|
return flask.Response(event_stream_getImportantPasteByModule(module_name), mimetype="text/event-stream")
|
||||||
|
|
||||||
@app.route("/moduletrending/")
|
@app.route("/moduletrending/")
|
||||||
def moduletrending():
|
def moduletrending():
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<table class="table table-striped table-bordered table-hover" id="myTable">
|
<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 }}">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
|
@ -25,10 +26,47 @@
|
||||||
</br>
|
</br>
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<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'));
|
||||||
|
console.log(curr_numElem);
|
||||||
|
if (feed.index > curr_numElem & feed.module == moduleName) { // Avoid doubling the pastes
|
||||||
|
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,
|
||||||
|
"<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>"
|
||||||
|
] ).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>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var moduleName = "{{ moduleName }}";
|
||||||
|
var search_table;
|
||||||
|
$("#myTable_"+moduleName).attr('data-numElem', "{{ all_path|length }}");
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
$('#myTable').dataTable({ "order": [[ 2, "desc" ]] });
|
|
||||||
|
search_table = $('#myTable_'+moduleName).DataTable({ "order": [[ 2, "desc" ]] });
|
||||||
|
|
||||||
|
deploy_source();
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -131,8 +131,6 @@
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
console.log($('[data-toggle="tooltip"]'));
|
|
||||||
|
|
||||||
|
|
||||||
$("#button_show_path").hide();
|
$("#button_show_path").hide();
|
||||||
var search_table = $('#myTable').DataTable();
|
var search_table = $('#myTable').DataTable();
|
||||||
|
|
Loading…
Reference in a new issue