diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e696687..33487a8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -65,8 +65,9 @@ import {MatDialogModule} from '@angular/material/dialog'; import {MatTooltipModule} from '@angular/material/tooltip'; import {MatExpansionModule} from '@angular/material/expansion'; import {MatDatepickerModule} from '@angular/material/datepicker'; -import {MatNativeDateModule} from '@angular/material/'; +import {MatNativeDateModule, MatProgressBarModule} from '@angular/material/'; import {MatSnackBarModule} from '@angular/material/snack-bar'; +import {DialogFileUploadComponent} from './components/profile/fileUpload/fileUpload.component'; const config: SocketIoConfig = { url: 'http://localhost:4444', options: {} }; @@ -107,6 +108,7 @@ const appRoutes: Routes = [ GroupComponent, DialogCreateEventComponent, UserlistComponent, + DialogFileUploadComponent, ], imports: [ BrowserModule, @@ -124,7 +126,7 @@ const appRoutes: Routes = [ MatIconModule, BrowserAnimationsModule, MatSliderModule, - MatFormFieldModule , + MatFormFieldModule, MatInputModule, ReactiveFormsModule, MatToolbarModule, @@ -151,8 +153,13 @@ const appRoutes: Routes = [ MatExpansionModule, MatDatepickerModule, MatSnackBarModule, + MatProgressBarModule, + ], + entryComponents: [ + DialogCreateGroupComponent, + DialogCreateEventComponent, + DialogFileUploadComponent ], - entryComponents: [ DialogCreateGroupComponent, DialogCreateEventComponent ], providers: [], bootstrap: [AppComponent] }) diff --git a/src/app/components/profile/fileUpload/fileUpload.component.sass b/src/app/components/profile/fileUpload/fileUpload.component.sass new file mode 100644 index 0000000..a515920 --- /dev/null +++ b/src/app/components/profile/fileUpload/fileUpload.component.sass @@ -0,0 +1,23 @@ +@import '../../../../styles/greenvironment-material-theme' + +.dialogFormField + width: 100% + +.confirmationButton + background-color: $primary-color + +.uploadDialogContent + overflow: hidden + text-align: center + +#inputPreview + max-width: 75% + max-height: 100% + width: auto + clip-path: circle() + mask-mode: luminance + +#inputPreviewWrapper + margin: auto + text-align: center + max-height: 512px diff --git a/src/app/components/profile/fileUpload/fileUpload.component.ts b/src/app/components/profile/fileUpload/fileUpload.component.ts new file mode 100644 index 0000000..fe24bb1 --- /dev/null +++ b/src/app/components/profile/fileUpload/fileUpload.component.ts @@ -0,0 +1,79 @@ +import {Component, EventEmitter} from '@angular/core'; +import {MatDialogRef} from '@angular/material/dialog'; +import {SelfService} from '../../../services/selfservice/self.service'; +import {environment} from '../../../../environments/environment'; +import {BehaviorSubject} from 'rxjs'; + +@Component({ + selector: 'file-upload-dialog', + templateUrl: 'fileUploadDialog.component.html', + styleUrls: ['./fileUpload.component.sass'], +}) +export class DialogFileUploadComponent { + public errorOccurred = false; + public uploading = false; + private errorMessage: string; + public profilePictureUrl: BehaviorSubject; + private file; + public localFileUrl; + + constructor(public dialogRef: MatDialogRef, private selfService: SelfService) { + this.profilePictureUrl = new BehaviorSubject(null); + } + + /** + * Getter for the error message + */ + getErrorMessage() { + return this.errorMessage; + } + + /** + * Fired when the cancel button of the dialog is pressed + */ + onCancelClicked() { + this.dialogRef.close(); + } + + /** + * 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; + this.errorOccurred = true; + } + }, (error) => { + this.uploading = false; + this.errorOccurred = true; + console.log(error); + if (error.error) { + this.errorMessage = error.error.error; + } else { + this.errorMessage = 'Failed to upload the profile picture.'; + } + }); + } + + /** + * Fired when the input of the file select changes. + * @param event + */ + onFileInputChange(event) { + this.errorOccurred = false; + this.errorMessage = ''; + this.file = event.target.files[0]; + const reader = new FileReader(); + reader.onload = (e: any) => { + this.localFileUrl = e.target.result; + }; + reader.readAsDataURL(this.file); + } +} diff --git a/src/app/components/profile/fileUpload/fileUploadDialog.component.html b/src/app/components/profile/fileUpload/fileUploadDialog.component.html new file mode 100644 index 0000000..7edfd5c --- /dev/null +++ b/src/app/components/profile/fileUpload/fileUploadDialog.component.html @@ -0,0 +1,16 @@ +
+

Upload a new Profile picture!

+
+ +
+

Preview:

+ +
+ +
+ {{getErrorMessage()}} +
+ + +
+
diff --git a/src/app/components/profile/profile.component.html b/src/app/components/profile/profile.component.html index cc5263c..75bbfb7 100644 --- a/src/app/components/profile/profile.component.html +++ b/src/app/components/profile/profile.component.html @@ -3,27 +3,26 @@ -
- +
+ camera_alt -
- + {{userProfile.username}} - - -
+ +
@{{userProfile.handle}} -
+
@@ -45,19 +44,18 @@ -
- +
+ camera_alt -
{{userProfile.username}} @{{userProfile.handle}} - @@ -72,20 +70,9 @@
- +
- -
@@ -94,4 +81,3 @@
- \ No newline at end of file diff --git a/src/app/components/profile/profile.component.sass b/src/app/components/profile/profile.component.sass index c6f8e7e..91a0d65 100644 --- a/src/app/components/profile/profile.component.sass +++ b/src/app/components/profile/profile.component.sass @@ -8,7 +8,7 @@ overflow: scroll overflow-x: hidden -#profile +#profile padding: 2em max-width: 1200px margin: 0 auto @@ -32,14 +32,14 @@ font-size: 14px margin-left: calc(100px + 0.5em) .info - margin-right: 1em + margin-right: 1em font-size: 14px #username margin: 0 0.5em #handle font-size: 14px -#icon +#icon display: none position: absolute z-index: 11 @@ -71,9 +71,7 @@ $mat-card-header-size: 100px !default z-index: 10 object-fit: cover - - #postlist margin: 0.5em auto padding: 0 - max-width: 690px \ No newline at end of file + max-width: 690px diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index e73df0b..17a7a62 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -9,13 +9,14 @@ import { HttpClient } from '@angular/common/http'; import { environment } from 'src/environments/environment'; import {MatSnackBar} from '@angular/material/snack-bar'; import {SelfService} from '../../services/selfservice/self.service'; +import {MatDialog} from '@angular/material'; +import {DialogFileUploadComponent} from './fileUpload/fileUpload.component'; @Component({ selector: 'app-profile', templateUrl: './profile.component.html', styleUrls: ['./profile.component.sass'] }) - export class ProfileComponent implements OnInit { levellist: Levellist = new Levellist(); ownProfile = false; @@ -34,7 +35,8 @@ export class ProfileComponent implements OnInit { private requestService: RequestService, private data: DatasharingService, private profileService: ProfileService, - private selfService: SelfService) { + private selfService: SelfService, + public dialog: MatDialog) { router.events.forEach((event) => { // check if the user is on the profile page (of userY) and routes to the page of userY (e.g. his own page) if (event instanceof NavigationEnd) { @@ -71,13 +73,17 @@ export class ProfileComponent implements OnInit { this.requestService.sendFriendRequest(user); } - onFileInput(event) { - this.selfService.changeProfilePicture(event.target.files[0]).subscribe((response) => { - this.userProfile.profilePicture = environment.greenvironmentUrl + response.fileName; - }, (error) => { - this._snackBar.open('failed to upload picture', 'okay', { - duration: 3000 - }); + /** + * Opens the file upload dialog + */ + openFileUploadDialog() { + const dialogRef = this.dialog.open(DialogFileUploadComponent, { + width: '400px' + }); + dialogRef.componentInstance.profilePictureUrl.subscribe((profilePictureUrl) => { + if (profilePictureUrl) { + this.userProfile.profilePicture = profilePictureUrl; + } }); } }