mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-16 15:40:11 +01:00
feat(layouts): add file uploader (#842)
This commit is contained in:
parent
1be434b437
commit
7d03461efb
8 changed files with 82 additions and 2 deletions
|
|
@ -16,6 +16,11 @@ export class Layouts {
|
|||
url: '',
|
||||
};
|
||||
|
||||
public fileUploaderOptions:NgUploaderOptions = {
|
||||
// url: 'http://website.com/upload'
|
||||
url: '',
|
||||
};
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,5 +41,10 @@
|
|||
<ba-picture-uploader [picture]="profile.picture" [defaultPicture]="defaultPicture" [uploaderOptions]="uploaderOptions"></ba-picture-uploader>
|
||||
</ba-card>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<ba-card title="File Uploader" baCardClass="with-scroll">
|
||||
<ba-file-uploader [fileUploaderOptions]="fileUploaderOptions"></ba-file-uploader>
|
||||
</ba-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
59
src/app/theme/components/baFileUploader/baFileUploader.component.ts
Executable file
59
src/app/theme/components/baFileUploader/baFileUploader.component.ts
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
import { Component, ViewChild, Input, Output, EventEmitter, ElementRef, Renderer } from '@angular/core';
|
||||
import { NgUploaderOptions } from 'ngx-uploader';
|
||||
@Component({
|
||||
selector: 'ba-file-uploader',
|
||||
styleUrls: ['./baFileUploader.scss'],
|
||||
templateUrl: './baFileUploader.html',
|
||||
})
|
||||
export class BaFileUploader {
|
||||
@Input() fileUploaderOptions: NgUploaderOptions = { url: '' };
|
||||
@Output() onFileUpload = new EventEmitter<any>();
|
||||
@Output() onFileUploadCompleted = new EventEmitter<any>();
|
||||
@Input() defaultValue: string = '';
|
||||
|
||||
@ViewChild('fileUpload') public _fileUpload: ElementRef;
|
||||
@ViewChild('inputText') public _inputText: ElementRef;
|
||||
|
||||
public uploadFileInProgress: boolean;
|
||||
constructor(private renderer: Renderer) {
|
||||
}
|
||||
|
||||
bringFileSelector(): boolean {
|
||||
this.renderer.invokeElementMethod(this._fileUpload.nativeElement, 'click');
|
||||
return false;
|
||||
}
|
||||
|
||||
beforeFileUpload(uploadingFile): void {
|
||||
let files = this._fileUpload.nativeElement.files;
|
||||
if (files.length) {
|
||||
const file = files[0];
|
||||
this._onChangeFileSelect(files[0])
|
||||
if (!this._canFleUploadOnServer()) {
|
||||
uploadingFile.setAbort();
|
||||
} else {
|
||||
this.uploadFileInProgress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_onChangeFileSelect(file) {
|
||||
this._inputText.nativeElement.value = file.name
|
||||
}
|
||||
|
||||
_onFileUpload(data): void {
|
||||
if (data['done'] || data['abort'] || data['error']) {
|
||||
this._onFileUploadCompleted(data);
|
||||
} else {
|
||||
this.onFileUpload.emit(data);
|
||||
}
|
||||
}
|
||||
|
||||
_onFileUploadCompleted(data): void {
|
||||
this.uploadFileInProgress = false;
|
||||
this.onFileUploadCompleted.emit(data);
|
||||
}
|
||||
|
||||
_canFleUploadOnServer(): boolean {
|
||||
return !!this.fileUploaderOptions['url'];
|
||||
}
|
||||
}
|
||||
7
src/app/theme/components/baFileUploader/baFileUploader.html
Executable file
7
src/app/theme/components/baFileUploader/baFileUploader.html
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
<input #fileUpload ngFileSelect type="file" [options]="fileUploaderOptions" (onUpload)="_onFileUpload($event)" (beforeUpload)="beforeFileUpload($event)" hidden="true">
|
||||
<div class="input-group" [ngClass]="{uploading: uploadFileInProgress}">
|
||||
<input #inputText type="text" [value]="defaultValue" class="form-control" readonly>
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-success" type="button" (click)="bringFileSelector();">Browse</button>
|
||||
</span>
|
||||
</div>
|
||||
0
src/app/theme/components/baFileUploader/baFileUploader.scss
Executable file
0
src/app/theme/components/baFileUploader/baFileUploader.scss
Executable file
1
src/app/theme/components/baFileUploader/index.ts
Executable file
1
src/app/theme/components/baFileUploader/index.ts
Executable file
|
|
@ -0,0 +1 @@
|
|||
export * from './baFileUploader.component';
|
||||
|
|
@ -12,3 +12,4 @@ export * from './baFullCalendar';
|
|||
export * from './baPictureUploader';
|
||||
export * from './baCheckbox';
|
||||
export * from './baMultiCheckbox';
|
||||
export * from './baFileUploader';
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ import {
|
|||
BaMultiCheckbox,
|
||||
BaPageTop,
|
||||
BaPictureUploader,
|
||||
BaSidebar
|
||||
BaSidebar,
|
||||
BaFileUploader
|
||||
} from './components';
|
||||
|
||||
import { BaCardBlur } from './components/baCard/baCardBlur.directive';
|
||||
|
|
@ -70,7 +71,8 @@ const NGA_COMPONENTS = [
|
|||
BaMultiCheckbox,
|
||||
BaPageTop,
|
||||
BaPictureUploader,
|
||||
BaSidebar
|
||||
BaSidebar,
|
||||
BaFileUploader
|
||||
];
|
||||
|
||||
const NGA_DIRECTIVES = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue