Merge branch 'julius-dev' of Software_Engineering_I/greenvironment-frontend into master
commit
9d9d2dfbea
@ -1,4 +1,5 @@
|
||||
<div class='sidenav'>
|
||||
<span (click)='newDoc()'>New Document</span>
|
||||
<span [class.selected]='docId === currentDoc' (click)='loadDoc(docId)' *ngFor='let docId of documents | async'>{{ docId }}</span>
|
||||
<span [class.selected]='docId === currentDoc' (click)='loadDoc(docId)'
|
||||
*ngFor='let docId of documents | async'>{{ docId }}</span>
|
||||
</div>
|
||||
|
@ -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
|
@ -0,0 +1,79 @@
|
||||
import {Component} 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<string | null>;
|
||||
private file;
|
||||
public localFileUrl;
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<DialogFileUploadComponent>, private selfService: SelfService) {
|
||||
this.profilePictureUrl = new BehaviorSubject<string | null>(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);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<div id="file-upload-dialog">
|
||||
<h1 mat-dialog-title align="center">Upload a new Profile picture!</h1>
|
||||
<div class="uploadDialogContent" mat-dialog-content>
|
||||
<input type="file" accept="image/*" (change)="onFileInputChange($event)" #name>
|
||||
<div id="inputPreviewWrapper">
|
||||
<h2 *ngIf="localFileUrl">Preview:</h2>
|
||||
<img *ngIf="localFileUrl" id="inputPreview" [src]="localFileUrl"/>
|
||||
</div>
|
||||
<mat-progress-bar *ngIf="uploading" mode="indeterminate"></mat-progress-bar>
|
||||
</div>
|
||||
<mat-error *ngIf="errorOccurred">{{getErrorMessage()}}</mat-error>
|
||||
<div mat-dialog-actions align="end">
|
||||
<button mat-button (click)="onCancelClicked()">Cancel</button>
|
||||
<button class="confirmationButton" mat-raised-button cdkFocusInitial (click)="onOkClicked()">Upload</button>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,5 @@
|
||||
export interface IFileUploadResult {
|
||||
success: boolean;
|
||||
fileName?: string;
|
||||
error?: string;
|
||||
}
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.3 KiB |
Loading…
Reference in New Issue