Skip to content

Commit

Permalink
Notifications and CSS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aunefyren committed Apr 1, 2024
1 parent ea5f6ab commit e3d31ad
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
12 changes: 8 additions & 4 deletions controllers/debt.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func GenerateDebtForWeek(givenTime time.Time) (models.WeekResults, error) {
winner = &winners[0]
}

_, weekNumber := givenTime.ISOWeek()

for _, user := range losers {

_, debtFound, err := database.GetDebtForWeekForUserInSeasonID(givenTime, user, seasonObject.ID)
Expand Down Expand Up @@ -231,7 +233,7 @@ func GenerateDebtForWeek(givenTime time.Time) (models.WeekResults, error) {
} else {

// Notify loser by e-mail
err = utilities.SendSMTPForWeekLost(loserObject)
err = utilities.SendSMTPForWeekLost(loserObject, weekNumber)
if err != nil {
log.Println("Failed to notify user '" + user.String() + "' by e-mail. Ignoring. Error: " + err.Error())
}
Expand All @@ -251,7 +253,7 @@ func GenerateDebtForWeek(givenTime time.Time) (models.WeekResults, error) {
} else {

// Notify winner by e-mail
err = utilities.SendSMTPForWheelSpinWin(winnerObject)
err = utilities.SendSMTPForWheelSpinWin(winnerObject, weekNumber)
if err != nil {
log.Println("Failed to notify user '" + user.String() + "' by e-mail. Ignoring. Error: " + err.Error())
}
Expand All @@ -275,7 +277,7 @@ func GenerateDebtForWeek(givenTime time.Time) (models.WeekResults, error) {
} else {

// Notify loser by e-mail
err = utilities.SendSMTPForWheelSpin(loserObject)
err = utilities.SendSMTPForWheelSpin(loserObject, weekNumber)
if err != nil {
log.Println("Failed to notify user '" + user.String() + "' by e-mail. Ignoring. Error: " + err.Error())
}
Expand Down Expand Up @@ -684,8 +686,10 @@ func APIChooseWinnerForDebt(context *gin.Context) {
log.Println("Failed to get object for user '" + user.User.ID.String() + "'. Ignoring. Error: " + err.Error())
} else {

_, weekNumber := debtObject.Date.ISOWeek()

// Notify winner by e-mail
err = utilities.SendSMTPForWheelSpinCheck(winnerObject)
err = utilities.SendSMTPForWheelSpinCheck(winnerObject, weekNumber)
if err != nil {
log.Println("Failed to notify user '" + user.User.ID.String() + "' by e-mail. Ignoring. Error: " + err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func SendSundayReminders() {
}

for _, user := range usersToAlert {
utilities.SendSMTPSundayReminderEmail(user)
utilities.SendSMTPSundayReminderEmail(user, season, time.Now())
}

// Send push notifications
Expand Down
22 changes: 12 additions & 10 deletions utilities/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"strconv"
"strings"
"time"

"github.com/go-mail/mail"
)
Expand Down Expand Up @@ -77,7 +78,7 @@ func SendSMTPResetEmail(user models.User) error {

}

func SendSMTPSundayReminderEmail(user models.User) error {
func SendSMTPSundayReminderEmail(user models.User, season models.Season, timeStamp time.Time) error {

// Get configuration
config, err := config.GetConfig()
Expand All @@ -92,12 +93,13 @@ func SendSMTPSundayReminderEmail(user models.User) error {
log.Println("Sending e-mail to: " + user.Email + ".")

link := config.TreninghetenExternalURL
_, weekNumber := timeStamp.ISOWeek()

m := mail.NewMessage()
m.SetAddressHeader("From", config.SMTPFrom, config.TreninghetenName)
m.SetHeader("To", user.Email)
m.SetHeader("Subject", "Sunday reminder")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>It's Sunday and the week is almost over.<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and log your workouts.<br><br>You can disable this alert in your settings.")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>It's Sunday and week "+strconv.Itoa(weekNumber)+" within '"+season.Name+"' is almost over.<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and log your workouts.<br><br>You can disable this alert in your settings.")

d := mail.NewDialer(config.SMTPHost, config.SMTPPort, config.SMTPUsername, config.SMTPPassword)

Expand Down Expand Up @@ -159,7 +161,7 @@ func SendSMTPSeasonStartEmail(season models.SeasonObject) error {

}

func SendSMTPForWeekLost(user models.User) error {
func SendSMTPForWeekLost(user models.User, weekNumber int) error {

// Get configuration
config, err := config.GetConfig()
Expand All @@ -179,7 +181,7 @@ func SendSMTPForWeekLost(user models.User) error {
m.SetAddressHeader("From", config.SMTPFrom, config.TreninghetenName)
m.SetHeader("To", user.Email)
m.SetHeader("Subject", "Your week didn't go as planned")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>You didn't hit your goal this week. 😢<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and check who won.")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>You didn't hit your goal for week "+strconv.Itoa(weekNumber)+". 😢<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and check who won.")

d := mail.NewDialer(config.SMTPHost, config.SMTPPort, config.SMTPUsername, config.SMTPPassword)

Expand All @@ -193,7 +195,7 @@ func SendSMTPForWeekLost(user models.User) error {

}

func SendSMTPForWheelSpin(user models.User) error {
func SendSMTPForWheelSpin(user models.User, weekNumber int) error {

// Get configuration
config, err := config.GetConfig()
Expand All @@ -213,7 +215,7 @@ func SendSMTPForWheelSpin(user models.User) error {
m.SetAddressHeader("From", config.SMTPFrom, config.TreninghetenName)
m.SetHeader("To", user.Email)
m.SetHeader("Subject", "You have a wheel to spin")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>You didn't hit your goal this week. 😢<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and spin the wheel.")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>You didn't hit your goal for week "+strconv.Itoa(weekNumber)+". 😢<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and spin the wheel.")

d := mail.NewDialer(config.SMTPHost, config.SMTPPort, config.SMTPUsername, config.SMTPPassword)

Expand All @@ -227,7 +229,7 @@ func SendSMTPForWheelSpin(user models.User) error {

}

func SendSMTPForWheelSpinCheck(user models.User) error {
func SendSMTPForWheelSpinCheck(user models.User, weekNumber int) error {

// Get configuration
config, err := config.GetConfig()
Expand All @@ -247,7 +249,7 @@ func SendSMTPForWheelSpinCheck(user models.User) error {
m.SetAddressHeader("From", config.SMTPFrom, config.TreninghetenName)
m.SetHeader("To", user.Email)
m.SetHeader("Subject", "Someone spun the wheel")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>Someone spun the wheel, check if you won. 🏆<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and check out the wheel spin.")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>Someone spun the wheel, check if you won in week "+strconv.Itoa(weekNumber)+". 🏆<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and check out the wheel spin.")

d := mail.NewDialer(config.SMTPHost, config.SMTPPort, config.SMTPUsername, config.SMTPPassword)

Expand All @@ -261,7 +263,7 @@ func SendSMTPForWheelSpinCheck(user models.User) error {

}

func SendSMTPForWheelSpinWin(user models.User) error {
func SendSMTPForWheelSpinWin(user models.User, weekNumber int) error {

// Get configuration
config, err := config.GetConfig()
Expand All @@ -281,7 +283,7 @@ func SendSMTPForWheelSpinWin(user models.User) error {
m.SetAddressHeader("From", config.SMTPFrom, config.TreninghetenName)
m.SetHeader("To", user.Email)
m.SetHeader("Subject", "Someone just paid their dues")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>Someone failed to hit their goal, and you won. 🏆<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and check out your prize.")
m.SetBody("text/html", "Hello <b>"+user.FirstName+"</b>!<br><br>Someone failed to hit their goal, and you won for week "+strconv.Itoa(weekNumber)+". 🏆<br><br>If you haven't already, head to Treningheten using <a href='"+link+"' target='_blank'>this link</a> and check out your prize.")

d := mail.NewDialer(config.SMTPHost, config.SMTPPort, config.SMTPUsername, config.SMTPPassword)

Expand Down
2 changes: 1 addition & 1 deletion web/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ input[type=checkbox]
box-sizing: content-box;
}

.achievement:hover .overlay {
.achievement:focus .overlay {
opacity: 1;
}

Expand Down
18 changes: 9 additions & 9 deletions web/js/frontpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_1_group">
<div class="day-check">
<label for="day_1_check" title="Have you been working out?">Monday</label>
<label style="margin: 0;" for="day_1_check" title="Have you been working out?">Monday</label>
<div class="number-box" id="day_1_check">
0
</div>
Expand All @@ -94,7 +94,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_2_group">
<div class="day-check">
<label for="day_2_check" title="Have you been working out?">Tuesday</label>
<label style="margin: 0;" for="day_2_check" title="Have you been working out?">Tuesday</label>
<div class="number-box" id="day_2_check">
0
</div>
Expand All @@ -116,7 +116,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_3_group">
<div class="day-check">
<label for="day_3_check" title="Have you been working out?">Wednesday</label>
<label style="margin: 0;" for="day_3_check" title="Have you been working out?">Wednesday</label>
<div class="number-box" id="day_3_check">
0
</div>
Expand All @@ -138,7 +138,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_4_group">
<div class="day-check">
<label for="day_4_check" title="Have you been working out?">Thursday</label>
<label style="margin: 0;" for="day_4_check" title="Have you been working out?">Thursday</label>
<div class="number-box" id="day_4_check">
0
</div>
Expand All @@ -160,7 +160,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_5_group">
<div class="day-check">
<label for="day_5_check" title="Have you been working out?">Friday</label>
<label style="margin: 0;" for="day_5_check" title="Have you been working out?">Friday</label>
<div class="number-box" id="day_5_check">
0
</div>
Expand All @@ -182,7 +182,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_6_group">
<div class="day-check">
<label for="day_6_check" title="Have you been working out?">Saturday</label>
<label style="margin: 0;" for="day_6_check" title="Have you been working out?">Saturday</label>
<div class="number-box" id="day_6_check">
0
</div>
Expand All @@ -204,7 +204,7 @@ function load_page(result) {
<div class="form-group" style="" id="day_7_group">
<div class="day-check">
<label for="day_7_check" title="Have you been working out?">Sunday</label>
<label style="margin: 0;" for="day_7_check" title="Have you been working out?">Sunday</label>
<div class="number-box" id="day_7_check">
0
</div>
Expand Down Expand Up @@ -1055,7 +1055,7 @@ function placeDebtOverview(overviewArray) {
html += `
<div class="debt-module-notification-view" id="">
${overviewArray.debt_unviewed[i].debt.loser.first_name} ${overviewArray.debt_unviewed[i].debt.loser.last_name} spun the wheel for week ${date_str}.<br>See if you won!<br>
<img src="assets/arrow-right.svg" class="small-button-icon" onclick="location.replace('/wheel?debt_id=${overviewArray.debt_unviewed[i].debt.id}'); ">
<img src="assets/arrow-right.svg" class="small-button-icon clickable" onclick="location.replace('/wheel?debt_id=${overviewArray.debt_unviewed[i].debt.id}'); ">
</div>
`;
}
Expand All @@ -1077,7 +1077,7 @@ function placeDebtOverview(overviewArray) {
html += `
<div class="debt-module-notification-prize" id="">
${overviewArray.debt_won[i].loser.first_name} ${overviewArray.debt_won[i].loser.last_name} spun the wheel for week ${date_str} and you won <b>${overviewArray.debt_won[i].season.prize.quantity} ${overviewArray.debt_won[i].season.prize.name}</b>!<br>Have you received it?<br>
<img src="assets/done.svg" class="small-button-icon" onclick="setPrizeReceived('${overviewArray.debt_won[i].id}');">
<img src="assets/done.svg" class="small-button-icon clickable" onclick="setPrizeReceived('${overviewArray.debt_won[i].id}');">
</div>
`;
}
Expand Down

0 comments on commit e3d31ad

Please sign in to comment.