Merge branch 'release/4.5' into develop

This commit is contained in:
Nino
2025-12-02 17:18:11 +01:00
16 changed files with 599 additions and 112 deletions

View File

@@ -1,5 +1,11 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
import {
Component,
ChangeDetectionStrategy,
OnDestroy,
inject,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TabService } from '@isa/core/tabs';
import { map } from 'rxjs/operators';
@Component({
@@ -9,8 +15,17 @@ import { map } from 'rxjs/operators';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class CustomerComponent {
export class CustomerComponent implements OnDestroy {
private _tabService = inject(TabService);
processId$ = this._activatedRoute.data.pipe(map((data) => data.processId));
constructor(private _activatedRoute: ActivatedRoute) {}
ngOnDestroy() {
const tab = this._tabService.activatedTab();
// #5512 Always clear preserved select-customer context if navigating out of customer area
this._tabService.patchTabMetadata(tab.id, {
'select-customer': null,
});
}
}

View File

@@ -1,16 +1,43 @@
@if (modalRef.data.subtitle; as subtitle) {
<h2 class="subtitle">{{ subtitle }}</h2>
}
@if (modalRef.data.content; as content) {
<p class="content">
{{ content }}
</p>
<!-- QR Code Display Mode -->
@if (shouldShowQrCode(); as showQr) {
@if (parsedContent(); as parsed) {
@if (parsed.textBefore) {
<p class="content">{{ parsed.textBefore }}</p>
}
<div class="qr-code-container">
<qrcode
[qrdata]="parsed.url!"
[width]="200"
[errorCorrectionLevel]="'M'"
[margin]="2"
></qrcode>
</div>
@if (parsed.textAfter) {
<p class="content">{{ parsed.textAfter }}</p>
}
}
} @else {
<!-- Default Text Display Mode -->
@if (modalRef.data.content; as content) {
<p class="content">
{{ content }}
</p>
}
}
@if (modalRef.data.actions; as actions) {
<div class="actions">
@for (action of actions; track action) {
<button [class.selected]="action.selected" (click)="handleCommand(action.command)">
<button
[class.selected]="action.selected"
(click)="handleCommand(action.command)"
>
{{ action.label }}
</button>
}

View File

@@ -15,11 +15,15 @@
@apply text-lg text-center whitespace-pre-wrap mb-8 px-16;
}
.qr-code-container {
@apply flex flex-col items-center justify-center mb-8;
}
.actions {
@apply text-center mb-8;
button {
@apply border-2 border-solid border-brand bg-white text-brand rounded-full py-3 px-6 font-bold text-lg outline-none self-end whitespace-nowrap ml-4;
@apply border-2 border-solid border-brand bg-white text-brand rounded-full py-3 px-6 font-bold text-lg outline-none self-end whitespace-nowrap;
&.selected {
@apply bg-brand text-white;

View File

@@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Component, computed, OnInit } from '@angular/core';
import { CommandService } from '@core/command';
import { UiModalRef } from '../defs/modal-ref';
import { DialogModel } from './dialog.model';
import { parseDialogContentForUrl } from './dialog.helper';
@Component({
selector: 'ui-dialog-modal',
@@ -10,6 +11,26 @@ import { DialogModel } from './dialog.model';
standalone: false,
})
export class UiDialogModalComponent implements OnInit {
/**
* Parsed content with URL extracted for QR code display.
* Only relevant when showUrlAsQrCode is true.
*/
readonly parsedContent = computed(() => {
const data = this.modalRef.data;
if (!data.showUrlAsQrCode) {
return null;
}
return parseDialogContentForUrl(data.content);
});
/**
* Whether to show the QR code instead of the URL text.
*/
readonly shouldShowQrCode = computed(() => {
const parsed = this.parsedContent();
return parsed !== null && parsed.url !== null;
});
constructor(
public modalRef: UiModalRef<any, DialogModel<any>>,
private _command: CommandService,

View File

@@ -0,0 +1,48 @@
import { ParsedDialogContent } from './dialog.model';
/**
* Regular expression to match URLs in text.
* Matches http:// and https:// URLs.
*/
const URL_REGEX = /https?:\/\/[^\s]+/i;
/**
* Parses the dialog content and extracts the first URL.
* Splits the content into text before the URL, the URL itself, and text after.
*
* @param content - The dialog content string to parse
* @returns ParsedDialogContent with the split content
*/
export const parseDialogContentForUrl = (
content: string | undefined,
): ParsedDialogContent => {
if (!content) {
return { textBefore: '', url: null, textAfter: '' };
}
const match = content.match(URL_REGEX);
if (!match || match.index === undefined) {
return { textBefore: content, url: null, textAfter: '' };
}
const url = match[0];
const urlIndex = match.index;
const textBefore = content.substring(0, urlIndex).trim();
const textAfter = content.substring(urlIndex + url.length).trim();
return { textBefore, url, textAfter };
};
/**
* Checks if the given content contains a URL.
*
* @param content - The content string to check
* @returns true if a URL is found, false otherwise
*/
export const contentHasUrl = (content: string | undefined): boolean => {
if (!content) {
return false;
}
return URL_REGEX.test(content);
};

View File

@@ -0,0 +1,152 @@
import { contentHasUrl, parseDialogContentForUrl } from './dialog.helper';
import { ParsedDialogContent } from './dialog.model';
describe('parseDialogContentForUrl', () => {
it('should return empty result for undefined content', () => {
const result = parseDialogContentForUrl(undefined);
expect(result).toEqual<ParsedDialogContent>({
textBefore: '',
url: null,
textAfter: '',
});
});
it('should return empty result for empty string', () => {
const result = parseDialogContentForUrl('');
expect(result).toEqual<ParsedDialogContent>({
textBefore: '',
url: null,
textAfter: '',
});
});
it('should return content as textBefore when no URL is found', () => {
const content = 'This is some text without a URL';
const result = parseDialogContentForUrl(content);
expect(result).toEqual<ParsedDialogContent>({
textBefore: content,
url: null,
textAfter: '',
});
});
it('should extract https URL from content', () => {
const content = 'Text before https://example.com text after';
const result = parseDialogContentForUrl(content);
expect(result).toEqual<ParsedDialogContent>({
textBefore: 'Text before',
url: 'https://example.com',
textAfter: 'text after',
});
});
it('should extract http URL from content', () => {
const content = 'Text before http://example.com text after';
const result = parseDialogContentForUrl(content);
expect(result).toEqual<ParsedDialogContent>({
textBefore: 'Text before',
url: 'http://example.com',
textAfter: 'text after',
});
});
it('should handle URL at the beginning of content', () => {
const content = 'https://example.com/path text after';
const result = parseDialogContentForUrl(content);
expect(result).toEqual<ParsedDialogContent>({
textBefore: '',
url: 'https://example.com/path',
textAfter: 'text after',
});
});
it('should handle URL at the end of content', () => {
const content = 'Text before https://example.com/path';
const result = parseDialogContentForUrl(content);
expect(result).toEqual<ParsedDialogContent>({
textBefore: 'Text before',
url: 'https://example.com/path',
textAfter: '',
});
});
it('should handle real-world content with newlines', () => {
const content = `Punkte: 80500
Um alle Vorteile der Kundenkarte nutzen zu können, ist eine Verknüpfung zu einem Online-Konto notwendig. Kund:innen können sich über den QR-Code selbstständig anmelden oder die Kundenkarte dem bestehendem Konto hinzufügen. Bereits gesammelte Punkte werden übernommen.
https://h-k.me/QOHNTFVA`;
const result = parseDialogContentForUrl(content);
expect(result.url).toBe('https://h-k.me/QOHNTFVA');
expect(result.textBefore).toContain('Punkte: 80500');
expect(result.textBefore).toContain(
'Bereits gesammelte Punkte werden übernommen.',
);
expect(result.textAfter).toBe('');
});
it('should extract only the first URL when multiple URLs are present', () => {
const content = 'First https://first.com then https://second.com';
const result = parseDialogContentForUrl(content);
expect(result).toEqual<ParsedDialogContent>({
textBefore: 'First',
url: 'https://first.com',
textAfter: 'then https://second.com',
});
});
it('should handle URLs with paths and query parameters', () => {
const content =
'Visit https://example.com/path?query=value&foo=bar for more';
const result = parseDialogContentForUrl(content);
expect(result.url).toBe('https://example.com/path?query=value&foo=bar');
expect(result.textBefore).toBe('Visit');
expect(result.textAfter).toBe('for more');
});
});
describe('contentHasUrl', () => {
it('should return false for undefined content', () => {
expect(contentHasUrl(undefined)).toBe(false);
});
it('should return false for empty string', () => {
expect(contentHasUrl('')).toBe(false);
});
it('should return false for content without URL', () => {
expect(contentHasUrl('This is text without a URL')).toBe(false);
});
it('should return true for content with https URL', () => {
expect(contentHasUrl('Check out https://example.com')).toBe(true);
});
it('should return true for content with http URL', () => {
expect(contentHasUrl('Check out http://example.com')).toBe(true);
});
it('should return true for real-world content', () => {
const content = `Punkte: 80500
Um alle Vorteile der Kundenkarte nutzen zu können...
https://h-k.me/QOHNTFVA`;
expect(contentHasUrl(content)).toBe(true);
});
});

View File

@@ -1,4 +1,7 @@
import { DialogSettings, KeyValueDTOOfStringAndString } from '@generated/swagger/crm-api';
import {
DialogSettings,
KeyValueDTOOfStringAndString,
} from '@generated/swagger/crm-api';
export interface DialogModel<T = any> {
actions?: Array<KeyValueDTOOfStringAndString>;
@@ -14,4 +17,21 @@ export interface DialogModel<T = any> {
* default: true
*/
handleCommand?: boolean;
/**
* If true, URLs in the content will be displayed as QR codes.
* default: false
*/
showUrlAsQrCode?: boolean;
}
/**
* Result of parsing content for URLs
*/
export interface ParsedDialogContent {
/** Text before the URL */
textBefore: string;
/** The extracted URL (if any) */
url: string | null;
/** Text after the URL */
textAfter: string;
}

View File

@@ -13,6 +13,7 @@ import { Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { DialogModel } from './dialog.model';
import { ToasterService } from '@shared/shell';
import { contentHasUrl } from './dialog.helper';
@Injectable()
export class OpenDialogInterceptor implements HttpInterceptor {
@@ -21,7 +22,10 @@ export class OpenDialogInterceptor implements HttpInterceptor {
private _toast: ToasterService,
) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
intercept(
req: HttpRequest<any>,
next: HttpHandler,
): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
tap((response) => {
if (response instanceof HttpResponse) {
@@ -59,9 +63,17 @@ export class OpenDialogInterceptor implements HttpInterceptor {
}
openDialog(model: DialogModel<any>) {
// Auto-detect URLs and enable QR code display if URL is found
// Can be overridden by explicitly setting showUrlAsQrCode in the model
const showUrlAsQrCode =
model.showUrlAsQrCode ?? contentHasUrl(model.content);
this._modal.open({
content: UiDialogModalComponent,
data: model,
data: {
...model,
showUrlAsQrCode,
},
title: model.title,
config: {
canClose: (model.settings & 1) === 1,

View File

@@ -2,7 +2,6 @@ import { OverlayModule } from '@angular/cdk/overlay';
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { UiModalComponent } from './modal.component';
import { UiModalService } from './modal.service';
import { UiDebugModalComponent } from './debug-modal/debug-modal.component';
import { UiMessageModalComponent } from './message-modal.component';
import { UiIconModule } from '@ui/icon';
@@ -10,9 +9,10 @@ import { UiDialogModalComponent } from './dialog/dialog-modal.component';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { OpenDialogInterceptor } from './dialog/open-dialog.interceptor';
import { UiPromptModalComponent } from './prompt-modal';
import { QRCodeComponent } from 'angularx-qrcode';
@NgModule({
imports: [CommonModule, OverlayModule, UiIconModule],
imports: [CommonModule, OverlayModule, UiIconModule, QRCodeComponent],
declarations: [
UiModalComponent,
UiDebugModalComponent,