Replaces the strings of the communication protocol with enums

parent cf72ff0d
Pipeline #18336 failed with stages
in 6 minutes and 41 seconds
......@@ -52,8 +52,8 @@ app.use(compress());
app.param('project', (req, res, next, project) => {
if (!project || !i18nFileBaseLocation[project]) {
res.status(500).send({
status: 'STATUS:FAILED',
data: 'Invalid Project specified',
status: COMMUNICATION_PROTOCOL.STATUS.FAILED,
data: COMMUNICATION_PROTOCOL.I18N.INVALID_PROJECT_SPECIFIED,
payload: { project },
});
} else {
......@@ -252,7 +252,7 @@ app.get('/api/v1/plugin/i18nator/:project/langFile', async (req, res) => {
payload.branch = cache[req.projectCache].branch;
res.send({
status: 'STATUS:SUCCESSFUL',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
payload,
});
});
......@@ -262,16 +262,16 @@ app.post('/api/v1/plugin/i18nator/:project/updateLang', async (req, res) => {
if (!username || !token) {
res.send({
status: 'STATUS:FAILED',
step: 'AUTHENTICATE_STATIC',
status: COMMUNICATION_PROTOCOL.STATUS.FAILED,
step: COMMUNICATION_PROTOCOL.AUTHORIZATION.AUTHENTICATE_STATIC,
payload: { reason: 'UNKOWN_LOGIN' },
});
return;
}
if (!req.body.data) {
res.status(500).send({
status: 'STATUS:FAILED',
data: 'Invalid Data',
status: COMMUNICATION_PROTOCOL.STATUS.FAILED,
data: COMMUNICATION_PROTOCOL.I18N.INVALID_DATA,
payload: { body: req.body },
});
return;
......@@ -287,7 +287,7 @@ app.post('/api/v1/plugin/i18nator/:project/updateLang', async (req, res) => {
response.on('end', () => {
data = JSON.parse(data);
if (!data && data.status !== 'STATUS:SUCCESSFUL') {
if (!data && data.status !== COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
return;
}
......@@ -312,15 +312,15 @@ app.post('/api/v1/plugin/i18nator/:project/updateLang', async (req, res) => {
const exists = fs.existsSync(fileLocation);
if (!exists) {
res.status(404).send({
status: 'STATUS:FAILED',
data: 'File not found',
status: COMMUNICATION_PROTOCOL.STATUS.FAILED,
data: COMMUNICATION_PROTOCOL.I18N.FILE_NOT_FOUND,
payload: { fileLocation },
});
return;
}
fs.writeFileSync(fileLocation, JSON.stringify(fileContent));
if (index === langKeys.length - 1) {
res.send({ status: 'STATUS:SUCCESSFUL' });
res.send({ status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL });
}
});
});
......@@ -330,8 +330,8 @@ app.post('/api/v1/plugin/i18nator/:project/updateLang', async (req, res) => {
console.log('error at validating login token', error);
request.abort();
res.send({
status: 'STATUS:FAILED',
step: 'UPDATE_LANG',
status: COMMUNICATION_PROTOCOL.STATUS.FAILED,
step: COMMUNICATION_PROTOCOL.I18N.UPDATE_LANG,
payload: { error },
});
return;
......
import { Component, Inject, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { IModal } from 'arsnova-click-v2-types/src/modals/interfaces';
import { IQuestionGroup } from 'arsnova-click-v2-types/src/questions/interfaces';
import { questionGroupReflection } from 'arsnova-click-v2-types/src/questions/questionGroup_reflection';
......@@ -62,17 +63,17 @@ export class AvailableQuizzesComponent implements IModal {
});
const quizStatusData = await this.quizApiService.getQuizStatus(session.hashtag).toPromise();
if (quizStatusData.status !== 'STATUS:SUCCESSFUL') {
if (quizStatusData.status !== COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
resolve();
return;
}
if (quizStatusData.step === 'QUIZ:UNDEFINED') {
if (quizStatusData.step === COMMUNICATION_PROTOCOL.QUIZ.UNDEFINED) {
await this.quizApiService.postQuizReservationOverride({
quizName: session.hashtag,
privateKey: await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.PRIVATE_KEY).toPromise(),
}).toPromise();
} else if (quizStatusData.step === 'QUIZ:AVAILABLE') {
} else if (quizStatusData.step === COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE) {
const blob = new Blob([JSON.stringify(session.serialize())], { type: 'application/json' });
this.fileUploadService.renameFilesQueue.set('uploadFiles[]', blob, session.hashtag);
......@@ -97,7 +98,7 @@ export class AvailableQuizzesComponent implements IModal {
quiz: this.currentQuizService.quiz.serialize(),
}).toPromise();
if (openQuizRequestData.status === 'STATUS:SUCCESSFUL') {
if (openQuizRequestData.status === COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
this.router.navigate(['/quiz', 'flow']);
}
......
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
import { IMessage } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { Subscription } from 'rxjs/index';
import { MemberApiService } from '../../../service/api/member/member-api.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
......@@ -81,28 +82,28 @@ export class ConfidenceRateComponent implements OnInit {
private handleMessages(): void {
this.connectionService.socket.subscribe((data: IMessage) => {
switch (data.step) {
case 'QUIZ:NEXT_QUESTION':
case COMMUNICATION_PROTOCOL.QUIZ.NEXT_QUESTION:
this.currentQuizService.questionIndex = data.payload.questionIndex;
break;
case 'QUIZ:START':
case COMMUNICATION_PROTOCOL.QUIZ.START:
this.router.navigate(['/quiz', 'flow', 'voting']);
break;
case 'QUIZ:STOP':
case COMMUNICATION_PROTOCOL.QUIZ.STOP:
this.router.navigate(['/quiz', 'flow', 'results']);
break;
case 'MEMBER:UPDATED_RESPONSE':
case COMMUNICATION_PROTOCOL.MEMBER.UPDATED_RESPONSE:
console.log('modify response data for nickname in confidence rate view', data.payload.nickname);
this.attendeeService.modifyResponse(data.payload.nickname);
break;
case 'QUIZ:READING_CONFIRMATION_REQUESTED':
case COMMUNICATION_PROTOCOL.QUIZ.READING_CONFIRMATION_REQUESTED:
this.router.navigate(['/quiz', 'flow', 'reading-confirmation']);
break;
case 'QUIZ:RESET':
case COMMUNICATION_PROTOCOL.QUIZ.RESET:
this.attendeeService.clearResponses();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
}
......
......@@ -2,6 +2,7 @@ import { Component, OnInit, SecurityContext } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { ILeaderBoardItem, IMessage } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { Subscription } from 'rxjs';
import { parseGithubFlavoredMarkdown } from '../../../../lib/markdown/markdown';
import { LeaderboardApiService } from '../../../service/api/leaderboard/leaderboard-api.service';
......@@ -186,19 +187,19 @@ export class LeaderboardComponent implements OnInit {
private handleMessages(): void {
this.connectionService.socket.subscribe((data: IMessage) => {
switch (data.step) {
case 'QUIZ:START':
case COMMUNICATION_PROTOCOL.QUIZ.START:
this.router.navigate(['/quiz', 'flow', 'voting']);
break;
case 'MEMBER:UPDATED_RESPONSE':
case COMMUNICATION_PROTOCOL.MEMBER.UPDATED_RESPONSE:
console.log('modify response data for nickname in leaderboard view', data.payload.nickname);
this.attendeeService.modifyResponse(data.payload.nickname);
break;
case 'QUIZ:RESET':
case COMMUNICATION_PROTOCOL.QUIZ.RESET:
this.attendeeService.clearResponses();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
}
......
......@@ -117,7 +117,8 @@ describe('QuizLobbyComponent', () => {
const modalContent = '<div></div>';
const nickToRemove = 'TestNick';
spyOn(modalService, 'open').and.callFake(() => {});
component['_ownsQuiz'] = true;
spyOn(modalService, 'open').and.returnValue({ close: () => {} });
spyOn(component, 'kickMember').and.callThrough();
component.openKickMemberModal(modalContent, nickToRemove);
......
......@@ -4,6 +4,7 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { IMessage, INickname } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { questionGroupReflection } from 'arsnova-click-v2-types/src/questions/questionGroup_reflection';
import { parseGithubFlavoredMarkdown } from '../../../../lib/markdown/markdown';
import { ActiveQuestionGroupService } from '../../../service/active-question-group/active-question-group.service';
......@@ -110,7 +111,7 @@ export class QuizLobbyComponent implements OnDestroy {
this._kickMemberModalRef.close();
const quizName = this.currentQuizService.quiz.hashtag;
const data = await this.memberApiService.deleteMember(quizName, name).toPromise();
if (data.status !== 'STATUS:SUCCESSFUL') {
if (data.status !== COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
console.log(data);
}
}
......@@ -186,7 +187,7 @@ export class QuizLobbyComponent implements OnDestroy {
this.quizApiService.postQuizData(target, {
quizName: this.currentQuizService.quiz.hashtag,
}).subscribe((data: IMessage) => {
this.currentQuizService.readingConfirmationRequested = data.step === 'QUIZ:READING_CONFIRMATION_REQUESTED';
this.currentQuizService.readingConfirmationRequested = data.step === COMMUNICATION_PROTOCOL.QUIZ.READING_CONFIRMATION_REQUESTED;
this.router.navigate(['/quiz', 'flow', 'results']);
});
};
......@@ -214,8 +215,8 @@ export class QuizLobbyComponent implements OnDestroy {
private handleMessages(): void {
if (!this.attendeeService.attendees.length) {
this.connectionService.sendMessage({
status: 'STATUS:SUCCESSFUL',
step: 'LOBBY:GET_PLAYERS',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.LOBBY.GET_PLAYERS,
payload: {
quizName: this.currentQuizService.quiz.hashtag,
},
......@@ -223,18 +224,18 @@ export class QuizLobbyComponent implements OnDestroy {
}
this.connectionService.socket.subscribe(async (data: IMessage) => {
switch (data.step) {
case 'LOBBY:INACTIVE':
case COMMUNICATION_PROTOCOL.LOBBY.INACTIVE:
setTimeout(this.handleMessages.bind(this), 500);
break;
case 'LOBBY:ALL_PLAYERS':
case COMMUNICATION_PROTOCOL.LOBBY.ALL_PLAYERS:
data.payload.members.forEach((elem: INickname) => {
this.attendeeService.addMember(elem);
});
break;
case 'MEMBER:ADDED':
case COMMUNICATION_PROTOCOL.MEMBER.ADDED:
this.attendeeService.addMember(data.payload.member);
break;
case 'MEMBER:REMOVED':
case COMMUNICATION_PROTOCOL.MEMBER.REMOVED:
this.attendeeService.removeMember(data.payload.name);
break;
}
......@@ -244,13 +245,13 @@ export class QuizLobbyComponent implements OnDestroy {
private handleMessagesForOwner(data: IMessage): void {
switch (data.step) {
case 'LOBBY:ALL_PLAYERS':
case COMMUNICATION_PROTOCOL.LOBBY.ALL_PLAYERS:
this.footerBarService.footerElemStartQuiz.isActive = !!this.attendeeService.attendees.length;
break;
case 'MEMBER:ADDED':
case COMMUNICATION_PROTOCOL.MEMBER.ADDED:
this.footerBarService.footerElemStartQuiz.isActive = true;
break;
case 'MEMBER:REMOVED':
case COMMUNICATION_PROTOCOL.MEMBER.REMOVED:
if (!this.attendeeService.attendees.length) {
this.footerBarService.footerElemStartQuiz.isActive = false;
}
......@@ -260,16 +261,16 @@ export class QuizLobbyComponent implements OnDestroy {
private async handleMessagesForAttendee(data: IMessage): Promise<void> {
switch (data.step) {
case 'QUIZ:NEXT_QUESTION':
case COMMUNICATION_PROTOCOL.QUIZ.NEXT_QUESTION:
this.currentQuizService.questionIndex = data.payload.questionIndex;
break;
case 'QUIZ:START':
case COMMUNICATION_PROTOCOL.QUIZ.START:
this.router.navigate(['/quiz', 'flow', 'voting']);
break;
case 'QUIZ:READING_CONFIRMATION_REQUESTED':
case COMMUNICATION_PROTOCOL.QUIZ.READING_CONFIRMATION_REQUESTED:
this.router.navigate(['/quiz', 'flow', 'reading-confirmation']);
break;
case 'MEMBER:REMOVED':
case COMMUNICATION_PROTOCOL.MEMBER.REMOVED:
if (isPlatformBrowser(this.platformId)) {
const existingNickname = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.NICK).toPromise();
if (existingNickname === data.payload.name) {
......@@ -277,7 +278,7 @@ export class QuizLobbyComponent implements OnDestroy {
}
}
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
}
......
......@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { IMessage, INickname } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { IQuestion } from 'arsnova-click-v2-types/src/questions/interfaces';
import { AttendeeService } from '../../../../service/attendee/attendee.service';
import { ConnectionService } from '../../../../service/connection/connection.service';
......@@ -96,25 +97,25 @@ export class QuestionDetailsComponent implements OnInit {
private handleMessages(): void {
if (!this.attendeeService.attendees.length) {
this.connectionService.sendMessage({
status: 'STATUS:SUCCESSFUL',
step: 'LOBBY:GET_PLAYERS',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.LOBBY.GET_PLAYERS,
payload: { quizName: this.currentQuizService.quiz.hashtag },
});
}
this.connectionService.socket.subscribe(async (data: IMessage) => {
switch (data.step) {
case 'LOBBY:ALL_PLAYERS':
case COMMUNICATION_PROTOCOL.LOBBY.ALL_PLAYERS:
data.payload.members.forEach((elem: INickname) => {
this.attendeeService.addMember(elem);
});
break;
case 'MEMBER:UPDATED_RESPONSE':
case COMMUNICATION_PROTOCOL.MEMBER.UPDATED_RESPONSE:
this.attendeeService.modifyResponse(data.payload.nickname);
break;
case 'QUIZ:NEXT_QUESTION':
case COMMUNICATION_PROTOCOL.QUIZ.NEXT_QUESTION:
this.currentQuizService.questionIndex = data.payload.questionIndex;
break;
case 'QUIZ:RESET':
case COMMUNICATION_PROTOCOL.QUIZ.RESET:
this.attendeeService.clearResponses();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
......@@ -133,13 +134,13 @@ export class QuestionDetailsComponent implements OnInit {
private handleMessagesForAttendee(data: IMessage): void {
switch (data.step) {
case 'QUIZ:START':
case COMMUNICATION_PROTOCOL.QUIZ.START:
this.router.navigate(['/quiz', 'flow', 'voting']);
break;
case 'QUIZ:READING_CONFIRMATION_REQUESTED':
case COMMUNICATION_PROTOCOL.QUIZ.READING_CONFIRMATION_REQUESTED:
this.router.navigate(['/quiz', 'flow', 'reading-confirmation']);
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
}
......
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { IMessage, INickname } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { IQuestion } from 'arsnova-click-v2-types/src/questions/interfaces';
import { FreeTextQuestion } from 'arsnova-click-v2-types/src/questions/question_freetext';
import { RangedQuestion } from 'arsnova-click-v2-types/src/questions/question_ranged';
......@@ -194,7 +195,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
this.handleMessages();
this.quizApiService.getCurrentQuizState(this.currentQuizService.quiz.hashtag).toPromise().then(currentStateData => {
if (currentStateData.status === 'STATUS:SUCCESSFUL') {
if (currentStateData.status === COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
const question = this.currentQuizService.currentQuestion();
if (question.timer && new Date().getTime() - currentStateData.payload.startTimestamp < 0) {
......@@ -220,7 +221,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
this.quizApiService.postQuizStop({
quizName: this.currentQuizService.quiz.hashtag,
}).subscribe(data => {
if (data.status !== 'STATUS:SUCCESSFUL') {
if (data.status !== COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
console.log(data);
}
});
......@@ -268,31 +269,32 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
private handleMessages(): void {
if (!this.attendeeService.attendees.length) {
this.connectionService.sendMessage({
status: 'STATUS:SUCCESSFUL',
step: 'LOBBY:GET_PLAYERS',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.LOBBY.GET_PLAYERS,
payload: { quizName: this.currentQuizService.quiz.hashtag },
});
}
this.connectionService.socket.subscribe(async (data: IMessage) => {
switch (data.step) {
case 'LOBBY:ALL_PLAYERS':
case COMMUNICATION_PROTOCOL.LOBBY.ALL_PLAYERS:
data.payload.members.forEach((elem: INickname) => {
this.attendeeService.addMember(elem);
});
break;
case 'MEMBER:UPDATED_RESPONSE':
case COMMUNICATION_PROTOCOL.MEMBER.UPDATED_RESPONSE:
this.attendeeService.modifyResponse(data.payload.nickname);
if (this.attendeeService.attendees.filter(attendee => {
return attendee.responses[this.currentQuizService.questionIndex] ? attendee.responses[this.currentQuizService.questionIndex].value : false;
return attendee.responses[this.currentQuizService.questionIndex] ? attendee.responses[this.currentQuizService.questionIndex].value
: false;
}).length === this.attendeeService.attendees.length && this.countdown) {
this.countdown.stop();
}
break;
case 'QUIZ:NEXT_QUESTION':
case COMMUNICATION_PROTOCOL.QUIZ.NEXT_QUESTION:
this.currentQuizService.questionIndex = data.payload.questionIndex;
this._selectedQuestionIndex = data.payload.questionIndex;
break;
case 'QUIZ:RESET':
case COMMUNICATION_PROTOCOL.QUIZ.RESET:
this.attendeeService.clearResponses();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
......@@ -311,16 +313,16 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
private handleMessagesForAttendee(data: IMessage): void {
switch (data.step) {
case 'QUIZ:START':
case COMMUNICATION_PROTOCOL.QUIZ.START:
this.router.navigate(['/quiz', 'flow', 'voting']);
break;
case 'QUIZ:READING_CONFIRMATION_REQUESTED':
case COMMUNICATION_PROTOCOL.QUIZ.READING_CONFIRMATION_REQUESTED:
this.router.navigate(['/quiz', 'flow', 'reading-confirmation']);
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
case 'QUIZ:STOP':
case COMMUNICATION_PROTOCOL.QUIZ.STOP:
this.countdown.stop();
break;
}
......@@ -333,7 +335,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
const startQuizData = await this.quizApiService.postQuizData(target, {
quizName: this.currentQuizService.quiz.hashtag,
}).toPromise();
if (startQuizData.status !== 'STATUS:SUCCESSFUL') {
if (startQuizData.status !== COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
console.log(startQuizData);
return;
}
......@@ -341,7 +343,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
const question = this.currentQuizService.currentQuestion();
await this.generateAnswers(question);
if (startQuizData.step === 'QUIZ:READING_CONFIRMATION_REQUESTED') {
if (startQuizData.step === COMMUNICATION_PROTOCOL.QUIZ.READING_CONFIRMATION_REQUESTED) {
this.currentQuizService.readingConfirmationRequested = true;
return;
}
......
......@@ -2,6 +2,7 @@ import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { IMessage } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { MemberApiService } from '../../../service/api/member/member-api.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionService } from '../../../service/connection/connection.service';
......@@ -70,19 +71,19 @@ export class ReadingConfirmationComponent implements OnInit {
private handleMessages(): void {
this.connectionService.socket.subscribe((data: IMessage) => {
switch (data.step) {
case 'QUIZ:START':
case COMMUNICATION_PROTOCOL.QUIZ.START:
this.router.navigate(['/quiz', 'flow', 'voting']);
break;
case 'MEMBER:UPDATED_RESPONSE':
case COMMUNICATION_PROTOCOL.MEMBER.UPDATED_RESPONSE:
console.log('modify response data for nickname in reading confirmation view', data.payload.nickname);
this.attendeeService.modifyResponse(data.payload.nickname);
break;
case 'QUIZ:RESET':
case COMMUNICATION_PROTOCOL.QUIZ.RESET:
this.attendeeService.clearResponses();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
}
......
......@@ -2,6 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { IMessage } from 'arsnova-click-v2-types/src/common';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { MultipleChoiceQuestion } from 'arsnova-click-v2-types/src/questions/question_choice_multiple';
import { SingleChoiceQuestion } from 'arsnova-click-v2-types/src/questions/question_choice_single';
import { FreeTextQuestion } from 'arsnova-click-v2-types/src/questions/question_freetext';
......@@ -127,9 +128,8 @@ export class VotingComponent implements OnInit, OnDestroy {
)) {
return;
}
this.isSelected(index) ? this._selectedAnswers.splice(this._selectedAnswers.indexOf(index)) : this.toggleSelectedAnswers() ? this._selectedAnswers = [index]
: this._selectedAnswers.push(
index);
this.isSelected(index) ? this._selectedAnswers.splice(this._selectedAnswers.indexOf(index)) : this.toggleSelectedAnswers() ? this._selectedAnswers
= [index] : this._selectedAnswers.push(index);
if (this.toggleSelectedAnswers()) {
this.sendResponses();
}
......@@ -154,7 +154,7 @@ export class VotingComponent implements OnInit, OnDestroy {
this.questionTextService.changeMultiple(this.currentQuizService.currentQuestion().answerOptionList.map(answer => answer.answerText));
this.quizApiService.getQuizStartTime(this.currentQuizService.quiz.hashtag).subscribe((data) => {
if (data.status === 'STATUS:SUCCESSFUL' && data.payload.startTimestamp) {
if (data.status === COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL && data.payload.startTimestamp) {
if (this.currentQuizService.currentQuestion().timer) {
this.countdown = new Countdown(this.currentQuizService.currentQuestion(), data.payload.startTimestamp);
......@@ -188,7 +188,7 @@ export class VotingComponent implements OnInit, OnDestroy {
nickname: this.attendeeService.getOwnNick(),
value: this._selectedAnswers,
}).subscribe((data: IMessage) => {
if (data.status !== 'STATUS:SUCCESSFUL') {
if (data.status !== COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL) {
console.log(data);
}
});
......@@ -197,18 +197,18 @@ export class VotingComponent implements OnInit, OnDestroy {
private handleMessages(): void {
this.connectionService.socket.subscribe((data: IMessage) => {
switch (data.step) {
case 'MEMBER:UPDATED_RESPONSE':
case COMMUNICATION_PROTOCOL.MEMBER.UPDATED_RESPONSE:
this.attendeeService.modifyResponse(data.payload.nickname);
break;
case 'QUIZ:RESET':
case COMMUNICATION_PROTOCOL.QUIZ.RESET:
this.attendeeService.clearResponses();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
break;
case 'LOBBY:CLOSED':
case COMMUNICATION_PROTOCOL.LOBBY.CLOSED:
this.router.navigate(['/']);
break;
case 'QUIZ:STOP':
case COMMUNICATION_PROTOCOL.QUIZ.STOP:
this._selectedAnswers = [];
this.router.navigate(['/quiz', 'flow', 'results']);
break;
......
......@@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { JWT_OPTIONS, JwtModule } from '@auth0/angular-jwt';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { COMMUNICATION_PROTOCOL } from 'arsnova-click-v2-types/src/communication_protocol';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
import { of } from 'rxjs/index';
import { jwtOptionsFactory } from '../../../lib/jwt.factory';
......@@ -118,8 +119,8 @@ describe('QuizJoinComponent', () => {
it('should redirect the user to / on failure', async(inject([Router, QuizApiService], (router: Router, quizApiService: QuizApiService) => {
const quizStatusData = {
status: 'STATUS:FAILED',
step: 'QUIZ:UNAVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.FAILED,
step: COMMUNICATION_PROTOCOL.QUIZ.UNAVAILABLE,
payload: {
authorizeViaCas: true,
provideNickSelection: false,
......@@ -142,16 +143,16 @@ describe('QuizJoinComponent', () => {
lobbyApiService: LobbyApiService,
) => {
const quizStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
authorizeViaCas: true,
provideNickSelection: false,
},
};
const lobbyStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
quiz: {
originalObject: currentQuizService.quiz.serialize(),
......@@ -174,16 +175,16 @@ describe('QuizJoinComponent', () => {
const customQuiz = currentQuizService.quiz;
customQuiz.sessionConfig.nicks.memberGroups = ['Group1', 'Group2'];
const quizStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
authorizeViaCas: true,
provideNickSelection: false,
},
};
const lobbyStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
quiz: {
originalObject: customQuiz.serialize(),
......@@ -203,16 +204,16 @@ describe('QuizJoinComponent', () => {
inject([CurrentQuizService, Router, QuizApiService, LobbyApiService],
(currentQuizService: CurrentQuizService, router: Router, quizApiService: QuizApiService, lobbyApiService: LobbyApiService) => {
const quizStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
authorizeViaCas: true,
provideNickSelection: false,
},
};
const lobbyStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
quiz: {
originalObject: currentQuizService.quiz.serialize(),
......@@ -236,16 +237,16 @@ describe('QuizJoinComponent', () => {
customQuiz.sessionConfig.nicks.addSelectedNick('Predefined1');
customQuiz.sessionConfig.nicks.addSelectedNick('Predefined2');
const quizStatusData = {
status: 'STATUS:SUCCESSFUL',
step: 'QUIZ:AVAILABLE',
status: COMMUNICATION_PROTOCOL.STATUS.SUCCESSFUL,
step: COMMUNICATION_PROTOCOL.QUIZ.AVAILABLE,
payload: {
authorizeViaCas: true,