diff --git a/api/lottery.js b/api/lottery.js index 2a0145f..e336ada 100644 --- a/api/lottery.js +++ b/api/lottery.js @@ -77,11 +77,13 @@ const byEpochDate = (req, res) => { .then(highscore => getHighscoreByDates(highscore)) .then(async (lotteries) => { const lottery = lotteries[date]; + let highscoreWithResolvedWines = await resolveWineReferences(lottery) + highscoreWithResolvedWines = highscoreWithResolvedWines.reverse() if (lottery != null) { return res.send({ message: `Lottery for date: ${dateString}`, - lottery: await resolveWineReferences(lottery) + lottery: highscoreWithResolvedWines }) } else { return res.status(404).send({ @@ -93,15 +95,18 @@ const byEpochDate = (req, res) => { const byName = (req, res) => { const { name } = req.params; + const regexName = new RegExp(name, "i"); // lowercase regex of the name - return Highscore.find({ name }) + return Highscore.find({ "name": { $regex : regexName } }) .then(async (highscore) => { highscore = highscore[0] if (highscore) { - const highscoreWithResolvedWines = await resolveWineReferences(highscore.wins) + let highscoreWithResolvedWines = await resolveWineReferences(highscore.wins) + highscoreWithResolvedWines = highscoreWithResolvedWines.reverse() return res.send({ message: `Lottery winnings by name: ${name}`, + name: name, highscore: highscoreWithResolvedWines }) } else { diff --git a/src/api.js b/src/api.js index 05145b9..2733701 100644 --- a/src/api.js +++ b/src/api.js @@ -333,6 +333,19 @@ const historyAll = () => { }); } +const getWinnerByName = (name) => { + const encodedName = encodeURIComponent(name) + const url = new URL(`/api/lottery/by-name/${name}`, BASE_URL); + + return fetch(url.href).then(resp => { + if (resp.ok) { + return resp.json(); + } else { + return handleErrors(resp); + } + }) +} + export { statistics, colorStatistics, @@ -364,5 +377,6 @@ export { finishedDraw, getAmIWinner, postWineChosen, - historyAll + historyAll, + getWinnerByName }; diff --git a/src/components/HighscorePage.vue b/src/components/HighscorePage.vue index 574f45c..3b9bf8d 100644 --- a/src/components/HighscorePage.vue +++ b/src/components/HighscorePage.vue @@ -1,56 +1,24 @@ @@ -58,16 +26,15 @@ diff --git a/src/components/PersonalHighscorePage.vue b/src/components/PersonalHighscorePage.vue new file mode 100644 index 0000000..69610cd --- /dev/null +++ b/src/components/PersonalHighscorePage.vue @@ -0,0 +1,273 @@ + + + + + \ No newline at end of file diff --git a/src/components/VirtualLotteryRegistrationPage.vue b/src/components/VirtualLotteryRegistrationPage.vue index cff8fe8..153c6e9 100644 --- a/src/components/VirtualLotteryRegistrationPage.vue +++ b/src/components/VirtualLotteryRegistrationPage.vue @@ -18,7 +18,7 @@

Vinnere

-
+
{{ winner.name }} {{ winner.phoneNumber }} Rød: {{ winner.red }} @@ -47,11 +47,11 @@ {{ attendee.name }} {{ attendee.phoneNumber }}
-
-
{{ attendee.red }}
-
{{ attendee.blue }}
-
{{ attendee.green }}
-
{{ attendee.yellow }}
+
+
{{ attendee.red }}
+
{{ attendee.blue }}
+
{{ attendee.green }}
+
{{ attendee.yellow }}
@@ -140,7 +140,7 @@ export default { blue: 0, green: 0, yellow: 0, - ballots: 0, + raffles: 0, randomColors: false, attendees: [], winners: [], @@ -197,7 +197,7 @@ export default { blue: this.blue, green: this.green, yellow: this.yellow, - ballots: this.ballots + raffles: this.raffles }); if (response == true) { @@ -354,7 +354,7 @@ hr { } } -.ballot-element { +.raffle-element { width: 140px; height: 150px; margin: 20px 0; @@ -378,19 +378,19 @@ hr { font-size: 1rem; } - &.green-ballot { + &.green-raffle { background-color: $light-green; } - &.blue-ballot { + &.blue-raffle { background-color: $light-blue; } - &.yellow-ballot { + &.yellow-raffle { background-color: $light-yellow; } - &.red-ballot { + &.red-raffle { background-color: $light-red; } } @@ -422,7 +422,7 @@ button { margin: 0 auto; & .name-and-phone, - & .ballots-container { + & .raffles-container { display: flex; justify-content: center; } @@ -431,7 +431,7 @@ button { flex-direction: column; } - & .ballots-container { + & .raffles-container { flex-direction: row; } } diff --git a/src/router.js b/src/router.js index 757cf6a..78064b4 100644 --- a/src/router.js +++ b/src/router.js @@ -12,6 +12,7 @@ import WinnerPage from "@/components/WinnerPage"; import LotteryPage from "@/components/LotteryPage"; import HistoryPage from "@/components/HistoryPage"; import HighscorePage from "@/components/HighscorePage"; +import PersonalHighscorePage from "@/components/PersonalHighscorePage"; import RequestWine from "@/components/RequestWine"; import AllRequestedWines from "@/components/AllRequestedWines"; @@ -57,6 +58,10 @@ const routes = [ path: "/history", component: HistoryPage }, + { + path: "/highscore/:name", + component: PersonalHighscorePage + }, { path: "/highscore", component: HighscorePage diff --git a/src/styles/global.scss b/src/styles/global.scss index e4e6f07..3680f58 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -18,6 +18,10 @@ body { margin: 0; } +a { + text-decoration: none; +} + .title { text-align: center; width: fit-content; @@ -242,7 +246,7 @@ textarea { margin: 0 !important; } -.ballot-element { +.raffle-element { margin: 20px 0; -webkit-mask-image: url(/../../public/assets/images/lodd.svg); background-repeat: no-repeat; @@ -251,19 +255,19 @@ textarea { mask-repeat: no-repeat; color: #333333; - &.green-ballot { + &.green-raffle { background-color: $light-green; } - &.blue-ballot { + &.blue-raffle { background-color: $light-blue; } - &.yellow-ballot { + &.yellow-raffle { background-color: $light-yellow; } - &.red-ballot { + &.red-raffle { background-color: $light-red; } } diff --git a/src/styles/positioning.scss b/src/styles/positioning.scss index 15e36e4..09e53c6 100644 --- a/src/styles/positioning.scss +++ b/src/styles/positioning.scss @@ -1,15 +1,15 @@ .flex { display: flex; - & .column { + &.column { flex-direction: column; } - & .row { + &.row { flex-direction: row; } - & .wrap { + &.wrap { flex-wrap: wrap; } diff --git a/src/styles/variables.scss b/src/styles/variables.scss index 7529b3e..da5fe60 100644 --- a/src/styles/variables.scss +++ b/src/styles/variables.scss @@ -16,4 +16,6 @@ $light-red: #fbd7de; $red: #ef5878; $dark-red: #ec3b61; -$link-color: #ff5fff; \ No newline at end of file +$link-color: #ff5fff; + +$matte-text-color: #333333; \ No newline at end of file diff --git a/src/ui/Attendees.vue b/src/ui/Attendees.vue index 6b6b819..2cf1afb 100644 --- a/src/ui/Attendees.vue +++ b/src/ui/Attendees.vue @@ -4,10 +4,10 @@
{{ attendee.name }} -
{{ attendee.red }}
-
{{ attendee.blue }}
-
{{ attendee.green }}
-
{{ attendee.yellow }}
+
{{ attendee.red }}
+
{{ attendee.blue }}
+
{{ attendee.green }}
+
{{ attendee.yellow }}
@@ -46,7 +46,7 @@ export default { width: 60%; } -.ballot-element { +.raffle-element { font-size: 0.75rem; width: 45px; height: 45px; diff --git a/src/ui/TotalBought.vue b/src/ui/TotalBought.vue index 217cd84..c68d899 100644 --- a/src/ui/TotalBought.vue +++ b/src/ui/TotalBought.vue @@ -8,7 +8,7 @@ color.name + '-container ' + color.name + - '-ballot inner-bought-container ballot-element' + '-raffle inner-bought-container ballot-element' " :key="color.name" > @@ -24,7 +24,7 @@
-
+
Totalt 
@@ -136,7 +136,7 @@ export default { align-items: center; } -.ballot-element { +.raffle-element { width: 140px; height: 150px; margin: 20px 0; @@ -166,7 +166,7 @@ export default { } } -.total-ballots { +.total-raffles { width: 150px; height: 150px; margin: 20px 0; diff --git a/src/ui/WinnerDraw.vue b/src/ui/WinnerDraw.vue index 1cd3d8d..c7ca7b2 100644 --- a/src/ui/WinnerDraw.vue +++ b/src/ui/WinnerDraw.vue @@ -3,7 +3,7 @@

TREKKER

@@ -19,7 +19,7 @@

VINNER

@@ -204,7 +204,7 @@ h2 { align-items: center; } -.ballot-element { +.raffle-element { width: 140px; height: 140px; font-size: 1.2rem; diff --git a/src/ui/Winners.vue b/src/ui/Winners.vue index fc76fd6..132119d 100644 --- a/src/ui/Winners.vue +++ b/src/ui/Winners.vue @@ -3,7 +3,7 @@

{{ title ? title : 'Vinnere' }}

-
{{ winner.name }}
+
{{ winner.name }}
@@ -40,7 +40,7 @@ h2 { flex-wrap: wrap; } -.ballot-element { +.raffle-element { font-size: 1rem; width: 145px; height: 145px; diff --git a/src/utils.js b/src/utils.js index 7644e4b..644a673 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,6 +7,18 @@ const dateString = (date) => { return `${ye}-${mo}-${da}` } -module.exports = { - dateString +function humanReadableDate(date) { + const options = { year: 'numeric', month: 'long', day: 'numeric' }; + return new Date(date).toLocaleDateString(undefined, options); +} + +function daysAgo(date) { + const day = 24 * 60 * 60 * 1000; + return Math.round(Math.abs((new Date() - new Date(date)) / day)); +} + +module.exports = { + dateString, + humanReadableDate, + daysAgo }