Added updating of datamaps with new bubbles

pull/174/head
Jordan Wright 2016-02-23 18:50:07 -06:00
parent 95fb02bade
commit 0c72e8b69a
1 changed files with 42 additions and 10 deletions

View File

@ -63,6 +63,7 @@ var statuses = {
} }
var campaign = {} var campaign = {}
var bubbles = []
function dismiss() { function dismiss() {
$("#modal\\.flashes").empty() $("#modal\\.flashes").empty()
@ -169,6 +170,15 @@ function renderTimeline(data) {
return results return results
} }
/* poll - Queries the API and updates the UI with the results
*
* Updates:
* * Timeline Chart
* * Email (Donut) Chart
* * Map Bubbles
* * Datatables
*/
function poll() { function poll() {
api.campaignId.get(campaign.id) api.campaignId.get(campaign.id)
.success(function(c) { .success(function(c) {
@ -222,19 +232,42 @@ function poll() {
/* Update the datatable */ /* Update the datatable */
resultsTable = $("#resultsTable").DataTable() resultsTable = $("#resultsTable").DataTable()
resultsTable.rows().every(function(i, tableLoop, rowLoop) { resultsTable.rows().every(function(i, tableLoop, rowLoop) {
var rowData = this.row(i).data() var rowData = this.row(i).data()
var rid = rowData[0] var rid = rowData[0]
$.each(campaign.results, function(j, result) { $.each(campaign.results, function(j, result) {
if (result.id == rid) { if (result.id == rid) {
var label = statuses[result.status].label || "label-default"; var label = statuses[result.status].label || "label-default";
rowData[6] = "<span class=\"label " + label + "\">" + result.status + "</span>" rowData[6] = "<span class=\"label " + label + "\">" + result.status + "</span>"
resultsTable.row(i).data(rowData).draw() resultsTable.row(i).data(rowData).draw()
return false
}
})
})
/* Update the map information */
$.each(campaign.results, function(i, result) {
// Check that it wasn't an internal IP
if (result.latitude == 0 && result.longitude == 0) {
return true;
}
newIP = true
$.each(bubbles, function(i, bubble) {
if (bubble.ip == result.ip) {
bubbles[i].radius += 1
newIP = false
return false return false
} }
}) })
if (newIP) {
bubbles.push({
latitude: result.latitude,
longitude: result.longitude,
name: result.ip,
fillKey: "point",
radius: 2
})
}
}) })
map.bubbles(bubbles)
}) })
} }
@ -440,7 +473,6 @@ function load() {
} }
}); });
} }
bubbles = []
$.each(campaign.results, function(i, result) { $.each(campaign.results, function(i, result) {
// Check that it wasn't an internal IP // Check that it wasn't an internal IP
if (result.latitude == 0 && result.longitude == 0) { if (result.latitude == 0 && result.longitude == 0) {