Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12 from hmcts/feature/rotation-service
Browse files Browse the repository at this point in the history
included input for rotation function
  • Loading branch information
pawelkaczmarekuk committed Mar 6, 2019
2 parents f6304b0 + ebf8fb7 commit ed22dd1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
[annotate]="false"
[url]="'http://localhost:3000/assets/non-dm.pdf'"
[isDM]="false"
[contentType]="'pdf'">
[contentType]="'pdf'"
[rotate]="true">
</app-document-viewer>
<app-document-viewer *ngIf="documentTypeToShow === 'nonDM_image'"
[baseUrl]="'http://localhost:3000/api'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class DocumentViewerComponent implements OnChanges, OnInit {
@Input() baseUrl: string;
@Input() isDM: boolean;
@Input() contentType: string;
@Input() rotate = false;

viewerComponent: any;
error: HttpErrorResponse;
Expand Down Expand Up @@ -66,13 +67,13 @@ export class DocumentViewerComponent implements OnChanges, OnInit {
});
} else {
this.viewerComponent = this.viewerFactoryService.buildComponent(this.viewerAnchor.viewContainerRef,
this.contentType, this.url, this.baseUrl, this.url, this.annotate, null);
this.contentType, this.url, this.baseUrl, this.url, this.annotate, null, this.rotate);
}
}

buildComponent(metadata, url, annotationSet?) {
this.viewerFactoryService.buildComponent(this.viewerAnchor.viewContainerRef,
metadata.mimeType, url, this.baseUrl, metadata._links.self.href, this.annotate, annotationSet);
metadata.mimeType, url, this.baseUrl, metadata._links.self.href, this.annotate, annotationSet, this.rotate);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class AnnotationPdfViewerComponent implements OnInit, AfterViewInit, OnDe
@Input() url: string;
@Input() annotationSet: IAnnotationSet;
@Input() baseUrl: string;
@Input() rotate: boolean;

private page: number;
private focusedAnnotationSubscription: Subscription;
Expand Down Expand Up @@ -67,14 +68,16 @@ export class AnnotationPdfViewerComponent implements OnInit, AfterViewInit, OnDe
[]
));

this.pdfPageSubscription = this.pdfRenderService.listPagesSubject
.subscribe((listPages: RotationModel[]) => {
if (this.rotate) {
this.pdfPageSubscription = this.pdfRenderService.listPagesSubject
.subscribe((listPages: RotationModel[]) => {
this.rotationComponents.forEach(rc => rc.destroy());
listPages.forEach(pageDetails => {
this.rotationComponents.push(this.rotationFactoryService.addToDom(pageDetails));
this.rotationComponents.push(this.rotationFactoryService.addToDom(pageDetails));
});
});

});
}

this.pdfRenderService.render(this.viewerElementRef);
this.pdfService.setAnnotationWrapper(this.annotationWrapper);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

<div id="viewer-wrapper">
<button
*ngIf="rotate"
class="govuk-button hmcts hmcts-button--secondary rotate"
title="Clockwise"
role="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class ImageViewerComponent implements OnInit {

@Input() url: string;
@Input() originalUrl: string;
@Input() rotate: boolean;

@ViewChild('img') img: ElementRef;
rotation: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ export class ViewerFactoryService {
}

buildComponent(viewContainerRef: ViewContainerRef, contentType: string,
url: string, baseUrl: string, originalUrl: string, annotate: boolean, annotationSet: any) {
url: string, baseUrl: string, originalUrl: string, annotate: boolean, annotationSet: any, rotate: boolean) {
if (ViewerFactoryService.isPdf(contentType) && annotate) {
this.log.info('Selected pdf viewer with annotations enabled');
return this.buildAnnotateUi(url, viewContainerRef, baseUrl, annotate, annotationSet);
return this.buildAnnotateUi(url, viewContainerRef, baseUrl, annotate, annotationSet, rotate);

} else if (ViewerFactoryService.isPdf(contentType) && !annotate) {
this.log.info('Selected pdf viewer with annotations disabled');
return this.buildAnnotateUi(url, viewContainerRef, baseUrl, annotate, null);
return this.buildAnnotateUi(url, viewContainerRef, baseUrl, annotate, null, rotate);
} else if (ViewerFactoryService.isImage(contentType)) {
this.log.info('Selected image viewer');
return this.createComponent(ImageViewerComponent, viewContainerRef, originalUrl, url);
return this.createComponent(ImageViewerComponent, viewContainerRef, originalUrl, url, rotate);

} else {
this.log.info('Unsupported type for viewer');
Expand All @@ -57,7 +57,7 @@ export class ViewerFactoryService {
}

buildAnnotateUi(url: any, viewContainerRef: ViewContainerRef, baseUrl: string,
annotate: boolean, annotationSet: IAnnotationSet): ComponentRef<any>['instance'] {
annotate: boolean, annotationSet: IAnnotationSet, rotate: boolean): ComponentRef<any>['instance'] {

viewContainerRef.clear();
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(AnnotationPdfViewerComponent);
Expand All @@ -68,17 +68,19 @@ export class ViewerFactoryService {
componentRef.instance.outputDmDocumentId = null; // '4fbdde23-e9a7-4843-b6c0-24d5bf2140ab';
componentRef.instance.baseUrl = baseUrl;
componentRef.instance.url = url;
componentRef.instance.rotate = rotate;

return componentRef.instance;
}

createComponent(component: any, viewContainerRef: ViewContainerRef, originalUrl: string, url: string) {
createComponent(component: any, viewContainerRef: ViewContainerRef, originalUrl: string, url: string, rotate?: boolean) {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(component);
viewContainerRef.clear();

const componentRef: ComponentRef<any> = viewContainerRef.createComponent(componentFactory);
componentRef.instance.originalUrl = originalUrl;
componentRef.instance.url = url;
componentRef.instance.rotate = rotate;
return componentRef.instance;
}

Expand Down

0 comments on commit ed22dd1

Please sign in to comment.