From ba4d7f6d0594706f33fcb6af54c46b3e68f4c905 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Wed, 17 May 2023 01:38:33 +0300 Subject: [PATCH] ng 16 --- .../listing/workflow/workflow.component.ts | 2 +- src/lib/services/entities-map.service.ts | 7 +++-- src/lib/services/generic.service.ts | 27 ++++--------------- .../services/iqser-user-preference.service.ts | 7 +++-- src/lib/services/stats.service.ts | 5 ++-- .../translations/iqser-translate.module.ts | 7 ++--- src/lib/users/services/iqser-user.service.ts | 14 ++++------ tsconfig.json | 5 +++- 8 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/lib/listing/workflow/workflow.component.ts b/src/lib/listing/workflow/workflow.component.ts index 7f076e0..c3f1d5e 100644 --- a/src/lib/listing/workflow/workflow.component.ts +++ b/src/lib/listing/workflow/workflow.component.ts @@ -52,7 +52,7 @@ export class WorkflowComponent extends Co @Output() readonly noDataAction = new EventEmitter(); @Output() readonly addElement = new EventEmitter(); - @ContentChild('workflowItemTemplate') readonly itemTemplate!: TemplateRef; + @ContentChild('workflowItemTemplate') readonly itemTemplate!: TemplateRef<{ entity: T }>; readonly trackBy = trackByFactory(); itemHeight?: number; diff --git a/src/lib/services/entities-map.service.ts b/src/lib/services/entities-map.service.ts index b7b9379..5f2ea90 100644 --- a/src/lib/services/entities-map.service.ts +++ b/src/lib/services/entities-map.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { filter, map, startWith } from 'rxjs/operators'; import { Entity, Id } from '../listing'; -import { List, RequiredParam, shareLast, Validate } from '../utils'; +import { List, shareLast } from '../utils'; import { isArray } from '../permissions'; @Injectable() @@ -116,7 +116,7 @@ export abstract class EntitiesMapService { + watch$(key: string, entityId: PrimaryKey): Observable { return this.#entityChanged$.pipe( filter(entity => entity.id === entityId), startWith(this.get(key, entityId) as Class), @@ -124,8 +124,7 @@ export abstract class EntitiesMapService { + watchChanged$(key: Id): Observable { // TODO: This is wrong, entityChanged emits only one entity at a time return this.#entityChanged$.pipe( startWith(this.get(key)), diff --git a/src/lib/services/generic.service.ts b/src/lib/services/generic.service.ts index 2f1af1e..daa5c2b 100644 --- a/src/lib/services/generic.service.ts +++ b/src/lib/services/generic.service.ts @@ -1,7 +1,7 @@ import { HttpClient, HttpEvent, HttpParams } from '@angular/common/http'; import { inject } from '@angular/core'; import { Observable } from 'rxjs'; -import { HeadersConfiguration, List, RequiredParam, Validate } from '../utils'; +import { HeadersConfiguration, List } from '../utils'; import { map } from 'rxjs/operators'; export const ROOT_CHANGES_KEY = 'root'; @@ -53,8 +53,7 @@ export abstract class GenericService { return this.getAll(`${this._defaultModelPath}/${entityId}`, queryParams); } - @Validate() - delete(@RequiredParam() body: unknown, modelPath = this._defaultModelPath, queryParams?: List): Observable { + delete(body: unknown, modelPath = this._defaultModelPath, queryParams?: List): Observable { let path = `/${encodeURI(modelPath)}`; if (typeof body === 'string') { @@ -69,7 +68,6 @@ export abstract class GenericService { }); } - @Validate() upload(data?: Blob, modelPath = this._defaultModelPath): Observable> { const formParams = new FormData(); @@ -94,12 +92,7 @@ export abstract class GenericService { ); } - @Validate() - protected _post( - @RequiredParam() body: unknown, - modelPath = this._defaultModelPath, - queryParams?: List, - ): Observable { + protected _post(body: unknown, modelPath = this._defaultModelPath, queryParams?: List): Observable { return this._http.post(`/${encodeURI(modelPath)}`, body, { params: this._queryParams(queryParams), headers: HeadersConfiguration.getHeaders(), @@ -107,12 +100,7 @@ export abstract class GenericService { }); } - @Validate() - protected _put( - @RequiredParam() body: unknown, - modelPath = this._defaultModelPath, - queryParams?: List, - ): Observable { + protected _put(body: unknown, modelPath = this._defaultModelPath, queryParams?: List): Observable { return this._http.put(`/${encodeURI(modelPath)}`, body, { params: this._queryParams(queryParams), headers: HeadersConfiguration.getHeaders(), @@ -120,12 +108,7 @@ export abstract class GenericService { }); } - @Validate() - protected _getOne( - @RequiredParam() path: List, - modelPath = this._defaultModelPath, - queryParams?: List, - ): Observable { + protected _getOne(path: List, modelPath = this._defaultModelPath, queryParams?: List): Observable { const entityPath = path.map(item => encodeURIComponent(item)).join('/'); return this._http.get(`/${encodeURI(modelPath)}/${entityPath}`, { diff --git a/src/lib/services/iqser-user-preference.service.ts b/src/lib/services/iqser-user-preference.service.ts index 1e1083a..aa5359c 100644 --- a/src/lib/services/iqser-user-preference.service.ts +++ b/src/lib/services/iqser-user-preference.service.ts @@ -1,6 +1,6 @@ import { inject, Injectable } from '@angular/core'; import { firstValueFrom } from 'rxjs'; -import { BASE_HREF, List, RequiredParam, Validate } from '../utils'; +import { BASE_HREF, List } from '../utils'; import { GenericService } from './generic.service'; export type UserAttributes = Record; @@ -51,12 +51,11 @@ export abstract class IqserUserPreferenceService extends GenericService { + async save(key: string, value: string): Promise { this.userAttributes[key] = [value]; await firstValueFrom(this.savePreferences([value], key)); } diff --git a/src/lib/services/stats.service.ts b/src/lib/services/stats.service.ts index 6fb3eef..658f594 100644 --- a/src/lib/services/stats.service.ts +++ b/src/lib/services/stats.service.ts @@ -2,7 +2,7 @@ import { inject, Injectable } from '@angular/core'; import { BehaviorSubject, Observable, switchMap } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { tap } from 'rxjs/operators'; -import { HeadersConfiguration, mapEach, RequiredParam, Validate } from '../utils'; +import { HeadersConfiguration, mapEach } from '../utils'; @Injectable() export abstract class StatsService { @@ -13,8 +13,7 @@ export abstract class StatsService { readonly #http = inject(HttpClient); readonly #map = new Map>(); - @Validate() - getFor(@RequiredParam() ids: string[]): Observable { + getFor(ids: string[]): Observable { const request = this.#http.post(`/${encodeURI(this._defaultModelPath)}`, ids, { headers: HeadersConfiguration.getHeaders(), observe: 'body', diff --git a/src/lib/translations/iqser-translate.module.ts b/src/lib/translations/iqser-translate.module.ts index b1242b6..2023cde 100644 --- a/src/lib/translations/iqser-translate.module.ts +++ b/src/lib/translations/iqser-translate.module.ts @@ -1,4 +1,4 @@ -import { Inject, ModuleWithProviders, NgModule, Optional } from '@angular/core'; +import { inject, InjectionToken, ModuleWithProviders, NgModule } from '@angular/core'; import { TranslateCompiler, TranslateLoader, TranslateModule, TranslateParser } from '@ngx-translate/core'; import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'; import { pruningTranslationLoaderFactory } from './http-loader-factory'; @@ -6,7 +6,7 @@ import { IqserTranslateModuleOptions } from './iqser-translate-module-options'; import { IqserTranslateParser } from './iqser-translate-parser.service'; import { HttpClientModule } from '@angular/common/http'; -const translateLoaderToken = 'translateLoader'; +const translateLoaderToken = new InjectionToken('translateLoader'); @NgModule({ imports: [ @@ -29,7 +29,8 @@ const translateLoaderToken = 'translateLoader'; exports: [TranslateModule], }) export class IqserTranslateModule { - constructor(@Optional() @Inject(translateLoaderToken) translateLoader: TranslateLoader) { + constructor() { + const translateLoader = inject(translateLoaderToken, { optional: true }); if (!translateLoader) { throw new Error('Call forRoot() in AppModule to use IqserTranslateModule'); } diff --git a/src/lib/users/services/iqser-user.service.ts b/src/lib/users/services/iqser-user.service.ts index 4c9bf0e..804e416 100644 --- a/src/lib/users/services/iqser-user.service.ts +++ b/src/lib/users/services/iqser-user.service.ts @@ -2,7 +2,7 @@ import { inject, Injectable } from '@angular/core'; import { KeycloakService } from 'keycloak-angular'; import { BehaviorSubject, firstValueFrom, Observable, throwError } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; -import { List, mapEach, RequiredParam, Validate } from '../../utils'; +import { List, mapEach } from '../../utils'; import { QueryParam, Toaster } from '../../services'; import { CacheApiService } from '../../caching'; import { EntitiesService } from '../../listing'; @@ -117,13 +117,11 @@ export abstract class IqserUserService< return super.getAll(url, [{ key: 'refreshCache', value: true }]); } - @Validate() - updateProfile(@RequiredParam() body: T, @RequiredParam() userId: string) { + updateProfile(body: T, userId: string) { return this._post(body, `${this._defaultModelPath}/profile/${userId}`); } - @Validate() - updateMyProfile(@RequiredParam() body: T) { + updateMyProfile(body: T) { const showToast = (error: HttpErrorResponse) => { switch (error.status) { case HttpStatusCode.BadRequest: @@ -143,13 +141,11 @@ export abstract class IqserUserService< return this._post(body, `${this._defaultModelPath}/my-profile`).pipe(catchError(showToast)); } - @Validate() - resetPassword(@RequiredParam() body: T, @RequiredParam() userId: string) { + resetPassword(body: T, userId: string) { return this._post(body, `${this._defaultModelPath}/${userId}/reset-password`); } - @Validate() - create(@RequiredParam() body: T) { + create(body: T) { return this._post(body); } diff --git a/tsconfig.json b/tsconfig.json index 0ff4633..b132006 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,10 @@ "target": "ES2022", "module": "ES2022", "lib": ["ES2022", "dom"], - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "paths": { + "@biesbjerg/ngx-translate-extract-marker": ["src/lib/translations/ngx-translate-extract-marker"] + } }, "include": ["./**/*"], "angularCompilerOptions": {