This commit is contained in:
Dan Percic 2023-05-17 01:38:33 +03:00
parent e46649c656
commit ba4d7f6d05
8 changed files with 27 additions and 47 deletions

View File

@ -52,7 +52,7 @@ export class WorkflowComponent<T extends IListable, K extends string> extends Co
@Output() readonly noDataAction = new EventEmitter<void>();
@Output() readonly addElement = new EventEmitter<void>();
@ContentChild('workflowItemTemplate') readonly itemTemplate!: TemplateRef<T>;
@ContentChild('workflowItemTemplate') readonly itemTemplate!: TemplateRef<{ entity: T }>;
readonly trackBy = trackByFactory<T>();
itemHeight?: number;

View File

@ -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<Interface, Class extends Entity<Interfa
return false;
}
watch$(key: string, @RequiredParam() entityId: PrimaryKey): Observable<Class> {
watch$(key: string, entityId: PrimaryKey): Observable<Class> {
return this.#entityChanged$.pipe(
filter(entity => entity.id === entityId),
startWith(this.get(key, entityId) as Class),
@ -124,8 +124,7 @@ export abstract class EntitiesMapService<Interface, Class extends Entity<Interfa
);
}
@Validate()
watchChanged$(@RequiredParam() key: Id): Observable<boolean> {
watchChanged$(key: Id): Observable<boolean> {
// TODO: This is wrong, entityChanged emits only one entity at a time
return this.#entityChanged$.pipe(
startWith(this.get(key)),

View File

@ -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<I> {
return this.getAll<R>(`${this._defaultModelPath}/${entityId}`, queryParams);
}
@Validate()
delete(@RequiredParam() body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<unknown> {
delete(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<unknown> {
let path = `/${encodeURI(modelPath)}`;
if (typeof body === 'string') {
@ -69,7 +68,6 @@ export abstract class GenericService<I> {
});
}
@Validate()
upload<R = I>(data?: Blob, modelPath = this._defaultModelPath): Observable<HttpEvent<R>> {
const formParams = new FormData();
@ -94,12 +92,7 @@ export abstract class GenericService<I> {
);
}
@Validate()
protected _post<R = I>(
@RequiredParam() body: unknown,
modelPath = this._defaultModelPath,
queryParams?: List<QueryParam>,
): Observable<R> {
protected _post<R = I>(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
return this._http.post<R>(`/${encodeURI(modelPath)}`, body, {
params: this._queryParams(queryParams),
headers: HeadersConfiguration.getHeaders(),
@ -107,12 +100,7 @@ export abstract class GenericService<I> {
});
}
@Validate()
protected _put<R = I>(
@RequiredParam() body: unknown,
modelPath = this._defaultModelPath,
queryParams?: List<QueryParam>,
): Observable<R> {
protected _put<R = I>(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
return this._http.put<R>(`/${encodeURI(modelPath)}`, body, {
params: this._queryParams(queryParams),
headers: HeadersConfiguration.getHeaders(),
@ -120,12 +108,7 @@ export abstract class GenericService<I> {
});
}
@Validate()
protected _getOne<R = I>(
@RequiredParam() path: List,
modelPath = this._defaultModelPath,
queryParams?: List<QueryParam>,
): Observable<R> {
protected _getOne<R = I>(path: List, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
const entityPath = path.map(item => encodeURIComponent(item)).join('/');
return this._http.get<R>(`/${encodeURI(modelPath)}/${entityPath}`, {

View File

@ -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<string, List>;
@ -51,12 +51,11 @@ export abstract class IqserUserPreferenceService extends GenericService<UserAttr
this.#userAttributes = attributes ?? {};
}
@Validate()
savePreferences(@RequiredParam() body: List, @RequiredParam() key: string) {
savePreferences(body: List, key: string) {
return this._put(body, `${this._defaultModelPath}/${key}`);
}
public async save(key: string, value: string): Promise<void> {
async save(key: string, value: string): Promise<void> {
this.userAttributes[key] = [value];
await firstValueFrom(this.savePreferences([value], key));
}

View File

@ -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<E, I = E> {
@ -13,8 +13,7 @@ export abstract class StatsService<E, I = E> {
readonly #http = inject(HttpClient);
readonly #map = new Map<string, BehaviorSubject<E>>();
@Validate()
getFor(@RequiredParam() ids: string[]): Observable<E[]> {
getFor(ids: string[]): Observable<E[]> {
const request = this.#http.post<I[]>(`/${encodeURI(this._defaultModelPath)}`, ids, {
headers: HeadersConfiguration.getHeaders(),
observe: 'body',

View File

@ -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<TranslateLoader>(translateLoaderToken, { optional: true });
if (!translateLoader) {
throw new Error('Call forRoot() in AppModule to use IqserTranslateModule');
}

View File

@ -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<T = IProfileUpdateRequest>(@RequiredParam() body: T, @RequiredParam() userId: string) {
updateProfile<T = IProfileUpdateRequest>(body: T, userId: string) {
return this._post<unknown>(body, `${this._defaultModelPath}/profile/${userId}`);
}
@Validate()
updateMyProfile<T = IMyProfileUpdateRequest>(@RequiredParam() body: T) {
updateMyProfile<T = IMyProfileUpdateRequest>(body: T) {
const showToast = (error: HttpErrorResponse) => {
switch (error.status) {
case HttpStatusCode.BadRequest:
@ -143,13 +141,11 @@ export abstract class IqserUserService<
return this._post<unknown>(body, `${this._defaultModelPath}/my-profile`).pipe(catchError(showToast));
}
@Validate()
resetPassword<T = IResetPasswordRequest>(@RequiredParam() body: T, @RequiredParam() userId: string) {
resetPassword<T = IResetPasswordRequest>(body: T, userId: string) {
return this._post<unknown>(body, `${this._defaultModelPath}/${userId}/reset-password`);
}
@Validate()
create<T = ICreateUserRequest>(@RequiredParam() body: T) {
create<T = ICreateUserRequest>(body: T) {
return this._post(body);
}

View File

@ -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": {