diff --git a/src/app/components/shared/statistics/statistics.component.ts b/src/app/components/shared/statistics/statistics.component.ts index e11b46cb9319c134d93e49be571f1087d2fc80a3..af34902cd0c7fe8c9b88e66034195f270e9468ed 100644 --- a/src/app/components/shared/statistics/statistics.component.ts +++ b/src/app/components/shared/statistics/statistics.component.ts @@ -1,59 +1,69 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { RoomService } from '../../../services/http/room.service'; import { Content } from '../../../models/content'; import { ContentService } from '../../../services/http/content.service'; -import { ContentAnswerService } from '../../../services/http/content-answer.service'; -import { AnswerText } from '../../../models/answer-text'; -import { AnswerChoice } from '../../../models/answer-choice'; -import { ContentType } from '../../../models/content-type.enum'; +import { ContentGroup } from '../../../models/content-group'; /* TODO: Use TranslateService */ +export interface ContentPercents { + content: string; + percent: string; +} @Component({ selector: 'app-statistics', templateUrl: './statistics.component.html', styleUrls: ['./statistics.component.scss'] }) + export class StatisticsComponent implements OnInit { - @Input() content: Content[]; - @Input() textAnswers: AnswerText[] = []; - @Input() choiceAnswers: AnswerChoice[] = []; - statistics: any = null; - selectedContent: any = { name: 'HOW TO MAKE CONTENT GREAT AGAIN', index: '1', length: '1' }; - evaluation: any = [ - { name: 'Skill', percent: 10, correct: false, answers: 1, }, - { name: 'Knowledge', percent: 10, correct: false, answers: 1, }, - { name: '???', percent: 30, correct: true, answers: 3, }, - { name: 'Not at all', percent: 50, correct: true, answers: 5, } - ]; - states = [ - { value: '1', viewValue: 'Text answers' }, - { value: '2', viewValue: 'Choice answers' } - ]; - selected: number = null; + + contents: Content[] = []; + contentGroups: ContentGroup[] = []; + contentGroup: ContentGroup; + percents: number[] = [73, 87, 69, 92, 77]; + displayedColumns: string[] = ['content', 'percentage']; + dataSource: ContentPercents[] = []; constructor( private route: ActivatedRoute, private roomService: RoomService, - private contentService: ContentService, - private contentAnswerService: ContentAnswerService ) { } + private contentService: ContentService) { + } ngOnInit(): void { this.route.params.subscribe(params => { - this.getContent(params['roomId']); + this.roomService.getRoomByShortId(params['roomId']).subscribe(room => { + this.contentGroups = room.contentGroups; + }); }); + this.getContents(); + const contentLength = this.contents.length; + for (let i = 0; i < contentLength - 1; i++) { + this.dataSource[i].content = this.contents[i].subject; + this.dataSource[i].percent = this.percents[i].toFixed(0); + } } - getContent(roomId: string): void { - this.contentService.getContents(roomId).subscribe(content => { - this.content = content; - this.getAnswers(); + getContents(): void { + this.contentService.getContentsByIds(this.contentGroup.contentIds).subscribe( contents => { + console.log(contents.length); + const contentLength: number = contents.length; + for (let j = 0; j < contentLength - 1; j++) { + console.log(contents[j].subject); + console.log(j); + this.contents[j].subject = contents[j].subject; + this.contents[j].id = contents[j].id; + } }); } +} + /* + getAnswers(): void { - for (const c of this.content) { + for (const c of this.contents) { this.contentAnswerService.getAnswers(c.id).subscribe( answer => { [].push.apply(this.textAnswers, answer); }); @@ -65,7 +75,7 @@ export class StatisticsComponent implements OnInit { showStatistic(value) { // refactor answer class structure for less code and more abstraction this.statistics = []; - for (const c of this.content) { + for (const c of this.contents) { if (value === '1') { if (c.format === ContentType.TEXT) { const count = this.countTextAnswers(c.id); @@ -96,4 +106,4 @@ export class StatisticsComponent implements OnInit { showEvaluation(index: number) { // coming with api connection, logic doesnt make sense without knowledge about api } -} +*/