Skip to content

Commit

Permalink
Change reports loading
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian committed Mar 7, 2024
1 parent e791fdf commit 97f385f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/app/quizzes-report-ap/quizzes-report-ap.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="row">
<div class="col-md-12">
<div class="float-right">
<select name="member" class="form-control mt-4" [(ngModel)]="memberId" (ngModelChange)="changeMember()" [disabled]="members.length <= 1">
<option *ngFor="let member of members" [ngValue]="member.id">{{ member.name.text }}</option>
<select name="member" class="form-control mt-4" [(ngModel)]="selectedMember" [compareWith]="compareMember" (ngModelChange)="changeMember()" [disabled]="members.length <= 1">
<option *ngFor="let member of members" [ngValue]="member">{{ member.name.text }}</option>
</select>
</div>
<h2 class="mb-0">{{ 'ap_report' | translate }}</h2>
Expand Down
31 changes: 19 additions & 12 deletions src/app/quizzes-report-ap/quizzes-report-ap.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class QuizzesReportApComponent implements OnInit {
loading = false;
eventId: number;
event: Event;
memberId: number;
selectedMember?: Member;
members: Member[] = [];
quizzes: Quiz[] = [];
people: PersonSearch[] = [];
Expand Down Expand Up @@ -80,15 +80,10 @@ export class QuizzesReportApComponent implements OnInit {
sort: '1058',
l: 'en',
});
const attemptMemberReportObservable = this.attemptMemberReportService.getAttemptMemberReport(this.eventId, this.QUIZ_ACCESS_PROGRAMME_IDS.map(String));
combineLatest([eventObservable, membersObservable, attemptMemberReportObservable, this.authService.currentUser]).subscribe(([event, members, reports, currentUser]) => {

this.event = event;
combineLatest([eventObservable, membersObservable, this.authService.currentUser]).subscribe(([event, members, currentUser]) => {

this.reports = reports;
this.reports.sort(function (a, b) {
return b.attempts_count - a.attempts_count;
});
this.event = event;

if (currentUser && currentUser.roles) {
const canViewAllMembers = UserRoleUtil.userHasRolesOfEntity(currentUser, this.QUIZZES_APP_ID, event.ws_entity.id, 'Admin', 'ViewAllAttempts');
Expand All @@ -100,7 +95,7 @@ export class QuizzesReportApComponent implements OnInit {
}

if (this.members.length > 0) {
this.memberId = this.members[0].id;
this.selectedMember = this.members[0];
}

this.loadMemberReport();
Expand All @@ -124,19 +119,31 @@ export class QuizzesReportApComponent implements OnInit {
this.loadMemberReport();
}

compareMember(a: Member, b: Member) {
return a && b ? a.id === b.id : a === b;
}

loadMemberReport() {
this.loading = true;
this.peopleService.getPeoplePublic({
const peopleObservable = this.peopleService.getPeoplePublic({
base_position: this.BASE_POSITION_ID_EXPERT,
member_id: this.memberId,
member_id: this.selectedMember.id,
show_inactive: 0,
include_history: 0,
limit: 1000,
event: this.eventId,
}).subscribe(people => {
})
const reportObservable = this.attemptMemberReportService.getAttemptMemberReport(this.eventId, this.QUIZ_ACCESS_PROGRAMME_IDS.map(String), [this.selectedMember.ws_entity.id + '']);
combineLatest([peopleObservable, reportObservable]).subscribe(([people, reports]) => {

this.loading = false;
this.people = people.people;

this.reports = reports;
this.reports.sort(function (a, b) {
return b.attempts_count - a.attempts_count;
});

// find reports for each person
for (let person of this.people) {

Expand Down
26 changes: 17 additions & 9 deletions src/app/quizzes-report/quizzes-report.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {faCheck, faTimes} from '@fortawesome/free-solid-svg-icons';
import {AppService} from "../../services/app/app.service";
import {QuizService} from '../../services/quiz/quiz.service';
import {AttemptMemberReportService} from '../../services/attempt-member-report/attempt-member-report.service';
import { NgAuthService } from '@worldskills/worldskills-angular-lib';

@Component({
selector: 'app-quizzes-report',
Expand All @@ -15,6 +16,8 @@ import {AttemptMemberReportService} from '../../services/attempt-member-report/a
})
export class QuizzesReportComponent implements OnInit {

readonly QUIZZES_APP_ID = 1300;

faCheck = faCheck;
faTimes = faTimes;
loading = false;
Expand All @@ -26,25 +29,30 @@ export class QuizzesReportComponent implements OnInit {
private appService: AppService,
private quizService: QuizService,
private attemptMemberReportService: AttemptMemberReportService,
private authService: NgAuthService,
private route: ActivatedRoute,
) { }

ngOnInit(): void {
this.eventId = this.route.snapshot.params.eventId;

const quizIds = this.route.snapshot.queryParams.quiz;

this.appService.showBreadcrumbs.next(false);

const quizIds = this.route.snapshot.queryParams.quiz;

this.loading = true;
this.attemptMemberReportService.getAttemptMemberReport(this.eventId, quizIds)
.subscribe(reports => {
this.loading = false;
this.reports = reports;
this.reports.sort(function (a, b) {
return b.attempts_count - a.attempts_count;
this.authService.currentUser.subscribe(currentUser => {
const wsEntityIds = currentUser.roles.filter(role => role.name === 'ViewMemberAttempts' && role.role_application.application_code === this.QUIZZES_APP_ID).map(role => role.ws_entity.id + '');

this.attemptMemberReportService.getAttemptMemberReport(this.eventId, quizIds, wsEntityIds)
.subscribe(reports => {
this.loading = false;
this.reports = reports;
this.reports.sort(function (a, b) {
return b.attempts_count - a.attempts_count;
});
});
});
});

let quizObservables: Observable<Quiz>[] = [];
for (let quizId of quizIds) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import {HttpClient, HttpParams} from '@angular/common/http';
import {HttpClient} from '@angular/common/http';

import {Observable} from 'rxjs';

Expand All @@ -15,8 +15,8 @@ export class AttemptMemberReportService {
private http: HttpClient,
) { }

getAttemptMemberReport(eventId: number, quizIds: string[]): Observable<AttemptMemberReport[]> {
var params = new HttpParams({fromObject: {quiz: quizIds}});
getAttemptMemberReport(eventId: number, quizIds: string[], memberEntityId: string[]): Observable<AttemptMemberReport[]> {
var params = {quiz: quizIds, member_entity: memberEntityId};
return this.http.get<AttemptMemberReport[]>(`${environment.worldskillsApiEndpoint}/quizzes/attempt_member_report/${eventId}`, {params});
}
}

0 comments on commit 97f385f

Please sign in to comment.