refactor: handle api models identifiers
parent
baccbf8d56
commit
09ff7433ed
|
@ -64,11 +64,6 @@ export default class Quiz extends Vue {
|
||||||
})
|
})
|
||||||
public color !: string;
|
public color !: string;
|
||||||
|
|
||||||
// private responses = new Map<string, {
|
|
||||||
// score?: number;
|
|
||||||
// comment?: string | null
|
|
||||||
// }>();
|
|
||||||
|
|
||||||
get cssVars() {
|
get cssVars() {
|
||||||
return {
|
return {
|
||||||
'--color': this.color
|
'--color': this.color
|
||||||
|
@ -76,21 +71,21 @@ export default class Quiz extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
onRate(score: number, question: Question) {
|
onRate(score: number, question: Question) {
|
||||||
quizStore.updateScoreResponse({axeId: this.axeNumber, questionId: question._links.self.href, score});
|
quizStore.updateScoreResponse({axeId: this.axeNumber, questionId: question.id, score});
|
||||||
this.emitRatingState();
|
this.emitRatingState();
|
||||||
}
|
}
|
||||||
|
|
||||||
onComment(comment: string, question: Question) {
|
onComment(comment: string, question: Question) {
|
||||||
quizStore.updateCommentResponse({axeId: this.axeNumber, questionId: question._links.self.href, comment});
|
quizStore.updateCommentResponse({axeId: this.axeNumber, questionId: question.id, comment});
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentScore(question: Question): number | undefined {
|
getCurrentScore(question: Question): number | undefined {
|
||||||
const rate = quizStore.responses.get(question._links.self.href) as QuizRate;
|
const rate = quizStore.responses.get(question.id) as QuizRate;
|
||||||
return rate ? rate.score : undefined;
|
return rate ? rate.score : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentComment(question: Question): string | undefined {
|
getCurrentComment(question: Question): string | undefined {
|
||||||
const rate = quizStore.responses.get(question._links.self.href) as QuizRate;
|
const rate = quizStore.responses.get(question.id) as QuizRate;
|
||||||
return rate ? rate.comment : undefined;
|
return rate ? rate.comment : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
<section v-if="currentResult" class="last-quiz">
|
<section v-if="currentResult" class="last-quiz">
|
||||||
<div class="last-quiz-header">
|
<div class="last-quiz-header">
|
||||||
<span class="date"> {{ currentResult.createdDate | formatDate }}</span>
|
<span class="date"> {{ currentResult.createdDate | formatDate }}</span>
|
||||||
<!-- FIXME remove this dirty trick -->
|
|
||||||
<nuxt-link
|
<nuxt-link
|
||||||
class="link"
|
class="link" :to="{ path: '/details', query: { quiz: currentResult.id }}">
|
||||||
:to="{ path: '/details', query: { quiz: currentResult._links.self.href.replace('http://localhost:8080/quizzes/','') }}">
|
|
||||||
+ Voir le détail
|
+ Voir le détail
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
|
@ -55,10 +53,7 @@ export default class History extends Vue {
|
||||||
this.quizzes = response.data._embedded.quizzes;
|
this.quizzes = response.data._embedded.quizzes;
|
||||||
});
|
});
|
||||||
for (const quiz of this.quizzes) {
|
for (const quiz of this.quizzes) {
|
||||||
// FIXME ugly : replace when scores will be handled as a REST resource
|
await this.quizRepository.findScores(quiz.id)
|
||||||
console.info(quiz);
|
|
||||||
const id = Number.parseInt(quiz._links.self.href.replace("http://localhost:8080/quizzes/", ""));
|
|
||||||
await this.quizRepository.findScores(id)
|
|
||||||
.then((value: AxiosResponse<Score[]>) => {
|
.then((value: AxiosResponse<Score[]>) => {
|
||||||
quiz.scores = value.data;
|
quiz.scores = value.data;
|
||||||
});
|
});
|
||||||
|
|
|
@ -87,7 +87,6 @@ export default class Result extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
getResponses(axe: Axe) {
|
getResponses(axe: Axe) {
|
||||||
console.info(this.responses)
|
|
||||||
return this.responses.filter((response: ResponseWithQuestion) => response.axeIdentifier === axe.identifier);
|
return this.responses.filter((response: ResponseWithQuestion) => response.axeIdentifier === axe.identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,8 @@ export default class Login extends Vue {
|
||||||
responsesFormatted.push({
|
responsesFormatted.push({
|
||||||
score: value.score ? value.score : 0,
|
score: value.score ? value.score : 0,
|
||||||
comment: value.comment,
|
comment: value.comment,
|
||||||
questionId: Number.parseInt(key.replace("http://localhost:8080/questions/", "")) // FIXME use correct url when score will be a REST ressource
|
questionId: key
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {RestLinks} from "~/repositories/models/rest-response.model";
|
import {RestLinks} from "~/repositories/models/rest-response.model";
|
||||||
|
|
||||||
export interface Question extends RestLinks {
|
export interface Question extends RestLinks {
|
||||||
|
id: number;
|
||||||
label: string;
|
label: string;
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ export interface Quiz extends RestLinks {
|
||||||
|
|
||||||
export interface Response {
|
export interface Response {
|
||||||
axeId: number;
|
axeId: number;
|
||||||
questionId: string;
|
questionId: number;
|
||||||
score?: number;
|
score?: number;
|
||||||
comment?: string;
|
comment?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import {AxiosResponse} from "axios";
|
||||||
|
import {$axios} from "~/utils/api";
|
||||||
import {RestResponse} from "~/repositories/models/rest-response.model";
|
import {RestResponse} from "~/repositories/models/rest-response.model";
|
||||||
import {Question} from "~/repositories/models/question.model";
|
import {Question} from "~/repositories/models/question.model";
|
||||||
import {$axios} from "~/utils/api";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
findAllByAxeId(axeId: number) {
|
findAllByAxeId(axeId: number) {
|
||||||
|
@ -8,6 +9,12 @@ export default {
|
||||||
params: {
|
params: {
|
||||||
id: axeId
|
id: axeId
|
||||||
}
|
}
|
||||||
|
}).then((response: AxiosResponse<RestResponse<Question>>) => {
|
||||||
|
response.data._embedded.questions.map(question => {
|
||||||
|
question.id = Number(question._links.self.href.replace($axios.defaults.baseURL + "/questions/", ""));
|
||||||
|
return question;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import {AxiosResponse} from "axios";
|
||||||
|
import {$axios} from "~/utils/api";
|
||||||
import {RestResponse} from "~/repositories/models/rest-response.model";
|
import {RestResponse} from "~/repositories/models/rest-response.model";
|
||||||
import {Quiz, Response, ResponseWithQuestion, Score} from "~/repositories/models/quiz.model";
|
import {Quiz, Response, ResponseWithQuestion, Score} from "~/repositories/models/quiz.model";
|
||||||
import {$axios} from "~/utils/api";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
|
@ -9,6 +10,13 @@ export default {
|
||||||
params: {
|
params: {
|
||||||
sort: "createdDate,desc"
|
sort: "createdDate,desc"
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.then((response: AxiosResponse<RestResponse<Quiz>>) => {
|
||||||
|
response.data._embedded.quizzes.map(quiz => {
|
||||||
|
quiz.id = Number(quiz._links.self.href.replace($axios.defaults.baseURL + "/quizzes/", ""));
|
||||||
|
return quiz;
|
||||||
|
});
|
||||||
|
return response;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,15 @@ import {QuizRate, Response} from "~/repositories/models/quiz.model";
|
||||||
})
|
})
|
||||||
export default class Quiz extends VuexModule {
|
export default class Quiz extends VuexModule {
|
||||||
|
|
||||||
responses = new Map<string, QuizRate>;
|
responses = new Map<number, QuizRate>;
|
||||||
questionsRatedPerAxe = new Map<number, { questionId: string; rated: boolean }[]>;
|
questionsRatedPerAxe = new Map<number, { questionId: number; rated: boolean }[]>;
|
||||||
|
|
||||||
@Mutation
|
@Mutation
|
||||||
initialize(questions: Map<number, Question[]>) {
|
initialize(questions: Map<number, Question[]>) {
|
||||||
questions.forEach((questions, axeId) => this.questionsRatedPerAxe.set(axeId, questions.map(value => {
|
questions.forEach((questions, axeId) => this.questionsRatedPerAxe.set(axeId, questions.map(value => {
|
||||||
return {
|
return {
|
||||||
questionId: value._links.self.href,
|
questionId: value.id,
|
||||||
rated: this.responses.has(value._links.self.href)
|
rated: this.responses.has(value.id)
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue