Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit da7332b

Browse files
committed
fixes initials, sends register to voting
1 parent ac56e3f commit da7332b

File tree

5 files changed

+126
-145
lines changed

5 files changed

+126
-145
lines changed

src/api/voting.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
import routes from "./routes";
2-
import request from "./request";
1+
import routes from './routes';
2+
import request from './request';
3+
4+
function lastInitial(item) {
5+
if (item.lastName) {
6+
return item.lastName[0];
7+
}
8+
9+
const split = item.username.split(' ');
10+
return split.length >= 2 ? split[1] : '';
11+
}
12+
13+
function firstInitial(item) {
14+
if (item.firstName) {
15+
return item.firstName[0];
16+
}
17+
if (item.display) {
18+
return item.display[0];
19+
}
20+
21+
return item.username.split(' ')[0];
22+
}
23+
24+
function initials(item) {
25+
return `${firstInitial(item)}${lastInitial(item)}`;
26+
}
327

428
async function getBallot(page, per) {
5-
return request(routes.voting_ballot, {
29+
const result = await request(routes.voting_ballot, {
630
params: { page, per }
731
});
32+
33+
if (result.items) {
34+
result.items = result.items.map(item => {
35+
return { ...item, ...{ initials: initials(item) } };
36+
});
37+
}
38+
return result;
839
}
940

1041
async function cast(answerId, email) {

src/plugins/router.js

Lines changed: 77 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Vue from "vue";
2-
import VueRouter from "vue-router";
3-
import { auth } from "@/api";
4-
import store from "@/store";
1+
import Vue from 'vue';
2+
import VueRouter from 'vue-router';
3+
import { auth } from '@/api';
4+
import store from '@/store';
55

66
Vue.use(VueRouter);
77

@@ -18,220 +18,197 @@ function isChallengeClosed() {
1818
}
1919

2020
async function logout() {
21-
await store.dispatch("Quiz/reset");
21+
await store.dispatch('Quiz/reset');
2222
await auth.logout();
2323
}
2424

2525
const routes = [
2626
{
2727
// basically a dynamic home page
28-
path: "/",
29-
name: "redirect",
28+
path: '/',
29+
name: 'redirect',
3030
beforeEnter(to, from, next) {
3131
if (isChallengeOpen() || isChallengePending()) {
32-
next({ name: "quiz" });
32+
next({ name: 'quiz' });
3333
return;
3434
}
3535

3636
if (isChallengeClosed()) {
37-
next({ name: "voting" });
37+
next({ name: 'voting' });
3838
return;
3939
}
4040
}
4141
},
4242
{
4343
// public routes
44-
path: "/",
45-
component: () => import("@/views/Public/App"),
44+
path: '/',
45+
component: () => import('@/views/Public/App'),
4646
children: [
4747
{
48-
path: "frequently-asked-questions",
49-
name: "faq",
50-
component: () => import("@/views/Public/FAQ")
48+
path: 'frequently-asked-questions',
49+
name: 'faq',
50+
component: () => import('@/views/Public/FAQ')
5151
}
5252
]
5353
},
5454
// FOR EXTERNAL IFRAME
5555
{
56-
path: "/iframe/leaderboard",
57-
name: "iframe-leaderboard",
58-
component: () => import("@/views/IFrame/Leaderboard")
56+
path: '/iframe/leaderboard',
57+
name: 'iframe-leaderboard',
58+
component: () => import('@/views/IFrame/Leaderboard')
5959
},
6060
{
6161
// account routes
62-
path: "/",
63-
component: () => import("@/views/Public/App"),
62+
path: '/',
63+
component: () => import('@/views/Public/App'),
6464
children: [
6565
{
66-
path: "login",
67-
name: "login",
68-
component: () => import("@/views/Accounts/Login"),
66+
path: 'login',
67+
name: 'login',
68+
component: () => import('@/views/Accounts/Login'),
6969
meta: { anon: true }
7070
},
7171
{
72-
path: "forgot-password",
73-
name: "forgot-password",
74-
component: () => import("@/views/Accounts/ForgotPassword")
72+
path: 'forgot-password',
73+
name: 'forgot-password',
74+
component: () => import('@/views/Accounts/ForgotPassword')
7575
},
7676
{
77-
path: "reset-password/:token",
78-
name: "reset-password",
79-
component: () => import("@/views/Accounts/ResetPassword")
77+
path: 'reset-password/:token',
78+
name: 'reset-password',
79+
component: () => import('@/views/Accounts/ResetPassword')
8080
},
8181
{
82-
path: "create-account",
83-
name: "register",
84-
component: () => import("@/views/Accounts/Register"),
85-
meta: { anon: true }
82+
path: 'create-account',
83+
name: 'register',
84+
component: () => import('@/views/Accounts/Register'),
85+
meta: { anon: true, challengeOpenOrPending: true }
8686
},
8787
{
88-
path: "logout",
89-
name: "logout",
90-
beforeEnter: (to, from, next) =>
91-
logout().then(() => next({ name: "login" })),
88+
path: 'logout',
89+
name: 'logout',
90+
beforeEnter: (to, from, next) => logout().then(() => next({ name: 'login' })),
9291
meta: { auth: true }
9392
},
9493
{
95-
path: "admin",
96-
name: "admin",
97-
component: () => import("@/views/Accounts/Admin"),
94+
path: 'admin',
95+
name: 'admin',
96+
component: () => import('@/views/Accounts/Admin'),
9897
meta: { auth: true }
9998
}
10099
]
101100
},
102101
{
103102
// voting routes
104-
path: "/",
105-
component: () => import("@/views/Voting/App"),
103+
path: '/',
104+
component: () => import('@/views/Voting/App'),
106105
meta: { challengeOver: true },
107106
children: [
108107
{
109-
path: "voting",
110-
name: "voting",
111-
component: () => import("@/views/Voting/Ballot")
108+
path: 'voting',
109+
name: 'voting',
110+
component: () => import('@/views/Voting/Ballot')
112111
},
113112
{
114-
path: "vote-confirmation",
115-
name: "voting-confirmation",
116-
component: () => import("@/views/Voting/Confirm")
113+
path: 'vote-confirmation',
114+
name: 'voting-confirmation',
115+
component: () => import('@/views/Voting/Confirm')
117116
}
118117
]
119118
},
120119
{
121120
// quiz routes
122-
path: "/",
123-
component: () => import("@/views/Public/App"),
121+
path: '/',
122+
component: () => import('@/views/Public/App'),
124123
meta: { secured: true, challengeOpenOrPending: true },
125124
children: [
126125
{
127-
path: "quiz",
128-
name: "quiz",
126+
path: 'quiz',
127+
name: 'quiz',
129128
component: async () => {
130129
// CHALLENGE HAS NOT STARTED
131130
if (!isChallengeOpen()) {
132-
return import("@/views/Quiz/QuizCountdown");
131+
return import('@/views/Quiz/QuizCountdown');
133132
}
134133

135134
// USER HAS FINISHED QUIZ
136135
if (store.state.Quiz.maxRank === store.state.User.rank - 1) {
137-
return import("@/views/Quiz/QuizFinished");
136+
return import('@/views/Quiz/QuizFinished');
138137
}
139138

140139
// MUST WAIT FOR NEXT QUESTION
141140
if (store.state.Quiz.awaitNextQuestion) {
142-
return import("@/views/Quiz/QuizCountdown");
141+
return import('@/views/Quiz/QuizCountdown');
143142
}
144143

145144
// SHOW THE LAST QUESTION
146145
if (store.state.Quiz.isLastQuestion) {
147-
return import("@/views/Quiz/QuizFinalQuestion");
146+
return import('@/views/Quiz/QuizFinalQuestion');
148147
}
149148

150149
// NORMAL QUIZ MODE
151-
return import("@/views/Quiz/Quiz");
150+
return import('@/views/Quiz/Quiz');
152151
},
153152
beforeEnter(from, to, next) {
154153
// USER MUST SEE INTRO VIDEO
155-
if (
156-
isChallengeOpen() &&
157-
!store.state.Quiz.hasSeenIntro &&
158-
store.state.User.rank == 1
159-
) {
160-
next({ name: "quiz-intro" });
154+
if (isChallengeOpen() && !store.state.Quiz.hasSeenIntro && store.state.User.rank == 1) {
155+
next({ name: 'quiz-intro' });
161156
return;
162157
}
163158
next();
164159
}
165160
},
166161
{
167-
path: "/quiz/intro",
168-
name: "quiz-intro",
169-
component: () => import("@/views/Quiz/QuizIntro")
162+
path: '/quiz/intro',
163+
name: 'quiz-intro',
164+
component: () => import('@/views/Quiz/QuizIntro')
170165
}
171166
]
172167
},
173168
{
174-
path: "*",
175-
name: "wildcard",
176-
redirect: { name: "redirect" }
169+
path: '*',
170+
name: 'wildcard',
171+
redirect: { name: 'redirect' }
177172
}
178173
];
179174

180175
const router = new VueRouter({
181-
mode: "history",
176+
mode: 'history',
182177
routes
183178
});
184179

185180
router.beforeEach(async (to, from, next) => {
186181
const requireAuth = to.matched.some(record => record.meta.secured);
187182
const requireAnon = to.matched.some(record => record.meta.anon);
188-
const requireChallengePending = to.matched.some(
189-
record => record.meta.challengePending
190-
);
191-
const requireChallengeOpen = to.matched.some(
192-
record => record.meta.challengeOpen
193-
);
194-
const requireChallengeClosed = to.matched.some(
195-
record => record.meta.challengeOver
196-
);
197-
const requireChallengeOpenPending = to.matched.some(
198-
record => record.meta.challengeOpenOrPending
199-
);
200-
201-
if (
202-
requireChallengePending ||
203-
requireChallengeOpen ||
204-
requireChallengeClosed ||
205-
requireChallengeOpenPending
206-
) {
183+
const requireChallengePending = to.matched.some(record => record.meta.challengePending);
184+
const requireChallengeOpen = to.matched.some(record => record.meta.challengeOpen);
185+
const requireChallengeClosed = to.matched.some(record => record.meta.challengeOver);
186+
const requireChallengeOpenPending = to.matched.some(record => record.meta.challengeOpenOrPending);
187+
if (requireChallengePending || requireChallengeOpen || requireChallengeClosed || requireChallengeOpenPending) {
207188
try {
208-
await store.dispatch("Quiz/refresh");
189+
await store.dispatch('Quiz/refresh');
209190

210191
const challengeIsClosed = isChallengeClosed();
211192
const challengeIsPending = isChallengePending();
212193
const challengeIsOpen = isChallengeOpen();
213194

214195
if (!challengeIsClosed && requireChallengeClosed) {
215-
next({ name: "redirect" });
196+
next({ name: 'redirect' });
216197
return;
217198
}
218199

219200
if (!challengeIsOpen && requireChallengeOpen) {
220-
next({ name: "redirect" });
201+
next({ name: 'redirect' });
221202
return;
222203
}
223204

224205
if (!challengeIsPending && requireChallengePending) {
225-
next({ name: "redirect" });
206+
next({ name: 'redirect' });
226207
return;
227208
}
228209

229-
if (
230-
!challengeIsOpen &&
231-
!challengeIsPending &&
232-
requireChallengeOpenPending
233-
) {
234-
next({ name: "redirect" });
210+
if (!challengeIsOpen && !challengeIsPending && requireChallengeOpenPending) {
211+
next({ name: 'redirect' });
235212
return;
236213
}
237214
} catch (err) {
@@ -243,12 +220,12 @@ router.beforeEach(async (to, from, next) => {
243220
const isAuthenticated = !!auth.currentUser().auth;
244221

245222
if (!isAuthenticated && requireAuth) {
246-
next({ name: "register" });
223+
next({ name: 'register' });
247224
return;
248225
}
249226

250227
if (isAuthenticated && requireAnon) {
251-
next({ name: "redirect" });
228+
next({ name: 'redirect' });
252229
return;
253230
}
254231
}

0 commit comments

Comments
 (0)