@corp-products/ui-components 3.2.8 → 3.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ng-package.json +7 -0
- package/package.json +22 -36
- package/src/enums/date-formatter.ts +21 -0
- package/src/helper/date-handler.ts +142 -0
- package/src/lib/app-accordion/app-accordion.component.html +15 -0
- package/src/lib/app-accordion/app-accordion.component.scss +0 -0
- package/src/lib/app-accordion/app-accordion.component.spec.ts +21 -0
- package/src/lib/app-accordion/app-accordion.component.ts +21 -0
- package/src/lib/app-accordion/index.ts +2 -0
- package/src/lib/app-breadcrumb/app-breadcrumb.component.html +7 -0
- package/src/lib/app-breadcrumb/app-breadcrumb.component.scss +25 -0
- package/src/lib/app-breadcrumb/app-breadcrumb.component.ts +140 -0
- package/src/lib/app-breadcrumb/app-breadcrumb.interface.ts +15 -0
- package/src/lib/app-button/app-button.component.html +7 -0
- package/src/lib/app-button/app-button.component.scss +0 -0
- package/src/lib/app-button/app-button.component.ts +14 -0
- package/src/lib/app-button/app-button.ts +15 -0
- package/src/lib/app-button/index.ts +2 -0
- package/src/lib/app-dropdown-menu/app-dropdown-menu.component.html +22 -0
- package/src/lib/app-dropdown-menu/app-dropdown-menu.component.scss +39 -0
- package/src/lib/app-dropdown-menu/app-dropdown-menu.component.spec.ts +21 -0
- package/src/lib/app-dropdown-menu/app-dropdown-menu.component.ts +43 -0
- package/src/lib/app-dropdown-menu/app-dropdown-menu.ts +17 -0
- package/src/lib/app-dropdown-menu/index.ts +2 -0
- package/src/lib/app-dropdown-menu/menu-popup.pipe.ts +18 -0
- package/src/lib/app-header/app-header.component.html +26 -0
- package/src/lib/app-header/app-header.component.scss +0 -0
- package/src/lib/app-header/app-header.component.ts +43 -0
- package/src/lib/app-side-menu/app-side-menu.component.html +20 -0
- package/src/lib/app-side-menu/app-side-menu.component.ts +28 -0
- package/src/lib/app-side-menu/routes-names.ts +28 -0
- package/src/lib/app-side-menu/side-menu-items.ts +45 -0
- package/src/lib/app-side-menu/side-menu.ts +12 -0
- package/src/lib/app-tabs/app-tab.interface.ts +27 -0
- package/src/lib/app-tabs/app-tabs.component.html +37 -0
- package/src/lib/app-tabs/app-tabs.component.scss +103 -0
- package/src/lib/app-tabs/app-tabs.component.spec.ts +21 -0
- package/src/lib/app-tabs/app-tabs.component.ts +67 -0
- package/src/lib/app-tabs/index.ts +2 -0
- package/src/lib/bottom-sheet/bottom-sheet.component.html +18 -0
- package/src/lib/bottom-sheet/bottom-sheet.component.scss +31 -0
- package/src/lib/bottom-sheet/bottom-sheet.component.ts +26 -0
- package/src/lib/confirmation-dialog/confirmation-dialog.component.html +37 -0
- package/src/lib/confirmation-dialog/confirmation-dialog.component.scss +0 -0
- package/src/lib/confirmation-dialog/confirmation-dialog.component.spec.ts +22 -0
- package/src/lib/confirmation-dialog/confirmation-dialog.component.ts +64 -0
- package/src/lib/confirmation-dialog/confirmation-dialog.interface.ts +13 -0
- package/src/lib/confirmation-dialog/confirmation-dialog.service.ts +34 -0
- package/src/lib/dual-calender/date-picker-switcher/date-picker-switcher.component.html +27 -0
- package/src/lib/dual-calender/date-picker-switcher/date-picker-switcher.component.scss +22 -0
- package/src/lib/dual-calender/date-picker-switcher/date-picker-switcher.component.ts +64 -0
- package/src/lib/dual-calender/dual-calendar.component.html +31 -0
- package/src/lib/dual-calender/dual-calendar.component.scss +229 -0
- package/src/lib/dual-calender/dual-calendar.component.ts +107 -0
- package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.html +10 -0
- package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.scss +0 -0
- package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.spec.ts +21 -0
- package/src/lib/dual-calender/gregorian-calendar/gregorian-calendar.component.ts +59 -0
- package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.html +10 -0
- package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.scss +0 -0
- package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.spec.ts +21 -0
- package/src/lib/dual-calender/hijri-calendar/hijri-calendar.component.ts +59 -0
- package/src/lib/dual-calender/services/gregorian-i18n.service.ts +123 -0
- package/src/lib/dual-calender/services/islamic-i18n.service.ts +119 -0
- package/src/lib/dual-calender/utils/date-i18n.utils.ts +58 -0
- package/src/lib/dynamic-form/dynamic-form.component.html +86 -0
- package/src/lib/dynamic-form/dynamic-form.component.scss +0 -0
- package/src/lib/dynamic-form/dynamic-form.component.spec.ts +21 -0
- package/src/lib/dynamic-form/dynamic-form.component.ts +58 -0
- package/src/lib/dynamic-form/dynamic-form.interface.ts +94 -0
- package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.component.html +32 -0
- package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.component.scss +3 -0
- package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.component.ts +82 -0
- package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.config.ts +31 -0
- package/src/lib/dynamic-side-bar-v2/dynamic-sidebar.service.ts +41 -0
- package/src/lib/form-components/@utils/form-utils.ts +12 -0
- package/src/lib/form-components/@utils/validations/error-keys.enum.ts +24 -0
- package/src/lib/form-components/@utils/validations/form-validation.service.ts +68 -0
- package/src/lib/form-components/@utils/validations/index.ts +3 -0
- package/src/lib/form-components/@utils/validations/validation-message.pipe.ts +24 -0
- package/src/lib/form-components/components/auto-complete/auto-complete.component.html +35 -0
- package/src/lib/form-components/components/auto-complete/auto-complete.component.scss +7 -0
- package/src/lib/form-components/components/auto-complete/auto-complete.component.spec.ts +21 -0
- package/src/lib/form-components/components/auto-complete/auto-complete.component.ts +57 -0
- package/src/lib/form-components/components/base-input.component.ts +35 -0
- package/src/lib/form-components/components/date-picker/date-picker.component.html +41 -0
- package/src/lib/form-components/components/date-picker/date-picker.component.scss +16 -0
- package/src/lib/form-components/components/date-picker/date-picker.component.spec.ts +21 -0
- package/src/lib/form-components/components/date-picker/date-picker.component.ts +54 -0
- package/src/lib/form-components/components/input/input.component.html +63 -0
- package/src/lib/form-components/components/input/input.component.scss +41 -0
- package/src/lib/form-components/components/input/input.component.spec.ts +21 -0
- package/src/lib/form-components/components/input/input.component.ts +45 -0
- package/src/lib/form-components/components/select/select.component.html +111 -0
- package/src/lib/form-components/components/select/select.component.scss +43 -0
- package/src/lib/form-components/components/select/select.component.spec.ts +21 -0
- package/src/lib/form-components/components/select/select.component.ts +56 -0
- package/src/lib/form-components/components/select-button/select-button.component.html +21 -0
- package/src/lib/form-components/components/select-button/select-button.component.scss +0 -0
- package/src/lib/form-components/components/select-button/select-button.component.spec.ts +21 -0
- package/src/lib/form-components/components/select-button/select-button.component.ts +22 -0
- package/src/lib/form-components/components/switcher/switch.component.html +5 -0
- package/src/lib/form-components/components/switcher/switch.component.scss +0 -0
- package/src/lib/form-components/components/switcher/switch.component.spec.ts +21 -0
- package/src/lib/form-components/components/switcher/switch.component.ts +25 -0
- package/src/lib/form-components/index.ts +9 -0
- package/src/lib/form-components/interfaces/index.ts +1 -0
- package/src/lib/form-components/interfaces/label-value.ts +4 -0
- package/src/lib/ico-moon-icon/ico-moon-icon.component.ts +23 -0
- package/src/lib/read-more/read-more.component.html +17 -0
- package/src/lib/read-more/read-more.component.scss +0 -0
- package/src/lib/read-more/read-more.component.spec.ts +21 -0
- package/src/lib/read-more/read-more.component.ts +21 -0
- package/src/lib/side-bar/side-bar.component.html +24 -0
- package/src/lib/side-bar/side-bar.component.scss +22 -0
- package/src/lib/side-bar/side-bar.component.spec.ts +21 -0
- package/src/lib/side-bar/side-bar.component.ts +33 -0
- package/src/lib/side-bar-dynamic/data-injector.pipe.ts +15 -0
- package/src/lib/side-bar-dynamic/dynamic-sidebar.service.ts +116 -0
- package/src/lib/side-bar-dynamic/side-bar-dynamic.component.html +42 -0
- package/src/lib/side-bar-dynamic/side-bar-dynamic.component.scss +5 -0
- package/src/lib/side-bar-dynamic/side-bar-dynamic.component.spec.ts +21 -0
- package/src/lib/side-bar-dynamic/side-bar-dynamic.component.ts +37 -0
- package/src/lib/side-bar-dynamic/side-bar-utils.ts +30 -0
- package/src/lib/side-bar-dynamic/sidebar-config.ts +48 -0
- package/src/lib/user-autocomplete-card/user-autocomplete-card.component.html +20 -0
- package/src/lib/user-autocomplete-card/user-autocomplete-card.component.scss +0 -0
- package/src/lib/user-autocomplete-card/user-autocomplete-card.component.spec.ts +21 -0
- package/src/lib/user-autocomplete-card/user-autocomplete-card.component.ts +21 -0
- package/src/lib/user-info/user-info.component.html +10 -0
- package/src/lib/user-info/user-info.component.ts +11 -0
- package/src/public-api.ts +26 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +14 -0
- package/fesm2022/corp-products-ui-components.mjs +0 -1416
- package/fesm2022/corp-products-ui-components.mjs.map +0 -1
- package/index.d.ts +0 -625
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<p-drawer
|
|
2
|
+
[(visible)]="show"
|
|
3
|
+
[position]="position"
|
|
4
|
+
appendTo="body"
|
|
5
|
+
[closable]="closable"
|
|
6
|
+
[closeOnEscape]="closeOnEscape"
|
|
7
|
+
[dismissible]="dismissible"
|
|
8
|
+
(onHide)="handleClose()"
|
|
9
|
+
[position]="'left'"
|
|
10
|
+
[styleClass]="'p-drawer-' + sidebarSize + ' custom-content bg-white ' + styleClass">
|
|
11
|
+
<ng-template pTemplate="header">
|
|
12
|
+
<p class="truncate" [pTooltip]="title">{{ title }}</p>
|
|
13
|
+
</ng-template>
|
|
14
|
+
<ng-template pTemplate="content">
|
|
15
|
+
<ng-template #contentContainer></ng-template>
|
|
16
|
+
</ng-template>
|
|
17
|
+
<ng-template pTemplate="footer">
|
|
18
|
+
<div class="flex gap-4 mt-4">
|
|
19
|
+
<div class="flex-auto">
|
|
20
|
+
<app-button (click)="handleSubmit()"
|
|
21
|
+
[icon]="actions?.save?.icon"
|
|
22
|
+
[iconPos]="actions?.save?.iconPos || 'right'"
|
|
23
|
+
[styleClass]="(actions?.save?.style || 'danger') + ' w-full'"
|
|
24
|
+
[label]="actions?.save?.title || ('actions.submit' | translate)"
|
|
25
|
+
[variant]="actions?.save?.variant"
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
<app-button (click)="handleClose()" severity="danger" variant="outlined"
|
|
29
|
+
[label]="actions?.cancel?.title || ('actions.cancel' | translate)" />
|
|
30
|
+
</div>
|
|
31
|
+
</ng-template>
|
|
32
|
+
</p-drawer>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AppButtonComponent } from './../app-button/app-button.component';
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import { CommonModule } from '@angular/common';
|
|
4
|
+
import {
|
|
5
|
+
AfterViewInit,
|
|
6
|
+
Component,
|
|
7
|
+
EventEmitter,
|
|
8
|
+
Input,
|
|
9
|
+
OnDestroy,
|
|
10
|
+
Output,
|
|
11
|
+
Type,
|
|
12
|
+
ViewChild,
|
|
13
|
+
ViewContainerRef
|
|
14
|
+
} from '@angular/core';
|
|
15
|
+
import { TranslatePipe } from '@ngx-translate/core';
|
|
16
|
+
import { DrawerModule } from 'primeng/drawer';
|
|
17
|
+
import { TooltipModule } from "primeng/tooltip";
|
|
18
|
+
import { SidebarV2Actions } from './dynamic-sidebar.config';
|
|
19
|
+
|
|
20
|
+
@Component({
|
|
21
|
+
selector: "app-dynamic-sidebar",
|
|
22
|
+
templateUrl: "./dynamic-sidebar.component.html",
|
|
23
|
+
styleUrls: ["./dynamic-sidebar.component.scss"],
|
|
24
|
+
standalone: true,
|
|
25
|
+
imports: [CommonModule, TranslatePipe, DrawerModule, TooltipModule, AppButtonComponent],
|
|
26
|
+
})
|
|
27
|
+
export class DynamicSidebarComponent implements AfterViewInit, OnDestroy {
|
|
28
|
+
|
|
29
|
+
@Input() component!: Type<any>;
|
|
30
|
+
@Input() data?: any;
|
|
31
|
+
@Input() title = '';
|
|
32
|
+
@Input() actions?: SidebarV2Actions;
|
|
33
|
+
@Input() sidebarSize: 'sm' | 'md' | 'lg' = 'md';
|
|
34
|
+
@Input() closable = true;
|
|
35
|
+
@Input() closeOnEscape = true;
|
|
36
|
+
@Input() dismissible = true;
|
|
37
|
+
@Input() position: 'left' | 'right' = 'left';
|
|
38
|
+
@Input() styleClass = '';
|
|
39
|
+
@Input() disabled = false;
|
|
40
|
+
|
|
41
|
+
@Output() closed = new EventEmitter();
|
|
42
|
+
|
|
43
|
+
@ViewChild('contentContainer', { read: ViewContainerRef })
|
|
44
|
+
private contentContainer!: ViewContainerRef;
|
|
45
|
+
|
|
46
|
+
private contentRef: any;
|
|
47
|
+
|
|
48
|
+
show = true;
|
|
49
|
+
|
|
50
|
+
ngAfterViewInit() {
|
|
51
|
+
this.renderContent();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private renderContent() {
|
|
55
|
+
if (!this.component) return;
|
|
56
|
+
this.contentContainer.clear();
|
|
57
|
+
this.contentRef = this.contentContainer.createComponent(this.component);
|
|
58
|
+
if (this.data) Object.assign(this.contentRef.instance, this.data);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
handleClose() {
|
|
62
|
+
if(this.contentRef.instance.close) this.contentRef.instance.close();
|
|
63
|
+
this.closed.emit(null);
|
|
64
|
+
this.destroy();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
handleSubmit() {
|
|
68
|
+
if(this.data.form) {
|
|
69
|
+
this.data.form.markAllAsTouched();
|
|
70
|
+
if(this.data.form.invalid) return;
|
|
71
|
+
}
|
|
72
|
+
if(this.contentRef.instance.submit) this.contentRef.instance.submit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private destroy() {
|
|
76
|
+
this.contentRef?.destroy();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ngOnDestroy() {
|
|
80
|
+
this.destroy();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Type, ViewContainerRef } from "@angular/core";
|
|
2
|
+
import { AppButtonIconPos, AppButtonSeverity, AppButtonSize, AppButtonVariant } from "../app-button";
|
|
3
|
+
|
|
4
|
+
export interface DynamicSidebarV2Actions {
|
|
5
|
+
submit: () => void;
|
|
6
|
+
close: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface DynamicSidebarV2Config<T = any> {
|
|
9
|
+
title?: string;
|
|
10
|
+
component: Type<T>;
|
|
11
|
+
data?: Partial<T>;
|
|
12
|
+
size?: 'sm' | 'md' | 'lg';
|
|
13
|
+
position?: 'left' | 'right';
|
|
14
|
+
styleClass?: string;
|
|
15
|
+
viewContainerRef?: ViewContainerRef;
|
|
16
|
+
actions?: SidebarV2Actions
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SidebarActionV2Config {
|
|
20
|
+
title?: string;
|
|
21
|
+
icon?: string;
|
|
22
|
+
size?: AppButtonSize;
|
|
23
|
+
style?: AppButtonSeverity;
|
|
24
|
+
iconPos?: AppButtonIconPos;
|
|
25
|
+
variant?: AppButtonVariant;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SidebarV2Actions {
|
|
29
|
+
cancel?: SidebarActionV2Config;
|
|
30
|
+
save?: SidebarActionV2Config;
|
|
31
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApplicationRef, ComponentRef, EnvironmentInjector, Injectable, Injector, createComponent, inject } from '@angular/core';
|
|
2
|
+
import { DynamicSidebarComponent } from './dynamic-sidebar.component';
|
|
3
|
+
import { DynamicSidebarV2Config } from './dynamic-sidebar.config';
|
|
4
|
+
|
|
5
|
+
@Injectable({ providedIn: 'root' })
|
|
6
|
+
export class DynamicSidebarV2Service {
|
|
7
|
+
private sidebarRef?: ComponentRef<DynamicSidebarComponent>;
|
|
8
|
+
private readonly appRef = inject(ApplicationRef);
|
|
9
|
+
private readonly injector = inject(Injector);
|
|
10
|
+
private readonly envInjector = inject(EnvironmentInjector);
|
|
11
|
+
|
|
12
|
+
open<T>(options: DynamicSidebarV2Config<T>) {
|
|
13
|
+
this.close();
|
|
14
|
+
|
|
15
|
+
this.sidebarRef = createComponent(DynamicSidebarComponent, {
|
|
16
|
+
environmentInjector: this.envInjector,
|
|
17
|
+
elementInjector: this.injector,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const instance = this.sidebarRef.instance;
|
|
21
|
+
instance.title = options.title ?? '';
|
|
22
|
+
instance.sidebarSize = options.size ?? 'md';
|
|
23
|
+
instance.position = options.position ?? 'left';
|
|
24
|
+
instance.styleClass = options.styleClass ?? '';
|
|
25
|
+
instance.component = options.component;
|
|
26
|
+
instance.data = options.data ?? {};
|
|
27
|
+
instance.actions = options.actions;
|
|
28
|
+
instance.closed.subscribe(() => this.close());
|
|
29
|
+
|
|
30
|
+
this.appRef.attachView(this.sidebarRef.hostView);
|
|
31
|
+
const domElem = (this.sidebarRef.hostView as any).rootNodes[0] as HTMLElement;
|
|
32
|
+
document.body.appendChild(domElem);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
close() {
|
|
36
|
+
if (this.sidebarRef) {
|
|
37
|
+
this.sidebarRef.destroy();
|
|
38
|
+
this.sidebarRef = undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {FormControl, FormGroup} from "@angular/forms";
|
|
2
|
+
|
|
3
|
+
export class FormUtils {
|
|
4
|
+
static getFormControl(controlName: string, form: FormGroup): FormControl {
|
|
5
|
+
if (!form) throw new Error(`Form is not initialized.`);
|
|
6
|
+
const formControl = form.get(controlName) as FormControl;
|
|
7
|
+
|
|
8
|
+
if (!formControl) throw new Error(`There's no form control with given name. '${controlName}'`);
|
|
9
|
+
|
|
10
|
+
return formControl;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export enum BasicErrorKeysEnum {
|
|
2
|
+
required = "REQUIRED",
|
|
3
|
+
email = "EMAIL",
|
|
4
|
+
pattern = "PATTERN",
|
|
5
|
+
invalidArFormat = "INVALID_AR_FORMAT",
|
|
6
|
+
invalidLink = "INVALID_LINK",
|
|
7
|
+
endDateBeforeStartDate = "END_DATE_BEFORE_START_DATE",
|
|
8
|
+
startDateEqualsEndDate = "START_DATE_EQUALS_END_DATE",
|
|
9
|
+
endTimeBeforeStartTime = "END_TIME_BEFORE_START_TIME",
|
|
10
|
+
startTimeEqualsEndTime = "START_TIME_EQUALS_END_TIME",
|
|
11
|
+
integer = "INTEGER",
|
|
12
|
+
positiveNumber = "POSITIVE_NUMBER",
|
|
13
|
+
fileSelected = "FILE_SELECTED",
|
|
14
|
+
default = "DEFAULT"
|
|
15
|
+
}
|
|
16
|
+
export enum ErrorsWithValuesKeysEnum {
|
|
17
|
+
minlength = "MIN_LENGTH",
|
|
18
|
+
maxlength = "MAX_LENGTH",
|
|
19
|
+
min = "MIN",
|
|
20
|
+
max = "MAX",
|
|
21
|
+
maxSize = "MAX_SIZE",
|
|
22
|
+
maxFiles = "MAX_FILES",
|
|
23
|
+
allowedTypes = "ALLOWED_TYPES"
|
|
24
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { inject, Injectable } from '@angular/core';
|
|
2
|
+
import { TranslateService } from '@ngx-translate/core';
|
|
3
|
+
import { InterpolationParameters } from '@ngx-translate/core';
|
|
4
|
+
import { BasicErrorKeysEnum, ErrorsWithValuesKeysEnum } from './error-keys.enum';
|
|
5
|
+
|
|
6
|
+
@Injectable({
|
|
7
|
+
providedIn: 'root',
|
|
8
|
+
})
|
|
9
|
+
export class FormValidationService {
|
|
10
|
+
private translate = inject(TranslateService);
|
|
11
|
+
|
|
12
|
+
private getTranslation(key: string, interpolateParams?: InterpolationParameters): string {
|
|
13
|
+
return this.translate.instant(`VALIDATION.${key}`, interpolateParams);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getErrorMessage(errorKey: string, errorValue: any): string {
|
|
17
|
+
if (this.isBasicErrorKey(errorKey)) {
|
|
18
|
+
return this.getTranslation(BasicErrorKeysEnum[errorKey as keyof typeof BasicErrorKeysEnum]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (this.isErrorWithValueKey(errorKey)) {
|
|
22
|
+
return this.getErrorWithValueMessage(
|
|
23
|
+
errorKey as keyof typeof ErrorsWithValuesKeysEnum,
|
|
24
|
+
errorValue
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this.getTranslation(BasicErrorKeysEnum.default);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Basic error keys are the keys that don't have any values to interpolate. like required, email, etc.
|
|
32
|
+
private isBasicErrorKey(key: string): key is keyof typeof BasicErrorKeysEnum {
|
|
33
|
+
return Object.keys(BasicErrorKeysEnum).includes(key as BasicErrorKeysEnum);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Error keys with values are the keys that have values to interpolate. like minlength, maxlength, etc.
|
|
37
|
+
private isErrorWithValueKey(key: string): key is keyof typeof ErrorsWithValuesKeysEnum {
|
|
38
|
+
return Object.keys(ErrorsWithValuesKeysEnum).includes(key as ErrorsWithValuesKeysEnum);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private getErrorWithValueMessage(
|
|
42
|
+
errorKey: keyof typeof ErrorsWithValuesKeysEnum,
|
|
43
|
+
errorValue: any
|
|
44
|
+
): string {
|
|
45
|
+
const messages: Record<keyof typeof ErrorsWithValuesKeysEnum, (value: any) => string> = {
|
|
46
|
+
minlength: (val) =>
|
|
47
|
+
this.getTranslation(ErrorsWithValuesKeysEnum.minlength, {
|
|
48
|
+
requiredLength: val?.requiredLength,
|
|
49
|
+
actualLength: val?.actualLength,
|
|
50
|
+
}),
|
|
51
|
+
maxlength: (val) =>
|
|
52
|
+
this.getTranslation(ErrorsWithValuesKeysEnum.maxlength, {
|
|
53
|
+
requiredLength: val?.requiredLength,
|
|
54
|
+
actualLength: val?.actualLength,
|
|
55
|
+
}),
|
|
56
|
+
min: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.min, { min: val?.min }),
|
|
57
|
+
max: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.max, { max: val?.max }),
|
|
58
|
+
maxSize: (val) =>
|
|
59
|
+
this.getTranslation(ErrorsWithValuesKeysEnum.maxSize, { size: val?.requiredLength }),
|
|
60
|
+
maxFiles: (val) =>
|
|
61
|
+
this.getTranslation(ErrorsWithValuesKeysEnum.maxFiles, { size: val?.requiredLength }),
|
|
62
|
+
allowedTypes: (val) =>
|
|
63
|
+
this.getTranslation(ErrorsWithValuesKeysEnum.allowedTypes, { types: val?.join(', ') }),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return messages[errorKey](errorValue);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { inject, Pipe, PipeTransform } from "@angular/core";
|
|
2
|
+
import { ValidationErrors } from "@angular/forms";
|
|
3
|
+
import { FormValidationService } from "./form-validation.service";
|
|
4
|
+
|
|
5
|
+
@Pipe({
|
|
6
|
+
name: "validationErrors",
|
|
7
|
+
standalone: true,
|
|
8
|
+
pure: true
|
|
9
|
+
})
|
|
10
|
+
export class ValidationErrorsPipe implements PipeTransform {
|
|
11
|
+
private formValidationService = inject(FormValidationService);
|
|
12
|
+
|
|
13
|
+
// allowed keys here to handle errors in case of cross-validators like startDate and endDate validators,
|
|
14
|
+
// we pass this custom key to handle the error messages only for the allowed keys
|
|
15
|
+
transform(errors: ValidationErrors | null, allowedKeys?: string[]): string[] {
|
|
16
|
+
if (!errors) return [];
|
|
17
|
+
|
|
18
|
+
return Object.keys(errors)
|
|
19
|
+
.filter((errorKey) => !allowedKeys || allowedKeys.includes(errorKey)) // Filter errors if allowedKeys are provided
|
|
20
|
+
.map((errorKey) => {
|
|
21
|
+
return this.formValidationService.getErrorMessage(errorKey, errors[errorKey]);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<div class="field flex flex-col gap-2 my-3 relative">
|
|
2
|
+
@if (!required) {
|
|
3
|
+
<span class="absolute top-[6px] left-0 text-[10px] text-gray-400">{{'forms.config.optional' | translate}}</span>
|
|
4
|
+
}
|
|
5
|
+
<p-floatlabel [variant]="variant">
|
|
6
|
+
<p-auto-complete (completeMethod)="search($event)" (onSelect)="onSelect($event)" [delay]="delay"
|
|
7
|
+
[disabled]="disabled" [formControl]="control" [id]="inputId" fluid [typeahead]="typeAhead"
|
|
8
|
+
[inputStyleClass]="'reset-default-styles w-full' + (basicInput ? ' basic-style': ' ')"
|
|
9
|
+
[minLength]="minLengthToSearch" [name]="name" [ngClass]="{ 'p-invalid ng-dirty ng-invalid': isInvalid}"
|
|
10
|
+
[placeholder]="placeholder" [styleClass]="'w-full'" multiple [suggestions]="items">
|
|
11
|
+
<ng-template let-item pTemplate="item">
|
|
12
|
+
@if (selectedItemTemplate) {
|
|
13
|
+
<ng-container [ngTemplateOutletContext]="{ $implicit: item }" [ngTemplateOutlet]="selectedItemTemplate" />
|
|
14
|
+
}
|
|
15
|
+
</ng-template>
|
|
16
|
+
</p-auto-complete>
|
|
17
|
+
<label [for]="inputId">
|
|
18
|
+
{{ label }}
|
|
19
|
+
@if (required) {
|
|
20
|
+
<span [class.text-required]="isInvalid">*</span>
|
|
21
|
+
}
|
|
22
|
+
</label>
|
|
23
|
+
</p-floatlabel>
|
|
24
|
+
@if (hint) {
|
|
25
|
+
<small class="p-mt-1">{{ hint }}</small>
|
|
26
|
+
}
|
|
27
|
+
@if (isInvalid && (control.dirty || control.touched)) {
|
|
28
|
+
<small class="p-error">
|
|
29
|
+
@for (error of control.errors | validationErrors; track error) {
|
|
30
|
+
{{ error }}<br>
|
|
31
|
+
}
|
|
32
|
+
</small>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { AutoCompleteComponent } from './auto-complete.component';
|
|
3
|
+
|
|
4
|
+
describe('AutoCompleteComponent', () => {
|
|
5
|
+
let component: AutoCompleteComponent;
|
|
6
|
+
let fixture: ComponentFixture<AutoCompleteComponent>;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
await TestBed.configureTestingModule({
|
|
10
|
+
imports: [AutoCompleteComponent],
|
|
11
|
+
}).compileComponents();
|
|
12
|
+
|
|
13
|
+
fixture = TestBed.createComponent(AutoCompleteComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { JsonPipe, NgClass, NgIf, NgTemplateOutlet } from '@angular/common';
|
|
2
|
+
import { Component, EventEmitter, Input, Output, TemplateRef } from '@angular/core';
|
|
3
|
+
import { ReactiveFormsModule } from '@angular/forms';
|
|
4
|
+
import { TranslatePipe } from '@ngx-translate/core';
|
|
5
|
+
import { PrimeTemplate } from 'primeng/api';
|
|
6
|
+
import {
|
|
7
|
+
AutoComplete,
|
|
8
|
+
AutoCompleteCompleteEvent,
|
|
9
|
+
AutoCompleteSelectEvent,
|
|
10
|
+
} from 'primeng/autocomplete';
|
|
11
|
+
import { FloatLabel } from 'primeng/floatlabel';
|
|
12
|
+
import { ValidationErrorsPipe } from '../../@utils/validations/validation-message.pipe';
|
|
13
|
+
import { BaseInputComponent } from '../base-input.component';
|
|
14
|
+
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'stc-auto-complete',
|
|
17
|
+
standalone: true,
|
|
18
|
+
imports: [
|
|
19
|
+
ReactiveFormsModule,
|
|
20
|
+
AutoComplete,
|
|
21
|
+
PrimeTemplate,
|
|
22
|
+
NgIf,
|
|
23
|
+
NgTemplateOutlet,
|
|
24
|
+
NgClass,
|
|
25
|
+
JsonPipe,
|
|
26
|
+
ValidationErrorsPipe,
|
|
27
|
+
TranslatePipe,
|
|
28
|
+
FloatLabel,
|
|
29
|
+
],
|
|
30
|
+
templateUrl: './auto-complete.component.html',
|
|
31
|
+
styleUrl: './auto-complete.component.scss',
|
|
32
|
+
})
|
|
33
|
+
export class AutoCompleteComponent extends BaseInputComponent {
|
|
34
|
+
@Input() selectedItemTemplate: TemplateRef<unknown> | null = null;
|
|
35
|
+
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
|
|
36
|
+
@Output() onSearch: EventEmitter<string> = new EventEmitter<string>();
|
|
37
|
+
@Output() selectOption: EventEmitter<AutoCompleteSelectEvent> =
|
|
38
|
+
new EventEmitter<AutoCompleteSelectEvent>();
|
|
39
|
+
@Input() items: any[] = [];
|
|
40
|
+
@Input() minLengthToSearch = 3;
|
|
41
|
+
@Input() delay = 300; // default value
|
|
42
|
+
@Input() basicInput!: boolean;
|
|
43
|
+
@Input() typeAhead: boolean = false;
|
|
44
|
+
@Input() variant: 'in' | 'over' | 'on' = 'over';
|
|
45
|
+
|
|
46
|
+
constructor() {
|
|
47
|
+
super();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
search(event: AutoCompleteCompleteEvent) {
|
|
51
|
+
this.onSearch.emit(event.query);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onSelect(event: AutoCompleteSelectEvent) {
|
|
55
|
+
this.selectOption.emit(event);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
|
2
|
+
import { FormControl, Validators } from '@angular/forms';
|
|
3
|
+
import { Subject, takeUntil } from 'rxjs';
|
|
4
|
+
@Component({
|
|
5
|
+
template: '',
|
|
6
|
+
})
|
|
7
|
+
export abstract class BaseInputComponent implements OnInit, OnDestroy {
|
|
8
|
+
@Input({ required: true }) control!: FormControl;
|
|
9
|
+
@Input() name: string = '';
|
|
10
|
+
@Input() label?: string;
|
|
11
|
+
@Input() placeholder: string = '';
|
|
12
|
+
@Input() inputId!: string;
|
|
13
|
+
@Input() readonly: boolean = false;
|
|
14
|
+
@Input() disabled: boolean = false;
|
|
15
|
+
@Input() hint?: string;
|
|
16
|
+
|
|
17
|
+
protected destroy$ = new Subject<void>();
|
|
18
|
+
|
|
19
|
+
get required(): boolean {
|
|
20
|
+
return this.control.hasValidator(Validators.required);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get isInvalid(): boolean {
|
|
24
|
+
return this.control.invalid && this.control.touched;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
ngOnInit() {
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ngOnDestroy(): void {
|
|
32
|
+
this.destroy$.next();
|
|
33
|
+
this.destroy$.complete();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<div class="field flex flex-col gap-2 my-3 relative">
|
|
2
|
+
|
|
3
|
+
<p-floatlabel [variant]="variant">
|
|
4
|
+
<p-datepicker [selectionMode]="selectionMode" [disabled]="disabled" [formControl]="control" [iconDisplay]="'input'"
|
|
5
|
+
[showClear]="showClear" (onClear)="afterClearDate()" [inputId]="inputId"
|
|
6
|
+
[inputStyleClass]="'reset-default-styles ' + (basicInput ? 'basic-style' : '')"
|
|
7
|
+
[ngClass]="{ 'p-invalid ng-dirty ng-invalid': isInvalid }" [placeholder]="placeholder" [showIcon]="showIcon"
|
|
8
|
+
[class]="'w-full'" appendTo="body" [timeOnly]="isTimeOnly" [hourFormat]="hourFormat" [minDate]="minDate"
|
|
9
|
+
[maxDate]="maxDate" panelStyleClass="d-ltr">
|
|
10
|
+
@if (isTimeOnly) {
|
|
11
|
+
<ng-template #inputicon let-clickCallBack="clickCallBack">
|
|
12
|
+
<i class="text-[18px] font-icon-time-clock" (click)="clickCallBack($event)"></i>
|
|
13
|
+
</ng-template>
|
|
14
|
+
<ng-template pTemplate="footer">
|
|
15
|
+
<div class="p-datepicker-buttonbar">
|
|
16
|
+
<button pButton type="button" class="p-button-text" (click)="selectCurrentTime($event)">الان
|
|
17
|
+
</button>
|
|
18
|
+
<button pButton type="button" class="p-button-text" (click)="clearButtonClick($event)"> الغاء</button>
|
|
19
|
+
</div>
|
|
20
|
+
</ng-template>
|
|
21
|
+
}
|
|
22
|
+
</p-datepicker>
|
|
23
|
+
|
|
24
|
+
<label [for]="inputId">
|
|
25
|
+
{{ label }}
|
|
26
|
+
@if (required) {
|
|
27
|
+
<span [class.text-required]="required">*</span>
|
|
28
|
+
}
|
|
29
|
+
</label>
|
|
30
|
+
</p-floatlabel>
|
|
31
|
+
@if (hint) {
|
|
32
|
+
<small class="p-mt-1">{{ hint }}</small>
|
|
33
|
+
}
|
|
34
|
+
@if (isInvalid && (control.dirty || control.touched)) {
|
|
35
|
+
<small class="p-error">
|
|
36
|
+
@for (error of control.errors | validationErrors; track error) {
|
|
37
|
+
{{ error }}<br>
|
|
38
|
+
}
|
|
39
|
+
</small>
|
|
40
|
+
}
|
|
41
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.p-datepicker-clear-icon {
|
|
2
|
+
@apply cursor-pointer absolute top-[50%] left-[13px] -translate-y-1/2 text-[var(--p-datepicker-input-icon-color)] ml-[calc(var(--p-icon-size))] leading-none;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.d-ltr{
|
|
6
|
+
direction: ltr;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
.text-required {
|
|
11
|
+
color: red;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.p-error {
|
|
15
|
+
color: #dc2626;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { DatePickerComponent } from 'nx-BOD-workspace/libs/ui-components/src/lib/form-components/components/date-picker/date-picker.component';
|
|
3
|
+
|
|
4
|
+
describe('DatePickerComponent', () => {
|
|
5
|
+
let component: DatePickerComponent;
|
|
6
|
+
let fixture: ComponentFixture<DatePickerComponent>;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
await TestBed.configureTestingModule({
|
|
10
|
+
imports: [DatePickerComponent],
|
|
11
|
+
}).compileComponents();
|
|
12
|
+
|
|
13
|
+
fixture = TestBed.createComponent(DatePickerComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NgClass } from '@angular/common';
|
|
2
|
+
import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
|
|
3
|
+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
4
|
+
import { TranslatePipe } from '@ngx-translate/core';
|
|
5
|
+
import { DatePicker, DatePickerModule } from 'primeng/datepicker';
|
|
6
|
+
import { FloatLabelModule } from 'primeng/floatlabel';
|
|
7
|
+
import { ValidationErrorsPipe } from '../../@utils/validations/validation-message.pipe';
|
|
8
|
+
import { BaseInputComponent } from '../base-input.component';
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'stc-date-picker',
|
|
11
|
+
standalone: true,
|
|
12
|
+
imports: [
|
|
13
|
+
FormsModule,
|
|
14
|
+
DatePicker,
|
|
15
|
+
ReactiveFormsModule,
|
|
16
|
+
NgClass,
|
|
17
|
+
DatePickerModule,
|
|
18
|
+
ValidationErrorsPipe,
|
|
19
|
+
FloatLabelModule,
|
|
20
|
+
],
|
|
21
|
+
templateUrl: './date-picker.component.html',
|
|
22
|
+
styleUrl: './date-picker.component.scss',
|
|
23
|
+
encapsulation: ViewEncapsulation.None,
|
|
24
|
+
})
|
|
25
|
+
export class DatePickerComponent extends BaseInputComponent {
|
|
26
|
+
@Input() showIcon: boolean = false;
|
|
27
|
+
@Input() showClear: boolean = false;
|
|
28
|
+
@Input() basicInput!: boolean;
|
|
29
|
+
@Input() isTimeOnly: boolean = false;
|
|
30
|
+
@Input() minDate: Date | undefined | null;
|
|
31
|
+
@Input() maxDate: Date | undefined | null;
|
|
32
|
+
@Input() hourFormat: '12' | '24' = '12';
|
|
33
|
+
nowTime = new Date();
|
|
34
|
+
@Input() selectionMode: 'single' | 'range' = 'single';
|
|
35
|
+
@Output() onAfterClearDate = new EventEmitter<void>();
|
|
36
|
+
@Input() variant: 'in' | 'over' | 'on' = 'over';
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
selectCurrentTime(e: any) {
|
|
43
|
+
this.control.setValue(this.nowTime);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
clearButtonClick(e: any) {
|
|
47
|
+
this.control.setValue(null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
afterClearDate() {
|
|
51
|
+
this.control.reset();
|
|
52
|
+
this.onAfterClearDate.emit();
|
|
53
|
+
}
|
|
54
|
+
}
|