[ADF-793] Ability to create PDF renditions in case of non supported formats (#1994)

* Style changes and button

* Convert to PDF button

* Convert to PDF button part II.

* Convert within the Not Supported Format component

* Rendition loading skeleton

* Conversion is working.

* Convert button behaviour tests

* Rebasing fix.
This commit is contained in:
Popovics András
2017-06-20 21:02:22 +01:00
committed by Eugenio Romano
parent 0ff4ff5f24
commit b457024cab
11 changed files with 331 additions and 49 deletions

View File

@@ -15,15 +15,18 @@
* limitations under the License.
*/
import { Component, Input } from '@angular/core';
import { ContentService } from 'ng2-alfresco-core';
import { Component, Input, OnInit } from '@angular/core';
import { ContentService, RenditionsService } from 'ng2-alfresco-core';
import { AlfrescoApiService } from 'ng2-alfresco-core';
const DEFAULT_CONVERSION_ENCODING = 'pdf';
@Component({
selector: 'not-supported-format',
templateUrl: './notSupportedFormat.component.html',
styleUrls: ['./notSupportedFormat.component.css']
})
export class NotSupportedFormat {
export class NotSupportedFormat implements OnInit {
@Input()
nameFile: string;
@@ -34,9 +37,23 @@ export class NotSupportedFormat {
@Input()
blobFile: Blob;
constructor(private contentService: ContentService) {
@Input()
nodeId: string|null = null;
}
@Input()
showToolbar: boolean = true;
convertible: boolean = false;
displayable: boolean = false;
isConversionStarted: boolean = false;
isConversionFinished: boolean = false;
renditionUrl: string|null = null;
constructor(
private contentService: ContentService,
private renditionsService: RenditionsService,
private apiService: AlfrescoApiService
) {}
/**
* Download file opening it in a new window
@@ -48,4 +65,56 @@ export class NotSupportedFormat {
this.contentService.downloadBlob(this.blobFile, this.nameFile);
}
}
ngOnInit() {
if (this.nodeId) {
this.checkRendition();
}
}
/**
* Update component's button according to the given rendition's availability
*
* @param {string} encoding - the rendition id
*/
checkRendition(encoding: string = DEFAULT_CONVERSION_ENCODING): void {
this.renditionsService.getRendition(this.nodeId, encoding)
.subscribe(
(response: any) => {
if (response.entry.status === 'NOT_CREATED') {
this.convertible = true;
this.displayable = false;
} else if (response.entry.status === 'CREATED') {
this.convertible = false;
this.displayable = true;
}
},
() => {
this.convertible = false;
this.displayable = false;
}
);
}
/**
* Set the component to loading state and send the conversion starting signal to parent component
*/
convertToPdf(): void {
this.isConversionStarted = true;
this.renditionsService.convert(this.nodeId, DEFAULT_CONVERSION_ENCODING)
.subscribe({
error: (error) => { this.isConversionStarted = false; },
complete: () => { this.showPDF(); }
});
}
/**
* Show the PDF rendition of the node
*/
showPDF(): void {
this.renditionUrl = this.apiService.getInstance().content.getRenditionUrl(this.nodeId, DEFAULT_CONVERSION_ENCODING);
this.isConversionStarted = false;
this.isConversionFinished = true;
}
}