-
-
Notifications
You must be signed in to change notification settings - Fork 5
SF-3657 Move project progress calculation to back end #3626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,16 +5,16 @@ import { MatProgressSpinner } from '@angular/material/progress-spinner'; | |
| import { MatTooltip } from '@angular/material/tooltip'; | ||
| import { TranslocoModule } from '@ngneat/transloco'; | ||
| import { Canon } from '@sillsdev/scripture'; | ||
| import { filter, firstValueFrom } from 'rxjs'; | ||
| import { L10nPercentPipe } from 'xforge-common/l10n-percent.pipe'; | ||
| import { ProgressService } from '../progress-service/progress.service'; | ||
| import { estimatedActualBookProgress, ProgressService, ProjectProgress } from '../progress-service/progress.service'; | ||
| import { Book } from './book-multi-select'; | ||
|
|
||
| export interface BookOption { | ||
| bookNum: number; | ||
| bookId: string; | ||
| selected: boolean; | ||
| progressPercentage: number; | ||
| /** The progress of the book as a percentage between 0 and 100, or null if not available. */ | ||
| progressPercentage: number | null; | ||
| } | ||
|
|
||
| type Scope = 'OT' | 'NT' | 'DC'; | ||
|
|
@@ -37,6 +37,8 @@ export class BookMultiSelectComponent implements OnChanges { | |
| @Input() availableBooks: Book[] = []; | ||
| @Input() selectedBooks: Book[] = []; | ||
| @Input() readonly: boolean = false; | ||
| /** The ID of the project to get the progress. */ | ||
| @Input() projectId?: string; | ||
| @Input() projectName?: string; | ||
| @Input() basicMode: boolean = false; | ||
| @Output() bookSelect = new EventEmitter<number[]>(); | ||
|
|
@@ -66,15 +68,26 @@ export class BookMultiSelectComponent implements OnChanges { | |
| } | ||
|
|
||
| async initBookOptions(): Promise<void> { | ||
| await firstValueFrom(this.progressService.isLoaded$.pipe(filter(loaded => loaded))); | ||
| // Only load progress if not in basic mode | ||
| let progress: ProjectProgress | undefined; | ||
| if (this.basicMode !== true) { | ||
|
||
| if (this.projectId == null) { | ||
| throw new Error('app-book-multi-select requires a projectId input to initialize when not in basic mode'); | ||
| } | ||
| progress = await this.progressService.getProgress(this.projectId, { maxStalenessMs: 30_000 }); | ||
| } | ||
| this.loaded = true; | ||
| const progress = this.progressService.texts; | ||
|
|
||
| const progressPercentageByBookNum = (progress?.books ?? []).map(b => ({ | ||
| bookNum: Canon.bookIdToNumber(b.bookId), | ||
| percentage: estimatedActualBookProgress(b) * 100 | ||
| })); | ||
|
|
||
| this.bookOptions = this.availableBooks.map((book: Book) => ({ | ||
| bookNum: book.number, | ||
| bookId: Canon.bookNumberToId(book.number), | ||
| selected: this.selectedBooks.find(b => book.number === b.number) !== undefined, | ||
| progressPercentage: progress.find(p => p.text.bookNum === book.number)?.percentage ?? 0 | ||
| progressPercentage: progressPercentageByBookNum.find(p => p.bookNum === book.number)?.percentage ?? null | ||
| })); | ||
|
|
||
| this.booksOT = this.selectedBooks.filter(n => Canon.isBookOT(n.number)); | ||
|
|
@@ -136,8 +149,8 @@ export class BookMultiSelectComponent implements OnChanges { | |
| return this.availableBooks.findIndex(n => Canon.isBookDC(n.number)) > -1; | ||
| } | ||
|
|
||
| getPercentage(book: BookOption): number { | ||
| // avoid showing 100% when it's not quite there | ||
| return (book.progressPercentage > 99 && book.progressPercentage < 100 ? 99 : book.progressPercentage) / 100; | ||
| /** Takes a number between 0 and 100, and rounds it by flooring any number between 99 and 100 to 99 */ | ||
| normalizePercentage(percentage: number): number { | ||
| return (percentage > 99 && percentage < 100 ? 99 : percentage) / 100; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO comment references issue #3622, but the non-null assertion operator is being used without checking if this will actually be resolved by that issue. The backend method GetProjectProgress returns BookProgress[] directly, not a nullable type, so the non-null assertion may not be needed at all. Verify if this TODO is accurate and if the assertion is actually necessary.