-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
273 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { InputValue } from "./content.model"; | ||
|
||
export type ResultValue = Result | Progress | Record<string, InputValue> | undefined; | ||
|
||
export interface Result { | ||
[key: string]: ResultValue; | ||
data?: Record<string, InputValue>; | ||
progress: Progress; | ||
} | ||
|
||
export interface Progress { | ||
count: number; | ||
total: number; | ||
percent: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<app-loading [loading]="loading"> | ||
@for (unit of summary; track $index) { | ||
<div class="header"> | ||
<h2> | ||
{{resource('unit')}} {{$index + 1}} | ||
</h2> | ||
<span class="sub">{{title($index)}}</span> | ||
<app-progress-spinner [size]="40" [value]="unit.progress.percent"> | ||
<small>{{unit.progress.percent}}%</small> | ||
</app-progress-spinner> | ||
</div> | ||
<mat-accordion multi> | ||
<ng-container *ngFor="let page of pages($index) | async"> | ||
@if (data(unit[page.slug])) { | ||
<mat-expansion-panel expanded> | ||
<mat-expansion-panel-header> | ||
<mat-panel-title class="header"> | ||
<span>{{page.title}}</span> | ||
<small>{{percent(unit[page.slug])}}%</small> | ||
</mat-panel-title> | ||
</mat-expansion-panel-header> | ||
<div class="content"> | ||
@for (item of data(unit[page.slug]) | keyvalue: doneAtLast; track $index) { | ||
@if (item.key === doneKey) { | ||
<mat-divider /><br/> | ||
<label [title]="item.value + 's'"> | ||
<mat-icon fontIcon="task_alt"/> Erledigt | ||
</label> | ||
} @else { | ||
<label> | ||
{{caption(page, item.key)}} | ||
</label> | ||
<div class="value"> | ||
{{format(item.value) || 'Keine Angabe'}} | ||
</div> | ||
} | ||
} | ||
</div> | ||
</mat-expansion-panel> | ||
} | ||
</ng-container> | ||
</mat-accordion> | ||
<mat-divider class="spacer" /> | ||
} | ||
|
||
<app-settings /> | ||
</app-loading> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 1rem; | ||
|
||
h2 { | ||
font-size: large; | ||
letter-spacing: .1rem; | ||
} | ||
|
||
.sub { | ||
font-size: large; | ||
font-weight: normal; | ||
} | ||
|
||
small { | ||
font-size: 8pt; | ||
} | ||
} | ||
|
||
.content { | ||
padding: 1rem; | ||
line-height: 1.5; | ||
|
||
label { | ||
display: flex; | ||
align-items: center; | ||
gap: .4rem; | ||
color: var(--primary); | ||
font-weight: 500; | ||
} | ||
|
||
.value { | ||
padding: 1rem; | ||
font-weight: 100; | ||
} | ||
} | ||
|
||
.spacer { | ||
margin-bottom: 4rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { SummaryComponent } from './summary.component'; | ||
|
||
describe('SummaryComponent', () => { | ||
let component: SummaryComponent; | ||
let fixture: ComponentFixture<SummaryComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [SummaryComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(SummaryComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { CommonModule, KeyValue } from '@angular/common'; | ||
import { MatAccordion, MatExpansionModule } from '@angular/material/expansion'; | ||
import { MatDividerModule } from '@angular/material/divider'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { SettingsComponent } from '../settings/settings.component'; | ||
import { LoadingComponent } from '../../components/ui/loading/loading.component'; | ||
import { ProgressSpinnerComponent } from '../../components/ui/progress-spinner/progress-spinner.component'; | ||
import { GuideService } from '../../services/guide.service'; | ||
import { Guide } from '../../models/guide.model'; | ||
import { Result, ResultValue } from '../../models/result.model'; | ||
import { InputDefinition, InputValue } from '../../models/content.model'; | ||
import { Page } from '../../models/page.model'; | ||
import { CommonService } from '../../services/common.service'; | ||
import { UserResultService } from '../../services/user-result.service'; | ||
import { pageReadTime } from '../../services/user-data.service'; | ||
|
||
@Component({ | ||
selector: 'app-summary', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
MatAccordion, | ||
MatExpansionModule, | ||
MatDividerModule, | ||
MatIconModule, | ||
LoadingComponent, | ||
ProgressSpinnerComponent, | ||
SettingsComponent | ||
], | ||
templateUrl: './summary.component.html', | ||
styleUrl: './summary.component.scss', | ||
}) | ||
export class SummaryComponent { | ||
private readonly _commonService = inject(CommonService); | ||
private readonly _guideService = inject(GuideService); | ||
private readonly _resultService = inject(UserResultService); | ||
|
||
private _resources: Record<string, unknown> = {}; | ||
private _units!: Guide[]; | ||
private _results!: Result[]; | ||
readonly doneKey = pageReadTime; | ||
loading = true; | ||
|
||
async ngOnInit() { | ||
this._units = await this._guideService.dataPromise; | ||
this._results = await this._resultService.resultTree; | ||
this._resources = await this._commonService.getResources('start'); | ||
|
||
this.loading = false; | ||
} | ||
|
||
get summary() { | ||
return this._results; | ||
} | ||
|
||
resource(key: string) { | ||
return this._resources[key]; | ||
} | ||
|
||
title(index: number) { | ||
return this._units[index].title; | ||
} | ||
|
||
pages(index: number) { | ||
return this._units[index].pages; | ||
} | ||
|
||
data(result: ResultValue) { | ||
const data = (<Result>result).data; | ||
if (data && data[this.doneKey]) { | ||
return Object.keys(data).reduce((acc, key) => { | ||
acc[key] = data[key]; | ||
return acc; | ||
}, {} as Record<string, InputValue>); | ||
} | ||
return null; | ||
} | ||
|
||
percent(result: ResultValue) { | ||
return (<Result>result).progress.percent; | ||
} | ||
|
||
caption(page: Page, id: string) { | ||
return page.content | ||
.filter(item => item.type === 'stepper') | ||
.flatMap(item => item.value as InputDefinition[]) | ||
.find(item => item.value.id === id)?.value?.caption || id; | ||
} | ||
|
||
format(value: InputValue) { | ||
return Array.isArray(value) | ||
? value.join(', ') | ||
: value; | ||
} | ||
|
||
doneAtLast(a: KeyValue<string, InputValue>) { | ||
return a.key.startsWith('__') ? 1 : -1; | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...pp/services/user-progress.service.spec.ts → src/app/services/user-result.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.