@solidev/data 0.0.1-alpha.0 → 0.0.1-alpha.2

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.
@@ -3,8 +3,8 @@ import { InjectionToken, PLATFORM_ID, Injectable, Inject, Optional, Component, I
3
3
  import 'reflect-metadata';
4
4
  import * as i2$2 from '@angular/forms';
5
5
  import { FormControl, Validators, FormGroup, UntypedFormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR, UntypedFormGroup } from '@angular/forms';
6
- import { throwError, ReplaySubject, combineLatest, share, of, takeUntil, NEVER, debounceTime, Subject, distinctUntilChanged, isObservable, firstValueFrom, timer, Observable, BehaviorSubject } from 'rxjs';
7
- import { tap, switchMap, map, filter, mergeMap, finalize, catchError, take } from 'rxjs/operators';
6
+ import { throwError, ReplaySubject, share, combineLatest, of, takeUntil, NEVER, Subject, debounceTime, distinctUntilChanged, isObservable, firstValueFrom, timer, Observable, BehaviorSubject } from 'rxjs';
7
+ import { tap, switchMap, map, throttleTime, filter, mergeMap, finalize, catchError, take } from 'rxjs/operators';
8
8
  import * as i2 from '@angular/platform-browser';
9
9
  import { makeStateKey } from '@angular/platform-browser';
10
10
  import * as i1$1 from '@angular/common';
@@ -495,11 +495,25 @@ class Queryset {
495
495
  this.pageSize = 500;
496
496
  /** Current page number */
497
497
  this.page = 1;
498
- this._pristine = true;
499
498
  this._loading = new ReplaySubject(1);
499
+ /** Loading status (true if currently fetching data) */
500
+ this.loading = this._loading.asObservable().pipe(share());
500
501
  this._meta = new ReplaySubject(1);
502
+ /** Results meta part observable */
503
+ this.meta = this._meta.asObservable().pipe(share());
501
504
  this._results = new ReplaySubject(1);
505
+ /** Results data part observable */
506
+ this.results = this._results.asObservable().pipe(share());
507
+ this._full = combineLatest([
508
+ this.results,
509
+ this.loading,
510
+ this.meta,
511
+ ]);
512
+ /** Full results observable (results, loading, meta) */
513
+ this.full = this._full.pipe(share());
514
+ this._pristine = true;
502
515
  /** Default options */
516
+ // console.log('@solidev/data: Creating collection', _coll);
503
517
  this.options = { emitFields: true };
504
518
  Object.assign(this.options, options);
505
519
  }
@@ -507,25 +521,6 @@ class Queryset {
507
521
  get pristine() {
508
522
  return this._pristine;
509
523
  }
510
- /** Loading status (true if currently fetching data) */
511
- get loading() {
512
- return this._loading.asObservable();
513
- }
514
- /** Results meta part observable */
515
- get meta() {
516
- return this._meta.asObservable();
517
- }
518
- /** Results data part observable */
519
- get results() {
520
- return this._results.asObservable();
521
- }
522
- /** Full results observable (results, loading, meta) */
523
- get full() {
524
- if (!this._full) {
525
- this._full = combineLatest([this.results, this.loading, this.meta]);
526
- }
527
- return this._full.pipe(share());
528
- }
529
524
  /**
530
525
  * Update current filter data. Null or undefined values are removed from filter data.
531
526
  * @param params filter data
@@ -601,10 +596,11 @@ class Queryset {
601
596
  return f;
602
597
  }
603
598
  get(refresh = true) {
604
- console.log('queryset:get', this, refresh);
605
599
  if (!refresh && !this._pristine) {
600
+ // console.log('@solidev/data: Get not refreshing, return current result observable');
606
601
  return this.results;
607
602
  }
603
+ // console.log('@solidev/data: start get (query)');
608
604
  this._loading.next(true);
609
605
  return this._coll
610
606
  .raw({
@@ -613,6 +609,7 @@ class Queryset {
613
609
  })
614
610
  .pipe(switchMap((result) => {
615
611
  // Process results
612
+ // console.log('@solidev/data: have meta');
616
613
  this._meta.next({ nav: result.nav, parameters: result.parameters });
617
614
  const out = [];
618
615
  for (const r of result.results) {
@@ -620,8 +617,11 @@ class Queryset {
620
617
  out.push(m);
621
618
  }
622
619
  this._pristine = false;
620
+ // console.log('@solidev/data: have loading');
623
621
  this._loading.next(false);
622
+ // console.log('@solidev/data: have result');
624
623
  this._results.next(out);
624
+ // console.log('@solidev/data: done get');
625
625
  return this.results;
626
626
  }));
627
627
  }
@@ -1305,7 +1305,7 @@ class ModelList {
1305
1305
  get results() {
1306
1306
  if (!this._results) {
1307
1307
  this._results = this.queryset.results.pipe(
1308
- // tap(() => console.log('RESULTS')),
1308
+ // tap(() => console.log('@solidev/data: modellist result')),
1309
1309
  share(), takeUntil(this.unsubscribe || NEVER));
1310
1310
  }
1311
1311
  return this._results;
@@ -1313,7 +1313,7 @@ class ModelList {
1313
1313
  get meta() {
1314
1314
  if (!this._meta) {
1315
1315
  this._meta = this.queryset.meta.pipe(
1316
- // tap(() => console.log('META')),
1316
+ // tap(() => console.log('@solidev/data: modellist meta')),
1317
1317
  share(), takeUntil(this.unsubscribe || NEVER));
1318
1318
  }
1319
1319
  return this._meta;
@@ -1321,7 +1321,7 @@ class ModelList {
1321
1321
  get loading() {
1322
1322
  if (!this._loading) {
1323
1323
  this._loading = this.queryset.loading.pipe(
1324
- // tap(() => console.log('LOADING')),
1324
+ // tap(() => console.log('@solidev/data: modellist loading')),
1325
1325
  share(), takeUntil(this.unsubscribe || NEVER));
1326
1326
  }
1327
1327
  return this._loading;
@@ -1329,7 +1329,7 @@ class ModelList {
1329
1329
  get full() {
1330
1330
  if (!this._full) {
1331
1331
  this._full = this.queryset.full.pipe(
1332
- // tap(() => console.log('FULL')),
1332
+ // tap(() => console.log('@solidev/data: modellist full')),
1333
1333
  share(), takeUntil(this.unsubscribe || NEVER));
1334
1334
  }
1335
1335
  return this._full;
@@ -1353,7 +1353,7 @@ class ModelList {
1353
1353
  this.sorter.output,
1354
1354
  this.fields.output,
1355
1355
  ])
1356
- .pipe(debounceTime(200), switchMap(([reload, filter, manualFilter, paginator, sorter, fields]) => {
1356
+ .pipe(throttleTime(200), switchMap(([reload, filter, manualFilter, paginator, sorter, fields]) => {
1357
1357
  this.queryset
1358
1358
  .filter(filter)
1359
1359
  .filter(manualFilter || {}, true)
@@ -1364,12 +1364,14 @@ class ModelList {
1364
1364
  return this.queryset.get(true);
1365
1365
  }), takeUntil(this.unsubscribe || NEVER))
1366
1366
  .subscribe({
1367
- next: (results) => { },
1367
+ next: (results) => {
1368
+ // console.log('@solidev/data: modellist:get results');
1369
+ },
1368
1370
  error: (error) => {
1369
- console.error('Error while getting model list results : ', error);
1371
+ console.error('@solidev/data: error while getting model list results : ', error);
1370
1372
  },
1371
1373
  complete: () => {
1372
- // console.log('modellist:completed', this.name);
1374
+ // console.log('@solidev/data: modellist:completed', this.name);
1373
1375
  this.started = false;
1374
1376
  },
1375
1377
  });
@@ -2546,6 +2548,45 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImpor
2546
2548
  standalone: true,
2547
2549
  }]
2548
2550
  }] });
2551
+ class PChoicePipe {
2552
+ transform(value, model, field, mode = 'desc') {
2553
+ if (!model) {
2554
+ return '-';
2555
+ }
2556
+ if (!value) {
2557
+ return '-';
2558
+ }
2559
+ const fvalue = model[field];
2560
+ if (mode === 'code') {
2561
+ return `${fvalue}`;
2562
+ }
2563
+ const manager = model.FM(field);
2564
+ const choices = manager.choices;
2565
+ if (!choices) {
2566
+ return `${fvalue}`;
2567
+ }
2568
+ for (const ch of choices) {
2569
+ if (ch.value === fvalue) {
2570
+ if (mode === 'desc') {
2571
+ return ch.desc;
2572
+ }
2573
+ else {
2574
+ return `[${fvalue}] ${ch.desc}`;
2575
+ }
2576
+ }
2577
+ }
2578
+ return `[${fvalue}] ??`;
2579
+ }
2580
+ }
2581
+ PChoicePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: PChoicePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2582
+ PChoicePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.9", ngImport: i0, type: PChoicePipe, isStandalone: true, name: "pchoice" });
2583
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: PChoicePipe, decorators: [{
2584
+ type: Pipe,
2585
+ args: [{
2586
+ name: 'pchoice',
2587
+ standalone: true,
2588
+ }]
2589
+ }] });
2549
2590
 
2550
2591
  function isValue(value) {
2551
2592
  return !(value == null || value === '' || value !== value);
@@ -2593,6 +2634,40 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImpor
2593
2634
  args: [LOCALE_ID]
2594
2635
  }] }];
2595
2636
  } });
2637
+ class PFactorPipe {
2638
+ constructor(_locale) {
2639
+ this._locale = _locale;
2640
+ }
2641
+ transform(value, model, field, digitsInfo, locale) {
2642
+ if (!model)
2643
+ return null;
2644
+ if (!value)
2645
+ return null;
2646
+ locale = locale || this._locale;
2647
+ const fvalue = model[field];
2648
+ if (!isValue(fvalue))
2649
+ return null;
2650
+ const manager = model.FM(field);
2651
+ let factor = manager.factor;
2652
+ factor = factor || 1;
2653
+ const num = strToNumber(fvalue);
2654
+ return formatNumber(num / factor, locale, digitsInfo);
2655
+ }
2656
+ }
2657
+ PFactorPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: PFactorPipe, deps: [{ token: LOCALE_ID }], target: i0.ɵɵFactoryTarget.Pipe });
2658
+ PFactorPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.9", ngImport: i0, type: PFactorPipe, isStandalone: true, name: "pfactor" });
2659
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: PFactorPipe, decorators: [{
2660
+ type: Pipe,
2661
+ args: [{
2662
+ name: 'pfactor',
2663
+ standalone: true,
2664
+ }]
2665
+ }], ctorParameters: function () {
2666
+ return [{ type: undefined, decorators: [{
2667
+ type: Inject,
2668
+ args: [LOCALE_ID]
2669
+ }] }];
2670
+ } });
2596
2671
 
2597
2672
  class FactorcPipe {
2598
2673
  constructor(_locale, _defaultCurrencyCode = 'EUR') {
@@ -2641,6 +2716,55 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImpor
2641
2716
  args: [DEFAULT_CURRENCY_CODE]
2642
2717
  }] }];
2643
2718
  } });
2719
+ class PFactorcPipe {
2720
+ constructor(_locale, _defaultCurrencyCode = 'EUR') {
2721
+ this._locale = _locale;
2722
+ this._defaultCurrencyCode = _defaultCurrencyCode;
2723
+ }
2724
+ transform(value, model, field, currencyCode, display, digitsInfo, locale) {
2725
+ if (!model)
2726
+ return null;
2727
+ if (!value)
2728
+ return null;
2729
+ const fvalue = model[field];
2730
+ if (!isValue(fvalue))
2731
+ return null;
2732
+ locale = locale || this._locale;
2733
+ let currency = currencyCode || this._defaultCurrencyCode;
2734
+ if (!display) {
2735
+ display = 'symbol';
2736
+ }
2737
+ if (display !== 'code') {
2738
+ if (display === 'symbol' || display === 'symbol-narrow') {
2739
+ currency = getCurrencySymbol(currency, display === 'symbol' ? 'wide' : 'narrow', locale);
2740
+ }
2741
+ else {
2742
+ currency = display;
2743
+ }
2744
+ }
2745
+ const manager = model.FM(field);
2746
+ const factor = manager.factor || 1;
2747
+ const num = strToNumber(fvalue);
2748
+ return formatCurrency(num / factor, locale, currency, currencyCode, digitsInfo);
2749
+ }
2750
+ }
2751
+ PFactorcPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: PFactorcPipe, deps: [{ token: LOCALE_ID }, { token: DEFAULT_CURRENCY_CODE }], target: i0.ɵɵFactoryTarget.Pipe });
2752
+ PFactorcPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.9", ngImport: i0, type: PFactorcPipe, isStandalone: true, name: "pfactorc" });
2753
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.9", ngImport: i0, type: PFactorcPipe, decorators: [{
2754
+ type: Pipe,
2755
+ args: [{
2756
+ name: 'pfactorc',
2757
+ standalone: true,
2758
+ }]
2759
+ }], ctorParameters: function () {
2760
+ return [{ type: undefined, decorators: [{
2761
+ type: Inject,
2762
+ args: [LOCALE_ID]
2763
+ }] }, { type: undefined, decorators: [{
2764
+ type: Inject,
2765
+ args: [DEFAULT_CURRENCY_CODE]
2766
+ }] }];
2767
+ } });
2644
2768
 
2645
2769
  class FkselectComponent {
2646
2770
  constructor() {
@@ -5407,5 +5531,5 @@ const slugify = (str) => {
5407
5531
  * Generated bundle index. Do not edit.
5408
5532
  */
5409
5533
 
5410
- export { AuthInterceptor, AuthServiceBase, BanAdapter, BootstrapDataDisplayConfig, BreadcrumbComponent, ChoicePipe, Collection, CollectionMock, DATA_API_URL, DATA_AUTH_PARAMS, DATA_AUTH_SERVICE, DATA_AUTH_USER_SERVICE, DATA_DISPLAY_CONFIG, DATA_MAX_TRANSFERSTATE_TIME, DATA_MESSAGE_SOUNDS, DEFAULT_TIMEOUTS, DataBackend, DataMessageService, DataModel, DataUploaderService, DispeditComponent, FactorPipe, FactorcPipe, FkselectComponent, FlagsComponent, Jwt, Link, M2mselectComponent, Message, MessageZoneComponent, ModelList, ModelListAutocompleteFilter, ModelListAutocompleteMultiFilter, ModelListDateFilter, ModelListDatetimeFilter, ModelListDatetimerangeFilter, ModelListFieldHeaderComponent, ModelListFieldsSelectorComponent, ModelListFilters, ModelListFiltersComponent, ModelListFiltersSelectComponent, ModelListFlagsFilter, ModelListGeodistanceFilter, ModelListNumberFilter, ModelListNumberOperations, ModelListPaginatorComponent, ModelListSelectFilter, ModelListSelectMultiFilter, ModelListService, ModelListSorterComponent, ModelListTextFilter, ModelListTreeFilter, NavDriver, NgFileDropDirective, NgFileSelectDirective, NgxUploaderModule, Queryset, RData, RicheditComponent, STATUS, SafeDeleteComponent, TabMemoryService, UploadStatus, booleanField, charField, dateField, datetimeField, decimalField, detailsField, emailField, floatField, foreignKeyField, humanizeBytes, integerField, isValue, manyToManyField, passwordField, primaryField, reverseForeignKeyField, slugify, strToNumber, textField };
5534
+ export { AuthInterceptor, AuthServiceBase, BanAdapter, BootstrapDataDisplayConfig, BreadcrumbComponent, ChoicePipe, Collection, CollectionMock, DATA_API_URL, DATA_AUTH_PARAMS, DATA_AUTH_SERVICE, DATA_AUTH_USER_SERVICE, DATA_DISPLAY_CONFIG, DATA_MAX_TRANSFERSTATE_TIME, DATA_MESSAGE_SOUNDS, DEFAULT_TIMEOUTS, DataBackend, DataMessageService, DataModel, DataUploaderService, DispeditComponent, FactorPipe, FactorcPipe, FkselectComponent, FlagsComponent, Jwt, Link, M2mselectComponent, Message, MessageZoneComponent, ModelList, ModelListAutocompleteFilter, ModelListAutocompleteMultiFilter, ModelListDateFilter, ModelListDatetimeFilter, ModelListDatetimerangeFilter, ModelListFieldHeaderComponent, ModelListFieldsSelectorComponent, ModelListFilters, ModelListFiltersComponent, ModelListFiltersSelectComponent, ModelListFlagsFilter, ModelListGeodistanceFilter, ModelListNumberFilter, ModelListNumberOperations, ModelListPaginatorComponent, ModelListSelectFilter, ModelListSelectMultiFilter, ModelListService, ModelListSorterComponent, ModelListTextFilter, ModelListTreeFilter, NavDriver, NgFileDropDirective, NgFileSelectDirective, NgxUploaderModule, PChoicePipe, PFactorPipe, PFactorcPipe, Queryset, RData, RicheditComponent, STATUS, SafeDeleteComponent, TabMemoryService, UploadStatus, booleanField, charField, dateField, datetimeField, decimalField, detailsField, emailField, floatField, foreignKeyField, humanizeBytes, integerField, isValue, manyToManyField, passwordField, primaryField, reverseForeignKeyField, slugify, strToNumber, textField };
5411
5535
  //# sourceMappingURL=solidev-data.mjs.map