Skip to content
Snippets Groups Projects
Commit c75b3e38 authored by Heinrich Marks's avatar Heinrich Marks :hibiscus:
Browse files

Adjust logic to show respective answer list items only now

parent c35ac8bb
No related merge requests found
...@@ -16,8 +16,9 @@ export class ContentAnswerService extends ErrorHandlingService { ...@@ -16,8 +16,9 @@ export class ContentAnswerService extends ErrorHandlingService {
super(); super();
} }
getAnswerTexts(): Observable<AnswerText[]> { getAnswerTexts(contentId: string): Observable<AnswerText[]> {
return this.http.get<AnswerText[]>(this.answerUrl).pipe( const url = `${this.answerUrl}/?contentId=${contentId}`;
return this.http.get<AnswerText[]>(url).pipe(
catchError(this.handleError('getAnswerTexts', [])) catchError(this.handleError('getAnswerTexts', []))
); );
} }
......
<mat-list> <mat-list>
<h3 mat-subheader>Answers</h3> <h3 mat-subheader>Answers</h3>
<mat-list-item *ngFor="let textAnswer of filteredTextAnswers"> <mat-list-item *ngFor="let textAnswer of textAnswers">
<button mat-button routerLink="{{textAnswer.id}}"> <button mat-button routerLink="{{textAnswer.id}}">
<!-- *ngIf="textAnswer.subject === content($id)"> -->
{{textAnswer.body}} {{textAnswer.body}}
</button> </button>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
\ No newline at end of file
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ContentAnswerService } from '../content-answer.service'; import { ContentAnswerService } from '../content-answer.service';
import { AnswerText } from '../answer-text'; import { AnswerText } from '../answer-text';
import { ContentDetailComponent } from '../content-detail/content-detail.component';
import { Content } from '../content';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { forEach } from '@angular/router/src/utils/collection'; import { ContentService } from '../content.service';
@Component({ @Component({
selector: 'app-content-answers-list', selector: 'app-content-answers-list',
...@@ -13,29 +11,29 @@ import { forEach } from '@angular/router/src/utils/collection'; ...@@ -13,29 +11,29 @@ import { forEach } from '@angular/router/src/utils/collection';
}) })
export class ContentAnswersListComponent implements OnInit { export class ContentAnswersListComponent implements OnInit {
textAnswers: AnswerText[]; textAnswers: AnswerText[];
content: Content[];
filteredTextAnswers: AnswerText[];
constructor(private contentAnswerService: ContentAnswerService, constructor(
private contentDetailComponent: ContentDetailComponent, private contentService: ContentService,
private route: ActivatedRoute) {} private contentAnswerService: ContentAnswerService,
private route: ActivatedRoute
) { }
ngOnInit() { ngOnInit() {
this.getAnswerTexts();
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.contentDetailComponent.getContent(params['id']); // todo: filtered answers befüllen this.getContent(params['id']);
}); });
for (let i = 0; i < this.textAnswers.length; i++) {
console.log('kre');
for (let j = 0; i < this.content.length; j++) {
if (this.textAnswers[i].contentId === this.content[j].id) { this.filteredTextAnswers.push(this.textAnswers[i]); }
}
}
} }
getAnswerTexts(): void { getContent(id: string): void {
this.contentAnswerService.getAnswerTexts().subscribe(textAnswers => { this.contentService.getContent(id).subscribe(params => {
this.textAnswers = textAnswers; this.getAnswerTexts(params['id']);
}); })
}
getAnswerTexts(id: string): void {
this.contentAnswerService.getAnswerTexts(id)
.subscribe(textAnswers => {
this.textAnswers = textAnswers;
});
} }
} }
...@@ -107,7 +107,7 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -107,7 +107,7 @@ export class InMemoryDataService implements InMemoryDbService {
{ {
id: '1', id: '1',
revision: '1', revision: '1',
contendId: '1', contentId: '1',
round: '1', round: '1',
subject: 'Textaufgabe 1', subject: 'Textaufgabe 1',
body: 'gamma, delta', body: 'gamma, delta',
...@@ -117,7 +117,7 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -117,7 +117,7 @@ export class InMemoryDataService implements InMemoryDbService {
{ {
id: '1', id: '1',
revision: '1', revision: '1',
contendId: '1', contentId: '1',
round: '1', round: '1',
subject: 'Textaufgabe 1', subject: 'Textaufgabe 1',
body: 'epsilon, phi', body: 'epsilon, phi',
...@@ -127,7 +127,7 @@ export class InMemoryDataService implements InMemoryDbService { ...@@ -127,7 +127,7 @@ export class InMemoryDataService implements InMemoryDbService {
{ {
id: '2', id: '2',
revision: '2', revision: '2',
contendId: '2', contentId: '2',
round: '3', round: '3',
subject: 'Textaufgabe 2', subject: 'Textaufgabe 2',
body: 'Der Turm ist 20m hoch', body: 'Der Turm ist 20m hoch',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment