mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 1992: ♻️ refactor(catalog): extract shared Reihe prefix pattern to constants
♻️ refactor(catalog): extract shared Reihe prefix pattern to constants Ref: #5421 - Create reihe.constants.ts with REIHE_PREFIX_PATTERN constant - Update LineTypePipe to use shared pattern and fix capture group index - Update ReiheRoutePipe to use shared pattern - Pattern now matches "Reihe:", "Reihe/Set:", and "Set/Reihe:" Related work items: #5421
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { REIHE_PREFIX_PATTERN } from './reihe.constants';
|
||||
|
||||
@Pipe({
|
||||
name: 'lineType',
|
||||
@@ -7,8 +8,8 @@ import { Pipe, PipeTransform } from '@angular/core';
|
||||
})
|
||||
export class LineTypePipe implements PipeTransform {
|
||||
transform(value: string, ...args: any[]): 'text' | 'reihe' {
|
||||
const REIHE_REGEX = /^Reihe:\s*"(.+)\"$/g;
|
||||
const reihe = REIHE_REGEX.exec(value)?.[1];
|
||||
const REIHE_REGEX = new RegExp(`^${REIHE_PREFIX_PATTERN}:\\s*"(.+)"$`, 'g');
|
||||
const reihe = REIHE_REGEX.exec(value)?.[2];
|
||||
return reihe ? 'reihe' : 'text';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectorRef,
|
||||
OnDestroy,
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
} from '@angular/core';
|
||||
import { ApplicationService } from '@core/application';
|
||||
import { ProductCatalogNavigationService } from '@shared/services/navigation';
|
||||
import { isEqual } from 'lodash';
|
||||
import { Subscription, combineLatest, BehaviorSubject } from 'rxjs';
|
||||
import { distinctUntilChanged } from 'rxjs/operators';
|
||||
import { REIHE_PREFIX_PATTERN } from './reihe.constants';
|
||||
|
||||
@Pipe({
|
||||
name: 'reiheRoute',
|
||||
@@ -22,10 +28,13 @@ export class ReiheRoutePipe implements PipeTransform, OnDestroy {
|
||||
private application: ApplicationService,
|
||||
private cdr: ChangeDetectorRef,
|
||||
) {
|
||||
this.subscription = combineLatest([this.application.activatedProcessId$, this.value$])
|
||||
this.subscription = combineLatest([
|
||||
this.application.activatedProcessId$,
|
||||
this.value$,
|
||||
])
|
||||
.pipe(distinctUntilChanged(isEqual))
|
||||
.subscribe(([processId, value]) => {
|
||||
const REIHE_REGEX = /[";]|Reihe:/g; // Entferne jedes Semikolon, Anführungszeichen und den String Reihe:
|
||||
const REIHE_REGEX = new RegExp(`[";]|${REIHE_PREFIX_PATTERN}:`, 'g'); // Entferne jedes Semikolon, Anführungszeichen und den String Reihe:/Reihe/Set:/Set/Reihe:
|
||||
const reihe = value?.replace(REIHE_REGEX, '')?.trim();
|
||||
|
||||
if (!reihe) {
|
||||
@@ -33,9 +42,15 @@ export class ReiheRoutePipe implements PipeTransform, OnDestroy {
|
||||
return;
|
||||
}
|
||||
|
||||
const main_qs = reihe.split('/')[0];
|
||||
// Entferne Zahlen am Ende, die mit Leerzeichen, Komma, Slash oder Semikolon getrennt sind
|
||||
// Beispiele: "Harry Potter 1" -> "Harry Potter", "Harry Potter,1" -> "Harry Potter", "Harry Potter/2" -> "Harry Potter"
|
||||
const main_qs = reihe
|
||||
.split('/')[0]
|
||||
.replace(/[\s,;]+\d+$/g, '')
|
||||
.trim();
|
||||
|
||||
const path = this.navigation.getArticleSearchResultsPath(processId).path;
|
||||
const path =
|
||||
this.navigation.getArticleSearchResultsPath(processId).path;
|
||||
|
||||
this.result = {
|
||||
path,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Shared regex pattern for matching Reihe line prefixes.
|
||||
* Matches: "Reihe:", "Reihe/Set:", or "Set/Reihe:"
|
||||
*/
|
||||
export const REIHE_PREFIX_PATTERN = '(Reihe|Reihe\\/Set|Set\\/Reihe)';
|
||||
Reference in New Issue
Block a user