Browse Source

UI: Remove selector selectMaxResourceSize

pull/9901/head
Vladyslav_Prykhodko 3 years ago
parent
commit
6b95db4807
  1. 5
      ui-ngx/src/app/core/auth/auth.selectors.ts
  2. 13
      ui-ngx/src/app/modules/home/pages/admin/resource/resources-library.component.ts
  3. 12
      ui-ngx/src/app/shared/components/file-input.component.ts
  4. 12
      ui-ngx/src/app/shared/components/image/upload-image-dialog.component.ts

5
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

13
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<Resource> impleme
readonly resourceTypes: ResourceType[] = Object.values(this.resourceType);
readonly resourceTypesTranslationMap = ResourceTypeTranslationMap;
maxResourceSize = 0;
maxResourceSize = getCurrentAuthState(this.store).maxResourceSize;
private destroy$ = new Subject<void>();
@ -55,11 +55,6 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> 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() {

12
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 {

12
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<AppState>,
protected router: Router,
@ -63,11 +62,6 @@ export class UploadImageDialogComponent extends
public dialogRef: MatDialogRef<UploadImageDialogComponent, ImageResourceInfo>,
public fb: UntypedFormBuilder) {
super(store, router, dialogRef);
this.store.pipe(select(selectMaxResourceSize)).pipe(
take(1)
).subscribe(maxResourceSize => {
this.maxResourceSize = maxResourceSize;
});
}
ngOnInit(): void {

Loading…
Cancel
Save