Add message for file size limit in background-upload.
This commit is contained in:
parent
ced4fe404d
commit
3b4ea6102c
|
@ -9,7 +9,8 @@ declare var UIkit;
|
||||||
selector: 'background-upload',
|
selector: 'background-upload',
|
||||||
template: `
|
template: `
|
||||||
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/>
|
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/>
|
||||||
<div *ngIf="!background.imageFile" class=" upload uk-text-center uk-height-small uk-flex uk-flex-middle uk-flex-center uk-text-uppercase">
|
<div *ngIf="!background.imageFile"
|
||||||
|
class=" upload uk-text-center uk-height-small uk-flex uk-flex-middle uk-flex-center uk-text-uppercase">
|
||||||
<span uk-icon="icon: cloud-upload"></span>
|
<span uk-icon="icon: cloud-upload"></span>
|
||||||
<div uk-form-custom>
|
<div uk-form-custom>
|
||||||
<span class="uk-link uk-margin-small-left" (click)="file.click()">upload image</span>
|
<span class="uk-link uk-margin-small-left" (click)="file.click()">upload image</span>
|
||||||
|
@ -17,37 +18,39 @@ declare var UIkit;
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="background.imageFile" class="uk-width-1-1 uk-flex uk-flex-middle ">
|
<div *ngIf="background.imageFile" class="uk-width-1-1 uk-flex uk-flex-middle ">
|
||||||
<div class="uk-width-1-1 uk-height-small" style = "background-size:cover"
|
<div class="uk-width-1-1 uk-height-small" style="background-size:cover"
|
||||||
[style.background-image]=" getUrl()">
|
[style.background-image]=" getUrl()">
|
||||||
|
|
||||||
|
|
||||||
<a (click)="removePhoto()" uk-tooltip="Remove" class="uk-float-right uk-border-rounded uk-margin-top uk-margin-right uk-background-muted uk-button uk-button-link">
|
<a (click)="removePhoto()" uk-tooltip="Remove"
|
||||||
|
class="uk-float-right uk-border-rounded uk-margin-top uk-margin-right uk-background-muted uk-button uk-button-link">
|
||||||
<icon name="delete" [defaultSize]="true" [flex]="true"></icon>
|
<icon name="delete" [defaultSize]="true" [flex]="true"></icon>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="background.imageFile" class="uk-margin-top">
|
<div *ngIf="background.imageFile" class="uk-margin-top">
|
||||||
<div class="uk-text-bold uk-text-uppercase uk-text-meta uk-margin-small-bottom uk-margin-large-top">position</div>
|
<div class="uk-text-bold uk-text-uppercase uk-text-meta uk-margin-small-bottom uk-margin-large-top">position</div>
|
||||||
<div class="uk-width-expand uk-padding-remove-left" input type="select" inputClass="flat x-small" [(value)]="background.position"
|
<div class="uk-width-expand uk-padding-remove-left" input type="select" inputClass="flat x-small"
|
||||||
[options]="['top','center','bottom']" >
|
[(value)]="background.position"
|
||||||
|
[options]="['top','center','bottom']">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
`,
|
`,
|
||||||
styles:[`
|
styles: [`
|
||||||
.upload{
|
.upload {
|
||||||
border: 1px dotted grey;
|
border: 1px dotted grey;
|
||||||
}
|
}
|
||||||
`]
|
`]
|
||||||
})
|
})
|
||||||
|
|
||||||
export class BackgroundUploadComponent implements OnInit {
|
export class BackgroundUploadComponent implements OnInit {
|
||||||
@Input() label:string = "";
|
@Input() label: string = "";
|
||||||
@Input() background;
|
@Input() background;
|
||||||
@Input() oldBackground;
|
@Input() oldBackground;
|
||||||
// @Input() light:boolean;
|
// @Input() light:boolean;
|
||||||
@Input() communityId:string = "";
|
@Input() communityId: string = "";
|
||||||
|
|
||||||
public file: File;
|
public file: File;
|
||||||
// public photo: string | ArrayBuffer;
|
// public photo: string | ArrayBuffer;
|
||||||
|
@ -63,6 +66,7 @@ export class BackgroundUploadComponent implements OnInit {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.subscriptions.forEach(subscription => {
|
this.subscriptions.forEach(subscription => {
|
||||||
if (subscription instanceof Subscription) {
|
if (subscription instanceof Subscription) {
|
||||||
|
@ -78,7 +82,7 @@ export class BackgroundUploadComponent implements OnInit {
|
||||||
}
|
}
|
||||||
// this.initPhoto();
|
// this.initPhoto();
|
||||||
console.log(this.background.imageFile + " " + this.oldBackground.imageFile)
|
console.log(this.background.imageFile + " " + this.oldBackground.imageFile)
|
||||||
if(this.background.imageFile != this.oldBackground.imageFile){
|
if (this.background.imageFile != this.oldBackground.imageFile) {
|
||||||
this.deletePhoto();
|
this.deletePhoto();
|
||||||
}
|
}
|
||||||
this.background.imageFile = null;
|
this.background.imageFile = null;
|
||||||
|
@ -87,10 +91,9 @@ export class BackgroundUploadComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public deletePhoto() {
|
public deletePhoto() {
|
||||||
if (this.background.imageFile) {
|
if (this.background.imageFile) {
|
||||||
this.subscriptions.push(this.utilsService.deletePhoto(properties.utilsService + '/delete/community/' + this.communityId + "/" +this.background.imageFile).subscribe());
|
this.subscriptions.push(this.utilsService.deletePhoto(properties.utilsService + '/delete/community/' + this.communityId + "/" + this.background.imageFile).subscribe());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +108,7 @@ export class BackgroundUploadComponent implements OnInit {
|
||||||
});
|
});
|
||||||
this.removePhoto();
|
this.removePhoto();
|
||||||
} else if (this.file.size > this.maxsize) {
|
} else if (this.file.size > this.maxsize) {
|
||||||
UIkit.notification('File exceeds size\'s limit ('+this.maxsize/1024+'KB)! ', {
|
UIkit.notification('File exceeds size\'s limit (' + this.maxsize / 1024 + 'KB)! ', {
|
||||||
status: 'danger',
|
status: 'danger',
|
||||||
timeout: 6000,
|
timeout: 6000,
|
||||||
pos: 'bottom-right'
|
pos: 'bottom-right'
|
||||||
|
@ -125,24 +128,31 @@ export class BackgroundUploadComponent implements OnInit {
|
||||||
|
|
||||||
public save() {
|
public save() {
|
||||||
if (this.file) {
|
if (this.file) {
|
||||||
this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/community/"+ this.communityId + "/" + encodeURIComponent(this.communityId+"-"+this.label)+"?big=1", this.file).subscribe(res => {
|
this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/community/" + this.communityId + "/" + encodeURIComponent(this.communityId + "-" + this.label) + "?big=1", this.file).subscribe(res => {
|
||||||
this.deletePhoto();
|
this.deletePhoto();
|
||||||
this.removePhoto();
|
this.removePhoto();
|
||||||
this.background.imageFile = res.filename;
|
this.background.imageFile = res.filename;
|
||||||
|
|
||||||
}, error => {
|
}, error => {
|
||||||
|
if (error.error.message) {
|
||||||
|
UIkit.notification('The maximum size of an image is 1MB, please check if your file exceeds this limit.', {
|
||||||
|
status: 'danger',
|
||||||
|
timeout: 6000,
|
||||||
|
pos: 'bottom-right'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
UIkit.notification("An error has been occurred during upload your image. Try again later", {
|
UIkit.notification("An error has been occurred during upload your image. Try again later", {
|
||||||
status: 'danger',
|
status: 'danger',
|
||||||
timeout: 6000,
|
timeout: 6000,
|
||||||
pos: 'bottom-right'
|
pos: 'bottom-right'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getUrl()
|
getUrl() {
|
||||||
{
|
return "url('" + (this.background.imageFile.indexOf('data:') == -1 ? (this.properties.utilsService +
|
||||||
return "url('" +(this.background.imageFile.indexOf('data:')==-1?(this.properties.utilsService +
|
'/download/' + this.background.imageFile) : this.background.imageFile) + "')";
|
||||||
'/download/'+this.background.imageFile):this.background.imageFile) +"')";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue