From 07647c02a7569d366cc6139c8ce0991d9c5d6e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=A4sler?= <tom.kaesler@mni.thm.de> Date: Wed, 15 Aug 2018 13:41:03 +0200 Subject: [PATCH] rename content id to id fix add content in service --- .../content-choice-creator.component.html | 4 ++-- .../content-choice-participant.component.ts | 2 +- .../content-list/content-list.component.ts | 12 +++++------ .../content-text-participant.component.ts | 2 +- .../statistics/statistics.component.ts | 20 +++++++++---------- .../content-carousel-page.component.ts | 2 +- src/app/models/content-choice.ts | 4 ++-- src/app/models/content-text.ts | 4 ++-- src/app/models/content.ts | 6 +++--- src/app/services/http/content.service.ts | 5 ++--- 10 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html index 77e4e73c0..39efb1df0 100644 --- a/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html +++ b/src/app/components/fragments/content-choice-creator/content-choice-creator.component.html @@ -69,7 +69,7 @@ </button> </div> - <div *ngIf="!editDialogMode"> + <div *ngIf="!editDialogMode" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="50px"> <button mat-raised-button type="submit" color="primary">Submit</button> <button mat-raised-button (click)="reset($event)" color="primary">Reset</button> <button mat-raised-button *ngIf="lastDeletedDisplayAnswer" (click)="recoverDeletedAnswer($event)" color="primary"> @@ -77,7 +77,7 @@ deletion </button> </div> - <div *ngIf="editDialogMode"> + <div *ngIf="editDialogMode" fxLayout="row" fxLayoutAlign="center" fxLayoutGap="50px"> <button mat-raised-button (click)="editDialogClose($event,'edit')" color="primary">Update</button> <button mat-raised-button (click)="editDialogClose($event,'abort')" color="primary">Abort</button> <button mat-raised-button (click)="openDeletionContentDialog($event)" color="warn">Delete</button> diff --git a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts index e7c988b7d..344593533 100644 --- a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts +++ b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts @@ -93,7 +93,7 @@ export class ContentChoiceParticipantComponent implements OnInit { this.answerService.addAnswerChoice({ id: '', revision: '', - contentId: this.content.contentId, + contentId: this.content.id, round: 1, selectedChoiceIndexes: [] } as AnswerChoice).subscribe(); diff --git a/src/app/components/fragments/content-list/content-list.component.ts b/src/app/components/fragments/content-list/content-list.component.ts index 7f623f975..38cff1335 100644 --- a/src/app/components/fragments/content-list/content-list.component.ts +++ b/src/app/components/fragments/content-list/content-list.component.ts @@ -35,13 +35,13 @@ export class ContentListComponent implements OnInit { ngOnInit() { this.roomId = localStorage.getItem(`roomId`); - this.getContents(this.roomId); + this.getContent(this.roomId); } - getContents(roomId: string): void { + getContent(roomId: string): void { this.contentService.getContents(roomId) - .subscribe(contents => { - this.contents = contents; + .subscribe(content => { + this.contents = content; }); } @@ -69,7 +69,7 @@ export class ContentListComponent implements OnInit { } this.contentBackup = new ContentChoice( - content.contentId, + content.id, content.revision, content.roomId, content.subject, @@ -85,7 +85,7 @@ export class ContentListComponent implements OnInit { createTextContentBackup(content: ContentText) { this.contentBackup = new ContentText( - content.contentId, + content.id, content.revision, content.roomId, content.subject, diff --git a/src/app/components/fragments/content-text-participant/content-text-participant.component.ts b/src/app/components/fragments/content-text-participant/content-text-participant.component.ts index c2130674d..a81d230fa 100644 --- a/src/app/components/fragments/content-text-participant/content-text-participant.component.ts +++ b/src/app/components/fragments/content-text-participant/content-text-participant.component.ts @@ -44,7 +44,7 @@ export class ContentTextParticipantComponent implements OnInit { this.answerService.addAnswerText({ id: '0', revision: '0', - contentId: this.content.contentId, + contentId: this.content.id, round: this.content.round, subject: this.content.subject, body: this.textAnswer, diff --git a/src/app/components/fragments/statistics/statistics.component.ts b/src/app/components/fragments/statistics/statistics.component.ts index 8880c11d8..1a69bf7e3 100644 --- a/src/app/components/fragments/statistics/statistics.component.ts +++ b/src/app/components/fragments/statistics/statistics.component.ts @@ -52,11 +52,11 @@ export class StatisticsComponent implements OnInit { } getAnswers(): void { - for (const question of this.content) { - this.contentAnswerService.getAnswers(question.contentId).subscribe( answer => { + for (const c of this.content) { + this.contentAnswerService.getAnswers(c.id).subscribe( answer => { [].push.apply(this.textAnswers, answer); }); - this.contentAnswerService.getAnswers(question.contentId).subscribe( answer => { + this.contentAnswerService.getAnswers(c.id).subscribe( answer => { [].push.apply(this.choiceAnswers, answer); }); } @@ -64,19 +64,19 @@ export class StatisticsComponent implements OnInit { showStatistic(value) { // refactor answer class structure for less code and more abstraction this.statistics = []; - for (const question of this.content) { + for (const c of this.content) { if (value === '1') { - if (question.format === ContentType.TEXT) { - const count = this.countTextAnswers(question.contentId); + if (c.format === ContentType.TEXT) { + const count = this.countTextAnswers(c.id); this.statistics.push({ - name: question.subject, answers: count, percent: count * 100 / this.textAnswers.length, + name: c.subject, answers: count, percent: count * 100 / this.textAnswers.length, }); } } else { - if (question.format === ContentType.CHOICE) { - const count = this.countChoiceAnswers(question.contentId); + if (c.format === ContentType.CHOICE) { + const count = this.countChoiceAnswers(c.id); this.statistics.push({ - name: question.subject, answers: count, percent: count * 100 / this.choiceAnswers.length, + name: c.subject, answers: count, percent: count * 100 / this.choiceAnswers.length, }); } } diff --git a/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts b/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts index 7f356336e..88ad6abf4 100644 --- a/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts +++ b/src/app/components/pages/content-carousel-page/content-carousel-page.component.ts @@ -24,7 +24,7 @@ export class ContentCarouselPageComponent implements OnInit { ngOnInit() { this.route.params.subscribe(params => { // ToDo: Check api call - /* this.contentService.getContents(params['roomId']).subscribe(result => { + /* this.contentService.getContent(params['roomId']).subscribe(result => { this.contents = result; }); */ }); diff --git a/src/app/models/content-choice.ts b/src/app/models/content-choice.ts index a97525656..44c4e60ce 100644 --- a/src/app/models/content-choice.ts +++ b/src/app/models/content-choice.ts @@ -7,7 +7,7 @@ export class ContentChoice extends Content { correctOptionIndexes: number[]; multiple: boolean; - constructor(contentId: string, + constructor(id: string, revision: string, roomId: string, subject: string, @@ -18,7 +18,7 @@ export class ContentChoice extends Content { correctOptionIndexes: number[], multiple: boolean, format: ContentType) { - super(contentId, + super(id, revision, roomId, subject, diff --git a/src/app/models/content-text.ts b/src/app/models/content-text.ts index 4a0a5db86..7f095006f 100644 --- a/src/app/models/content-text.ts +++ b/src/app/models/content-text.ts @@ -3,14 +3,14 @@ import { ContentType } from './content-type.enum'; export class ContentText extends Content { - constructor(contentId: string, + constructor(id: string, revision: string, roomId: string, subject: string, body: string, round: number, groups: string[]) { - super(contentId, + super(id, revision, roomId, subject, diff --git a/src/app/models/content.ts b/src/app/models/content.ts index 812413580..6debe09fa 100644 --- a/src/app/models/content.ts +++ b/src/app/models/content.ts @@ -1,7 +1,7 @@ import { ContentType } from './content-type.enum'; export class Content { - contentId: string; + id: string; revision: string; roomId: string; subject: string; @@ -11,7 +11,7 @@ export class Content { format: ContentType; formatAttributes: Map<string, string>; - constructor(contentId: string, + constructor(id: string, revision: string, roomId: string, subject: string, @@ -20,7 +20,7 @@ export class Content { groups: string[], format: ContentType, formatAttributes: Map<string, string>) { - this.contentId = contentId; + this.id = id; this.revision = revision; this.roomId = roomId; this.subject = subject; diff --git a/src/app/services/http/content.service.ts b/src/app/services/http/content.service.ts index fbb8a0c59..ac6c6d158 100644 --- a/src/app/services/http/content.service.ts +++ b/src/app/services/http/content.service.ts @@ -35,8 +35,7 @@ export class ContentService extends BaseHttpService { addContent(content: Content): Observable<Content> { const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/'; return this.http.post<Content>(connectionUrl, - { roomId: content.roomId, subject: content.subject, body: content.body, - format: content.format, group: 'preparation' }, + content, httpOptions).pipe( catchError(this.handleError<Content>('addContent')) ); @@ -53,7 +52,7 @@ export class ContentService extends BaseHttpService { } updateContent(updatedContent: Content): Observable<Content> { - const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/' + updatedContent.contentId; + const connectionUrl = this.apiUrl.base + this.apiUrl.content + '/' + updatedContent.id; return this.http.put(connectionUrl, updatedContent, httpOptions).pipe( tap(_ => ''), catchError(this.handleError<any>('updateContent')) -- GitLab