@processpuzzle/base-entity 1.0.2 → 1.0.3

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, Injectable, output, signal, forwardRef, ViewChild, Inject, Component, input, Injector, computed, effect, InjectionToken, Directive, HostBinding, EventEmitter, Output, DestroyRef, untracked, runInInjectionContext, provideAppInitializer } from '@angular/core';
2
+ import { inject, Injectable, output, signal, forwardRef, ViewChild, Inject, Component, input, computed, Injector, effect, InjectionToken, Directive, HostBinding, EventEmitter, Output, DestroyRef, untracked, runInInjectionContext, provideAppInitializer } from '@angular/core';
3
3
  import { MatSnackBar } from '@angular/material/snack-bar';
4
4
  import * as i1$1 from '@angular/common';
5
5
  import { CommonModule, NgClass, NgStyle, NgTemplateOutlet, SlicePipe } from '@angular/common';
@@ -1230,6 +1230,10 @@ class BaseEntityQueryComponent {
1230
1230
  ...(ngDevMode ? [{ debugName: "entityDescriptor" }] : /* istanbul ignore next */ []));
1231
1231
  queryValue = signal('', /* @ts-ignore */
1232
1232
  ...(ngDevMode ? [{ debugName: "queryValue" }] : /* istanbul ignore next */ []));
1233
+ appliedQuery = signal(undefined, /* @ts-ignore */
1234
+ ...(ngDevMode ? [{ debugName: "appliedQuery" }] : /* istanbul ignore next */ []));
1235
+ queryActive = computed(() => this.appliedQuery() !== undefined && this.queryValue() === this.appliedQuery(), /* @ts-ignore */
1236
+ ...(ngDevMode ? [{ debugName: "queryActive" }] : /* istanbul ignore next */ []));
1233
1237
  store;
1234
1238
  dialog = inject(MatDialog);
1235
1239
  parentInjector = inject(Injector);
@@ -1240,7 +1244,14 @@ class BaseEntityQueryComponent {
1240
1244
  const value = this.queryValue().trim();
1241
1245
  if (!value)
1242
1246
  return;
1247
+ this.queryValue.set(value);
1243
1248
  this.store.load({ query: value });
1249
+ this.appliedQuery.set(value);
1250
+ }
1251
+ onClearQuery() {
1252
+ this.queryValue.set('');
1253
+ this.appliedQuery.set(undefined);
1254
+ this.store.load({});
1244
1255
  }
1245
1256
  onOpenEditor() {
1246
1257
  const data = { initialQuery: this.queryValue() };
@@ -1258,7 +1269,7 @@ class BaseEntityQueryComponent {
1258
1269
  });
1259
1270
  }
