Updates all datetimes to use UTC on the backend. This includes a DB migration to convert existing dates.

Fixes #316
pull/733/head
Jordan Wright 2017-08-28 22:48:49 -05:00
parent 779e419ab4
commit 58a57589bd
11 changed files with 130 additions and 88 deletions

View File

@ -203,7 +203,7 @@ func API_Groups(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: "Group name already in use"}, http.StatusConflict) JSONResponse(w, models.Response{Success: false, Message: "Group name already in use"}, http.StatusConflict)
return return
} }
g.ModifiedDate = time.Now() g.ModifiedDate = time.Now().UTC()
g.UserId = ctx.Get(r, "user_id").(int64) g.UserId = ctx.Get(r, "user_id").(int64)
err = models.PostGroup(&g) err = models.PostGroup(&g)
if err != nil { if err != nil {
@ -256,7 +256,7 @@ func API_Groups_Id(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: "Error: /:id and group_id mismatch"}, http.StatusInternalServerError) JSONResponse(w, models.Response{Success: false, Message: "Error: /:id and group_id mismatch"}, http.StatusInternalServerError)
return return
} }
g.ModifiedDate = time.Now() g.ModifiedDate = time.Now().UTC()
g.UserId = ctx.Get(r, "user_id").(int64) g.UserId = ctx.Get(r, "user_id").(int64)
err = models.PutGroup(&g) err = models.PutGroup(&g)
if err != nil { if err != nil {
@ -305,7 +305,7 @@ func API_Templates(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: "Template name already in use"}, http.StatusConflict) JSONResponse(w, models.Response{Success: false, Message: "Template name already in use"}, http.StatusConflict)
return return
} }
t.ModifiedDate = time.Now() t.ModifiedDate = time.Now().UTC()
t.UserId = ctx.Get(r, "user_id").(int64) t.UserId = ctx.Get(r, "user_id").(int64)
err = models.PostTemplate(&t) err = models.PostTemplate(&t)
if err == models.ErrTemplateNameNotSpecified { if err == models.ErrTemplateNameNotSpecified {
@ -354,7 +354,7 @@ func API_Templates_Id(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: "Error: /:id and template_id mismatch"}, http.StatusBadRequest) JSONResponse(w, models.Response{Success: false, Message: "Error: /:id and template_id mismatch"}, http.StatusBadRequest)
return return
} }
t.ModifiedDate = time.Now() t.ModifiedDate = time.Now().UTC()
t.UserId = ctx.Get(r, "user_id").(int64) t.UserId = ctx.Get(r, "user_id").(int64)
err = models.PutTemplate(&t) err = models.PutTemplate(&t)
if err != nil { if err != nil {
@ -390,7 +390,7 @@ func API_Pages(w http.ResponseWriter, r *http.Request) {
Logger.Println(err) Logger.Println(err)
return return
} }
p.ModifiedDate = time.Now() p.ModifiedDate = time.Now().UTC()
p.UserId = ctx.Get(r, "user_id").(int64) p.UserId = ctx.Get(r, "user_id").(int64)
err = models.PostPage(&p) err = models.PostPage(&p)
if err != nil { if err != nil {
@ -431,7 +431,7 @@ func API_Pages_Id(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: "/:id and /:page_id mismatch"}, http.StatusBadRequest) JSONResponse(w, models.Response{Success: false, Message: "/:id and /:page_id mismatch"}, http.StatusBadRequest)
return return
} }
p.ModifiedDate = time.Now() p.ModifiedDate = time.Now().UTC()
p.UserId = ctx.Get(r, "user_id").(int64) p.UserId = ctx.Get(r, "user_id").(int64)
err = models.PutPage(&p) err = models.PutPage(&p)
if err != nil { if err != nil {
@ -467,7 +467,7 @@ func API_SMTP(w http.ResponseWriter, r *http.Request) {
Logger.Println(err) Logger.Println(err)
return return
} }
s.ModifiedDate = time.Now() s.ModifiedDate = time.Now().UTC()
s.UserId = ctx.Get(r, "user_id").(int64) s.UserId = ctx.Get(r, "user_id").(int64)
err = models.PostSMTP(&s) err = models.PostSMTP(&s)
if err != nil { if err != nil {
@ -513,7 +513,7 @@ func API_SMTP_Id(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
return return
} }
s.ModifiedDate = time.Now() s.ModifiedDate = time.Now().UTC()
s.UserId = ctx.Get(r, "user_id").(int64) s.UserId = ctx.Get(r, "user_id").(int64)
err = models.PutSMTP(&s) err = models.PutSMTP(&s)
if err != nil { if err != nil {

View File

@ -0,0 +1,16 @@
-- +goose Up
-- SQL in section 'Up' is executed when this migration is applied
UPDATE campaigns SET `created_date`=CONVERT_TZ(`created_date`, @@session.time_zone, '+00:00');
UPDATE campaigns SET `completed_date`=CONVERT_TZ(`completed_date`, @@session.time_zone, '+00:00');
UPDATE campaigns SET `launch_date`=CONVERT_TZ(`launch_date`, @@session.time_zone, '+00:00');
UPDATE events SET `time`=CONVERT_TZ(`time`, @@session.time_zone, '+00:00');
UPDATE groups SET `modified_date`=CONVERT_TZ(`modified_date`, @@session.time_zone, '+00:00');
UPDATE templates SET `modified_date`=CONVERT_TZ(`modified_date`, @@session.time_zone, '+00:00');
UPDATE pages SET `modified_date`=CONVERT_TZ(`modified_date`, @@session.time_zone, '+00:00');
UPDATE smtp SET `modified_date`=CONVERT_TZ(`modified_date`, @@session.time_zone, '+00:00');
-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back

View File

@ -0,0 +1,15 @@
-- +goose Up
-- SQL in section 'Up' is executed when this migration is applied
UPDATE campaigns SET created_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(created_date, 'utc'));
UPDATE campaigns SET completed_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(completed_date, 'utc'));
UPDATE campaigns SET launch_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(launch_date, 'utc'));
UPDATE events SET `time`=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(`time`, 'utc'));
UPDATE groups SET modified_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(modified_date, 'utc'));
UPDATE templates SET modified_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(modified_date, 'utc'));
UPDATE pages SET modified_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(modified_date, 'utc'));
UPDATE smtp SET modified_date=STRFTIME('%Y-%m-%d %H:%M:%S+00:00', DATETIME(modified_date, 'utc'));
-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back

View File

@ -140,7 +140,7 @@ func (c *Campaign) UpdateStatus(s string) error {
// AddEvent creates a new campaign event in the database // AddEvent creates a new campaign event in the database
func (c *Campaign) AddEvent(e Event) error { func (c *Campaign) AddEvent(e Event) error {
e.CampaignId = c.Id e.CampaignId = c.Id
e.Time = time.Now() e.Time = time.Now().UTC()
return db.Debug().Save(&e).Error return db.Debug().Save(&e).Error
} }
@ -279,6 +279,7 @@ func GetCampaignSummaries(uid int64) (CampaignSummaries, error) {
return overview, err return overview, err
} }
cs[i].Stats = s cs[i].Stats = s
Logger.Println(cs[i].CreatedDate.String())
} }
overview.Total = int64(len(cs)) overview.Total = int64(len(cs))
overview.Campaigns = cs overview.Campaigns = cs
@ -361,11 +362,13 @@ func PostCampaign(c *Campaign, uid int64) error {
} }
// Fill in the details // Fill in the details
c.UserId = uid c.UserId = uid
c.CreatedDate = time.Now() c.CreatedDate = time.Now().UTC()
c.CompletedDate = time.Time{} c.CompletedDate = time.Time{}
c.Status = CAMPAIGN_CREATED c.Status = CAMPAIGN_CREATED
if c.LaunchDate.IsZero() { if c.LaunchDate.IsZero() {
c.LaunchDate = time.Now() c.LaunchDate = time.Now().UTC()
} else {
c.LaunchDate = c.LaunchDate.UTC()
} }
// Check to make sure all the groups already exist // Check to make sure all the groups already exist
for i, g := range c.Groups { for i, g := range c.Groups {
@ -479,7 +482,7 @@ func CompleteCampaign(id int64, uid int64) error {
return nil return nil
} }
// Mark the campaign as complete // Mark the campaign as complete
c.CompletedDate = time.Now() c.CompletedDate = time.Now().UTC()
c.Status = CAMPAIGN_COMPLETE c.Status = CAMPAIGN_COMPLETE
err = db.Where("id=? and user_id=?", id, uid).Save(&c).Error err = db.Where("id=? and user_id=?", id, uid).Save(&c).Error
if err != nil { if err != nil {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -282,7 +282,7 @@ function renderTimeline(data) {
' <div class="timeline-icon ' + statuses[event.message].label + '">' + ' <div class="timeline-icon ' + statuses[event.message].label + '">' +
' <i class="fa ' + statuses[event.message].icon + '"></i></div>' + ' <i class="fa ' + statuses[event.message].icon + '"></i></div>' +
' <div class="timeline-message">' + escapeHtml(event.message) + ' <div class="timeline-message">' + escapeHtml(event.message) +
' <span class="timeline-date">' + moment(event.time).format('MMMM Do YYYY h:mm a') + '</span>' ' <span class="timeline-date">' + moment.utc(event.time).local().format('MMMM Do YYYY h:mm a') + '</span>'
if (event.details) { if (event.details) {
if (event.message == "Submitted Data") { if (event.message == "Submitted Data") {
results += '<div class="timeline-replay-button"><button onclick="replay(' + i + ')" class="btn btn-success">' results += '<div class="timeline-replay-button"><button onclick="replay(' + i + ')" class="btn btn-success">'
@ -461,7 +461,7 @@ function poll() {
/* Update the timeline */ /* Update the timeline */
var timeline_series_data = [] var timeline_series_data = []
$.each(campaign.timeline, function (i, event) { $.each(campaign.timeline, function (i, event) {
var event_date = moment(event.time) var event_date = moment.utc(event.time).local()
timeline_series_data.push({ timeline_series_data.push({
email: event.email, email: event.email,
x: event_date.valueOf(), x: event_date.valueOf(),
@ -470,7 +470,7 @@ function poll() {
}) })
var timeline_series_data = [] var timeline_series_data = []
$.each(campaign.timeline, function (i, event) { $.each(campaign.timeline, function (i, event) {
var event_date = moment(event.time) var event_date = moment.utc(event.time).local()
timeline_series_data.push({ timeline_series_data.push({
email: event.email, email: event.email,
message: event.message, message: event.message,
@ -661,7 +661,7 @@ function load() {
}); });
// Setup the graphs // Setup the graphs
$.each(campaign.timeline, function (i, event) { $.each(campaign.timeline, function (i, event) {
var event_date = moment(event.time) var event_date = moment.utc(event.time).local()
timeline_series_data.push({ timeline_series_data.push({
email: event.email, email: event.email,
message: event.message, message: event.message,

View File

@ -24,48 +24,49 @@ function launch() {
reverseButtons: true, reverseButtons: true,
allowOutsideClick: false, allowOutsideClick: false,
showLoaderOnConfirm: true, showLoaderOnConfirm: true,
preConfirm: function() { preConfirm: function () {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
groups = [] groups = []
$("#users").select2("data").forEach(function(group){ $("#users").select2("data").forEach(function (group) {
groups.push({name: group.text}); groups.push({ name: group.text });
}) })
// Validate our fields // Validate our fields
campaign = { campaign = {
name: $("#name").val(), name: $("#name").val(),
template: { template: {
name: $("#template").select2("data")[0].text name: $("#template").select2("data")[0].text
}, },
url: $("#url").val(), url: $("#url").val(),
page: { page: {
name: $("#page").select2("data")[0].text name: $("#page").select2("data")[0].text
}, },
smtp: { smtp: {
name: $("#profile").select2("data")[0].text name: $("#profile").select2("data")[0].text
}, },
launch_date: moment($("#launch_date").val(), "MM/DD/YYYY hh:mm a").format(), launch_date: moment($("#launch_date").val(), "MM/DD/YYYY hh:mm a").utc().format(),
groups: groups groups: groups
} }
// Submit the campaign console.log("Launching campaign at time: " + campaign.launch_date)
// Submit the campaign
api.campaigns.post(campaign) api.campaigns.post(campaign)
.success(function(data) { .success(function (data) {
resolve() resolve()
campaign = data campaign = data
}) })
.error(function(data) { .error(function (data) {
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ $("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>") <i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
swal.close() swal.close()
}) })
}) })
} }
}).then(function() { }).then(function () {
swal( swal(
'Campaign Scheduled!', 'Campaign Scheduled!',
'This campaign has been scheduled for launch!', 'This campaign has been scheduled for launch!',
'success' 'success'
); );
$('button:contains("OK")').on('click', function() { $('button:contains("OK")').on('click', function () {
window.location = "/campaigns/" + campaign.id.toString() window.location = "/campaigns/" + campaign.id.toString()
}) })
}) })
@ -91,14 +92,14 @@ function sendTestEmail() {
} }
btnHtml = $("#sendTestModalSubmit").html() btnHtml = $("#sendTestModalSubmit").html()
$("#sendTestModalSubmit").html('<i class="fa fa-spinner fa-spin"></i> Sending') $("#sendTestModalSubmit").html('<i class="fa fa-spinner fa-spin"></i> Sending')
// Send the test email // Send the test email
api.send_test_email(test_email_request) api.send_test_email(test_email_request)
.success(function(data) { .success(function (data) {
$("#sendTestEmailModal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-success\">\ $("#sendTestEmailModal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-success\">\
<i class=\"fa fa-check-circle\"></i> Email Sent!</div>") <i class=\"fa fa-check-circle\"></i> Email Sent!</div>")
$("#sendTestModalSubmit").html(btnHtml) $("#sendTestModalSubmit").html(btnHtml)
}) })
.error(function(data) { .error(function (data) {
$("#sendTestEmailModal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ $("#sendTestEmailModal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>") <i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
$("#sendTestModalSubmit").html(btnHtml) $("#sendTestModalSubmit").html(btnHtml)
@ -127,24 +128,24 @@ function deleteCampaign(idx) {
confirmButtonColor: "#428bca", confirmButtonColor: "#428bca",
reverseButtons: true, reverseButtons: true,
allowOutsideClick: false, allowOutsideClick: false,
preConfirm: function() { preConfirm: function () {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
api.campaignId.delete(campaigns[idx].id) api.campaignId.delete(campaigns[idx].id)
.success(function(msg) { .success(function (msg) {
resolve() resolve()
}) })
.error(function(data) { .error(function (data) {
reject(data.responseJSON.message) reject(data.responseJSON.message)
}) })
}) })
} }
}).then(function() { }).then(function () {
swal( swal(
'Campaign Deleted!', 'Campaign Deleted!',
'This campaign has been deleted!', 'This campaign has been deleted!',
'success' 'success'
); );
$('button:contains("OK")').on('click', function() { $('button:contains("OK")').on('click', function () {
location.reload() location.reload()
}) })
}) })
@ -152,12 +153,12 @@ function deleteCampaign(idx) {
function setupOptions() { function setupOptions() {
api.groups.get() api.groups.get()
.success(function(groups) { .success(function (groups) {
if (groups.length == 0) { if (groups.length == 0) {
modalError("No groups found!") modalError("No groups found!")
return false; return false;
} else { } else {
var group_s2 = $.map(groups, function(obj) { var group_s2 = $.map(groups, function (obj) {
obj.text = obj.name obj.text = obj.name
return obj return obj
}); });
@ -168,12 +169,12 @@ function setupOptions() {
} }
}); });
api.templates.get() api.templates.get()
.success(function(templates) { .success(function (templates) {
if (templates.length == 0) { if (templates.length == 0) {
modalError("No templates found!") modalError("No templates found!")
return false return false
} else { } else {
var template_s2 = $.map(templates, function(obj) { var template_s2 = $.map(templates, function (obj) {
obj.text = obj.name obj.text = obj.name
return obj return obj
}); });
@ -184,12 +185,12 @@ function setupOptions() {
} }
}); });
api.pages.get() api.pages.get()
.success(function(pages) { .success(function (pages) {
if (pages.length == 0) { if (pages.length == 0) {
modalError("No pages found!") modalError("No pages found!")
return false return false
} else { } else {
var page_s2 = $.map(pages, function(obj) { var page_s2 = $.map(pages, function (obj) {
obj.text = obj.name obj.text = obj.name
return obj return obj
}); });
@ -200,12 +201,12 @@ function setupOptions() {
} }
}); });
api.SMTP.get() api.SMTP.get()
.success(function(profiles) { .success(function (profiles) {
if (profiles.length == 0) { if (profiles.length == 0) {
modalError("No profiles found!") modalError("No profiles found!")
return false return false
} else { } else {
var profile_s2 = $.map(profiles, function(obj) { var profile_s2 = $.map(profiles, function (obj) {
obj.text = obj.name obj.text = obj.name
return obj return obj
}); });
@ -223,9 +224,9 @@ function edit(campaign) {
function copy(idx) { function copy(idx) {
setupOptions(); setupOptions();
// Set our initial values // Set our initial values
api.campaignId.get(campaigns[idx].id) api.campaignId.get(campaigns[idx].id)
.success(function(campaign) { .success(function (campaign) {
$("#name").val("Copy of " + campaign.name) $("#name").val("Copy of " + campaign.name)
if (!campaign.template.id) { if (!campaign.template.id) {
$("#template").select2({ $("#template").select2({
@ -250,29 +251,29 @@ function copy(idx) {
} }
$("#url").val(campaign.url) $("#url").val(campaign.url)
}) })
.error(function(data) { .error(function (data) {
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ $("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>") <i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
}) })
} }
$(document).ready(function() { $(document).ready(function () {
$("#launch_date").datetimepicker({ $("#launch_date").datetimepicker({
"widgetPositioning": { "widgetPositioning": {
"vertical": "bottom" "vertical": "bottom"
}, },
"showTodayButton": true, "showTodayButton": true,
"defaultDate": moment() "defaultDate": moment()
}) })
// Setup multiple modals // Setup multiple modals
// Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html // Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html
$('.modal').on('hidden.bs.modal', function(event) { $('.modal').on('hidden.bs.modal', function (event) {
$(this).removeClass('fv-modal-stack'); $(this).removeClass('fv-modal-stack');
$('body').data('fv_open_modals', $('body').data('fv_open_modals') - 1); $('body').data('fv_open_modals', $('body').data('fv_open_modals') - 1);
}); });
$('.modal').on('shown.bs.modal', function(event) { $('.modal').on('shown.bs.modal', function (event) {
// Keep track of the number of open modals // Keep track of the number of open modals
if (typeof($('body').data('fv_open_modals')) == 'undefined') { if (typeof ($('body').data('fv_open_modals')) == 'undefined') {
$('body').data('fv_open_modals', 0); $('body').data('fv_open_modals', 0);
} }
// if the z-index of this modal has been set, ignore. // if the z-index of this modal has been set, ignore.
@ -291,11 +292,11 @@ $(document).ready(function() {
$(document).on('hidden.bs.modal', '.modal', function () { $(document).on('hidden.bs.modal', '.modal', function () {
$('.modal:visible').length && $(document.body).addClass('modal-open'); $('.modal:visible').length && $(document.body).addClass('modal-open');
}); });
$('#modal').on('hidden.bs.modal', function(event) { $('#modal').on('hidden.bs.modal', function (event) {
dismiss() dismiss()
}); });
api.campaigns.summary() api.campaigns.summary()
.success(function(data) { .success(function (data) {
campaigns = data.campaigns campaigns = data.campaigns
$("#loading").hide() $("#loading").hide()
if (campaigns.length > 0) { if (campaigns.length > 0) {
@ -309,23 +310,25 @@ $(document).ready(function() {
[1, "desc"] [1, "desc"]
] ]
}); });
$.each(campaigns, function(i, campaign) { $.each(campaigns, function (i, campaign) {
console.log(campaign)
console.log(campaign.created_date)
label = labels[campaign.status] || "label-default"; label = labels[campaign.status] || "label-default";
//section for tooltips on the status of a campaign to show some quick stats //section for tooltips on the status of a campaign to show some quick stats
var launchDate; var launchDate;
if(moment(campaign.launch_date).isAfter(moment())){ if (moment(campaign.launch_date).isAfter(moment())) {
launchDate = "Scheduled to start: "+moment(campaign.launch_date).format('MMMM Do YYYY, h:mm:ss a') launchDate = "Scheduled to start: " + moment(campaign.launch_date).format('MMMM Do YYYY, h:mm:ss a')
var quickStats = launchDate+"<br><br>"+"Number of recipients: "+campaign.stats.total var quickStats = launchDate + "<br><br>" + "Number of recipients: " + campaign.stats.total
} else { } else {
launchDate = "Launch Date: "+moment(campaign.launch_date).format('MMMM Do YYYY, h:mm:ss a') launchDate = "Launch Date: " + moment(campaign.launch_date).format('MMMM Do YYYY, h:mm:ss a')
var quickStats = launchDate+"<br><br>"+"Number of recipients: "+campaign.stats.total+"<br><br>"+"Emails opened: "+campaign.stats.opened+"<br><br>"+"Emails clicked: "+campaign.stats.clicked+"<br><br>"+"Submitted Credentials: "+campaign.stats.submitted_data+"<br><br>"+"Errors : "+campaign.stats.error var quickStats = launchDate + "<br><br>" + "Number of recipients: " + campaign.stats.total + "<br><br>" + "Emails opened: " + campaign.stats.opened + "<br><br>" + "Emails clicked: " + campaign.stats.clicked + "<br><br>" + "Submitted Credentials: " + campaign.stats.submitted_data + "<br><br>" + "Errors : " + campaign.stats.error
} }
campaignTable.row.add([ campaignTable.row.add([
escapeHtml(campaign.name), escapeHtml(campaign.name),
moment(campaign.created_date).format('MMMM Do YYYY, h:mm:ss a'), moment(campaign.created_date).format('MMMM Do YYYY, h:mm:ss a'),
"<span class=\"label " + label + "\" data-toggle=\"tooltip\" data-placement=\"right\" data-html=\"true\" title=\""+quickStats+"\">" + campaign.status + "</span>", "<span class=\"label " + label + "\" data-toggle=\"tooltip\" data-placement=\"right\" data-html=\"true\" title=\"" + quickStats + "\">" + campaign.status + "</span>",
"<div class='pull-right'><a class='btn btn-primary' href='/campaigns/" + campaign.id + "' data-toggle='tooltip' data-placement='left' title='View Results'>\ "<div class='pull-right'><a class='btn btn-primary' href='/campaigns/" + campaign.id + "' data-toggle='tooltip' data-placement='left' title='View Results'>\
<i class='fa fa-bar-chart'></i>\ <i class='fa fa-bar-chart'></i>\
</a>\ </a>\
@ -342,7 +345,7 @@ $(document).ready(function() {
$("#emptyMessage").show() $("#emptyMessage").show()
} }
}) })
.error(function() { .error(function () {
$("#loading").hide() $("#loading").hide()
errorFlash("Error fetching campaigns") errorFlash("Error fetching campaigns")
}) })

View File

@ -197,7 +197,7 @@ function generateStatsPieCharts(campaigns) {
function generateTimelineChart(campaigns) { function generateTimelineChart(campaigns) {
var overview_data = [] var overview_data = []
$.each(campaigns, function (i, campaign) { $.each(campaigns, function (i, campaign) {
var campaign_date = moment(campaign.created_date) var campaign_date = moment.utc(campaign.created_date).local()
// Add it to the chart data // Add it to the chart data
campaign.y = 0 campaign.y = 0
// Clicked events also contain our data submitted events // Clicked events also contain our data submitted events
@ -275,6 +275,11 @@ function generateTimelineChart(campaigns) {
} }
$(document).ready(function () { $(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
})
api.campaigns.summary() api.campaigns.summary()
.success(function (data) { .success(function (data) {
$("#loading").hide() $("#loading").hide()

View File

@ -36,7 +36,7 @@ func New() *Worker {
func (w *Worker) Start() { func (w *Worker) Start() {
Logger.Println("Background Worker Started Successfully - Waiting for Campaigns") Logger.Println("Background Worker Started Successfully - Waiting for Campaigns")
for t := range time.Tick(1 * time.Minute) { for t := range time.Tick(1 * time.Minute) {
cs, err := models.GetQueuedCampaigns(t) cs, err := models.GetQueuedCampaigns(t.UTC())
// Not really sure of a clean way to catch errors per campaign... // Not really sure of a clean way to catch errors per campaign...
if err != nil { if err != nil {
Logger.Println(err) Logger.Println(err)