Skip to content
Snippets Groups Projects
Commit 544b6a95 authored by paf's avatar paf
Browse files

Fix Bug: Featured Unit only appears after first update

parent 94fce97a
No related branches found
No related tags found
No related merge requests found
......@@ -15,17 +15,14 @@
</td>
<td *ngIf="displayOptions.groupColumn === 'show'"><div class="vertical-align-middle">{{testSession.groupLabel}}</div></td>
<td>
<p *ngIf="featuredUnit$ | async as fU; else: shit">{{fU.unit.label}}</p><ng-template #shit>NOOO</ng-template>
<td *ngIf="displayOptions.groupColumn === 'show'">
<div class="vertical-align-middle">{{testSession.groupLabel}}</div>
</td>
<ng-container *ngIf="(booklet$ | async) as booklet">
<ng-container *ngIf="isBooklet(booklet); else: noBooklet">
<td class="booklet">
<td class="booklet" >
<ng-container *ngIf="(booklet$ | async) as booklet">
<ng-container *ngIf="isBooklet(booklet); else: noBooklet">
<div class="vertical-align-middle">
......@@ -49,58 +46,56 @@
>done_all
</mat-icon>
</div>
</td>
<td *ngIf="booklet.units as testlet">
<div
class="units-container"
[class]="hasState(testSession.testState, 'status', 'locked') ? 'locked' : ''"
[ngSwitch]="displayOptions.view"
>
<div class="units full" *ngSwitchCase="'full'" >
<ng-container *ngTemplateOutlet="testletFull; context: {$implicit: testlet}">
</ng-container>
</div>
<div class="units medium" *ngSwitchCase="'medium'" >
<ng-container *ngTemplateOutlet="bookletMedium; context: {$implicit: testlet}">
</ng-container>
</div>
<div class="units small" *ngSwitchCase="'small'" >
<ng-container *ngTemplateOutlet="bookletSmall; context: {$implicit: testlet}">
</ng-container>
</div>
</ng-container>
</ng-container>
<ng-template #noBooklet>
<div class="vertical-align-middle">
<h1 class="warning">{{testSession.bookletName}}</h1>
</div>
</ng-template>
</td>
<td class="activity">
<ng-container *ngIf="(booklet$ | async) as booklet">
<ng-container *ngIf="isBooklet(booklet); else: noBookletReason">
<div *ngIf="booklet.units as testlet"
class="units-container"
[class]="hasState(testSession.testState, 'status', 'locked') ? 'locked' : ''"
[ngSwitch]="displayOptions.view"
>
<div class="units full" *ngSwitchCase="'full'" >
<ng-container *ngTemplateOutlet="testletFull; context: {$implicit: testlet}"></ng-container>
</div>
<div class="units medium" *ngSwitchCase="'medium'" >
<ng-container *ngTemplateOutlet="bookletMedium; context: {$implicit: testlet}"></ng-container>
</div>
<div class="units small" *ngSwitchCase="'small'" >
<ng-container *ngTemplateOutlet="bookletSmall; context: {$implicit: testlet}"></ng-container>
</div>
</div>
</ng-container>
<ng-container *ngIf="displayOptions.view === 'full'">
<ng-container *ngTemplateOutlet="featuredUnit"></ng-container>
</ng-container>
<ng-template #noBookletReason>
<span *ngIf="booklet.error == 'missing-id'">Kein Testheft zugeordnet</span>
<span *ngIf="booklet.error == 'missing-file'" class="warning">Kein Zugriff auf Testheft-Datei!</span>
<span *ngIf="booklet.error == 'xml'" class="warning">Konnte Testheft-Datei lesen!</span>
<span *ngIf="booklet.error == 'general'" class="warning">Fehler beim Zugriff aus Testheft-Datei!</span>
</ng-template>
</ng-container>
</td>
<ng-container *ngIf="displayOptions.view === 'full'">
<ng-container *ngTemplateOutlet="featuredUnit"></ng-container>
</ng-container>
</td>
<ng-template #noBooklet>
<td colspan="2" class="booklet">
<span *ngIf="booklet.error == 'missing-id'">Kein Testheft zugeordnet</span>
<span *ngIf="booklet.error == 'missing-file'" class="warning">
Kein Zugriff auf Testheft-Datei (`{{testSession.bookletName}}`)!
</span>
<span *ngIf="booklet.error == 'xml'" class="warning">
Konnte Testheft-Datei (`{{testSession.bookletName}}`) lesen!
</span>
<span *ngIf="booklet.error == 'general'" class="warning">>
Fehler beim Zugriff aus Testheft-Datei (`{{testSession.bookletName}}`)!
</span>
</td>
</ng-template>
</ng-container>
<ng-template #featuredUnit>
XXX
<div class="featured-unit" *ngIf="(featuredUnit$| async) as unitContext; else: XXX">
<div class="featured-unit" *ngIf="featuredUnit$ | async as unitContext">
<h1>{{unitContext.parent.label || 'Aktueller Abschnitt'}}</h1>
......@@ -130,18 +125,15 @@
</div>
</ng-template>
<ng-template #XXX>
!!!
</ng-template>
<ng-template #testletFull let-testlet>
<span *ngIf="testlet.restrictions && testlet.restrictions.codeToEnter as codeToEnter"
class="unit restriction"
matTooltip="Freigabewort: {{codeToEnter.code.toUpperCase()}}"
matTooltip="Freigabewort: {{codeToEnter | json}}"
matTooltipPosition="above"
>
<!-- TODO fix this .code.toUpperCase() -->
<mat-icon>sms</mat-icon>
</span>
......
......@@ -32,76 +32,45 @@ export class TestViewComponent implements OnInit, OnChanges {
@Input() testSession: TestSession;
@Input() displayOptions: TestViewDisplayOptions;
private testStatus$: Subject<TestSession>;
public booklet$: Observable<Booklet|BookletError>;
public featuredUnit$: Observable<UnitContext|null>;
public testSession$: Subject<TestSession> = new Subject<TestSession>();
public booklet$: Observable<Booklet|BookletError>;// = new Subject<Booklet|BookletError>();
public featuredUnit$: Observable<UnitContext|null>
public maxTimeLeft: object|null;
public maxTimeLeft: object|null; // TODO make observable maybe
constructor(
private bookletsService: BookletService,
) {
this.testStatus$ = new Subject<TestSession>();
}
ngOnInit() {
console.log('NEW:' + this.testSession.personId, this.testSession.bookletName);
console.log('NEW test-view component:' + this.testSession.personId, this.testSession.bookletName);
this.booklet$ = this.bookletsService.getBooklet(this.testSession.bookletName || "");
this.featuredUnit$ = combineLatest<[Booklet|BookletError, TestSession]>([this.booklet$, this.testStatus$])
.pipe(map((bookletAndSession: [Booklet|BookletError, TestSession]) => {
this.featuredUnit$ = combineLatest<[Booklet|BookletError, TestSession]>([this.booklet$, this.testSession$])
.pipe(map((bookletAndSession: [Booklet|BookletError, TestSession]): UnitContext|null => {
const booklet: Booklet|BookletError = bookletAndSession[0];
const bId = (this.isBooklet(booklet) ? booklet.metadata.id : booklet.error);
console.log("B-" + bId, bookletAndSession[1]);
if (!this.isBooklet(booklet)) {
console.log("X-" + bId + ' --> NULL');
return null;
}
if (this.testSession.unitName) {
console.log("X-" + bId + ' --> sessn');
return this.getUnitContext(booklet.units, this.testSession.unitName);
}
}));
//
// setTimeout(() => {
// this.featuredUnit$.next({
// unit: {
// id: 'FAKEFAKEFAKE',
// label: "FAKAKAAKA",
// labelShort: "FUCKA"
// },
// indexAncestor: 0, indexGlobal: 0, indexLocal: 0, unitCount: 0, unitCountAncestor: 0, unitCountGlobal: 0
//
// });
// }, 500);
this.featuredUnit$.subscribe((uc: UnitContext) => {
console.log ("C-", uc);
});
const fakeSession: TestSession = {
personId: this.testSession.personId,
timestamp: this.testSession.timestamp,
unitState: this.testSession.unitState,
testId: this.testSession.testId,
testState: this.testSession.testState,
personLabel: "FAKE"
}
// use setTimeout to put this event at the end of js task queue, so testSession$-initialization happens
// after (!) subscription from async-pipe
setTimeout(() => {
this.testStatus$.next(fakeSession);
this.testSession$.next(this.testSession);
});
}
ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
console.log("XXXX");
this.testStatus$.next(this.testSession);
this.testSession$.next(this.testSession);
this.maxTimeLeft = this.parseJsonState(this.testSession.testState, 'MAXTIMELEFT');
}
......
......@@ -73,7 +73,7 @@ export abstract class WebsocketBackendService<T> extends WebsocketService implem
} else {
this.connectionStatus$.next("polling-sleep");
// this.scheduleNextPoll();
this.scheduleNextPoll();
}
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment