dolfo-angular 1.209.0 → 1.211.0

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.
@@ -1,11 +1,13 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Input, ChangeDetectionStrategy, Component, InjectionToken, Injectable, inject, Inject, Pipe, EventEmitter, Output, ViewChild, signal, forwardRef, booleanAttribute, ChangeDetectorRef, ViewChildren, TemplateRef, ContentChild, EnvironmentInjector, createComponent, Injector, NgModule } from '@angular/core';
2
+ import { Directive, Input, ChangeDetectionStrategy, Component, InjectionToken, Injectable, inject, Inject, signal, Pipe, EventEmitter, Output, ViewChild, forwardRef, booleanAttribute, Injector, ChangeDetectorRef, ViewChildren, TemplateRef, ContentChild, EnvironmentInjector, createComponent, NgModule } from '@angular/core';
3
3
  import * as i1$1 from '@angular/forms';
4
4
  import { ControlContainer, FormControl, Validators, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormGroupDirective, FormGroup, ReactiveFormsModule } from '@angular/forms';
5
- import { BehaviorSubject, map, tap, distinctUntilChanged, filter, fromEvent, delay, mergeMap, catchError, of, race, zip } from 'rxjs';
5
+ import { BehaviorSubject, map, tap, distinctUntilChanged, filter, mergeMap, of, delay, catchError, throwError, zip, fromEvent, from, concatAll, race } from 'rxjs';
6
6
  import * as i1 from '@angular/common';
7
- import { formatDate, DecimalPipe, CommonModule } from '@angular/common';
8
- import { HttpClient } from '@angular/common/http';
7
+ import { formatDate, DecimalPipe, APP_BASE_HREF, CommonModule } from '@angular/common';
8
+ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
9
+ import * as i2 from '@angular/router';
10
+ import { Router } from '@angular/router';
9
11
  import * as i1$2 from '@angular/platform-browser';
10
12
  import { DomSanitizer } from '@angular/platform-browser';
11
13
 
@@ -126,6 +128,25 @@ const ICON_COMPONENT = new InjectionToken("ICON_COMPONENT", {
126
128
  factory: () => IconComponent
127
129
  });
128
130
 
131
+ const ROUTE_CHECK_SERVICE = new InjectionToken("ROUTE_CHECK_SERVICE", {
132
+ providedIn: "root",
133
+ factory: () => {
134
+ throw new Error("RouteCheckService not provided");
135
+ }
136
+ });
137
+
138
+ var StoreLists;
139
+ (function (StoreLists) {
140
+ StoreLists[StoreLists["EMPTY"] = 0] = "EMPTY";
141
+ })(StoreLists || (StoreLists = {}));
142
+ var StorageValues;
143
+ (function (StorageValues) {
144
+ StorageValues["TOKEN"] = "token";
145
+ StorageValues["LANG"] = "lang";
146
+ })(StorageValues || (StorageValues = {}));
147
+ const MAX_DEVICE_SIZE = 750;
148
+ const MAX_SMALL_DEVICE = 500;
149
+
129
150
  const TRANSLATE_STORAGE_KEY = "dolfo-lang-stored";
130
151
  const LANGUAGE_TOKEN = new InjectionToken("LANGUAGE_TOKEN");
131
152
  const provideDolfoLanguages = (langs, defaultLanguage) => ({
@@ -273,6 +294,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
273
294
  }]
274
295
  }], ctorParameters: () => [{ type: TranslateService }] });
275
296
 
297
+ class DialogUtilsService {
298
+ dialogService;
299
+ translateService;
300
+ constructor(dialogService, translateService) {
301
+ this.dialogService = dialogService;
302
+ this.translateService = translateService;
303
+ }
304
+ showLoading$ = (obs) => mergeMap(res => of(res).pipe(delay(0), tap(() => this.dialogService.showLoading().subscribe()), mergeMap(res => obs(res)), catchError(err => {
305
+ this.closeLatestDialog();
306
+ return throwError(() => err);
307
+ })));
308
+ hideLoading = () => this.closeLatestDialog();
309
+ closeLatestDialog = () => this.dialogService.close();
310
+ closeWithAction = (data) => {
311
+ this.dialogService.action({ type: DialogActionType.OK, data });
312
+ this.closeLatestDialog();
313
+ };
314
+ openDialogComponent = (component) => this.dialogService.openDialogComponent(component);
315
+ openDialog = (input) => this.dialogService.openDialog(input);
316
+ askConfirmAndLoad = (input, obs, getDialogResp = false) => this.dialogService.openDialog({
317
+ title: this.translateService.translate(input.title),
318
+ message: this.translateService.translate(input.message),
319
+ type: "confirm",
320
+ hideCloseX: input.hideCloseX,
321
+ width: input.width
322
+ }).pipe(filter(res => res.type === DialogActionType.OK || getDialogResp), this.showLoading$(res => obs(res.type)), tap(() => this.hideLoading()));
323
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogUtilsService, deps: [{ token: DialogService }, { token: TranslateService }], target: i0.ɵɵFactoryTarget.Injectable });
324
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogUtilsService, providedIn: "root" });
325
+ }
326
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogUtilsService, decorators: [{
327
+ type: Injectable,
328
+ args: [{
329
+ providedIn: "root"
330
+ }]
331
+ }], ctorParameters: () => [{ type: DialogService }, { type: TranslateService }] });
332
+
276
333
  class NotificationService {
277
334
  notification$ = new BehaviorSubject(null);
278
335
  history$ = new BehaviorSubject([]);
@@ -309,6 +366,72 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
309
366
  }]
310
367
  }] });
311
368
 
369
+ class RouteCheckService {
370
+ storeService = inject(StoreService);
371
+ routeService = inject(ROUTE_CHECK_SERVICE);
372
+ canActivate({ routeConfig }) {
373
+ if (!this.storeService.isInitialized())
374
+ return false;
375
+ return this.routeService.load$().pipe(catchError(() => of(null)), mergeMap(() => this.routeService.checkRoute(routeConfig.path)));
376
+ }
377
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RouteCheckService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
378
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RouteCheckService, providedIn: "root" });
379
+ }
380
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RouteCheckService, decorators: [{
381
+ type: Injectable,
382
+ args: [{
383
+ providedIn: "root"
384
+ }]
385
+ }] });
386
+
387
+ class StoreService extends Subscriptable {
388
+ appInitialized = signal(false, ...(ngDevMode ? [{ debugName: "appInitialized" }] : /* istanbul ignore next */ []));
389
+ constructor() {
390
+ super();
391
+ this.addSubscription(zip([
392
+ fromEvent(window, "keydown").pipe(filter(e => !this.isPressingCtrl() && e.ctrlKey), tap(() => this.setCtrlKey(true))),
393
+ fromEvent(window, "keyup").pipe(filter(e => this.isPressingCtrl() && e.key === "Control"), tap(() => this.setCtrlKey(false))),
394
+ fromEvent(window, "blur").pipe(filter(() => this.isPressingCtrl()), tap(() => this.setCtrlKey(false)))
395
+ ]).subscribe());
396
+ }
397
+ store$ = new BehaviorSubject({
398
+ lists: {},
399
+ entities: {},
400
+ pressingCtrl: false
401
+ });
402
+ addList = (key, list) => this.store$.next({
403
+ ...this.store$.getValue(),
404
+ lists: {
405
+ ...this.store$.getValue().lists,
406
+ [key]: list
407
+ }
408
+ });
409
+ getList = (key) => this.store$.getValue().lists[key];
410
+ addEntity = (key, entity) => this.store$.next({
411
+ ...this.store$.getValue(),
412
+ entities: {
413
+ ...this.store$.getValue().entities,
414
+ [key]: entity
415
+ }
416
+ });
417
+ getEntity = (key) => this.store$.getValue().entities[key];
418
+ setCtrlKey = (pressingCtrl) => this.store$.next({
419
+ ...this.store$.getValue(),
420
+ pressingCtrl
421
+ });
422
+ isPressingCtrl = () => this.store$.getValue().pressingCtrl;
423
+ isInitialized = () => this.appInitialized();
424
+ initialize = () => this.appInitialized.set(true);
425
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: StoreService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
426
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: StoreService, providedIn: "root" });
427
+ }
428
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: StoreService, decorators: [{
429
+ type: Injectable,
430
+ args: [{
431
+ providedIn: "root"
432
+ }]
433
+ }], ctorParameters: () => [] });
434
+
312
435
  class TooltipService {
313
436
  tooltip$ = new BehaviorSubject(null);
314
437
  showTooltip = (input) => this.tooltip$.next(input);
@@ -964,6 +1087,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
964
1087
  args: [{ transform: booleanAttribute }]
965
1088
  }] } });
966
1089
 
1090
+ class BaseAppComponent extends Subscriptable {
1091
+ injector = inject(Injector);
1092
+ router = inject(Router);
1093
+ storeService = inject(StoreService);
1094
+ loading = signal(0, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1095
+ loadingMessage = signal("...", ...(ngDevMode ? [{ debugName: "loadingMessage" }] : /* istanbul ignore next */ []));
1096
+ ngOnInit() {
1097
+ from(Object.values(this.streams)).pipe(concatAll(), tap(desc => {
1098
+ this.loading.update(item => item + 1);
1099
+ this.loadingMessage.set(desc + "...");
1100
+ })).subscribe(() => {
1101
+ if (this.loading() === Object.keys(this.streams).length) {
1102
+ setTimeout(() => {
1103
+ this.loadingMessage.set(null);
1104
+ this.storeService.initialize();
1105
+ this.router.initialNavigation();
1106
+ }, 500);
1107
+ }
1108
+ });
1109
+ }
1110
+ ngAfterViewInit() {
1111
+ new OverlayManager(this.injector, this.container).init().forEach(s => this.addSubscription(s));
1112
+ }
1113
+ get percentage() {
1114
+ return (this.loading() * 100) / Object.keys(this.streams).length;
1115
+ }
1116
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: BaseAppComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
1117
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: BaseAppComponent, isStandalone: true, usesInheritance: true, ngImport: i0 });
1118
+ }
1119
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: BaseAppComponent, decorators: [{
1120
+ type: Directive
1121
+ }] });
1122
+
967
1123
  class Formable extends Subscriptable {
968
1124
  formRef;
969
1125
  inputs;
@@ -2064,6 +2220,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2064
2220
  type: Input
2065
2221
  }] } });
2066
2222
 
2223
+ class NavigateDirective extends Subscriptable {
2224
+ elementRef;
2225
+ url;
2226
+ isLink;
2227
+ publicUrl = inject(APP_BASE_HREF);
2228
+ constructor(storeService, router, elementRef) {
2229
+ super();
2230
+ this.elementRef = elementRef;
2231
+ this.isLink = elementRef.nativeElement.tagName.toLocaleLowerCase() === "a";
2232
+ this.addSubscription(fromEvent(elementRef.nativeElement, "click").subscribe(e => {
2233
+ if (this.isLink)
2234
+ e.preventDefault();
2235
+ if (storeService.isPressingCtrl())
2236
+ this.openBlank();
2237
+ else
2238
+ router.navigateByUrl(this.url);
2239
+ }));
2240
+ this.addSubscription(fromEvent(elementRef.nativeElement, "mousedown").pipe(filter(e => e.button === 1)).subscribe(e => {
2241
+ if (this.isLink)
2242
+ e.stopPropagation();
2243
+ else
2244
+ this.openBlank();
2245
+ }));
2246
+ }
2247
+ ngOnChanges(changes) {
2248
+ if ((this.isLink || (changes.url && changes.url.currentValue !== this.url)) && !!this.url)
2249
+ this.elementRef.nativeElement.setAttribute("href", this.url);
2250
+ }
2251
+ openBlank = () => window.open(this.publicUrl + this.url, "_blank");
2252
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigateDirective, deps: [{ token: StoreService }, { token: i2.Router }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
2253
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: NavigateDirective, isStandalone: false, selector: "[dolfoNavigate]", inputs: { url: ["dolfoNavigate", "url"] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
2254
+ }
2255
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigateDirective, decorators: [{
2256
+ type: Directive,
2257
+ args: [{
2258
+ selector: "[dolfoNavigate]",
2259
+ standalone: false
2260
+ }]
2261
+ }], ctorParameters: () => [{ type: StoreService }, { type: i2.Router }, { type: i0.ElementRef }], propDecorators: { url: [{
2262
+ type: Input,
2263
+ args: [{ required: true, alias: "dolfoNavigate" }]
2264
+ }] } });
2265
+
2067
2266
  class PopoverDirective extends Subscriptable {
2068
2267
  el;
2069
2268
  ps;
@@ -2156,14 +2355,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2156
2355
 
2157
2356
  class DirectivesModule {
2158
2357
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2159
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective], exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective] });
2358
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective], exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective] });
2160
2359
  static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule });
2161
2360
  }
2162
2361
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, decorators: [{
2163
2362
  type: NgModule,
2164
2363
  args: [{
2165
- declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective],
2166
- exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective]
2364
+ declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective],
2365
+ exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective]
2167
2366
  }]
2168
2367
  }] });
2169
2368
 
@@ -2311,6 +2510,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2311
2510
  }]
2312
2511
  }] });
2313
2512
 
2513
+ const authInterceptor = (req, next) => {
2514
+ const translateService = inject(TranslateService), clone = req.clone({
2515
+ headers: req.headers.set("Client-lang", translateService.getLang().name)
2516
+ });
2517
+ if (!!localStorage.getItem(StorageValues.TOKEN)) {
2518
+ return next(clone.clone({
2519
+ headers: clone.headers.set("Authorization", "Bearer " + localStorage.getItem(StorageValues.TOKEN))
2520
+ }));
2521
+ }
2522
+ return next(clone);
2523
+ };
2524
+
2525
+ const errorInterceptor = (req, next) => {
2526
+ const notificationService = inject(NotificationService), translateService = inject(TranslateService);
2527
+ return next(req).pipe(catchError(err => {
2528
+ if (err instanceof HttpErrorResponse) {
2529
+ if (err.status === 401)
2530
+ localStorage.removeItem(StorageValues.TOKEN);
2531
+ notificationService.show({
2532
+ type: "error",
2533
+ title: translateService.translate("dialog.errorApi"),
2534
+ message: typeof err.error === "string" ? err.error : err.message
2535
+ });
2536
+ }
2537
+ return throwError(() => err);
2538
+ }));
2539
+ };
2540
+
2314
2541
  /*
2315
2542
  * Public API Surface of dolfo-angular
2316
2543
  */
@@ -2320,5 +2547,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2320
2547
  * Generated bundle index. Do not edit.
2321
2548
  */
2322
2549
 
2323
- export { AutocompleteComponent, BaseFormInput, ButtonComponent, CONTEXT_MENU_DESTROY_TOKEN, ColumnAlign, ColumnDataType, ComboboxComponent, ContextMenuComponent, ContextMenuDirective, ContextMenuService, DatepickerComponent, DialogActionType, DialogComponent, DialogContentComponent, DialogFooterComponent, DialogHeaderComponent, DialogLayoutComponent, DialogLayoutModule, DialogService, DirectivesModule, FormComponent, FormModule, Formable, GridComponent, GridConfig, GridModule, ICON_COMPONENT, IconComponent, IconWrapperComponent, InputCheckboxComponent, InputContainerComponent, InputRadioComponent, InputTextComponent, LANGUAGE_TOKEN, LayoutModule, LoaderComponent, NotificationComponent, NotificationService, OverlayManager, POPOVER_DESTROY_TOKEN, PopoverComponent, PopoverDirective, PopoverService, ScrollDragDirective, Subscriptable, TOOLTIP_DESTROY_TOKEN, TRANSLATE_STORAGE_KEY, TooltipComponent, TooltipDirective, TooltipService, TranslatePipe, TranslateService, isDeepEqual, passwordValidator, provideDolfoLanguages };
2550
+ export { AutocompleteComponent, BaseAppComponent, BaseFormInput, ButtonComponent, CONTEXT_MENU_DESTROY_TOKEN, ColumnAlign, ColumnDataType, ComboboxComponent, ContextMenuComponent, ContextMenuDirective, ContextMenuService, DatepickerComponent, DialogActionType, DialogComponent, DialogContentComponent, DialogFooterComponent, DialogHeaderComponent, DialogLayoutComponent, DialogLayoutModule, DialogService, DialogUtilsService, DirectivesModule, FormComponent, FormModule, Formable, GridComponent, GridConfig, GridModule, ICON_COMPONENT, IconComponent, IconWrapperComponent, InputCheckboxComponent, InputContainerComponent, InputRadioComponent, InputTextComponent, LANGUAGE_TOKEN, LayoutModule, LoaderComponent, MAX_DEVICE_SIZE, MAX_SMALL_DEVICE, NavigateDirective, NotificationComponent, NotificationService, OverlayManager, POPOVER_DESTROY_TOKEN, PopoverComponent, PopoverDirective, PopoverService, ROUTE_CHECK_SERVICE, RouteCheckService, ScrollDragDirective, StorageValues, StoreLists, StoreService, Subscriptable, TOOLTIP_DESTROY_TOKEN, TRANSLATE_STORAGE_KEY, TooltipComponent, TooltipDirective, TooltipService, TranslatePipe, TranslateService, authInterceptor, errorInterceptor, isDeepEqual, passwordValidator, provideDolfoLanguages };
2324
2551
  //# sourceMappingURL=dolfo-angular.mjs.map