@solidev/data 0.0.1-dev.0 → 0.0.1-dev.1

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,7 +3,7 @@ import { InjectionToken, PLATFORM_ID, Injectable, Inject, Optional, Component, I
3
3
  import 'reflect-metadata';
4
4
  import * as i3$1 from '@angular/forms';
5
5
  import { FormControl, Validators, FormGroup, UntypedFormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR, UntypedFormGroup } from '@angular/forms';
6
- import { throwError, ReplaySubject, combineLatest, of, takeUntil, debounceTime, Subject, distinctUntilChanged, timer, firstValueFrom, Observable, BehaviorSubject } from 'rxjs';
6
+ import { throwError, ReplaySubject, combineLatest, share, of, takeUntil, NEVER, debounceTime, Subject, distinctUntilChanged, timer, firstValueFrom, Observable, BehaviorSubject } from 'rxjs';
7
7
  import { tap, switchMap, map, mergeMap, finalize, catchError, filter, take } from 'rxjs/operators';
8
8
  import * as i2 from '@angular/platform-browser';
9
9
  import { makeStateKey } from '@angular/platform-browser';
@@ -520,7 +520,10 @@ class Queryset {
520
520
  }
521
521
  /** Full results observable (results, loading, meta) */
522
522
  get full() {
523
- return combineLatest([this.results, this.loading, this.meta]);
523
+ if (!this._full) {
524
+ this._full = combineLatest([this.results, this.loading, this.meta]);
525
+ }
526
+ return this._full.pipe(share());
524
527
  }
525
528
  /**
526
529
  * Update current filter data. Null or undefined values are removed from filter data.
@@ -597,6 +600,7 @@ class Queryset {
597
600
  return f;
598
601
  }
599
602
  get(refresh = true) {
603
+ console.log('queryset:get', this, refresh);
600
604
  if (!refresh && !this._pristine) {
601
605
  return this.results;
602
606
  }
@@ -1296,16 +1300,36 @@ class ModelList {
1296
1300
  this.name = name;
1297
1301
  }
1298
1302
  get results() {
1299
- return this.queryset.results;
1303
+ if (!this._results) {
1304
+ this._results = this.queryset.results.pipe(
1305
+ // tap(() => console.log('RESULTS')),
1306
+ share(), takeUntil(this.unsubscribe || NEVER));
1307
+ }
1308
+ return this._results;
1300
1309
  }
1301
1310
  get meta() {
1302
- return this.queryset.meta;
1311
+ if (!this._meta) {
1312
+ this._meta = this.queryset.meta.pipe(
1313
+ // tap(() => console.log('META')),
1314
+ share(), takeUntil(this.unsubscribe || NEVER));
1315
+ }
1316
+ return this._meta;
1303
1317
  }
1304
1318
  get loading() {
1305
- return this.queryset.loading;
1319
+ if (!this._loading) {
1320
+ this._loading = this.queryset.loading.pipe(
1321
+ // tap(() => console.log('LOADING')),
1322
+ share(), takeUntil(this.unsubscribe || NEVER));
1323
+ }
1324
+ return this._loading;
1306
1325
  }
1307
1326
  get full() {
1308
- return this.queryset.full;
1327
+ if (!this._full) {
1328
+ this._full = this.queryset.full.pipe(
1329
+ // tap(() => console.log('FULL')),
1330
+ share(), takeUntil(this.unsubscribe || NEVER));
1331
+ }
1332
+ return this._full;
1309
1333
  }
1310
1334
  start(params) {
1311
1335
  let filter$;
@@ -1326,7 +1350,7 @@ class ModelList {
1326
1350
  this.sorter.output,
1327
1351
  this.fields.output,
1328
1352
  ])
1329
- .pipe(takeUntil(this.unsubscribe), debounceTime(200), switchMap(([reload, filter, manualFilter, paginator, sorter, fields]) => {
1353
+ .pipe(debounceTime(200), switchMap(([reload, filter, manualFilter, paginator, sorter, fields]) => {
1330
1354
  this.queryset
1331
1355
  .filter(filter)
1332
1356
  .filter(manualFilter || {}, true)
@@ -1335,14 +1359,14 @@ class ModelList {
1335
1359
  .sort(...sorter)
1336
1360
  .setFields(fields);
1337
1361
  return this.queryset.get(true);
1338
- }))
1362
+ }), takeUntil(this.unsubscribe || NEVER))
1339
1363
  .subscribe({
1340
1364
  next: (results) => { },
1341
1365
  error: (error) => {
1342
1366
  console.error('Error while getting model list results : ', error);
1343
1367
  },
1344
1368
  complete: () => {
1345
- console.log('modellist:completed', this.name);
1369
+ // console.log('modellist:completed', this.name);
1346
1370
  this.started = false;
1347
1371
  },
1348
1372
  });
@@ -1352,11 +1376,11 @@ class ModelList {
1352
1376
  }
1353
1377
  class ModelListService {
1354
1378
  constructor() {
1355
- this._instances = {};
1379
+ this._instances = new Map();
1356
1380
  }
1357
1381
  get(name, collection, defaults) {
1358
1382
  let ml;
1359
- if (!name || !this._instances[name] || !defaults.keep) {
1383
+ if (!name || !this._instances.has(name) || !defaults.keep) {
1360
1384
  ml = new ModelList(name);
1361
1385
  ml.queryset = collection.queryset();
1362
1386
  ml.fields = new ModelListFields(collection, defaults.fields);
@@ -1364,11 +1388,11 @@ class ModelListService {
1364
1388
  ml.paginator = new ModelListPaginator(defaults.paginator);
1365
1389
  ml.filters = new ModelListFilters(defaults.filters);
1366
1390
  if (defaults.keep) {
1367
- this._instances[name] = ml;
1391
+ this._instances.set(name, ml);
1368
1392
  }
1369
1393
  }
1370
1394
  else {
1371
- ml = this._instances[name];
1395
+ ml = this._instances.get(name);
1372
1396
  }
1373
1397
  if (!ml.started) {
1374
1398
  if (defaults.reload) {
@@ -3317,6 +3341,7 @@ class SafeDeleteComponent {
3317
3341
  this._ofc = _ofc;
3318
3342
  this.checks = {};
3319
3343
  this.deleted = new EventEmitter();
3344
+ this.display = 'button';
3320
3345
  }
3321
3346
  async checkDelete(model) {
3322
3347
  this.result = await firstValueFrom(this.service.delete(this.model, { params: { doit: 'no' } }));
@@ -3331,10 +3356,10 @@ class SafeDeleteComponent {
3331
3356
  }
3332
3357
  }
3333
3358
  SafeDeleteComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: SafeDeleteComponent, deps: [{ token: i2$1.NgbOffcanvas }], target: i0.ɵɵFactoryTarget.Component });
3334
- SafeDeleteComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.0", type: SafeDeleteComponent, isStandalone: true, selector: "data-safe-delete", inputs: { model: "model", service: "service", checks: "checks" }, outputs: { deleted: "deleted" }, viewQueries: [{ propertyName: "_dialogRef", first: true, predicate: ["dialog"], descendants: true, static: true }], ngImport: i0, template: "\n<ng-template #dialog let-offcanvas>\n <div class=\"offcanvas-header\">\n <h2 class=\"offcanvas-title text-danger text-center\"><i class=\"bi bi-trash me-2\"></i>Supprimer r\u00E9ellement ??</h2>\n </div>\n <div class=\"offcanvas-body text-danger\" *ngIf=\"result\">\n <div class=\"text-center my-4 fs-1\"><i class=\"bi bi-exclamation-diamond my-5\"></i></div>\n <div class=\"fs-4\">\n <p>La suppression de cet \u00E9l\u00E9ment supprimera {{result.count}} \u00E9l\u00E9ments dans la base de donn\u00E9es..</p>\n </div>\n <table class=\"table table-sm table-striped table-danger\">\n <thead>\n <tr>\n <th>Type d'\u00E9l\u00E9ment</th>\n <th>Nombre</th>\n </tr>\n </thead>\n <tbody>\n <ng-container *ngFor=\"let rl of result.details\">\n <tr>\n <td>{{checks[rl[0]] ? checks[rl[0]] : rl[0]}}</td>\n <td>{{rl[1]}}</td>\n </tr>\n </ng-container>\n </tbody>\n </table>\n <button class=\"w-100 btn btn-lg btn-danger\" (click)=\"reallyDelete()\"><i class=\"bi bi-trash me-2\"></i>Je confirme la suppression</button>\n <button class=\"w-100 btn btn-outline-secondary my-3\" (click)=\"offcanvas.close()\"><i class=\"bi bi-door-open me-2\"></i>Je renonce \u00E0 la suppression</button>\n </div>\n</ng-template>\n<button class=\"btn btn-sm btn-outline-danger float-end\" (click)=\"checkDelete(model)\"><i class=\"bi bi-trash mx-2\"></i></button>", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: NgbOffcanvasModule }] });
3359
+ SafeDeleteComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.0", type: SafeDeleteComponent, isStandalone: true, selector: "data-safe-delete", inputs: { model: "model", service: "service", checks: "checks", display: "display" }, outputs: { deleted: "deleted" }, viewQueries: [{ propertyName: "_dialogRef", first: true, predicate: ["dialog"], descendants: true, static: true }], ngImport: i0, template: "\n<ng-template #dialog let-offcanvas>\n <div class=\"offcanvas-header\">\n <h2 class=\"offcanvas-title text-danger text-center\"><i class=\"bi bi-trash me-2\"></i>Supprimer r\u00E9ellement ??</h2>\n </div>\n <div class=\"offcanvas-body text-danger\" *ngIf=\"result\">\n <div class=\"text-center my-4 fs-1\"><i class=\"bi bi-exclamation-diamond my-5\"></i></div>\n <div class=\"fs-4\">\n <p>La suppression de cet \u00E9l\u00E9ment supprimera {{result.count}} \u00E9l\u00E9ments dans la base de donn\u00E9es..</p>\n </div>\n <table class=\"table table-sm table-striped table-danger\">\n <thead>\n <tr>\n <th>Type d'\u00E9l\u00E9ment</th>\n <th>Nombre</th>\n </tr>\n </thead>\n <tbody>\n <ng-container *ngFor=\"let rl of result.details\">\n <tr>\n <td>{{checks[rl[0]] ? checks[rl[0]] : rl[0]}}</td>\n <td>{{rl[1]}}</td>\n </tr>\n </ng-container>\n </tbody>\n </table>\n <button class=\"w-100 btn btn-lg btn-danger\" (click)=\"reallyDelete()\"><i class=\"bi bi-trash me-2\"></i>Je confirme la suppression</button>\n <button class=\"w-100 btn btn-outline-secondary my-3\" (click)=\"offcanvas.close()\"><i class=\"bi bi-door-open me-2\"></i>Je renonce \u00E0 la suppression</button>\n </div>\n</ng-template>\n<button class=\"btn btn-sm btn-outline-danger float-end\" (click)=\"checkDelete(model)\" *ngIf=\"display==='button'\"><i class=\"bi bi-trash mx-2\"></i></button><i class=\"bi bi-trash mx-2\" (click)=\"checkDelete(model)\" *ngIf=\"display==='icon'\" role=\"button\"></i>\n<div (click)=\"checkDelete(model)\" *ngIf=\"display==='custom'\" role=\"button\">\n <ng-content></ng-content>\n</div>", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: NgbOffcanvasModule }] });
3335
3360
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: SafeDeleteComponent, decorators: [{
3336
3361
  type: Component,
3337
- args: [{ selector: 'data-safe-delete', standalone: true, imports: [CommonModule, NgbOffcanvasModule], template: "\n<ng-template #dialog let-offcanvas>\n <div class=\"offcanvas-header\">\n <h2 class=\"offcanvas-title text-danger text-center\"><i class=\"bi bi-trash me-2\"></i>Supprimer r\u00E9ellement ??</h2>\n </div>\n <div class=\"offcanvas-body text-danger\" *ngIf=\"result\">\n <div class=\"text-center my-4 fs-1\"><i class=\"bi bi-exclamation-diamond my-5\"></i></div>\n <div class=\"fs-4\">\n <p>La suppression de cet \u00E9l\u00E9ment supprimera {{result.count}} \u00E9l\u00E9ments dans la base de donn\u00E9es..</p>\n </div>\n <table class=\"table table-sm table-striped table-danger\">\n <thead>\n <tr>\n <th>Type d'\u00E9l\u00E9ment</th>\n <th>Nombre</th>\n </tr>\n </thead>\n <tbody>\n <ng-container *ngFor=\"let rl of result.details\">\n <tr>\n <td>{{checks[rl[0]] ? checks[rl[0]] : rl[0]}}</td>\n <td>{{rl[1]}}</td>\n </tr>\n </ng-container>\n </tbody>\n </table>\n <button class=\"w-100 btn btn-lg btn-danger\" (click)=\"reallyDelete()\"><i class=\"bi bi-trash me-2\"></i>Je confirme la suppression</button>\n <button class=\"w-100 btn btn-outline-secondary my-3\" (click)=\"offcanvas.close()\"><i class=\"bi bi-door-open me-2\"></i>Je renonce \u00E0 la suppression</button>\n </div>\n</ng-template>\n<button class=\"btn btn-sm btn-outline-danger float-end\" (click)=\"checkDelete(model)\"><i class=\"bi bi-trash mx-2\"></i></button>" }]
3362
+ args: [{ selector: 'data-safe-delete', standalone: true, imports: [CommonModule, NgbOffcanvasModule], template: "\n<ng-template #dialog let-offcanvas>\n <div class=\"offcanvas-header\">\n <h2 class=\"offcanvas-title text-danger text-center\"><i class=\"bi bi-trash me-2\"></i>Supprimer r\u00E9ellement ??</h2>\n </div>\n <div class=\"offcanvas-body text-danger\" *ngIf=\"result\">\n <div class=\"text-center my-4 fs-1\"><i class=\"bi bi-exclamation-diamond my-5\"></i></div>\n <div class=\"fs-4\">\n <p>La suppression de cet \u00E9l\u00E9ment supprimera {{result.count}} \u00E9l\u00E9ments dans la base de donn\u00E9es..</p>\n </div>\n <table class=\"table table-sm table-striped table-danger\">\n <thead>\n <tr>\n <th>Type d'\u00E9l\u00E9ment</th>\n <th>Nombre</th>\n </tr>\n </thead>\n <tbody>\n <ng-container *ngFor=\"let rl of result.details\">\n <tr>\n <td>{{checks[rl[0]] ? checks[rl[0]] : rl[0]}}</td>\n <td>{{rl[1]}}</td>\n </tr>\n </ng-container>\n </tbody>\n </table>\n <button class=\"w-100 btn btn-lg btn-danger\" (click)=\"reallyDelete()\"><i class=\"bi bi-trash me-2\"></i>Je confirme la suppression</button>\n <button class=\"w-100 btn btn-outline-secondary my-3\" (click)=\"offcanvas.close()\"><i class=\"bi bi-door-open me-2\"></i>Je renonce \u00E0 la suppression</button>\n </div>\n</ng-template>\n<button class=\"btn btn-sm btn-outline-danger float-end\" (click)=\"checkDelete(model)\" *ngIf=\"display==='button'\"><i class=\"bi bi-trash mx-2\"></i></button><i class=\"bi bi-trash mx-2\" (click)=\"checkDelete(model)\" *ngIf=\"display==='icon'\" role=\"button\"></i>\n<div (click)=\"checkDelete(model)\" *ngIf=\"display==='custom'\" role=\"button\">\n <ng-content></ng-content>\n</div>" }]
3338
3363
  }], ctorParameters: function () { return [{ type: i2$1.NgbOffcanvas }]; }, propDecorators: { model: [{
3339
3364
  type: Input
3340
3365
  }], service: [{
@@ -3343,6 +3368,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImpor
3343
3368
  type: Input
3344
3369
  }], deleted: [{
3345
3370
  type: Output
3371
+ }], display: [{
3372
+ type: Input
3346
3373
  }], _dialogRef: [{
3347
3374
  type: ViewChild,
3348
3375
  args: ['dialog', { static: true }]
@@ -3522,18 +3549,26 @@ class DateFieldManager extends BaseFieldManager {
3522
3549
  return v;
3523
3550
  }
3524
3551
  fromJson(data) {
3525
- if (data === null) {
3552
+ if (data === null || data === undefined) {
3526
3553
  return null;
3527
3554
  }
3528
- return new Date(data);
3555
+ const date = new Date(data);
3556
+ if (date instanceof Date && !isNaN(date)) {
3557
+ return date;
3558
+ }
3559
+ return null;
3529
3560
  }
3530
3561
  toJson(data) {
3531
3562
  if (data === null || data === undefined) {
3532
3563
  return null;
3533
3564
  }
3534
- // if (typeof data === "string") {
3535
- // return data;
3536
- // }
3565
+ if (typeof data === 'string') {
3566
+ const d = this.fromJson(data);
3567
+ if (d === null) {
3568
+ return null;
3569
+ }
3570
+ data = d;
3571
+ }
3537
3572
  return `${data.getUTCFullYear()}-${data.getUTCMonth() + 1}-${data.getUTCDate()}`;
3538
3573
  }
3539
3574
  /**
@@ -3565,6 +3600,13 @@ class DatetimeFieldManager extends DateFieldManager {
3565
3600
  if (data === null || data === undefined) {
3566
3601
  return null;
3567
3602
  }
3603
+ if (typeof data === 'string') {
3604
+ const d = this.fromJson(data);
3605
+ if (d === null) {
3606
+ return null;
3607
+ }
3608
+ data = d;
3609
+ }
3568
3610
  try {
3569
3611
  return data.toISOString();
3570
3612
  }