Skip to content

Commit

Permalink
feat: display search id and sort according to search term order (TT-1…
Browse files Browse the repository at this point in the history
…728) (#9)

Co-authored-by: Sindre Østrem <sindreoestrem@gmail.com>
  • Loading branch information
fredrikmonsen and Sindrir authored Sep 27, 2024
1 parent 5cd86e3 commit 9d6e3de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@
multiTemplateDataRows
class="mat-elevation-z8"
>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Objekt-ID </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
<ng-container matColumnDef="searchId">
<th mat-header-cell *matHeaderCellDef> Søke-ID </th>
<td mat-cell *matCellDef="let element"> {{element.searchId}} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> Navn </th>
<td mat-cell *matCellDef="let element"> {{element.description}} </td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> Materialtype </th>
<td mat-cell *matCellDef="let element"> {{element.type}} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> Navn </th>
<td mat-cell *matCellDef="let element"> {{element.description}} </td>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Objekt-ID </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell class="centered-cell" *matHeaderCellDef> Kan sendes videre? </th>
Expand Down
27 changes: 13 additions & 14 deletions src/app/components/production-status/production-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export class ProductionStatusComponent {
readonly relationUrl = `${environment.relationUrl}/periodicals/issue`;

readonly displayedColumns: string[] = [
'id',
'searchId',
'description',
'id',
'type',
'status',
'relationLink'
Expand Down Expand Up @@ -92,21 +93,22 @@ export class ProductionStatusComponent {
const searchInputs = this.searchInputValue.split('\n').map(s => s.trim());
const uniqueSearchInputs = Array.from(new Set(searchInputs));
const tempData: DigitizedItem[] = [];
forkJoin(this.normalizeNames(uniqueSearchInputs).filter(Boolean).map(searchTerm => {
forkJoin(uniqueSearchInputs.filter(Boolean).map(searchTerm => {
const normalizedSearchTerm = this.normalizeName(searchTerm);
return this.productionService
.searchItem(searchTerm)
.searchItem(normalizedSearchTerm)
.pipe(tap(item => {
if (!item) this.notFoundIds.push(searchTerm);
else tempData.push(item);
else tempData.push({...item, searchId: searchTerm});
}))
}))
.subscribe({
next: () => {
this.dataSource.data = tempData.sort((a, b) => {
if (!a.description || !b.description) {
if (!a.searchId || !b.searchId) {
return 0;
}
return uniqueSearchInputs.indexOf(a.description) - uniqueSearchInputs.indexOf(b.description)
return uniqueSearchInputs.indexOf(a.searchId) - uniqueSearchInputs.indexOf(b.searchId)
});
this.displayResults = true;
},
Expand All @@ -117,15 +119,12 @@ export class ProductionStatusComponent {
})
}

// Helper method to allow searching for digibok without the digibok_ prefix
normalizeNames(descriptions: string[]): string[] {
normalizeName(description: string): string {
const regex = /^(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{5}$/;
return descriptions.map(description => {
if (regex.test(description)) {
return 'digibok_' + description;
}
return description;
});
if (regex.test(description)) {
return 'digibok_' + description;
}
return description;
}

itemIsFinished(item: DigitizedItem): boolean {
Expand Down
1 change: 1 addition & 0 deletions src/app/models/digitized-item.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {MaterialTypeEnum} from "../enums/material-type.enum";
export class DigitizedItem {
id?: number;
description?: string;
searchId?: string;
type?: MaterialTypeEnum;
status?: string;
createdBy?: string;
Expand Down

0 comments on commit 9d6e3de

Please sign in to comment.