2015-06-24 04:02:29 +00:00
|
|
|
var overview_chart_options = {
|
2015-07-07 03:26:08 +00:00
|
|
|
animationEasing:"linear",
|
|
|
|
customTooltips: function(tooltip) {
|
|
|
|
console.log(tooltip)
|
|
|
|
}
|
2015-06-24 04:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load(){
|
|
|
|
api.campaigns.get()
|
|
|
|
.success(function(campaigns){
|
|
|
|
if (campaigns.length > 0){
|
|
|
|
var overview_ctx = $("#overview_chart").get(0).getContext("2d");
|
|
|
|
// Create the overview chart data
|
2015-07-07 03:26:08 +00:00
|
|
|
var overview_data = {labels:[],datasets:[{data:[]}]}
|
2015-06-24 04:02:29 +00:00
|
|
|
var average = 0
|
|
|
|
$("#emptyMessage").hide()
|
|
|
|
$("#campaignTable").show()
|
|
|
|
campaignTable = $("#campaignTable").DataTable();
|
|
|
|
$.each(campaigns, function(i, campaign){
|
2015-07-07 03:26:08 +00:00
|
|
|
var campaign_date = moment(campaign.created_date).format('MMMM Do YYYY, h:mm:ss a')
|
2015-06-24 04:02:29 +00:00
|
|
|
// Add it to the table
|
|
|
|
campaignTable.row.add([
|
|
|
|
campaign.name,
|
2015-07-07 03:26:08 +00:00
|
|
|
campaign_date,
|
2015-06-24 04:02:29 +00:00
|
|
|
campaign.status
|
|
|
|
]).draw()
|
|
|
|
// Add it to the chart data
|
2015-07-07 03:26:08 +00:00
|
|
|
overview_data.labels.push(campaign_date)
|
|
|
|
campaign.y = 0
|
2015-06-24 04:02:29 +00:00
|
|
|
$.each(campaign.results, function(j, result){
|
|
|
|
if (result.status == "Success"){
|
|
|
|
campaign.y++;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
campaign.y = Math.floor((campaign.y / campaign.results.length) * 100)
|
|
|
|
average += campaign.y
|
2015-07-07 03:26:08 +00:00
|
|
|
overview_data.datasets[0].data.push({y:campaign.y, test: "test"})
|
2015-06-24 04:02:29 +00:00
|
|
|
})
|
|
|
|
average = Math.floor(average / campaigns.length);
|
2015-07-07 03:26:08 +00:00
|
|
|
var overview_chart = new Chart(overview_ctx).Line(overview_data, overview_chart_options);
|
2015-06-24 04:02:29 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.error(function(){
|
|
|
|
errorFlash("Error fetching campaigns")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
load()
|
|
|
|
})
|