diff --git a/ui-ngx/src/app/core/auth/auth.selectors.ts b/ui-ngx/src/app/core/auth/auth.selectors.ts index cbfd43cff3..4bf2f2276d 100644 --- a/ui-ngx/src/app/core/auth/auth.selectors.ts +++ b/ui-ngx/src/app/core/auth/auth.selectors.ts @@ -72,11 +72,6 @@ export const selectPersistDeviceStateToTelemetry = createSelector( (state: AuthState) => state.persistDeviceStateToTelemetry ); -export const selectMaxResourceSize = createSelector( - selectAuthState, - (state: AuthState) => state.maxResourceSize -); - export const selectUserSettings = createSelector( selectAuthState, (state: AuthState) => state.userSettings diff --git a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts index 6d37a2e7f4..128a4ddb21 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts @@ -16,7 +16,7 @@ import { ChangeDetectorRef, Component, Inject, OnDestroy, OnInit } from '@angular/core'; import { Subject } from 'rxjs'; -import { select, Store } from '@ngrx/store'; +import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { TranslateService } from '@ngx-translate/core'; import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; @@ -29,10 +29,10 @@ import { ResourceTypeMIMETypes, ResourceTypeTranslationMap } from '@shared/models/resource.models'; -import { filter, startWith, take, takeUntil } from 'rxjs/operators'; +import { filter, startWith, takeUntil } from 'rxjs/operators'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { isDefinedAndNotNull } from '@core/utils'; -import { selectMaxResourceSize } from '@core/auth/auth.selectors'; +import { getCurrentAuthState } from '@core/auth/auth.selectors'; @Component({ selector: 'tb-resources-library', @@ -44,7 +44,7 @@ export class ResourcesLibraryComponent extends EntityComponent impleme readonly resourceTypes: ResourceType[] = Object.values(this.resourceType); readonly resourceTypesTranslationMap = ResourceTypeTranslationMap; - maxResourceSize = 0; + maxResourceSize = getCurrentAuthState(this.store).maxResourceSize; private destroy$ = new Subject(); @@ -55,11 +55,6 @@ export class ResourcesLibraryComponent extends EntityComponent impleme public fb: FormBuilder, protected cd: ChangeDetectorRef) { super(store, fb, entityValue, entitiesTableConfigValue, cd); - this.store.pipe(select(selectMaxResourceSize)).pipe( - take(1) - ).subscribe(maxResourceSize => { - this.maxResourceSize = maxResourceSize; - }); } ngOnInit() { diff --git a/ui-ngx/src/app/shared/components/file-input.component.ts b/ui-ngx/src/app/shared/components/file-input.component.ts index d55470f9fc..3215baf10f 100644 --- a/ui-ngx/src/app/shared/components/file-input.component.ts +++ b/ui-ngx/src/app/shared/components/file-input.component.ts @@ -147,10 +147,12 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, const readers = []; let showMaxSizeAlert = false; (event.event[0] as flowjs.FlowFile[]).forEach(file => { - if (!this.checkMaxSize(file)) { - showMaxSizeAlert = true; - } else if (this.filterFile(file)) { - readers.push(this.readerAsFile(file)); + if (this.filterFile(file)) { + if (this.checkMaxSize(file)) { + readers.push(this.readerAsFile(file)); + } else { + showMaxSizeAlert = true; + } } }); @@ -219,7 +221,7 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, } private checkMaxSize(file: flowjs.FlowFile): boolean { - return !(this.maxSizeByte && this.maxSizeByte < file.size); + return !this.maxSizeByte || file.size <= this.maxSizeByte; } private filterFile(file: flowjs.FlowFile): boolean { diff --git a/ui-ngx/src/app/shared/components/image/upload-image-dialog.component.ts b/ui-ngx/src/app/shared/components/image/upload-image-dialog.component.ts index f0d55022f6..75e53d38f2 100644 --- a/ui-ngx/src/app/shared/components/image/upload-image-dialog.component.ts +++ b/ui-ngx/src/app/shared/components/image/upload-image-dialog.component.ts @@ -17,7 +17,7 @@ import { Component, Inject, OnInit, SkipSelf } from '@angular/core'; import { ErrorStateMatcher } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { select, Store } from '@ngrx/store'; +import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { FormGroupDirective, @@ -31,8 +31,7 @@ import { DialogComponent } from '@shared/components/dialog.component'; import { Router } from '@angular/router'; import { ImageService } from '@core/http/image.service'; import { ImageResourceInfo, imageResourceType } from '@shared/models/resource.models'; -import { selectMaxResourceSize } from '@core/auth/auth.selectors'; -import { take } from 'rxjs/operators'; +import { getCurrentAuthState } from '@core/auth/auth.selectors'; export interface UploadImageDialogData { image?: ImageResourceInfo; @@ -53,7 +52,7 @@ export class UploadImageDialogComponent extends submitted = false; - maxResourceSize = 0; + maxResourceSize = getCurrentAuthState(this.store).maxResourceSize; constructor(protected store: Store, protected router: Router, @@ -63,11 +62,6 @@ export class UploadImageDialogComponent extends public dialogRef: MatDialogRef, public fb: UntypedFormBuilder) { super(store, router, dialogRef); - this.store.pipe(select(selectMaxResourceSize)).pipe( - take(1) - ).subscribe(maxResourceSize => { - this.maxResourceSize = maxResourceSize; - }); } ngOnInit(): void {