54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { ChangeDetectorRef, Component, HostListener, Input, OnDestroy, OnInit } from '@angular/core';
|
|
import { Store } from '@ngrx/store';
|
|
import { Subscription } from 'rxjs';
|
|
import * as commonActions from '../../actions/app-common.actions';
|
|
import * as commonReducer from '../../reducers/app-common.reducer';
|
|
import { File, ResumableFileUploadService } from './resumable-file-upload.service';
|
|
|
|
|
|
@Component({
|
|
selector: 'fm-resumable-file-upload',
|
|
templateUrl: './resumable-file-upload.component.html',
|
|
styleUrls: ['./resumable-file-upload.component.scss']
|
|
})
|
|
|
|
export class ResumableFileUploadComponent implements OnInit, OnDestroy {
|
|
|
|
@Input('parentCode')
|
|
set parentCode(parentCode: string) {
|
|
if (parentCode && parentCode != "null" && parentCode != "")
|
|
this.uploadService.parentCode = parentCode;
|
|
else
|
|
this.uploadService.parentCode = null;
|
|
}
|
|
|
|
constructor(private cd: ChangeDetectorRef, public uploadService: ResumableFileUploadService,public store: Store<commonReducer.State>) {
|
|
}
|
|
|
|
private refreshSub: Subscription;
|
|
|
|
ngOnInit() {
|
|
this.uploadService.init();
|
|
this.refreshSub = this.uploadService.refresh.subscribe(() => {
|
|
this.cd.markForCheck();
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if(this.refreshSub) this.refreshSub.unsubscribe();
|
|
}
|
|
|
|
handleUploadedFileClick(event:MouseEvent,file:File) {
|
|
event.preventDefault();
|
|
this.store.dispatch(new commonActions.UploadedFileClick(file.itemCode));
|
|
}
|
|
|
|
//TODO do this with an canunload guard
|
|
@HostListener('window:beforeunload')
|
|
windowBeforeUnload = function () {
|
|
if (this.uploadService.isUploading) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|