Working now

This commit is contained in:
Kasper Rynning-Tønnesen
2020-01-20 16:07:40 +01:00
parent 53e54726ca
commit 51c2ee2a0e
29 changed files with 11278 additions and 63 deletions

24
src/Vinlottis.vue Normal file
View File

@@ -0,0 +1,24 @@
<template>
<div class="container">
<router-view />
</div>
</template>
<script>
export default {
name: "vinlottis",
components: {},
props: {},
data() {
return {};
},
mounted() {
console.log("moutned");
},
computed: {},
methods: {}
};
</script>
<style lang="scss" scoped></style>

View File

@@ -0,0 +1,54 @@
<template>
<div class="outer">
<div>
<h2>Vinlottis</h2>
<form method="post" action="/register">
<input type="text" name="username" placeholder="Brukernavn" />
<input type="password" name="password" placeholder="Passord" />
<input type="submit" value="registrer bruker" />
</form>
</div>
</div>
</template>
<script>
export default {};
</script>
<style lang="scss" scoped>
div {
font-family: sans-serif;
}
.outer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
}
h2 {
width: 100vw;
text-align: center;
font-size: 3rem;
}
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100vw;
}
input {
margin: 20px;
width: 30vw;
font-size: 3rem;
border: none;
border-bottom: 1px solid black;
}
input[type="submit"] {
border: 1px solid black;
}
</style>

View File

@@ -0,0 +1,54 @@
<template>
<div class="outer">
<div>
<h2>Vinlottis</h2>
<form method="post" action="/login">
<input type="text" name="username" placeholder="Brukernavn" />
<input type="password" name="password" placeholder="Passord" />
<input type="submit" value="login" />
</form>
</div>
</div>
</template>
<script>
export default {};
</script>
<style lang="scss" scoped>
div {
font-family: sans-serif;
}
.outer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
}
h2 {
width: 100vw;
text-align: center;
font-size: 3rem;
}
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100vw;
}
input {
margin: 20px;
width: 30vw;
font-size: 3rem;
border: none;
border-bottom: 1px solid black;
}
input[type="submit"] {
border: 1px solid black;
}
</style>

View File

@@ -0,0 +1,198 @@
<template>
<div>
<h1>Registrering</h1>
<div class="color-container">
<div class="label-div">
<label for="blue">Blå</label>
<input id="blue" type="number" :value="blue" />
</div>
<div class="label-div">
<label for="red">Rød</label>
<input id="red" type="number" :value.sync="red" />
</div>
<div class="label-div">
<label for="green">Grønn</label>
<input id="green" type="number" :value="green" />
</div>
<div class="label-div">
<label for="yellow">Gul</label>
<input id="yellow" type="number" :value="yellow" />
</div>
</div>
<div class="button-container">
<button @click="addWinner">Legg til en vinner</button>
<button @click="sendInfo">Send inn</button>
</div>
<div class="winner-container" v-if="winners.length > 0">
Vinnere
<div v-for="winner in winners" class="winner-element">
<hr />
<div class="label-div">
<input type="text" v-model="winner.name" placeholder="Navn" />
</div>
<div class="label-div">
<select v-model="winner.color">
<option value="blue">Blå</option>
<option value="red">Rød</option>
<option value="green">Grønn</option>
<option value="yellow">Gul</option>
</select>
</div>
<div class="label-div">
<input type="text" :value="winner.wine.name" placeholder="Vin-navn" />
</div>
<div class="label-div">
<input
type="text"
:value="winner.wine.vivinoLink"
placeholder="Vivino-link"
/>
</div>
<div class="label-div">
<input type="text" :value="winner.wine.rating" placeholder="Rating" />
</div>
<hr />
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
red: 0,
blue: 0,
green: 0,
yellow: 0,
winners: []
};
},
methods: {
addWinner: function(event) {
console.log("clicked");
this.winners.push({
name: "",
color: "",
wine: {
name: "",
vivinoLink: "",
rating: ""
}
});
},
sendInfo: async function(event) {
let sendObject = {
purchase: {
date: new Date(),
blue: this.blue,
red: this.red,
yellow: this.yellow,
green: this.green
},
winners: this.winners
};
if (sendObject.purchase.red == undefined) {
alert("Rød må defineres");
return;
}
if (sendObject.purchase.green == undefined) {
alert("Grønn må defineres");
return;
}
if (sendObject.purchase.yellow == undefined) {
alert("Gul må defineres");
return;
}
if (sendObject.purchase.blue == undefined) {
alert("Blå må defineres");
return;
}
if (sendObject.winners.length == 0) {
alert("Det må være med vinnere");
return;
}
for (let i = 0; i < sendObject.winners.length; i++) {
let currentWinner = sendObject.winners[i];
if (currentWinner.name == undefined || currentWinner.name == "") {
alert("Navn må defineres");
return;
}
if (currentWinner.color == undefined || currentWinner.color == "") {
alert("Farge må defineres");
return;
}
}
let _response = await fetch("http://localhost:30030/api/log/", {
headers: {
"Content-Type": "application/json"
// 'Content-Type': 'application/x-www-form-urlencoded',
},
method: "POST",
body: JSON.stringify(sendObject)
});
let response = await _response.json();
console.log(response);
if (response == true) {
alert("Sendt!");
window.location.reload();
} else {
alert("Noe gikk galt under innsending");
}
}
}
};
</script>
<style lang="scss" scoped>
h1 {
width: 100vw;
text-align: center;
}
div {
font-size: 2rem;
}
input {
font-size: 1.5rem;
width: 100%;
}
.label-div {
display: flex;
flex-direction: column;
width: 50%;
padding-bottom: 20px;
}
hr {
width: 50vw;
}
.winner-container {
width: 50vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: auto;
}
.winner-element,
.color-container,
.button-container {
width: 100%;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
button {
font-size: 1.5rem;
width: 40%;
margin: 10px;
}
</style>

View File

@@ -0,0 +1,55 @@
<template>
<div class="outer">
<div class="container">
<h2>Knowit Vinlottis</h2>
<div class="chart-container">
<PurchaseGraph class="purchase" />
<WinGraph class="win" />
</div>
<TotalBought />
<Highscore />
</div>
</div>
</template>
<script>
import PurchaseGraph from "@/ui/PurchaseGraph";
import TotalBought from "@/ui/TotalBought";
import Highscore from "@/ui/Highscore";
import WinGraph from "@/ui/WinGraph";
export default {
components: {
PurchaseGraph,
TotalBought,
Highscore,
WinGraph
}
};
</script>
<style lang="scss" scoped>
.outer {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
h2 {
width: 100vw;
text-align: center;
font-family: sans-serif;
}
.purchase {
width: 50vw;
display: inline-block;
}
.win {
width: 45vw;
display: inline-block;
}
</style>

View File

@@ -0,0 +1,22 @@
import VinlottisPage from "@/components/VinlottisPage";
const routes = [
{
path: "*",
component: VinlottisPage
},
{
path: "/login",
component: resolve => require(["@/components/LoginPage"], resolve)
},
{
path: "/update",
component: resolve => require(["@/components/RegisterPage"], resolve)
},
{
path: "/create",
component: resolve => require(["@/components/CreatePage"], resolve)
}
];
export { routes };

13
src/templates/Create.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Vinlottis</title>
</head>
<body>
<div id="app"></div>
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
</body>
</html>

1
src/templates/Index.html Normal file
View File

@@ -0,0 +1 @@
<div id="app"></div>

37
src/ui/Highscore.vue Normal file
View File

@@ -0,0 +1,37 @@
<template>
<div>
<h3>Highscore</h3>
<ol>
<li v-for="person in highscore">
{{ person.name }} - {{ person.wins.length }}
</li>
</ol>
</div>
</template>
<script>
export default {
data() {
return { highscore: [] };
},
async mounted() {
let _response = await fetch(
"http://localhost:30030/api/highscore/statistics"
);
let response = await _response.json();
this.highscore = response;
}
};
</script>
<style lang="scss" scoped>
div {
font-family: sans-serif;
width: 70vw;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
</style>

104
src/ui/PurchaseGraph.vue Normal file
View File

@@ -0,0 +1,104 @@
<template>
<div>
<canvas ref="purchase-chart" width="100" height="50"></canvas>
</div>
</template>
<script>
import Chartjs from "chart.js";
export default {
async mounted() {
let canvas = this.$refs["purchase-chart"].getContext("2d");
console.log(canvas);
let _response = await fetch(
"http://localhost:30030/api/purchase/statistics"
);
let response = await _response.json();
let labels = [];
let blue = {
label: "Blå",
borderColor: "#4bcffa",
backgroundColor: "#4bcffa42",
data: []
};
let yellow = {
label: "Gul",
borderColor: "#ffdd59",
backgroundColor: "#ffdd5942",
data: []
};
let red = {
label: "Rød",
borderColor: "#ef5777",
backgroundColor: "#ef577742",
data: []
};
let green = {
label: "Grønn",
borderColor: "#0be881",
backgroundColor: "#0be88142",
data: []
};
let highestNumber = 0;
for (let i = 0; i < response.length; i++) {
let thisDate = response[i];
let dateObject = new Date(thisDate.date);
labels.push(this.getPrettierDateString(dateObject));
blue.data.push(thisDate.blue);
yellow.data.push(thisDate.yellow);
red.data.push(thisDate.red);
green.data.push(thisDate.green);
if (thisDate.blue > highestNumber) {
highestNumber = thisDate.blue;
}
if (thisDate.yellow > highestNumber) {
highestNumber = thisDate.yellow;
}
if (thisDate.green > highestNumber) {
highestNumber = thisDate.green;
}
if (thisDate.red > highestNumber) {
highestNumber = thisDate.red;
}
}
let datasets = [blue, yellow, green, red];
let chartdata = {
labels: labels,
datasets: datasets
};
let chart = new Chart(canvas, {
type: "line",
data: chartdata,
options: {
title: {
display: true,
text: "Antall kjøp"
},
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
suggestedMax: highestNumber + 5
}
}
]
}
}
});
},
methods: {
getPrettierDateString(date) {
return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
}
}
};
</script>
<style lang="scss" scoped></style>

