Skip to content

Commit

Permalink
Add support for startCanvas
Browse files Browse the repository at this point in the history
  • Loading branch information
t11r committed Aug 18, 2022
1 parent 0a56b64 commit d322e5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ window.Tify = function Tify(options = {}) {
manifestUrl: null,
viewer: {},
pageLabelFormat: 'P : L',
pages: [1],
pages: null,
pan: {},
rotation: null,
translationsDirUrl: null,
Expand Down
21 changes: 18 additions & 3 deletions src/mixins/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ export default {
clearTimeout(this.urlUpdateTimeout);
},
methods: {
getStartPages() {
const { pages } = this.options;

if (pages) {
return pages;
}

const { startCanvas } = this.manifest.sequences[0];
const startPage = startCanvas
? this.canvases.findIndex((canvas) => canvas['@id'] === startCanvas) + 1
: 1;

return [startPage];
},
isValidPagesArray(pages) {
if (!Array.isArray(pages)) {
return false;
Expand Down Expand Up @@ -42,6 +56,7 @@ export default {
}

if (pages.length === 1
&& this.options.pages
&& this.options.pages[0] % 2 < 1
&& (this.options.pages[1] === this.options.pages[0] + 1 || this.options.pages[1] === 0)
) {
Expand Down Expand Up @@ -105,12 +120,12 @@ export default {
}

if (params.pages && !this.isValidPagesArray(params.pages)) {
this.$root.error = 'Invalid pages, reset to first page';
params.pages = [1];
this.$root.error = 'Invalid pages, reset to start page';
params.pages = this.getStartPages();
}

this.options.filters = params.filters || this.options.filters;
this.options.pages = params.pages || this.options.pages;
this.options.pages = params.pages || this.getStartPages();
this.options.pan = params.panX || params.panY
? { x: params.panX, y: params.panY }
: params.pan || this.options.pan;
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/specs/export.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ describe('Export', () => {
cy.get('.tify').then(() => {
cy.contains('Export').click();
cy.contains('Download Individual Images').should('be.visible');
cy.contains('Page 1').should('be.visible');
cy.contains('Page 2').should('be.visible'); // NOTE: Page set by startCanvas
cy.get('[title="Next page"]').first().click();
cy.contains('Page 2').should('be.visible');
cy.contains('Page 3').should('be.visible');

cy.contains('PDFs for each element').click();
cy.contains('Titelseite').should('be.visible');
Expand Down
2 changes: 1 addition & 1 deletion tests/iiif-api/data/manifests/gdz-PPN857449303.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"label": "Current Page Order",
"viewingDirection": "left-to-right",
"viewingHint": "paged",
"startCanvas": "//localhost:8081/info/canvas/gdz:PPN857449303:00000001",
"startCanvas": "//localhost:8081/info/canvas/gdz:PPN857449303:00000002",
"canvases": [
{
"@id": "//localhost:8081/info/canvas/gdz:PPN857449303:00000001",
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const { app } = new Tify();
describe('main', () => {
app.manifest = manifest;

it('should determine the start page based on startCanvas', () => {
expect(app.getStartPages()).toEqual([2]);
});

it('should validate page numbers', () => {
expect(app.isValidPagesArray([1])).toEqual(true);
expect(app.isValidPagesArray([0, 1])).toEqual(true);
Expand Down

0 comments on commit d322e5c

Please sign in to comment.