From c0ce20f65ddaee9f8b22ef9248060babd94ef163 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 19 Jan 2020 00:09:52 +0100 Subject: [PATCH 1/2] Fix upload is permitted without a file being selected --- .../fileUpload/fileUpload.component.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/app/components/profile/fileUpload/fileUpload.component.ts b/src/app/components/profile/fileUpload/fileUpload.component.ts index b86767c..b4b5bf0 100644 --- a/src/app/components/profile/fileUpload/fileUpload.component.ts +++ b/src/app/components/profile/fileUpload/fileUpload.component.ts @@ -39,27 +39,32 @@ export class DialogFileUploadComponent { * Fired when the ok button was pressed */ onOkClicked() { - this.errorOccurred = false; - this.uploading = true; - this.selfService.changeProfilePicture(this.file).subscribe((response) => { - this.uploading = false; - if (response.success) { - this.profilePictureUrl.next(environment.greenvironmentUrl + response.fileName); - this.dialogRef.close(); - } else { - this.errorMessage = response.error; + if (this.file) { + this.errorOccurred = false; + this.uploading = true; + this.selfService.changeProfilePicture(this.file).subscribe((response) => { + this.uploading = false; + if (response.success) { + this.profilePictureUrl.next(environment.greenvironmentUrl + response.fileName); + this.dialogRef.close(); + } else { + this.errorMessage = response.error; + this.errorOccurred = true; + } + }, (error) => { + this.uploading = false; this.errorOccurred = true; - } - }, (error) => { - this.uploading = false; + console.log(error); + if (error.error) { + this.errorMessage = error.error.error; + } else { + this.errorMessage = 'Failed to upload the profile picture.'; + } + }); + } else { this.errorOccurred = true; - console.log(error); - if (error.error) { - this.errorMessage = error.error.error; - } else { - this.errorMessage = 'Failed to upload the profile picture.'; - } - }); + this.errorMessage = 'Please select a file to upload.'; + } } /** From 032d0f295ddd7effe568b07d0dad6c13156e74e8 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 19 Jan 2020 00:16:18 +0100 Subject: [PATCH 2/2] Change file input to material button --- .../profile/fileUpload/fileUploadDialog.component.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/components/profile/fileUpload/fileUploadDialog.component.html b/src/app/components/profile/fileUpload/fileUploadDialog.component.html index 7edfd5c..3ed10fd 100644 --- a/src/app/components/profile/fileUpload/fileUploadDialog.component.html +++ b/src/app/components/profile/fileUpload/fileUploadDialog.component.html @@ -1,7 +1,8 @@

Upload a new Profile picture!

- + +

Preview: