Make the rendition conversion great again (#2126)

This commit is contained in:
Popovics András
2017-07-25 14:49:32 +01:00
committed by Eugenio Romano
parent df32a49c9e
commit a17d85adb5
3 changed files with 100 additions and 14 deletions

View File

@@ -17,7 +17,7 @@
/* tslint:disable:component-selector */
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { ContentService, RenditionsService } from 'ng2-alfresco-core';
import { AlfrescoApiService } from 'ng2-alfresco-core';
@@ -28,7 +28,7 @@ const DEFAULT_CONVERSION_ENCODING = 'pdf';
templateUrl: './notSupportedFormat.component.html',
styleUrls: ['./notSupportedFormat.component.css']
})
export class NotSupportedFormatComponent implements OnInit {
export class NotSupportedFormatComponent implements OnInit, OnDestroy {
@Input()
nameFile: string;
@@ -50,6 +50,7 @@ export class NotSupportedFormatComponent implements OnInit {
isConversionStarted: boolean = false;
isConversionFinished: boolean = false;
renditionUrl: string|null = null;
conversionsubscription: any = null;
constructor(
private contentService: ContentService,
@@ -57,6 +58,15 @@ export class NotSupportedFormatComponent implements OnInit {
private apiService: AlfrescoApiService
) {}
/**
* Checks for available renditions if the nodeId is present
*/
ngOnInit() {
if (this.nodeId) {
this.checkRendition();
}
}
/**
* Download file opening it in a new window
*/
@@ -68,12 +78,6 @@ export class NotSupportedFormatComponent implements OnInit {
}
}
ngOnInit() {
if (this.nodeId) {
this.checkRendition();
}
}
/**
* Update component's button according to the given rendition's availability
*
@@ -104,7 +108,7 @@ export class NotSupportedFormatComponent implements OnInit {
convertToPdf(): void {
this.isConversionStarted = true;
this.renditionsService.convert(this.nodeId, DEFAULT_CONVERSION_ENCODING)
this.conversionsubscription = this.renditionsService.convert(this.nodeId, DEFAULT_CONVERSION_ENCODING)
.subscribe({
error: (error) => { this.isConversionStarted = false; },
complete: () => { this.showPDF(); }
@@ -119,4 +123,13 @@ export class NotSupportedFormatComponent implements OnInit {
this.isConversionStarted = false;
this.isConversionFinished = true;
}
/**
* Kills the subscription polling if it has been started
*/
ngOnDestroy(): void {
if (this.isConversionStarted) {
this.conversionsubscription.unsubscribe();
}
}
}