diff --git a/src/client.ts b/src/client.ts index f89910d..296cf63 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,7 +1,7 @@ // @deno-types="https://esm.sh/@types/mithril@2.2.4" import m from "https://esm.sh/mithril@2.2.2" import {verifyAuth} from "./auth.ts"; -import {Scores, Team} from "./shared.ts"; +import {Scores, Ballot} from "./shared.ts"; const scores: Scores = { @@ -10,7 +10,7 @@ const scores: Scores = { convinced: 75 }; -const teams: Team[] = [ +const ballots: Ballot[] = [ {id: 8787, name: "Les chacals de laval", scores: {...scores}}, {id: 18167, name: "Les rapides de blainville", scores: {...scores}}, {id: 17165, name: "Les pas-beaux du plateau", scores: {...scores}}, @@ -54,30 +54,30 @@ class ProgressBar implements m.ClassComponent{ } type VoteViewAttr = { - teamId: number, + ballotId: number, onchange?: () => void, }; -class VoteView implements m.ClassComponent { +class BallotView implements m.ClassComponent { - voteFor(team: Team, title: string, key: string, onchange: () => void){ + voteFor(ballot: Ballot, title: string, key: string, onchange: () => void){ return m("div.columns", m("div.column", title, ":"), m("div.column.is-two-thirds", - m(new ProgressBar(), {scores: team.scores, key: key, onchange: onchange}))); + m(new ProgressBar(), {scores: ballot.scores, key: key, onchange: onchange}))); } view(vnode: m.CVnode){ - const teamId = vnode.attrs.teamId; + const ballotId = vnode.attrs.ballotId; const onchange = vnode.attrs.onchange ?? function(){}; - const team = teams.find(team => team.id.toString() === teamId.toString()); - if(!team){ + const ballot = ballots.find(ballot => ballot.id.toString() === ballotId.toString()); + if(!ballot){ return []; } return [ - this.voteFor(team, "Qualité du README", 'readme', onchange), - this.voteFor(team, "Qualité des diagrammes", 'diagrams', onchange), - this.voteFor(team, "Êtes-vous convaincu?", 'convinced', onchange)] + this.voteFor(ballot, "Qualité du README", 'readme', onchange), + this.voteFor(ballot, "Qualité des diagrammes", 'diagrams', onchange), + this.voteFor(ballot, "Êtes-vous convaincu?", 'convinced', onchange)] } } @@ -91,18 +91,18 @@ class Submit{ } type MainVoteViewAttr = { - teamId: number, + ballotId: number, } class MainVoteView implements m.ClassComponent{ - async persistTeams(): Promise{ + async persistBallots(): Promise{ const params: RequestInit = { method: 'POST', headers: { "Content-Type": "application/json", }, - body: JSON.stringify(teams) + body: JSON.stringify(ballots) }; const resp = await fetch("/api/v1/vote/kkk", params); console.log(resp.status) @@ -113,31 +113,31 @@ class MainVoteView implements m.ClassComponent{ return m("div.columns.is-centered", m("div.column.is-two-thirds", m("h1.title.is-1", m(m.route.Link, {href: "/"}, `Votons - ${name}`)), - m(new VoteView(), {teamId: vnode.attrs.teamId, onchange: this.persistTeams}), + m(new BallotView(), {ballotId: vnode.attrs.ballotId, onchange: this.persistBallots}), m(new Submit()))); } } class MainView{ - createTeamRow(team: Team){ + createBallotRow(ballot: Ballot){ return m('tr', [ - m('td', m(m.route.Link, {href: `${m.route.get()}vote/${team.id}/`}, team.name)), - m('td', team.scores.readme), - m('td', team.scores.diagrams), - m('td', team.scores.convinced), + m('td', m(m.route.Link, {href: `${m.route.get()}vote/${ballot.id}/`}, ballot.name)), + m('td', ballot.scores.readme), + m('td', ballot.scores.diagrams), + m('td', ballot.scores.convinced), ]) } - votesTable(teams: Team[]){ + votesTable(ballots: Ballot[]){ return m('table.table.is-striped.is-fullwidth', m('thead', m('tr', ['Équipe', 'Readme', 'Diagrammes', 'Idée'].map(title => m('th', title)))), - m('tbody', teams.map(team => this.createTeamRow(team)))) + m('tbody', ballots.map(ballot => this.createBallotRow(ballot)))) } view(){ return m("div.columns.is-centered", m("div.column.is-two-thirds", - this.votesTable(teams))) + this.votesTable(ballots))) } } @@ -165,5 +165,5 @@ class PasscodeView{ m.route(window.document.body, "/", { "/": PasscodeView, "/voter-home/": MainView, - "/voter-home/vote/:teamId/": MainVoteView + "/voter-home/vote/:ballotId/": MainVoteView }) \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index d4c5e3d..345a1c5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,7 +1,7 @@ import { Application, Router } from "https://deno.land/x/oak/mod.ts"; import {createBundle} from "./bundler.ts"; import {Context} from "https://deno.land/x/oak@v12.2.0/context.ts"; -import {Team} from "./shared.ts"; +import {Ballot} from "./shared.ts"; const router = new Router(); @@ -40,7 +40,7 @@ function getUserIndex(userId: string, ballotId: string, questionId: string){ questionId] } -async function persistTeams(userId: any, ballots: Team[]): Promise { +async function persistBallots(userId: any, ballots: Ballot[]): Promise { const kv = await Deno.openKv(); for(const ballot of ballots){ for(const question of Object.keys(ballot.scores)){ @@ -58,8 +58,8 @@ router.post("/api/v1/vote/:userid", async (ctx: Context)=> { ctx.throw(415); } const body = await ctx.request.body().value; - const teams = body as Team[]; - await persistTeams(userId, teams); + const ballots = body as Ballot[]; + await persistBallots(userId, ballots); console.log(body); ctx.response.body = userId; diff --git a/src/shared.ts b/src/shared.ts index 63f9d9d..0c52fe4 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -4,7 +4,7 @@ export type Scores = { convinced: number, }; -export type Team = { +export type Ballot = { id: number, name: string, scores: Scores,