1260
1271
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: BaseEntityQueryComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1261
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.5", type: BaseEntityQueryComponent, isStandalone: true, selector: "base-entity-query", inputs: { entityDescriptor: { classPropertyName: "entityDescriptor", publicName: "entityDescriptor", isSignal: true, isRequired: true, transformFunction: null } }, providers: [provideTranslocoScope({ scope: 'base_entity', alias: 'base_entity' })], ngImport: i0, template: `
1272
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: BaseEntityQueryComponent, isStandalone: true, selector: "base-entity-query", inputs: { entityDescriptor: { classPropertyName: "entityDescriptor", publicName: "entityDescriptor", isSignal: true, isRequired: true, transformFunction: null } }, providers: [provideTranslocoScope({ scope: 'base_entity', alias: 'base_entity' })], ngImport: i0, template: `
1262
1273
  <ng-container *transloco="let t">
1263
1274
  <div class="query-wrapper">
1264
1275
  <label class="field-label" [attr.for]="entityDescriptor().createTestId('query-input')">{{ t('base_entity.toolbar.query_label') }}</label>
@@ -1274,9 +1285,15 @@ class BaseEntityQueryComponent {
1274
1285
  <button [attr.data-testid]="entityDescriptor().createTestId('query-editor-open')" type="button" mat-icon-button matSuffix aria-label="Open advanced query editor" (click)="onOpenEditor()">
1275
1286
  <mat-icon>edit_note</mat-icon>
1276
1287
  </button>
1277
- <button [attr.data-testid]="entityDescriptor().createTestId('query-send')" type="button" mat-icon-button matSuffix aria-label="Send query" [disabled]="!queryValue()" (click)="onSendQuery()">
1278
- <mat-icon>play_arrow</mat-icon>
1279
- </button>
1288
+ @if (queryActive()) {
1289
+ <button [attr.data-testid]="entityDescriptor().createTestId('query-clear')" type="button" mat-icon-button matSuffix aria-label="Clear query" (click)="onClearQuery()">
1290
+ <mat-icon>cancel</mat-icon>
1291
+ </button>
1292
+ } @else {
1293
+ <button [attr.data-testid]="entityDescriptor().createTestId('query-send')" type="button" mat-icon-button matSuffix aria-label="Send query" [disabled]="!queryValue()" (click)="onSendQuery()">
1294
+ <mat-icon>play_arrow</mat-icon>
1295
+ </button>
1296
+ }
1280
1297
  </mat-form-field>
1281
1298
  </div>
1282
1299
  </ng-container>
@@ -1300,9 +1317,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1300
1317
  <button [attr.data-testid]="entityDescriptor().createTestId('query-editor-open')" type="button" mat-icon-button matSuffix aria-label="Open advanced query editor" (click)="onOpenEditor()">
1301
1318
  <mat-icon>edit_note</mat-icon>
1302
1319
  </button>
1303
- <button [attr.data-testid]="entityDescriptor().createTestId('query-send')" type="button" mat-icon-button matSuffix aria-label="Send query" [disabled]="!queryValue()" (click)="onSendQuery()">
1304
- <mat-icon>play_arrow</mat-icon>
1305
- </button>
1320
+ @if (queryActive()) {
1321
+ <button [attr.data-testid]="entityDescriptor().createTestId('query-clear')" type="button" mat-icon-button matSuffix aria-label="Clear query" (click)="onClearQuery()">
1322
+ <mat-icon>cancel</mat-icon>
1323
+ </button>
1324
+ } @else {
1325
+ <button [attr.data-testid]="entityDescriptor().createTestId('query-send')" type="button" mat-icon-button matSuffix aria-label="Send query" [disabled]="!queryValue()" (click)="onSendQuery()">
1326
+ <mat-icon>play_arrow</mat-icon>
1327
+ </button>
1328
+ }
1306
1329
  </mat-form-field>
1307
1330
  </div>
1308
1331
  </ng-container>
@@ -1763,12 +1786,15 @@ let BaseEntityRestService = class BaseEntityRestService {
1763
1786
  if (httpResponse.status === 204 || this.isEmptyBody(httpResponse.body)) {
1764
1787
  throw new Error('The query returned no content.');
1765
1788
  }
1766
- return queryCondition.page ? this.mapPagedResponse(httpResponse.body) : this.mapSimpleResponse(httpResponse.body);
1789
+ return this.isPagedResponse(httpResponse.body) ? this.mapPagedResponse(httpResponse.body) : this.mapSimpleResponse(httpResponse.body);
1767
1790
  }));
1768
1791
  }
1769
1792
  else
1770
1793
  throw new Error('Could not determine the full url');
1771
1794
  }
1795
+ isPagedResponse(body) {
1796
+ return body !== null && typeof body === 'object' && !Array.isArray(body) && Array.isArray(body.content);
1797
+ }
1772
1798
  isEmptyBody(body) {
1773
1799
  if (body == null)
1774
1800
  return true;
@@ -1818,11 +1844,15 @@ let BaseEntityRestService = class BaseEntityRestService {
1818
1844
  // region protected, private helper methods
1819
1845
  buildFullUrl(resourceUri, queryCondition) {
1820
1846
  const queryParams = new Map();
1821
- if (queryCondition.page)
1847
+ if (queryCondition.page !== undefined)
1822
1848
  queryParams.set('page', queryCondition.page.toString());
1849
+ if (queryCondition.pageSize !== undefined)
1850
+ queryParams.set('size', queryCondition.pageSize.toString());
1851
+ if (queryCondition.orderBys?.length)
1852
+ queryParams.set('order', this.buildOrder(queryCondition.orderBys));
1823
1853
  const rsql = this.buildRsql(queryCondition);
1824
1854
  if (rsql)
1825
- queryParams.set('filter', rsql);
1855
+ queryParams.set('where', rsql);
1826
1856
  let params = {};
1827
1857
  if (queryParams.size > 0) {
1828
1858
  for (const [key, value] of queryParams) {
@@ -1853,16 +1883,17 @@ let BaseEntityRestService = class BaseEntityRestService {
1853
1883
  return toRsql(queryCondition.filters);
1854
1884
  return undefined;
1855
1885
  }
1886
+ buildOrder(orderBys) {
1887
+ return orderBys.map((o) => `${o.property},${o.direction}`).join(',');
1888
+ }
1856
1889
  mapPagedResponse(response) {
1857
- const pages = response;
1858
- const subjectPage = pages[0];
1859
- const content = subjectPage.content.map((dto, index) => {
1860
- return this.mapEntityResponse(dto, index);
1861
- });
1890
+ const page = response;
1891
+ const content = page.content.map((dto, index) => this.mapEntityResponse(dto, index));
1862
1892
  return {
1863
- page: subjectPage.page,
1864
- pageSize: subjectPage.pageSize,
1865
- totalPageCount: subjectPage.totalPageCount,
1893
+ number: page.number,
1894
+ size: page.size,
1895
+ totalElements: page.totalElements,
1896
+ totalPages: page.totalPages,
1866
1897
  content,
1867
1898
  };
1868
1899
  }
@@ -3688,9 +3719,10 @@ let BaseEntityFirestoreService = class BaseEntityFirestoreService {
3688
3719
  const results = await getDocs(builtQuery);
3689
3720
  const content = results.docs.map((docSnapshot) => this.mapDocument({ id: docSnapshot.id, ...docSnapshot.data() }));
3690
3721
  return {
3691
- page: queryCondition.page,
3692
- pageSize: queryCondition.pageSize,
3693
- totalPageCount: 1,
3722
+ number: queryCondition.page,
3723
+ size: queryCondition.pageSize,
3724
+ totalElements: content.length,
3725
+ totalPages: 1,
3694
3726
  content,
3695
3727
  };
3696
3728
  }
@@ -3788,7 +3820,7 @@ const updateEntity = (store, repository) => {
3788
3820
  };
3789
3821
 
3790
3822
  const findByQuery = (store, repository) => {
3791
- return rxMethod(pipe(tap((query) => patchState(store, { page: query.page, isLoading: true, error: undefined })),
3823
+ return rxMethod(pipe(tap((query) => patchState(store, { number: query.page, isLoading: true, error: undefined })),
3792
3824
  // debounceTime(1000),
3793
3825
  // distinctUntilChanged(),
3794
3826
  switchMap((parameters) => repository.findByQuery(parameters).pipe(tapResponse({
@@ -3797,9 +3829,10 @@ const findByQuery = (store, repository) => {
3797
3829
  const baseEntityResponse = response;
3798
3830
  patchState(store, {
3799
3831
  entities: baseEntityResponse.content,
3800
- page: baseEntityResponse.page,
3801
- pageSize: baseEntityResponse.pageSize,
3802
- totalPageCount: baseEntityResponse.totalPageCount,
3832
+ number: baseEntityResponse.number,
3833
+ size: baseEntityResponse.size,
3834
+ totalElements: baseEntityResponse.totalElements,
3835
+ totalPages: baseEntityResponse.totalPages,
3803
3836
  isLoading: false,
3804
3837
  });
3805
3838
  }
@@ -3807,9 +3840,10 @@ const findByQuery = (store, repository) => {
3807
3840
  const entities = response.slice();
3808
3841
  patchState(store, {
3809
3842
  entities,
3810
- page: undefined,
3811
- pageSize: entities.length,
3812
- totalPageCount: undefined,
3843
+ number: undefined,
3844
+ size: entities.length,
3845
+ totalElements: entities.length,
3846
+ totalPages: undefined,
3813
3847
  isLoading: false,
3814
3848
  });
3815
3849
  }
@@ -3823,9 +3857,10 @@ const BASE_ENTITY_STORE = new InjectionToken('BASE_ENTITY_STORE');
3823
3857
  function BaseEntityStore(entityType, getRepository) {
3824
3858
  return signalStoreFeature(withState({
3825
3859
  entities: [],
3826
- page: 0,
3827
- pageSize: 5,
3828
- totalPageCount: 0,
3860
+ number: 0,
3861
+ size: 5,
3862
+ totalElements: 0,
3863
+ totalPages: 0,
3829
3864
  currentEntity: undefined,
3830
3865
  currentId: undefined,
3831
3866
  isLoading: false,