feat: add progress tracking for return process questions and update UI to display progress

This commit is contained in:
Lorenz Hilpert
2025-03-24 16:13:20 +01:00
parent 9001850c1f
commit 453403cfde
3 changed files with 59 additions and 2 deletions

View File

@@ -53,6 +53,53 @@ export class ReturnProcessService {
return result;
}
/**
* Returns the progress of the return process questions
* Returns a tuple with the current question index and the total number of questions
* @param product Which questions to ask
* @param answers Answers to previous questions
*/
returnProcessQuestionsProgress(
product: Product,
answers: Record<string, unknown>,
): { answered: number; total: number } | undefined {
const questions = this.returnProcessQuestions(product);
if (!questions) {
return;
}
function computeLongestPath(data: ReturnProcessQuestionInfo, startKey: string) {
const findDepth = (key: string | undefined): number => {
if (!key) return 0;
const question = data.questions.find((q) => q.key === key);
if (!question) return 0;
if (question.type === ReturnProcessQuestionType.Select && question.options) {
if (answers[question.key]) {
const chosen = question.options.find((o) => o.value === answers[question.key]);
return 1 + findDepth(chosen?.nextQuestion);
}
return 1 + Math.max(...question.options.map((o) => findDepth(o.nextQuestion)));
} else if (question.type === ReturnProcessQuestionType.Product && question.nextQuestionId) {
return 1 + (answers[question.key] ? findDepth(question.nextQuestionId) : 0);
}
return 1;
};
return findDepth(startKey);
}
const activeQuestions = this.activeReturnProcessQuestions(product, answers);
const answered = activeQuestions.reduce((acc, q) => {
if (q.key in answers) {
return acc + 1;
}
return acc;
}, 0);
const totalCount = computeLongestPath(questions, questions.startsWithQuestion);
return { answered, total: totalCount };
}
eligibleForReturn(): Observable<boolean> {
throw new Error('Method not implemented.');
}

View File

@@ -1,7 +1,9 @@
@if (returnProcess(); as process) {
<div class="return-process-item-header">
<h3 class="isa-text-subtitle-2-bold">Rückgabe informationen</h3>
<ui-progress-bar mode="indeterminate"></ui-progress-bar>
@if (progress(); as progress) {
<ui-progress-bar [value]="progress.answered" [maxValue]="progress.total"></ui-progress-bar>
}
</div>
<div class="return-process-item-body">
<img

View File

@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core';
import { ProductImageDirective } from '@isa/shared/product-image';
import { ReturnProcessStore } from '@isa/oms/data-access';
import { ReturnProcessService, ReturnProcessStore } from '@isa/oms/data-access';
import { NgIconComponent, provideIcons } from '@ng-icons/core';
import { ProductFormatIconGroup } from '@isa/icons';
import { LowerCasePipe } from '@angular/common';
@@ -23,6 +23,7 @@ import { ProgressBarComponent } from '@isa/ui/progress-bar';
providers: [provideIcons(ProductFormatIconGroup)],
})
export class ReturnProcessItemComponent {
#returnProcessService = inject(ReturnProcessService);
returnProcessStore = inject(ReturnProcessStore);
returnProcessId = input.required<number>();
@@ -30,4 +31,11 @@ export class ReturnProcessItemComponent {
returnProcess = computed(() => {
return this.returnProcessStore.entityMap()[this.returnProcessId()];
});
progress = computed(() => {
return this.#returnProcessService.returnProcessQuestionsProgress(
this.returnProcess().product,
this.returnProcess().answers,
);
});
}