mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Fix error when the dialog is not initialized
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, ChangeDetectorRef, OnInit } from '@angular/core';
|
import { Component, ChangeDetectorRef, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { FileModel } from '../models/file.model';
|
import { FileModel } from '../models/file.model';
|
||||||
import { FileUploadingListComponent } from './file-uploading-list.component';
|
import { FileUploadingListComponent } from './file-uploading-list.component';
|
||||||
import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core';
|
||||||
@@ -43,7 +43,7 @@ declare let __moduleName: string;
|
|||||||
host: {'[class.dialog-show]': 'toggleShowDialog'},
|
host: {'[class.dialog-show]': 'toggleShowDialog'},
|
||||||
pipes: [AlfrescoPipeTranslate]
|
pipes: [AlfrescoPipeTranslate]
|
||||||
})
|
})
|
||||||
export class FileUploadingDialogComponent implements OnInit {
|
export class FileUploadingDialogComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
isDialogActive: boolean = false;
|
isDialogActive: boolean = false;
|
||||||
|
|
||||||
@@ -90,4 +90,8 @@ export class FileUploadingDialogComponent implements OnInit {
|
|||||||
toggleDialogMinimize() {
|
toggleDialogMinimize() {
|
||||||
this._isDialogMinimized = !this._isDialogMinimized;
|
this._isDialogMinimized = !this._isDialogMinimized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.cd.detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -102,7 +102,6 @@ export class UploadButtonComponent {
|
|||||||
*/
|
*/
|
||||||
onFilesAdded($event: any): void {
|
onFilesAdded($event: any): void {
|
||||||
let files = $event.currentTarget.files;
|
let files = $event.currentTarget.files;
|
||||||
this.printFileInfo(files);
|
|
||||||
this.uploadFiles(this.currentFolderPath, files);
|
this.uploadFiles(this.currentFolderPath, files);
|
||||||
// reset the value of the input file
|
// reset the value of the input file
|
||||||
$event.target.value = '';
|
$event.target.value = '';
|
||||||
@@ -115,7 +114,6 @@ export class UploadButtonComponent {
|
|||||||
*/
|
*/
|
||||||
onDirectoryAdded($event: any): void {
|
onDirectoryAdded($event: any): void {
|
||||||
let files = $event.currentTarget.files;
|
let files = $event.currentTarget.files;
|
||||||
this.printFileInfo(files);
|
|
||||||
let hashMapDir = this.convertIntoHashMap(files);
|
let hashMapDir = this.convertIntoHashMap(files);
|
||||||
|
|
||||||
hashMapDir.forEach((filesDir, directoryPath) => {
|
hashMapDir.forEach((filesDir, directoryPath) => {
|
||||||
@@ -265,18 +263,6 @@ export class UploadButtonComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints the basic information of a file
|
|
||||||
* @param files
|
|
||||||
*/
|
|
||||||
printFileInfo(files: any) {
|
|
||||||
for (let file of files) {
|
|
||||||
console.log('Name: ' + file.name);
|
|
||||||
console.log('Size: ' + file.size);
|
|
||||||
console.log('Path: ' + file.webkitRelativePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace a placeholder {0} in a message with the input keys
|
* Replace a placeholder {0} in a message with the input keys
|
||||||
* @param message - the message that conains the placeholder
|
* @param message - the message that conains the placeholder
|
||||||
|
@@ -91,16 +91,11 @@ export class UploadService {
|
|||||||
filesToUpload.forEach((uploadingFileModel: FileModel) => {
|
filesToUpload.forEach((uploadingFileModel: FileModel) => {
|
||||||
uploadingFileModel.setUploading();
|
uploadingFileModel.setUploading();
|
||||||
|
|
||||||
let _filesUploadObserverProgressBar = this.filesUploadObserverProgressBar;
|
|
||||||
let _queue = this.queue;
|
|
||||||
|
|
||||||
let promiseUpload = this.authService.getAlfrescoApi().
|
let promiseUpload = this.authService.getAlfrescoApi().
|
||||||
upload.uploadFile(uploadingFileModel.file, directory)
|
upload.uploadFile(uploadingFileModel.file, directory)
|
||||||
.on('progress', (progress: any) => {
|
.on('progress', (progress: any) => {
|
||||||
uploadingFileModel.setProgres(progress);
|
uploadingFileModel.setProgres(progress);
|
||||||
if (_filesUploadObserverProgressBar) {
|
this.updateFileListStream(this.queue);
|
||||||
_filesUploadObserverProgressBar.next(_queue);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on('abort', () => {
|
.on('abort', () => {
|
||||||
uploadingFileModel.setAbort();
|
uploadingFileModel.setAbort();
|
||||||
@@ -124,11 +119,9 @@ export class UploadService {
|
|||||||
data.response
|
data.response
|
||||||
);
|
);
|
||||||
|
|
||||||
_filesUploadObserverProgressBar.next(_queue);
|
this.updateFileListStream(this.queue);
|
||||||
if (!uploadingFileModel.abort && !uploadingFileModel.error) {
|
if (!uploadingFileModel.abort && !uploadingFileModel.error) {
|
||||||
if (this.totalCompletedObserver) {
|
this.updateFileCounterStream(++this.totalCompleted);
|
||||||
this.totalCompletedObserver.next(++this.totalCompleted);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -182,4 +175,16 @@ export class UploadService {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
return Observable.throw(error || 'Server error');
|
return Observable.throw(error || 'Server error');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateFileListStream(fileList: FileModel[]) {
|
||||||
|
if (this.filesUploadObserverProgressBar) {
|
||||||
|
this.filesUploadObserverProgressBar.next(fileList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateFileCounterStream(total: number) {
|
||||||
|
if (this.totalCompletedObserver) {
|
||||||
|
this.totalCompletedObserver.next(total);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user