From 1b146037facaa4d3e5a662fea64f67c0dd8b0110 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Sun, 22 May 2022 23:13:11 +0300 Subject: [PATCH] RED-3982 - added file properties on "upload-file" component --- src/lib/dialog/base-dialog.component.ts | 2 +- src/lib/form/base-form.component.ts | 6 +++- .../upload-file/upload-file.component.html | 34 ++++++++++--------- src/lib/upload-file/upload-file.component.ts | 6 ++-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/lib/dialog/base-dialog.component.ts b/src/lib/dialog/base-dialog.component.ts index 33b8f4a..3a22f68 100644 --- a/src/lib/dialog/base-dialog.component.ts +++ b/src/lib/dialog/base-dialog.component.ts @@ -24,7 +24,7 @@ export interface SaveOptions { * */ export abstract class BaseDialogComponent extends AutoUnsubscribe implements OnInit { form!: FormGroup; - initialFormValue; + initialFormValue!: Record; private readonly _confirmationDialogService: ConfirmationDialogService = this._injector.get(ConfirmationDialogService); private readonly _dialog: MatDialog = this._injector.get(MatDialog); diff --git a/src/lib/form/base-form.component.ts b/src/lib/form/base-form.component.ts index eefd3ed..ad9b033 100644 --- a/src/lib/form/base-form.component.ts +++ b/src/lib/form/base-form.component.ts @@ -15,5 +15,9 @@ export abstract class BaseFormComponent extends AutoUnsubscribe { return this.form?.valid; } - abstract save(): Promise; + get disabled(): boolean { + return !this.valid || !this.changed; + } + + abstract save(); } diff --git a/src/lib/upload-file/upload-file.component.html b/src/lib/upload-file/upload-file.component.html index 039f67e..110ec39 100644 --- a/src/lib/upload-file/upload-file.component.html +++ b/src/lib/upload-file/upload-file.component.html @@ -1,17 +1,19 @@ -
- -
-
-
- -

{{ file.name }}

- -
+
+
+ +
+
+
+ +

{{ file.name }}

+ +
- + +
diff --git a/src/lib/upload-file/upload-file.component.ts b/src/lib/upload-file/upload-file.component.ts index cb2a02d..5217fcc 100644 --- a/src/lib/upload-file/upload-file.component.ts +++ b/src/lib/upload-file/upload-file.component.ts @@ -1,5 +1,4 @@ import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core'; -import { BehaviorSubject } from 'rxjs'; @Component({ selector: 'iqser-upload-file', @@ -11,10 +10,11 @@ import { BehaviorSubject } from 'rxjs'; export class UploadFileComponent { @ViewChild('attachFileInput', { static: true }) attachFileInput: ElementRef; + @Input() file!: File | null; + @Input() readonly = false; + @Input() accept = 'application/pdf'; @Output() readonly fileChanged = new EventEmitter(); - file!: File | null; - triggerAttachFile() { this.attachFileInput.nativeElement.click(); }