mirror of https://github.com/MISP/misp-dashboard
Draft eventSource lastAwards
parent
c35fbe969b
commit
70561357c3
18
server.py
18
server.py
|
@ -39,6 +39,9 @@ subscriber_map = redis_server_map.pubsub(ignore_subscribe_messages=True)
|
|||
subscriber_map.psubscribe(cfg.get('RedisMap', 'channelDisp'))
|
||||
subscriber_lastContrib = redis_server_log.pubsub(ignore_subscribe_messages=True)
|
||||
subscriber_lastContrib.psubscribe(cfg.get('RedisLog', 'channelLastContributor'))
|
||||
subscriber_lastAwards = redis_server_log.pubsub(ignore_subscribe_messages=True)
|
||||
subscriber_lastAwards.psubscribe(cfg.get('RedisLog', 'channelLastAwards'))
|
||||
|
||||
eventNumber = 0
|
||||
|
||||
##########
|
||||
|
@ -300,6 +303,10 @@ def getLastContributors():
|
|||
def getLastContributor():
|
||||
return Response(eventStreamLastContributor(), mimetype="text/event-stream")
|
||||
|
||||
@app.route("/_eventStreamAwards")
|
||||
def getLastStreamAwards():
|
||||
return Response(eventStreamAwards(), mimetype="text/event-stream")
|
||||
|
||||
def eventStreamLastContributor():
|
||||
for msg in subscriber_lastContrib.listen():
|
||||
content = msg['data'].decode('utf8')
|
||||
|
@ -311,6 +318,17 @@ def eventStreamLastContributor():
|
|||
to_return['epoch'] = epoch
|
||||
yield 'data: {}\n\n'.format(json.dumps(to_return))
|
||||
|
||||
def eventStreamAwards():
|
||||
for msg in subscriber_lastAwards.listen():
|
||||
content = msg['data'].decode('utf8')
|
||||
contentJson = json.loads(content)
|
||||
lastContribJson = json.loads(contentJson['log'])
|
||||
org = lastContribJson['org']
|
||||
to_return = contributor_helper.getContributorFromRedis(org)
|
||||
epoch = lastContribJson['epoch']
|
||||
to_return['epoch'] = epoch
|
||||
yield 'data: {}\n\n'.format(json.dumps(to_return))
|
||||
|
||||
@app.route("/_getTopContributor")
|
||||
def getTopContributor(suppliedDate=None):
|
||||
if suppliedDate is None:
|
||||
|
|
|
@ -344,6 +344,18 @@ function addLastContributor(datatable, data, update) {
|
|||
}
|
||||
}
|
||||
|
||||
function addAwards(datatableAwards, json) {
|
||||
var date = new Date(json.epoch*1000);
|
||||
var to_add = [
|
||||
date.toTimeString().slice(0,-15) +' '+ date.toLocaleDateString(),
|
||||
getOrgRankIcon(json.orgRank, 60),
|
||||
createImg(json.logo_path, 32),
|
||||
createOrgLink(json.org),
|
||||
createHonorImg(json.honorBadge, 20),
|
||||
];
|
||||
datatableAwards.row.add(to_add);
|
||||
}
|
||||
|
||||
function updateProgressBar(org) {
|
||||
if(currOrg != org)
|
||||
return;
|
||||
|
@ -461,8 +473,10 @@ function updateProgressHeader(org) {
|
|||
$.getJSON( url_getHonorBadges+'?org='+org, function( data ) {
|
||||
for(var i=0; i<numberOfBadges; i++) { // remove
|
||||
$('#divBadge_'+(i+1)).removeClass('circlBadgeAcquired');
|
||||
$('#divBadge_'+(i+1)).addClass('circlBadgeNotAcquired');
|
||||
}
|
||||
for(var i=0; i<data.length; i++) { // add
|
||||
$('#divBadge_'+(i+1)).removeClass('circlBadgeNotAcquired');
|
||||
$('#divBadge_'+(data[i])).addClass('circlBadgeAcquired');
|
||||
}
|
||||
});
|
||||
|
@ -587,4 +601,11 @@ $(document).ready(function() {
|
|||
updateOvertakePnts();
|
||||
sec_before_reload = refresh_speed; //reset timer at each contribution
|
||||
};
|
||||
|
||||
source_awards = new EventSource(url_eventStreamAwards);
|
||||
source_awards.onmessage = function(event) {
|
||||
var json = jQuery.parseJSON( event.data );
|
||||
addAwards(datatableAwards, json);
|
||||
datatableAwards.draw();
|
||||
};
|
||||
});
|
||||
|
|
|
@ -136,22 +136,6 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<table>
|
||||
<tbody>
|
||||
{% for item in org_honor_badge_title_list %}
|
||||
<tr style="height: 85px">
|
||||
<td>
|
||||
<div id="divBadge_{{ loop.index }}" class="circleBadge">
|
||||
<img height='64px' width='64px' style="margin-top: 5px;" src="{{ url_for('static', filename='pics/MISPHonorableIcons/1.svg')[:-5]}}{{ item[0] }}.svg" type='image/svg' style="margin: auto;"</img>
|
||||
</div>
|
||||
</td>
|
||||
<td style="padding-left: 15px;">{{ item[1] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -187,7 +171,7 @@
|
|||
{% for item in org_honor_badge_title_list %}
|
||||
<tr>
|
||||
<td>
|
||||
<div id="divBadge_{{ loop.index }}" class="circleBadgeSmall circlBadgeAcquired">
|
||||
<div id="divBadge_{{ loop.index }}" class="circleBadgeSmall circlBadgeNotAcquired">
|
||||
<img height='64px' width='64px' class="" style="margin-top: 3px;" src="{{ url_for('static', filename='pics/MISPHonorableIcons/1.svg')[:-5]}}{{ item[0] }}.svg" type='image/svg' style="margin: auto;"</img>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -490,6 +474,7 @@
|
|||
var url_getLastContributor = "{{ url_for('getLastContributors') }}";
|
||||
var url_getLatestAwards = "{{ url_for('getLatestAwards') }}";
|
||||
var url_eventStreamLastContributor = "{{ url_for('getLastContributor') }}";
|
||||
var url_eventStreamAwards = "{{ url_for('getLastStreamAwards') }}";
|
||||
var url_getAllOrg = "{{ url_for('getAllOrg') }}";
|
||||
var url_getOrgRank = "{{ url_for('getOrgRank') }}";
|
||||
var url_getContributionOrgStatus = "{{ url_for('getContributionOrgStatus') }}";
|
||||
|
|
Loading…
Reference in New Issue