Giter VIP home page Giter VIP logo

media-viewer's Introduction

@hmcts/media-viewer

Coverage Status Build Status

This is an angular library that provides components to view and annotate PDF documents, as well as view images.

Running demo app

  • npm run package (deprecated)
  • npm run start:ng

Integrating into your own Angular application

add @hmcts/media-viewer as a dependency in package.json

npm install --save @hmcts/media-viewer

import MediaViewerModule and declare it in your NgModule imports.

import { MediaViewerModule } from 'media-viewer';

@NgModule({
  imports: [
    ...,
    MediaViewerModule,
  ]
})

import assets to your angular.json

{
    "glob": "**/*",
    "input": "node_modules/@hmcts/media-viewer/assets",
    "output": "/assets"
}

and styles

"styles": [
  "node_modules/@hmcts/media-viewer/assets/aui-styles.scss",
  ...
],

component entry point:

<mv-media-viewer [url]="'assets/example.pdf'"
                 [downloadFileName]="'example.pdf'"
                 [showToolbar]="true"
                 [contentType]="'pdf'">
</mv-media-viewer>  

Customisations

Toolbar

The toolbar may be toggled off by setting showToolbar to false. The toolbar itself is available as a module that can be included into the DOM at a different location if necessary.

Toolbar buttons

Toolbar buttons can be toggled on or off using the 'toolbarButtonOverrides' input. Each button can toggled on or off as follows:

toolbarButtons = { showRotate: true, showDownload: false }

<mv-media-viewer ...
                 [toolbarButtonOverrides]="toolbarButtons">
</mv-media-viewer>  

The full list of buttons is as follows:

showPrint
showDownload
showNavigation
showZoom
showRotate
showHighlightButton
showDrawButton
showSearchBar
showSidebar

Media Viewer Height and Width

You can set height and width of the media viewer otherwise it will be set to default settings of 100%.

<mv-media-viewer ...
                 [height]="'500px'"
                 [width]="'500px'">
</mv-media-viewer>  

Annotation API

To override the default Annotation API path (or URL for cross domain calls) use "annotationApiUrl" parameter

<mv-media-viewer annotationApiUrl=""http://my-gateway.com/my-context-path""  ... >
</mv-media-viewer>

Backend setup

  • the media-viewer expects calls to the backend to be proxied by the consuming application. This includes the following APIs:
    • '/documents', endpoint to be proxied to the 'document-store'
    • '/em-anno', endpoint to be proxied to the 'annotations-api', if annotations are turned on

Proxying the Annotation Api

In order to use annotations on the media viewer, you need to proxy the calls.

Example:

import * as proxy from "http-proxy-middleware";

Annotation Config:

const annotation = {
    endpoints: ["/em-anno"],
    target: "Enter URL",
    pathRewrite: {
        "^/em-anno": "/api"
    }
}

How to use the proxy:

this.app.use(proxy(annotation.endpoints, { target: annotation.target }));

Viewer Exceptions

The Media Viewer will return load status and provide exceptions if thrown for the host application to consume.

    <mv-media-viewer [url]="'assets/example.pdf'"
                     [downloadFileName]="'example.pdf'"
                     [showToolbar]="true"
                     [contentType]="'pdf'"
                     (mediaLoadStatus)="onMediaLoadStatus($event)"
                     (viewerException)="onMediaLoadException($event)">
    </mv-media-viewer>  

When exceptions are thrown by the different Media Viewers, the exception is encapsulated in an object called ViewerException and passed up the chain to be used by consuming service.

The structure of the ViewerException exception class can be seen below:

exceptionType: error.name,
detail: {
  httpResponseCode: error.status,
  message: error.message
}

Media Viewer Styles

Add these styles to your component.scss if you need them i.e. if you writing your own toolbar styles then do not import those

// Import GOV.UK Frontend
@import "~govuk-frontend/all";
@import "~@hmcts/frontend/all";
// Import Media Viewer Styles
@import "~media-viewer/src/assets/all"; // use this to import all the styles 
alternatevly it is possible to import file by file from assets/scss directory 
i.e. "~media-viewer/src/assets/toolbar/main"

The list of exceptions thrown by the Media Viewer are as follows:

  • UnknownErrorException
  • MissingPdfException
  • InvalidPDFException
  • UnexpectedResponseException
  • HttpErrorResponse
  • PasswordException

Cucumber Tests

 npm run package, npm run e2e:cucumber

media-viewer's People

Contributors

benouaer avatar dependabot[bot] avatar fazanki avatar jai-santhosh avatar jaisanthosh avatar jeroenrijks avatar linusnorton avatar pawelkaczmarekuk avatar phaniperla avatar russellwardink avatar tomxelliott avatar velimd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.