108
src/ui/TotalBought.vue Normal file
View File

@@ -0,0 +1,108 @@
<template>
<div class="bought-container">
<div class="red-container">
<div>
<span class="red">{{ red.total }}</span> kjøpt
</div>
<div>{{ red.win }} vinn</div>
<div>{{ redPercentage }}% vinn</div>
</div>
<div class="blue-container">
<div>
<span class="blue">{{ blue.total }}</span> kjøpt
</div>
<div>{{ blue.win }} vinn</div>
<div>{{ bluePercentage }}% vinn</div>
</div>
<div class="yellow-container">
<div>
<span class="yellow">{{ yellow.total }}</span> kjøpt
</div>
<div>{{ yellow.win }} vinn</div>
<div>{{ yellowPercentage }}% vinn</div>
</div>
<div class="green-container">
<div>
<span class="green">{{ green.total }}</span> kjøpt
</div>
<div>{{ green.win }} vinn</div>
<div>{{ greenPercentage }}% vinn</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
red: 0,
blue: 0,
yellow: 0,
green: 0,
total: 0,
totalWin: 0,
wins: 0,
redPercentage: 0,
yellowPercentage: 0,
greenPercentage: 0,
bluePercentage: 0
};
},
async mounted() {
let _response = await fetch(
"http://localhost:30030/api/purchase/statistics/color"
);
let response = await _response.json();
this.red = response.red;
this.blue = response.blue;
this.green = response.green;
this.yellow = response.yellow;
this.total = response.total;
this.totalWin =
this.red.win + this.yellow.win + this.blue.win + this.green.win;
this.redPercentage =
this.red.win == 0 ? 0 : (this.totalWin / this.red.win) * 100;
this.greenPercentage =
this.green.win == 0 ? 0 : (this.totalWin / this.green.win) * 100;
this.bluePercentage =
this.blue.win == 0 ? 0 : (this.totalWin / this.blue.win) * 100;
this.yellowPercentage =
this.yellow.win == 0 ? 0 : (this.totalWin / this.yellow.win) * 100;
console.log(response);
}
};
</script>
<style lang="scss" scoped>
.bought-container {
display: flex;
flex-direction: row;
width: 100vw;
justify-content: space-around;
font-family: sans-serif;
}
.green,
.blue,
.yellow,
.red {
font-size: 2rem;
font-weight: bold;
}
.green {
color: #0be881;
}
.red {
color: #ef5777;
}
.yellow {
color: #ffdd59;
}
.blue {
color: #4bcffa;
}
</style>

88
src/ui/WinGraph.vue Normal file
View File

@@ -0,0 +1,88 @@
<template>
<div>
<canvas ref="win-chart" width="100" height="50"></canvas>
</div>
</template>
<script>
export default {
async mounted() {
let canvas = this.$refs["win-chart"].getContext("2d");
console.log(canvas);
let _response = await fetch(
"http://localhost:30030/api/purchase/statistics/color"
);
let response = await _response.json();
let labels = ["Vunnet"];
let blue = {
label: "Blå",
borderColor: "#4bcffa",
backgroundColor: "#4bcffa42",
data: []
};
let yellow = {
label: "Gul",
borderColor: "#ffdd59",
backgroundColor: "#ffdd5942",
data: []
};
let red = {
label: "Rød",
borderColor: "#ef5777",
backgroundColor: "#ef577742",
data: []
};
let green = {
label: "Grønn",
borderColor: "#0be881",
backgroundColor: "#0be88142",
data: []
};
blue.data.push(response.blue.win);
yellow.data.push(response.yellow.win);
red.data.push(response.red.win);
green.data.push(response.green.win);
let highestNumber = 0;
if (response.blue.win > highestNumber) {
highestNumber = response.blue.win;
}
if (response.red.win > highestNumber) {
highestNumber = response.red.win;
}
if (response.green.win > highestNumber) {
highestNumber = response.green.win;
}
if (response.yellow.win > highestNumber) {
highestNumber = response.yellow.win;
}
let datasets = [blue, yellow, green, red];
let chartdata = {
labels: labels,
datasets: datasets
};
let chart = new Chart(canvas, {
type: "bar",
data: chartdata,
options: {
title: {
display: true,
text: "Antall vinn"
},
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
suggestedMax: highestNumber + 5
}
}
]
}
}
});
}
};
</script>

18
src/vinlottis-init.js Normal file
View File

@@ -0,0 +1,18 @@
import Vue from "vue";
import VueRouter from "vue-router";
import { routes } from "@/routes/vinlottisRouter";
import Vinlottis from "@/Vinlottis";
Vue.use(VueRouter);
const router = new VueRouter({
routes: routes
});
new Vue({
el: "#app",
router,
components: { Vinlottis },
template: "<Vinlottis/>",
render: h => h(Vinlottis)
});