UNPKG

@hmcts/annotation-ui-lib

Version:

PDF Viewer and ability to highlight text with and comment tracking

1,594 lines (1,583 loc) 116 kB
import { v4 } from 'uuid'; import { isPlatformServer, CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { WINDOW, NgtUniversalModule } from '@ng-toolkit/universal'; import { __values, __awaiter, __generator } from 'tslib'; import { Injectable, Inject, PLATFORM_ID, Component, ViewChildren, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef, Renderer2, ComponentFactoryResolver, Injector, ApplicationRef, Directive, ViewContainerRef, NgModule, defineInjectable, inject } from '@angular/core'; import { HttpClient, HttpErrorResponse, HttpClientModule } from '@angular/common/http'; import { BehaviorSubject, Subject, of, throwError } from 'rxjs'; import { TransferState, makeStateKey } from '@angular/platform-browser'; import { tap, catchError, map } from 'rxjs/operators'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Comment = /** @class */ (function () { function Comment(id, annotationId, createdBy, createdByDetails, createdDate, lastModifiedBy, lastModifiedByDetails, lastModifiedDate, content) { this.id = id; this.annotationId = annotationId; this.createdBy = createdBy; this.createdByDetails = createdByDetails; this.createdDate = createdDate; this.lastModifiedBy = lastModifiedBy; this.lastModifiedByDetails = lastModifiedByDetails; this.lastModifiedDate = lastModifiedDate; this.content = content; } return Comment; }()); var Annotation = /** @class */ (function () { function Annotation(id, annotationSetId, createdBy, createdDate, createdByDetails, lastModifiedBy, lastModifiedByDetails, lastModifiedDate, documentId, page, color, comments, rectangles, type) { this.id = id; this.annotationSetId = annotationSetId; this.createdBy = createdBy; this.createdDate = createdDate; this.createdByDetails = createdByDetails; this.lastModifiedBy = lastModifiedBy; this.lastModifiedByDetails = lastModifiedByDetails; this.lastModifiedDate = lastModifiedDate; this.documentId = documentId; this.page = page; this.color = color; this.comments = comments; this.rectangles = rectangles; this.type = type; } return Annotation; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PdfAnnotateWrapper = /** @class */ (function () { function PdfAnnotateWrapper() { } /** * @param {?} pageNumber * @return {?} */ PdfAnnotateWrapper.prototype.createPage = /** * @param {?} pageNumber * @return {?} */ function (pageNumber) { return PDFAnnotate.UI.createPage(pageNumber); }; /** * @param {?} pageNumber * @param {?} RENDER_OPTIONS * @return {?} */ PdfAnnotateWrapper.prototype.renderPage = /** * @param {?} pageNumber * @param {?} RENDER_OPTIONS * @return {?} */ function (pageNumber, RENDER_OPTIONS) { return PDFAnnotate.UI.renderPage(pageNumber, RENDER_OPTIONS); }; /** * @param {?} type * @return {?} */ PdfAnnotateWrapper.prototype.enableRect = /** * @param {?} type * @return {?} */ function (type) { PDFAnnotate.UI.enableRect(type); }; /** * @return {?} */ PdfAnnotateWrapper.prototype.disableRect = /** * @return {?} */ function () { PDFAnnotate.UI.disableRect(); }; /** * @param {?=} storeAdapter * @return {?} */ PdfAnnotateWrapper.prototype.setStoreAdapter = /** * @param {?=} storeAdapter * @return {?} */ function (storeAdapter) { if (storeAdapter) { PDFAnnotate.setStoreAdapter(storeAdapter); } else { PDFAnnotate.setStoreAdapter(new PDFAnnotate.LocalStoreAdapter()); } }; /** * @return {?} */ PdfAnnotateWrapper.prototype.getStoreAdapter = /** * @return {?} */ function () { return PDFAnnotate.getStoreAdapter(); }; /** * @return {?} */ PdfAnnotateWrapper.prototype.getUi = /** * @return {?} */ function () { return PDFAnnotate.UI; }; return PdfAnnotateWrapper; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var EmLoggerService = /** @class */ (function () { function EmLoggerService() { } /** * @param {?} loggingClass * @return {?} */ EmLoggerService.prototype.setClass = /** * @param {?} loggingClass * @return {?} */ function (loggingClass) { this.loggingClass = loggingClass; }; /** * @param {?} message * @return {?} */ EmLoggerService.prototype.error = /** * @param {?} message * @return {?} */ function (message) { this.buildLog('error-' + JSON.stringify(message)); }; /** * @param {?} message * @return {?} */ EmLoggerService.prototype.info = /** * @param {?} message * @return {?} */ function (message) { this.buildLog('info-' + JSON.stringify(message)); }; /** * @param {?} message * @return {?} */ EmLoggerService.prototype.buildLog = /** * @param {?} message * @return {?} */ function (message) { console.log(this.loggingClass + "-" + message); }; EmLoggerService.decorators = [ { type: Injectable } ]; return EmLoggerService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PdfService = /** @class */ (function () { function PdfService(log, pdfAnnotateWrapper) { this.log = log; this.pdfAnnotateWrapper = pdfAnnotateWrapper; log.setClass('PdfService'); } /** * @return {?} */ PdfService.prototype.preRun = /** * @return {?} */ function () { this.pageNumber = new BehaviorSubject(1); }; /** * @return {?} */ PdfService.prototype.getAnnotationWrapper = /** * @return {?} */ function () { return this.annotationWrapper; }; /** * @param {?} annotationWrapper * @return {?} */ PdfService.prototype.setAnnotationWrapper = /** * @param {?} annotationWrapper * @return {?} */ function (annotationWrapper) { this.annotationWrapper = annotationWrapper; }; /** * @return {?} */ PdfService.prototype.getPageNumber = /** * @return {?} */ function () { return this.pageNumber; }; /** * @param {?} pageNumber * @return {?} */ PdfService.prototype.setPageNumber = /** * @param {?} pageNumber * @return {?} */ function (pageNumber) { this.pageNumber.next(pageNumber); }; /** * @return {?} */ PdfService.prototype.setHighlightTool = /** * @return {?} */ function () { this.log.info('Highlight cursor is enabled'); this.pdfAnnotateWrapper.enableRect('highlight'); }; /** * @return {?} */ PdfService.prototype.setCursorTool = /** * @return {?} */ function () { this.pdfAnnotateWrapper.disableRect(); }; PdfService.decorators = [ { type: Injectable } ]; PdfService.ctorParameters = function () { return [ { type: EmLoggerService }, { type: PdfAnnotateWrapper } ]; }; return PdfService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Utils = /** @class */ (function () { function Utils() { } /** * @param {?} rectangles * @return {?} */ Utils.prototype.buildLineRectangle = /** * @param {?} rectangles * @return {?} */ function (rectangles) { this.sortByY(rectangles); /** @type {?} */ var lowestY = rectangles[0].y; /** @type {?} */ var lineHeight = rectangles[0].height; this.sortByX(rectangles); /** @type {?} */ var lowestX = rectangles[0].x; /** @type {?} */ var upperX = rectangles[rectangles.length - 1].x; /** @type {?} */ var width = rectangles[rectangles.length - 1].width; /** @type {?} */ var rectangle = { y: lowestY, x: lowestX, width: (upperX - lowestX) + width, height: lineHeight }; return rectangle; }; /** * @param {?} annotationRectangles * @param {?} generatedRectangles * @return {?} */ Utils.prototype.generateRectanglePerLine = /** * @param {?} annotationRectangles * @param {?} generatedRectangles * @return {?} */ function (annotationRectangles, generatedRectangles) { this.sortByY(annotationRectangles); /** @type {?} */ var highestY = annotationRectangles[annotationRectangles.length - 1].y; /** @type {?} */ var lowestY = annotationRectangles[0].y; /** @type {?} */ var lineHeight = this.getAnnotationLineHeight(annotationRectangles); if (this.difference(highestY, lowestY) > lineHeight) { /** @type {?} */ var currentLineRectangles = annotationRectangles.filter(function (rectangle) { return rectangle.y <= (lowestY + lineHeight); }); /** @type {?} */ var nextLineRectangles = annotationRectangles.filter(function (rectangle) { return rectangle.y > (lowestY + lineHeight); }); generatedRectangles.push(this.buildLineRectangle(currentLineRectangles)); this.generateRectanglePerLine(nextLineRectangles, generatedRectangles); } else { generatedRectangles.push(this.buildLineRectangle(annotationRectangles)); } }; /** * @param {?} rectangles * @return {?} */ Utils.prototype.getAnnotationLineHeight = /** * @param {?} rectangles * @return {?} */ function (rectangles) { return rectangles[0].height; }; /** * @param {?} rectangles * @param {?=} lowest * @return {?} */ Utils.prototype.sortByY = /** * @param {?} rectangles * @param {?=} lowest * @return {?} */ function (rectangles, lowest) { if (lowest === void 0) { lowest = true; } rectangles.sort(function (a, b) { /** @type {?} */ var keyA = a.y; /** @type {?} */ var keyB = b.y; if (keyA < keyB) { return lowest ? -1 : 1; } if (keyA > keyB) { return lowest ? 1 : -1; } return 0; }); }; /** * @param {?} rectangles * @param {?=} lowest * @return {?} */ Utils.prototype.sortByX = /** * @param {?} rectangles * @param {?=} lowest * @return {?} */ function (rectangles, lowest) { if (lowest === void 0) { lowest = true; } rectangles.sort(function (a, b) { /** @type {?} */ var keyA = a.x; /** @type {?} */ var keyB = b.x; if (keyA < keyB) { return lowest ? -1 : 1; } if (keyA > keyB) { return lowest ? 1 : -1; } return 0; }); }; /** * @param {?} a * @param {?} b * @return {?} */ Utils.prototype.sortByLinePosition = /** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { this.sortByX(a); this.sortByX(b); return (a[0].x > b[0].x) ? 1 : -1; }; /** * @param {?} a * @param {?} b * @return {?} */ Utils.prototype.difference = /** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { return Math.abs(a - b); }; /** * @param {?} event * @return {?} */ Utils.prototype.clickIsHighlight = /** * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var target = (/** @type {?} */ (event.target)); /** @type {?} */ var isHighlight = target.firstElementChild; if (isHighlight == null) { return false; } else if (isHighlight.id.includes('pdf-annotate-screenreader')) { return true; } else { return false; } }; /** * @param {?} event * @return {?} */ Utils.prototype.getClickedPage = /** * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var currentParent = event.target; for (var step = 0; step < 5; step++) { if (currentParent.parentNode != null) { /** @type {?} */ var pageNumber = currentParent.parentNode.getAttribute('data-page-number'); if (pageNumber != null) { return parseInt(pageNumber, null); } currentParent = currentParent.parentNode; } } }; return Utils; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PdfAdapter = /** @class */ (function () { function PdfAdapter(log, utils, window) { this.log = log; this.utils = utils; this.window = window; this.annotationChangeSubject = new Subject(); log.setClass('PdfAdapter'); } /** * @return {?} */ PdfAdapter.prototype.getAnnotationChangeSubject = /** * @return {?} */ function () { return this.annotationChangeSubject; }; /** * @param {?} annotationSet * @return {?} */ PdfAdapter.prototype.setStoreData = /** * @param {?} annotationSet * @return {?} */ function (annotationSet) { var _this = this; this.annotationSet = annotationSet; this.annotations = annotationSet.annotations; this.commentData = []; this.annotations.forEach(function (annotation) { annotation.comments.forEach(function (comment) { _this.commentData.push(comment); }); }); this.annotationSetId = annotationSet.id; }; /** * @param {?} comment * @return {?} */ PdfAdapter.prototype.editComment = /** * @param {?} comment * @return {?} */ function (comment) { var _this = this; this.annotations.forEach(function (annotation) { annotation.comments .filter(function (storeComment) { return storeComment.id === comment.id; }) .map(function (storeComment) { _this.log.info('Editing comment:' + comment.id); storeComment.content = comment.content; _this.annotationChangeSubject.next({ 'type': 'editComment', 'annotation': annotation }); }); }); }; /** * @param {?} documentId * @param {?} comment * @return {?} */ PdfAdapter.prototype.updateComments = /** * @param {?} documentId * @param {?} comment * @return {?} */ function (documentId, comment) { this.commentData.push(comment); }; /** * @param {?} documentId * @return {?} */ PdfAdapter.prototype._getAnnotations = /** * @param {?} documentId * @return {?} */ function (documentId) { return this.annotations || []; }; /** * @param {?} documentId * @return {?} */ PdfAdapter.prototype._getComments = /** * @param {?} documentId * @return {?} */ function (documentId) { return this.commentData || []; }; /** * @return {?} */ PdfAdapter.prototype.clearSelection = /** * @return {?} */ function () { /** @type {?} */ var sel = this.window.getSelection(); if (sel) { if (sel.removeAllRanges) { sel.removeAllRanges(); } else if (sel.empty) { sel.empty(); } } }; /** * @param {?} comment * @return {?} */ PdfAdapter.prototype.isDraftComment = /** * @param {?} comment * @return {?} */ function (comment) { return (comment.content === null || comment.content === ''); }; /** * @return {?} */ PdfAdapter.prototype.getStoreAdapter = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var getAnnotations = function (documentId, pageNumber) { return new Promise(function (resolve, reject) { /** @type {?} */ var annotations = _this._getAnnotations(documentId).filter(function (i) { return i.page === pageNumber; }); resolve({ documentId: documentId, pageNumber: pageNumber, annotations: annotations }); }); }; /** @type {?} */ var getComments = function (documentId, annotationId) { return new Promise(function (resolve, reject) { resolve(_this._getComments(documentId).filter(function (i) { return i.annotationId === annotationId; })); }); }; /** @type {?} */ var getAnnotation = function (documentId, annotationId) { return new Promise(function (resolve, reject) { /** @type {?} */ var annotation = _this._getAnnotations(documentId).find(function (i) { return i.id === annotationId; }); resolve(annotation); }); }; /** @type {?} */ var addAnnotation = function (documentId, pageNumber, annotation) { return new Promise(function (resolve, reject) { _this.clearSelection(); /** @type {?} */ var persistAnnotation = new Annotation(); persistAnnotation.id = v4(); persistAnnotation.page = pageNumber; persistAnnotation.color = annotation.color; persistAnnotation.type = annotation.type; persistAnnotation.comments = []; persistAnnotation.annotationSetId = _this.annotationSetId; /** @type {?} */ var rectangles = []; _this.log.info('Generating efficient rectangles for new annotation:' + persistAnnotation.id); _this.utils.generateRectanglePerLine(annotation.rectangles, rectangles); rectangles.forEach(function (rectangle) { rectangle.id = v4(); }); persistAnnotation.rectangles = rectangles; /** @type {?} */ var annotations = _this._getAnnotations(documentId); annotations.push(persistAnnotation); _this.log.info('Added annotation:' + annotation.id); _this.annotationChangeSubject.next({ 'type': 'addAnnotation', 'annotation': persistAnnotation }); resolve(persistAnnotation); }); }; /** @type {?} */ var deleteAnnotation = function (documentId, annotationId) { return new Promise(function (resolve, reject) { /** @type {?} */ var annotation = _this.findById(_this.annotations, annotationId); _this.remove(_this.annotations, annotationId); _this.log.info('Deleted annotation:' + annotationId); _this.annotationChangeSubject.next({ 'type': 'deleteAnnotation', 'annotation': annotation }); resolve(_this.annotations); }); }; /** @type {?} */ var addComment = function (documentId, annotationId, content) { return new Promise(function (resolve, reject) { /** @type {?} */ var comment = new Comment(v4(), annotationId, null, null, new Date(), null, null, null, content); _this.updateComments(documentId, comment); /** @type {?} */ var annotation = _this.findById(_this.annotations, annotationId); _this.log.info('Comment:' + comment.id + ' has been added to annotation:' + annotationId); annotation.comments.push(comment); if (_this.isDraftComment(comment)) { _this.log.info('Removing comment box because no content exists'); resolve(comment); } else { _this.log.info('Add comment:' + comment.id + '-' + 'annotationId:' + annotation.id); _this.annotationChangeSubject.next({ 'type': 'addComment', 'annotation': annotation }); resolve(comment); } }); }; /** @type {?} */ var deleteComment = function (documentId, commentId) { return new Promise(function (resolve, reject) { /** @type {?} */ var comment = _this.findById(_this.commentData, commentId); /** @type {?} */ var annotation = _this.findById(_this.annotations, comment.annotationId); _this.remove(_this.commentData, commentId); _this.remove(annotation.comments, commentId); if (_this.isDraftComment(comment)) { _this.log.info('Removing comment box because no content exists'); resolve(comment); } else { _this.log.info('Deleted comment:' + commentId + '-' + 'annotationId:' + annotation.id); _this.annotationChangeSubject.next({ 'type': 'deleteComment', 'annotation': annotation }); resolve(_this.annotations); } }); }; // Unused /** @type {?} */ var editAnnotation = function (documentId, pageNumber, annotation) { return new Promise(function (resolve, reject) { _this.annotationChangeSubject.next({ 'type': 'editAnnotation', 'annotation': annotation }); resolve(_this.commentData); }); }; return { getAnnotations: getAnnotations, getComments: getComments, getAnnotation: getAnnotation, addAnnotation: addAnnotation, editAnnotation: editAnnotation, deleteAnnotation: deleteAnnotation, addComment: addComment, deleteComment: deleteComment }; }; /** * @param {?} array * @param {?} id * @return {?} */ PdfAdapter.prototype.findById = /** * @param {?} array * @param {?} id * @return {?} */ function (array, id) { return array.find(function (e) { return e.id === id; }); }; /** * @param {?} array * @param {?} id * @return {?} */ PdfAdapter.prototype.remove = /** * @param {?} array * @param {?} id * @return {?} */ function (array, id) { return array.splice(array.findIndex(function (e) { return e.id === id; }), 1); }; PdfAdapter.decorators = [ { type: Injectable } ]; PdfAdapter.ctorParameters = function () { return [ { type: EmLoggerService }, { type: Utils }, { type: undefined, decorators: [{ type: Inject, args: [WINDOW,] }] } ]; }; return PdfAdapter; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ApiHttpService = /** @class */ (function () { function ApiHttpService(log, httpClient, platformId, transferState) { this.log = log; this.httpClient = httpClient; this.platformId = platformId; this.transferState = transferState; log.setClass('ApiHttpService'); } /** * @param {?} baseUrl * @return {?} */ ApiHttpService.prototype.setBaseUrl = /** * @param {?} baseUrl * @return {?} */ function (baseUrl) { this.baseUrl = baseUrl; }; /** * @return {?} */ ApiHttpService.prototype.getBaseUrl = /** * @return {?} */ function () { return this.baseUrl; }; /** * @param {?} baseUrl * @param {?} body * @return {?} */ ApiHttpService.prototype.createAnnotationSet = /** * @param {?} baseUrl * @param {?} body * @return {?} */ function (baseUrl, body) { return this.httpClient.post(baseUrl + "/em-anno/annotation-sets", body, { observe: 'response' }); }; /** * @param {?} baseUrl * @param {?} dmDocumentId * @return {?} */ ApiHttpService.prototype.fetch = /** * @param {?} baseUrl * @param {?} dmDocumentId * @return {?} */ function (baseUrl, dmDocumentId) { var _this = this; /** @type {?} */ var STATE_KEY = makeStateKey('annotationSet-' + dmDocumentId); if (this.transferState.hasKey(STATE_KEY)) { /** @type {?} */ var annotationSet = this.transferState.get(STATE_KEY, null); this.transferState.remove(STATE_KEY); return of(annotationSet); } else { /** @type {?} */ var url = baseUrl + "/em-anno/annotation-sets/" + dmDocumentId; return this.httpClient.get(url, { observe: 'response' }) .pipe(tap(function (annotationSet) { if (isPlatformServer(_this.platformId)) { _this.transferState.set(STATE_KEY, annotationSet); } })); } }; /** * @param {?} dmDocumentId * @param {?} outputDmDocumentId * @param {?} baseUrl * @return {?} */ ApiHttpService.prototype.documentTask = /** * @param {?} dmDocumentId * @param {?} outputDmDocumentId * @param {?} baseUrl * @return {?} */ function (dmDocumentId, outputDmDocumentId, baseUrl) { /** @type {?} */ var url = baseUrl + "/api/em-npa/document-tasks"; /** @type {?} */ var documentTasks = { inputDocumentId: dmDocumentId, outputDocumentId: outputDmDocumentId }; this.log.info('Calling NPA service-' + dmDocumentId); return this.httpClient.post(url, documentTasks, { observe: 'response' }); }; /** * @param {?} annotation * @return {?} */ ApiHttpService.prototype.deleteAnnotation = /** * @param {?} annotation * @return {?} */ function (annotation) { /** @type {?} */ var url = this.baseUrl + "/em-anno/annotations/" + annotation.id; return this.httpClient.delete(url, { observe: 'response' }); }; /** * @param {?} annotation * @return {?} */ ApiHttpService.prototype.saveAnnotation = /** * @param {?} annotation * @return {?} */ function (annotation) { /** @type {?} */ var url = this.baseUrl + "/em-anno/annotations"; return this.httpClient.post(url, annotation, { observe: 'response' }); }; ApiHttpService.decorators = [ { type: Injectable } ]; ApiHttpService.ctorParameters = function () { return [ { type: EmLoggerService }, { type: HttpClient }, { type: undefined, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }, { type: TransferState } ]; }; return ApiHttpService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PdfWrapper = /** @class */ (function () { function PdfWrapper() { } /** * @param {?} documentId * @return {?} */ PdfWrapper.prototype.getDocument = /** * @param {?} documentId * @return {?} */ function (documentId) { return PDFJS.getDocument(documentId); }; return PdfWrapper; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var RotationModel = /** @class */ (function () { function RotationModel(pageNumber, pageDom) { this.pageNumber = pageNumber; this.pageDom = pageDom; } return RotationModel; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var PdfRenderService = /** @class */ (function () { function PdfRenderService(pdfWrapper, log, pdfAnnotateWrapper) { this.pdfWrapper = pdfWrapper; this.log = log; this.pdfAnnotateWrapper = pdfAnnotateWrapper; this.listPages = []; this.log.setClass('PdfRenderService'); this.dataLoadedSubject = new BehaviorSubject(false); this.listPagesSubject = new Subject(); } /** * @return {?} */ PdfRenderService.prototype.getDataLoadedSub = /** * @return {?} */ function () { return this.dataLoadedSubject; }; /** * @param {?} isLoaded * @return {?} */ PdfRenderService.prototype.dataLoadedUpdate = /** * @param {?} isLoaded * @return {?} */ function (isLoaded) { this.dataLoadedSubject.next(isLoaded); }; /** * @return {?} */ PdfRenderService.prototype.getRenderOptions = /** * @return {?} */ function () { return Object.assign({}, this.RENDER_OPTIONS); }; /** * @param {?} RENDER_OPTIONS * @return {?} */ PdfRenderService.prototype.setRenderOptions = /** * @param {?} RENDER_OPTIONS * @return {?} */ function (RENDER_OPTIONS) { this.RENDER_OPTIONS = RENDER_OPTIONS; }; /** * @return {?} */ PdfRenderService.prototype.getViewerElementRef = /** * @return {?} */ function () { return this.viewerElementRef; }; /** * @return {?} */ PdfRenderService.prototype.getPdfPages = /** * @return {?} */ function () { return this.pdfPages; }; /** * @param {?=} viewerElementRef * @return {?} */ PdfRenderService.prototype.render = /** * @param {?=} viewerElementRef * @return {?} */ function (viewerElementRef) { var _this = this; if (viewerElementRef != null) { this.viewerElementRef = viewerElementRef; } /** @type {?} */ var renderOptions = this.getRenderOptions(); this.pdfWrapper.getDocument(renderOptions.documentId) .then(function (pdf) { renderOptions.pdfDocument = pdf; /** @type {?} */ var viewer = _this.viewerElementRef.nativeElement; viewer.innerHTML = ''; _this.pdfPages = pdf.pdfInfo.numPages; _this.listPages = []; var _loop_1 = function (i) { /** @type {?} */ var pageDom = _this.pdfAnnotateWrapper.createPage(i); // Create a copy of the render options for each page. /** @type {?} */ var pageOptions = Object.assign({}, renderOptions); viewer.appendChild(pageDom); _this.addDomPage(pageDom, i); pdf.getPage(i).then(function (pdfPage) { // Get current page rotation from page rotation objects pageOptions.rotate = _this.addPageRotation(renderOptions, pageOptions, pdfPage); setTimeout(function () { _this.pdfAnnotateWrapper.renderPage(i, pageOptions).then(function () { if (i === _this.pdfPages) { _this.setRenderOptions(renderOptions); _this.dataLoadedUpdate(true); _this.listPagesSubject.next(_this.listPages); } }); }); }); }; for (var i = 1; i < _this.pdfPages + 1; i++) { _loop_1(i); } }).catch(function (error) { /** @type {?} */ var errorMessage = new Error('Unable to render your supplied PDF. ' + renderOptions.documentId + '. Error is: ' + error); _this.log.error('Encountered error while rendering the PDF:' + errorMessage); }); }; /** * @param {?} pageDom * @param {?} pageNumber * @return {?} */ PdfRenderService.prototype.addDomPage = /** * @param {?} pageDom * @param {?} pageNumber * @return {?} */ function (pageDom, pageNumber) { /** @type {?} */ var pagedetails = new RotationModel(pageNumber, pageDom); /** @type {?} */ var index = this.listPages.findIndex(function (pageElement) { return pageElement.pageNumber === pageNumber; }); if (index > 0) { this.listPages[index] = pagedetails; } else { this.listPages.push(pagedetails); } }; /** * @param {?} renderOptions * @param {?} pageOptions * @param {?} pdfPage * @return {?} */ PdfRenderService.prototype.addPageRotation = /** * @param {?} renderOptions * @param {?} pageOptions * @param {?} pdfPage * @return {?} */ function (renderOptions, pageOptions, pdfPage) { /** @type {?} */ var rotation = this.getPageRotation(pageOptions, pdfPage); if (!rotation) { renderOptions.rotationPages.push({ page: pdfPage.pageNumber, rotate: pdfPage.rotate }); rotation = pdfPage.rotate; } return rotation; }; /** * @param {?} pageOptions * @param {?} pdfPage * @return {?} */ PdfRenderService.prototype.getPageRotation = /** * @param {?} pageOptions * @param {?} pdfPage * @return {?} */ function (pageOptions, pdfPage) { return pageOptions.rotationPages .filter(function (rotateObj) { return rotateObj.page === pdfPage.pageNumber; }) .map(function (rotateObj) { return rotateObj.rotate; })[0]; }; PdfRenderService.decorators = [ { type: Injectable } ]; PdfRenderService.ctorParameters = function () { return [ { type: PdfWrapper }, { type: EmLoggerService }, { type: PdfAnnotateWrapper } ]; }; return PdfRenderService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var AnnotationStoreService = /** @class */ (function () { function AnnotationStoreService(log, pdfAdapter, apiHttpService, pdfService, pdfAnnotateWrapper, pdfRenderService) { var _this = this; this.log = log; this.pdfAdapter = pdfAdapter; this.apiHttpService = apiHttpService; this.pdfService = pdfService; this.pdfAnnotateWrapper = pdfAnnotateWrapper; this.pdfRenderService = pdfRenderService; log.setClass('AnnotationStoreService'); this.commentBtnSubject = new Subject(); this.commentFocusSubject = new BehaviorSubject({ annotation: new Annotation(null, null, null, null, null, null, null, null, null, null, null, null) }); this.contextualToolBarOptions = new Subject(); this.annotationFocusSubject = new Subject(); this.annotationChangeSubscription = this.pdfAdapter.getAnnotationChangeSubject().subscribe(function (e) { return _this.handleAnnotationEvent(e); }); } /** * @return {?} */ AnnotationStoreService.prototype.getAnnotationFocusSubject = /** * @return {?} */ function () { return this.annotationFocusSubject; }; /** * @param {?} annotation * @return {?} */ AnnotationStoreService.prototype.setAnnotationFocusSubject = /** * @param {?} annotation * @return {?} */ function (annotation) { this.annotationFocusSubject.next(annotation); }; /** * @return {?} */ AnnotationStoreService.prototype.getCommentFocusSubject = /** * @return {?} */ function () { return this.commentFocusSubject; }; /** * @param {?} annotation * @param {?=} showButton * @return {?} */ AnnotationStoreService.prototype.setCommentFocusSubject = /** * @param {?} annotation * @param {?=} showButton * @return {?} */ function (annotation, showButton) { this.commentFocusSubject.next({ annotation: annotation, showButton: showButton }); }; /** * @return {?} */ AnnotationStoreService.prototype.getCommentBtnSubject = /** * @return {?} */ function () { return this.commentBtnSubject; }; /** * @param {?} commentId * @return {?} */ AnnotationStoreService.prototype.setCommentBtnSubject = /** * @param {?} commentId * @return {?} */ function (commentId) { this.commentBtnSubject.next(commentId); }; /** * @param {?} annotation * @param {?=} showDelete * @return {?} */ AnnotationStoreService.prototype.setToolBarUpdate = /** * @param {?} annotation * @param {?=} showDelete * @return {?} */ function (annotation, showDelete) { /** @type {?} */ var contextualOptions = { annotation: annotation, showDelete: showDelete }; this.contextualToolBarOptions.next(contextualOptions); }; /** * @return {?} */ AnnotationStoreService.prototype.getToolbarUpdate = /** * @return {?} */ function () { return this.contextualToolBarOptions; }; /** * @param {?} annotationData * @return {?} */ AnnotationStoreService.prototype.preLoad = /** * @param {?} annotationData * @return {?} */ function (annotationData) { if (annotationData != null) { this.pdfAdapter.setStoreData(annotationData); this.pdfAnnotateWrapper.setStoreAdapter(this.pdfAdapter.getStoreAdapter()); this.pdfService.setHighlightTool(); } else { this.pdfService.setCursorTool(); this.pdfAnnotateWrapper.setStoreAdapter(); } }; /** * @param {?} e * @return {?} */ AnnotationStoreService.prototype.handleAnnotationEvent = /** * @param {?} e * @return {?} */ function (e) { switch (e.type) { case 'addAnnotation': { this.saveAnnotation(e.annotation); break; } case 'addComment': { this.saveAnnotation(e.annotation, e.type); break; } case 'editComment': { this.saveAnnotation(e.annotation, e.type); break; } case 'deleteComment': { this.saveAnnotation(e.annotation); break; } case 'editAnnotation': { this.saveAnnotation(e.annotation); break; } case 'deleteAnnotation': { this.deleteAnnotation(e.annotation); break; } } }; /** * @param {?} baseUrl * @param {?} dmDocumentId * @return {?} */ AnnotationStoreService.prototype.getAnnotationSet = /** * @param {?} baseUrl * @param {?} dmDocumentId * @return {?} */ function (baseUrl, dmDocumentId) { var _this = this; return this.apiHttpService.fetch(baseUrl, dmDocumentId).pipe(catchError(function (err) { if (err instanceof HttpErrorResponse) { switch (err.status) { case 400: { _this.log.error('Bad request: ' + err.error); return throwError(err.error); } case 404: { /** @type {?} */ var body = { documentId: dmDocumentId, id: v4() }; _this.log.info('Creating new annotation set for document id:' + dmDocumentId); return _this.apiHttpService.createAnnotationSet(baseUrl, body); } case 500: { _this.log.error('Internal server error: ' + err); return throwError('Internal server error: ' + err); } } } })); }; /** * @return {?} */ AnnotationStoreService.prototype.saveData = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var loadedData; /** @type {?} */ var toKeepAnnotations; /** @type {?} */ var toRemoveAnnotations; loadedData = this.pdfAdapter.annotationSet; toKeepAnnotations = this.pdfAdapter.annotations; toRemoveAnnotations = this.pdfAdapter.annotationSet.annotations .filter(function (annotation) { return !_this.pdfAdapter.annotations.map(function (a) { return a.id; }).includes(annotation.id); }); toKeepAnnotations.forEach(function (annotation) { _this.apiHttpService.saveAnnotation(annotation).subscribe(function (response) { return _this.log.info('Successfully saved annotation:' + response); }, function (error) { return _this.log.error('There has been a problem saving the annotation:' + annotation.id + '-' + error); }); }); toRemoveAnnotations.forEach(function (annotation) { _this.apiHttpService.deleteAnnotation(annotation).subscribe(function (response) { return _this.log.info('Successfully deleted annotation:' + response); }, function (error) { return _this.log.error('There has been a problem deleting annotation:' + annotation.id + '-' + error); }); }); loadedData.annotations.splice(0, loadedData.annotations.length); loadedData.annotations.concat(toKeepAnnotations); this.pdfAdapter.annotationSet = loadedData; }; /** * @param {?} annotation * @param {?=} type * @return {?} */ AnnotationStoreService.prototype.saveAnnotation = /** * @param {?} annotation * @param {?=} type * @return {?} */ function (annotation, type) { var _this = this; this.apiHttpService.saveAnnotation(annotation).subscribe(function (response) { if (type === 'addComment' || type === 'editComment') { _this.pdfAdapter.annotationSet.annotations[_this.pdfAdapter.annotationSet.annotations .findIndex(function (x) { return x.id === annotation.id; })] = response.body; } _this.log.info('Successfully saved annotation:' + response); }, function (error) { return _this.log.error('There has been a problem saving the annotation:' + annotation.id + '-' + error); }); }; /** * @param {?} annotation * @return {?} */ AnnotationStoreService.prototype.deleteAnnotation = /** * @param {?} annotation * @return {?} */ function (annotation) { var _this = this; this.apiHttpService.deleteAnnotation(annotation).subscribe(function (response) { _this.log.info('Successfully deleted annotation:' + annotation.id + '-' + response); }, function (error) { return _this.log.error('There has been a problem deleting annotation:' + annotation.id + '-' + error); }); }; /** * @param {?} comment * @return {?} */ AnnotationStoreService.prototype.editComment = /** * @param {?} comment * @return {?} */ function (comment) { this.pdfAdapter.editComment(comment); }; /** * @param {?} annotationId * @return {?} */ AnnotationStoreService.prototype.getAnnotationById = /** * @param {?} annotationId * @return {?} */ function (annotationId) { var _this = this; return new Promise(function (resolve) { _this.getAnnotation(annotationId, function (annotation) { resolve(annotation); }); }); }; /** * @param {?} pageNumber * @return {?} */ AnnotationStoreService.prototype.getAnnotationsForPage = /** * @param {?} pageNumber * @return {?} */ function (pageNumber) { var _this = this; return new Promise(function (resolve) { _this.getAnnotations(pageNumber, function (pageData) { resolve(pageData); }); }); }; /** * @param {?} annotationId * @return {?} */ AnnotationStoreService.prototype.getCommentsForAnnotation = /** * @param {?} annotationId * @return {?} */ function (annotationId) { var _this = this; return new Promise(function (resolve) { _this.getComments(annotationId, function (comments) { resolve(comments); }); }); }; /** * @param {?} annotationId * @param {?} callback * @return {?} */ AnnotationStoreService.prototype.getAnnotation = /** * @param {?} annotationId * @param {?} callback * @return {?} */ function (annotationId, callback) { this.pdfAnnotateWrapper.getStoreAdapter() .getAnnotation(this.pdfRenderService.getRenderOptions().documentId, annotationId) .then(callback); }; /** * @param {?} annotationId * @param {?} callback * @return {?} */ AnnotationStoreService.prototype.getComments = /** * @param {?} annotationId * @param {?} callback * @return {?} */ function (annotationId, callback) { this.pdfAnnotateWrapper.getStoreAdapter() .getComments(this.pdfRenderService.getRenderOptions().documentId, annotationId) .then(callback); }; /** * @param {?} comment * @return {?} */ AnnotationStoreService.prototype.addComment = /** * @param {?} comment * @return {?} */ function (comment) { this.pdfAnnotateWrapper.getStoreAdapter() .addComment(this.pdfRenderService.getRenderOptions().documentId, comment.annotationId, comment.content) .then(); }; /** * @param {?} pageNumber * @param {?} callback * @return {?} */ AnnotationStoreService.prototype.getAnnotations = /** * @param {?} pageNumber * @param {?} callback * @return {?} */ function (pageNumber, callback) { this.pdfAnnotateWrapper.getStoreAdapter() .getAnnotations(this.pdfRenderService.getRenderOptions().documentId, pageNumber) .then(callback); }; /** * @param {?} commentId * @return {?} */ AnnotationStoreService.prototype.deleteComment = /** * @param {?} commentId * @return {?} */ function (commentId) { this.pdfAnnotateWrapper.getStoreAdapter() .deleteComment(this.pdfRenderService.getRenderOptions().documentId, commentId) .then(); }; /** * @param {?} annotationId * @param {?} pageNumber * @return {?} */ AnnotationStoreService.prototype.deleteAnnotationById = /** * @param {?} annotationId * @param {?} pageNumber * @return {?} */ function (annotationId, pageNumber) { return __awaiter(this, void 0, void 0, function () { var renderOptions; return __generator(this, function (_a) { switch (_a.label) { case 0: renderOptions = this.pdfRenderService.getRenderOptions(); return [4 /*yield*/, this.pdfAnnotateWrapper.getStoreAdapter() .deleteAnnotation(renderOptions.documentId, annotationId)]; case 1: _a.sent(); this.renderPage(renderOptions, pageNumber); return [2 /*return*/]; } }); }); }; /** * @param {?} renderOptions * @param {?} pageNumber * @return {?} */ AnnotationStoreService.prototype.renderPage = /** * @param {?} renderOptions * @param {?} pageNumber * @return {?} */ function (renderOptions, pageNumber) { renderOptions.rotate = this.pdfRenderService.getPageRotation(renderOptions, { pageNumber: pageNumber }); this.pdfAnnotateWrapper.renderPage(pageNumber, renderOptions); }; /** * @return {?} */ AnnotationStoreService.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.annotationChangeSubscrip