From a0b831282758c2b81261d49d3c9a5e9e88345f17 Mon Sep 17 00:00:00 2001 From: edsilv Date: Wed, 30 Aug 2017 15:52:21 +0100 Subject: [PATCH 1/7] added lunchroommanners test --- dist/client/manifesto.bundle.js | 26 ++- dist/client/manifesto.js | 26 ++- dist/server/manifesto.js | 26 ++- src/Manifest.ts | 20 +-- test/fixtures/lunchroom-manners.json | 229 +++++++++++++++++++++++++++ test/fixtures/manifests.js | 1 + test/lunchroommanners.js | 23 +++ test/nested.js | 170 ++++++++++---------- 8 files changed, 381 insertions(+), 140 deletions(-) create mode 100644 test/fixtures/lunchroom-manners.json create mode 100644 test/lunchroommanners.js diff --git a/dist/client/manifesto.bundle.js b/dist/client/manifesto.bundle.js index cd91b21b..af1cd918 100644 --- a/dist/client/manifesto.bundle.js +++ b/dist/client/manifesto.bundle.js @@ -1215,25 +1215,21 @@ var Manifesto; else { parentRange.members.push(range); } - if (r.ranges) { - for (var i = 0; i < r.ranges.length; i++) { - this._parseRanges(r.ranges[i], path + '/' + i, range); - } - } if (r.members) { - var _loop_1 = function (i) { + for (var i = 0; i < r.members.length; i++) { var child = r.members[i]; // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - if (r.members.en().where(function (m) { return m.id === child.id; }).first()) { - return "continue"; - } - if (child['@type'].toLowerCase() === 'sc:range') { - this_1._parseRanges(child, path + '/' + i, range); + // if (range.members.en().where(m => m.id === child.id).first()) { + // continue; + // } + if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range') { + this._parseRanges(child, path + '/' + i, range); } - }; - var this_1 = this; - for (var i = 0; i < r.members.length; i++) { - _loop_1(i); + } + } + else if (r.ranges) { + for (var i = 0; i < r.ranges.length; i++) { + this._parseRanges(r.ranges[i], path + '/' + i, range); } } }; diff --git a/dist/client/manifesto.js b/dist/client/manifesto.js index 37fdd335..09d6fa4c 100644 --- a/dist/client/manifesto.js +++ b/dist/client/manifesto.js @@ -1142,25 +1142,21 @@ var Manifesto; else { parentRange.members.push(range); } - if (r.ranges) { - for (var i = 0; i < r.ranges.length; i++) { - this._parseRanges(r.ranges[i], path + '/' + i, range); - } - } if (r.members) { - var _loop_1 = function (i) { + for (var i = 0; i < r.members.length; i++) { var child = r.members[i]; // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - if (r.members.en().where(function (m) { return m.id === child.id; }).first()) { - return "continue"; - } - if (child['@type'].toLowerCase() === 'sc:range') { - this_1._parseRanges(child, path + '/' + i, range); + // if (range.members.en().where(m => m.id === child.id).first()) { + // continue; + // } + if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range') { + this._parseRanges(child, path + '/' + i, range); } - }; - var this_1 = this; - for (var i = 0; i < r.members.length; i++) { - _loop_1(i); + } + } + else if (r.ranges) { + for (var i = 0; i < r.ranges.length; i++) { + this._parseRanges(r.ranges[i], path + '/' + i, range); } } }; diff --git a/dist/server/manifesto.js b/dist/server/manifesto.js index 9f7c81b1..23d68850 100644 --- a/dist/server/manifesto.js +++ b/dist/server/manifesto.js @@ -1214,25 +1214,21 @@ var Manifesto; else { parentRange.members.push(range); } - if (r.ranges) { - for (var i = 0; i < r.ranges.length; i++) { - this._parseRanges(r.ranges[i], path + '/' + i, range); - } - } if (r.members) { - var _loop_1 = function (i) { + for (var i = 0; i < r.members.length; i++) { var child = r.members[i]; // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - if (r.members.en().where(function (m) { return m.id === child.id; }).first()) { - return "continue"; - } - if (child['@type'].toLowerCase() === 'sc:range') { - this_1._parseRanges(child, path + '/' + i, range); + // if (range.members.en().where(m => m.id === child.id).first()) { + // continue; + // } + if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range') { + this._parseRanges(child, path + '/' + i, range); } - }; - var this_1 = this; - for (var i = 0; i < r.members.length; i++) { - _loop_1(i); + } + } + else if (r.ranges) { + for (var i = 0; i < r.ranges.length; i++) { + this._parseRanges(r.ranges[i], path + '/' + i, range); } } }; diff --git a/src/Manifest.ts b/src/Manifest.ts index c11aeea7..9e833f7f 100644 --- a/src/Manifest.ts +++ b/src/Manifest.ts @@ -111,26 +111,26 @@ namespace Manifesto { parentRange.members.push(range); } - if (r.ranges) { - for (let i = 0; i < r.ranges.length; i++) { - this._parseRanges(r.ranges[i], path + '/' + i, range); - } - } - if (r.members) { for (let i = 0; i < r.members.length; i++) { const child: any = r.members[i]; // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - if (r.members.en().where(m => m.id === child.id).first()) { - continue; - } + // if (range.members.en().where(m => m.id === child.id).first()) { + // continue; + // } - if (child['@type'].toLowerCase() === 'sc:range'){ + if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range'){ this._parseRanges(child, path + '/' + i, range); } } + } else if (r.ranges) { + for (let i = 0; i < r.ranges.length; i++) { + this._parseRanges(r.ranges[i], path + '/' + i, range); + } } + + } getAllRanges(): IRange[] { diff --git a/test/fixtures/lunchroom-manners.json b/test/fixtures/lunchroom-manners.json new file mode 100644 index 00000000..df43f48e --- /dev/null +++ b/test/fixtures/lunchroom-manners.json @@ -0,0 +1,229 @@ + +{ + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners", + "type": "Manifest", + "label": "Lunchroom manners", + "description": "Beginning Reponsibility: Lunchroom Manners [motion picture] Coronet Films", + "sequences": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/sequence/1", + "type": "Sequence", + "canvases": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1", + "type": "Canvas", + "label": "Beginning Reponsibility: Lunchroom Manners [motion picture] Coronet Films", + "description": "Lunchroom manners are taught by following a boy through his lunchroom experience", + "height": 360, + "width": 480, + "duration": 660, + "content": [ + { + "id": "...", + "type": "AnnotationPage", + "items": [ + { + "id": "...", + "type": "Annotation", + "motivation": "painting", + "body": [ + { + "type": "Choice", + "choiceHint": "user", + "items": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/high/lunchroom_manners_1024kb.mp4", + "type": "Video", + "label": "High" + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/medium/lunchroom_manners_512kb.mp4", + "type": "Video", + "label": "Medium" + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/low/lunchroom_manners_256kb.mp4", + "type": "Video", + "label": "Low" + } + ] + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/lunchroom_manners.vtt", + "type": "Text", + "format": "text/vtt", + "language": "en" + } + ], + "target": "http://dlib.indiana.edu/iiif_av/canvas/1" + } + ] + } + ] + } + ] + } + ], + "structures": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/0", + "type": "Range", + "label": "Table of Contents", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/1", + "type": "Range", + "label": "Getting Ready for Lunch" + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/3", + "type": "Range", + "label": "In the Lunchroom" + } + ] + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/1", + "type": "Range", + "label": "Getting Ready for Lunch", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/2", + "type": "Range", + "label": "Washing Hands", + "members": [ + { + "type": "Range", + "label": "Using Soap", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=157,160", + "type": "Canvas" + } + ] + }, + { + "type": "Range", + "label": "", + "viewingHint": "no-table-of-contents", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=160,165", + "type": "Canvas" + } + ] + }, + { + "type": "Range", + "label": "Rinsing Well", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=165,178", + "type": "Canvas" + } + ] + } + ] + } + ] + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/3", + "type": "Range", + "label": "In the Lunchroom", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/4", + "type": "Range", + "label": "At the Counter", + "members": [ + { + "type": "Range", + "label": "Getting Tray", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=227,245", + "type": "Canvas" + } + ] + }, + { + "type": "Range", + "label": "Choosing Food", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=258,288", + "type": "Canvas" + } + ] + }, + { + "type": "Range", + "label": "There will be Cake", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=301,308", + "type": "Canvas" + } + ] + } + ] + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/5", + "type": "Range", + "label": "At the Table", + "members": [ + { + "type": "Range", + "label": "Sitting Quietly", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=323,333", + "type": "Canvas" + } + ] + }, + { + "type": "Range", + "label": "Eating Neatly", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=362,378", + "type": "Canvas" + } + ] + } + ] + }, + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/6", + "type": "Range", + "label": "Leavning the Lunchroom", + "members": [ + { + "type": "Range", + "label": "Cleaning Up", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=448,492", + "type": "Canvas" + } + ] + }, + { + "type": "Range", + "label": "Putting Things Away", + "members": [ + { + "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=511,527", + "type": "Canvas" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/fixtures/manifests.js b/test/fixtures/manifests.js index 1f724e1d..e8840ce6 100644 --- a/test/fixtures/manifests.js +++ b/test/fixtures/manifests.js @@ -12,6 +12,7 @@ module.exports = { "herbal": "http://localhost:3001/herbal.json", "horriblemurders": "http://localhost:3001/horriblemurders.json", "illustrationsofchina": "http://localhost:3001/illustrationsofchina.json", + "lunchroommanners": "http://localhost:3001/lunchroom-manners.json", "members": "http://localhost:3001/members.json", "memberscollection": "http://localhost:3001/members-collection.json", "membersranges": "http://localhost:3001/members-ranges.json", diff --git a/test/lunchroommanners.js b/test/lunchroommanners.js new file mode 100644 index 00000000..b0d18bce --- /dev/null +++ b/test/lunchroommanners.js @@ -0,0 +1,23 @@ +var expect = require('chai').expect; +var manifesto = require('../dist/server/manifesto'); +var should = require('chai').should(); +var manifests = require('./fixtures/manifests'); +require('./shared'); + +var manifest, topRange; + +describe('#loadsMembersRanges', function() { + it('loads successfully', function (done) { + manifesto.loadManifest(manifests.lunchroommanners).then(function(data) { + manifest = manifesto.create(data); + done(); + }); + }); +}); + +describe('#hasRanges', function() { + it('has ranges', function () { + topRange = manifest.getTopRanges()[0]; + topRange.members.length.should.equal(3); + }); +}); \ No newline at end of file diff --git a/test/nested.js b/test/nested.js index 39d5c13d..c29e6df8 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,86 +1,86 @@ -// nested collections - -var expect = require('chai').expect; -var manifesto = require('../dist/server/manifesto'); -var should = require('chai').should(); -var manifests = require('./fixtures/manifests'); -require('./shared'); - -var collection, manifest, firstCollection, secondCollection; - -describe('#loadsTopNestedManifest', function() { - it('loads successfully', function (done) { - manifesto.loadManifest(manifests['nested-top']).then(function(data) { - collection = manifesto.create(data); - done(); - }); - }); -}); - -describe('#hasIIIFResourceType', function() { - it('has a IIIFResourceType property of "sc:collection"', function () { - var type = collection.getIIIFResourceType(); - type.toString().should.equal('sc:collection'); - }); -}); - -describe('#hasCollectionCount', function() { - it('has a collection count of 1', function () { - collection.getTotalCollections().should.equal(1); - }); -}); - -describe('#hasLabel', function() { - it('has a label', function() { - Manifesto.TranslationCollection.getValue(collection.getLabel()).should.equal('Villanova Digital Library'); - }); -}); - -describe('#firstCollectionHasLabel', function() { - it('has a first collection with a label', function(done) { - collection.getCollectionByIndex(0).then(function(data) { - firstCollection = data; - Manifesto.TranslationCollection.getValue(firstCollection.getLabel()).should.equal('Dime Novel and Popular Literature'); - done(); - }); - }); -}); - -describe('#firstCollectionHasEmptyManifestCount', function() { - it('has a first collection which contains 0 manifests', function () { - firstCollection.getTotalManifests().should.equal(0); - }); -}); - -describe('#getTree', function() { - it('has a tree', function () { - var tree = collection.getDefaultTree(); - expect(tree).to.exist; - }); -}); - -describe('#secondLevelCollectionHasLabel', function() { - it('has a second-level collection with a label', function (done) { - firstCollection.getCollectionByIndex(0).then(function(data) { - secondCollection = data; - Manifesto.TranslationCollection.getValue(secondCollection.getLabel()).should.equal('Covers and Illustrations'); - done(); - }); - }); -}); - -describe('#secondCollectionHasManifestCount', function() { - it('has a second-level collection which contains 9 manifests', function () { - secondCollection.getTotalManifests().should.equal(9); - }); -}); - -describe('#canAccessManifestFromSecondCollection', function() { - it('can access a deeply-nested manifest', function (done) { - secondCollection.getManifestByIndex(0).then(function(data) { - manifest = data; - Manifesto.TranslationCollection.getValue(manifest.getLabel()).should.equal('Wunder der Vererbung'); - done(); - }); - }); +// nested collections + +var expect = require('chai').expect; +var manifesto = require('../dist/server/manifesto'); +var should = require('chai').should(); +var manifests = require('./fixtures/manifests'); +require('./shared'); + +var collection, manifest, firstCollection, secondCollection; + +describe('#loadsTopNestedManifest', function() { + it('loads successfully', function (done) { + manifesto.loadManifest(manifests['nested-top']).then(function(data) { + collection = manifesto.create(data); + done(); + }); + }); +}); + +describe('#hasIIIFResourceType', function() { + it('has a IIIFResourceType property of "sc:collection"', function () { + var type = collection.getIIIFResourceType(); + type.toString().should.equal('sc:collection'); + }); +}); + +describe('#hasCollectionCount', function() { + it('has a collection count of 1', function () { + collection.getTotalCollections().should.equal(1); + }); +}); + +describe('#hasLabel', function() { + it('has a label', function() { + Manifesto.TranslationCollection.getValue(collection.getLabel()).should.equal('Villanova Digital Library'); + }); +}); + +describe('#firstCollectionHasLabel', function() { + it('has a first collection with a label', function(done) { + collection.getCollectionByIndex(0).then(function(data) { + firstCollection = data; + Manifesto.TranslationCollection.getValue(firstCollection.getLabel()).should.equal('Dime Novel and Popular Literature'); + done(); + }); + }); +}); + +describe('#firstCollectionHasEmptyManifestCount', function() { + it('has a first collection which contains 0 manifests', function () { + firstCollection.getTotalManifests().should.equal(0); + }); +}); + +describe('#getTree', function() { + it('has a tree', function () { + var tree = collection.getDefaultTree(); + expect(tree).to.exist; + }); +}); + +describe('#secondLevelCollectionHasLabel', function() { + it('has a second-level collection with a label', function (done) { + firstCollection.getCollectionByIndex(0).then(function(data) { + secondCollection = data; + Manifesto.TranslationCollection.getValue(secondCollection.getLabel()).should.equal('Covers and Illustrations'); + done(); + }); + }); +}); + +describe('#secondCollectionHasManifestCount', function() { + it('has a second-level collection which contains 9 manifests', function () { + secondCollection.getTotalManifests().should.equal(9); + }); +}); + +describe('#canAccessManifestFromSecondCollection', function() { + it('can access a deeply-nested manifest', function (done) { + secondCollection.getManifestByIndex(0).then(function(data) { + manifest = data; + Manifesto.TranslationCollection.getValue(manifest.getLabel()).should.equal('Wunder der Vererbung'); + done(); + }); + }); }); \ No newline at end of file From c7e287d7d893967239d9f0d4ac3451eebfd02379 Mon Sep 17 00:00:00 2001 From: edsilv Date: Wed, 30 Aug 2017 16:17:19 +0100 Subject: [PATCH 2/7] remove @ --- dist/client/manifesto.bundle.js | 6 +----- dist/client/manifesto.js | 6 +----- dist/server/manifesto.js | 6 +----- src/IIIFResource.ts | 6 ------ src/ManifestResource.ts | 2 +- 5 files changed, 4 insertions(+), 22 deletions(-) diff --git a/dist/client/manifesto.bundle.js b/dist/client/manifesto.bundle.js index af1cd918..4eb60a64 100644 --- a/dist/client/manifesto.bundle.js +++ b/dist/client/manifesto.bundle.js @@ -708,7 +708,7 @@ var Manifesto; return _this; } ManifestResource.prototype.getIIIFResourceType = function () { - return new Manifesto.IIIFResourceType(this.getProperty('@type')); + return new Manifesto.IIIFResourceType(this.getProperty('type')); }; ManifestResource.prototype.getLabel = function () { return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale); @@ -1031,10 +1031,6 @@ var Manifesto; }; IIIFResource.prototype.getIIIFResourceType = function () { var type = this.getProperty('type'); - if (type) { - return new Manifesto.IIIFResourceType(type); - } - type = this.getProperty('@type'); return new Manifesto.IIIFResourceType(type); }; IIIFResource.prototype.getLogo = function () { diff --git a/dist/client/manifesto.js b/dist/client/manifesto.js index 09d6fa4c..dd7e0494 100644 --- a/dist/client/manifesto.js +++ b/dist/client/manifesto.js @@ -635,7 +635,7 @@ var Manifesto; return _this; } ManifestResource.prototype.getIIIFResourceType = function () { - return new Manifesto.IIIFResourceType(this.getProperty('@type')); + return new Manifesto.IIIFResourceType(this.getProperty('type')); }; ManifestResource.prototype.getLabel = function () { return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale); @@ -958,10 +958,6 @@ var Manifesto; }; IIIFResource.prototype.getIIIFResourceType = function () { var type = this.getProperty('type'); - if (type) { - return new Manifesto.IIIFResourceType(type); - } - type = this.getProperty('@type'); return new Manifesto.IIIFResourceType(type); }; IIIFResource.prototype.getLogo = function () { diff --git a/dist/server/manifesto.js b/dist/server/manifesto.js index 23d68850..b715a2f5 100644 --- a/dist/server/manifesto.js +++ b/dist/server/manifesto.js @@ -707,7 +707,7 @@ var Manifesto; return _this; } ManifestResource.prototype.getIIIFResourceType = function () { - return new Manifesto.IIIFResourceType(this.getProperty('@type')); + return new Manifesto.IIIFResourceType(this.getProperty('type')); }; ManifestResource.prototype.getLabel = function () { return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale); @@ -1030,10 +1030,6 @@ var Manifesto; }; IIIFResource.prototype.getIIIFResourceType = function () { var type = this.getProperty('type'); - if (type) { - return new Manifesto.IIIFResourceType(type); - } - type = this.getProperty('@type'); return new Manifesto.IIIFResourceType(type); }; IIIFResource.prototype.getLogo = function () { diff --git a/src/IIIFResource.ts b/src/IIIFResource.ts index a57dfd92..8adfb86f 100644 --- a/src/IIIFResource.ts +++ b/src/IIIFResource.ts @@ -42,12 +42,6 @@ namespace Manifesto { getIIIFResourceType(): IIIFResourceType { let type: string = this.getProperty('type'); - - if (type) { - return new IIIFResourceType(type); - } - - type = this.getProperty('@type'); return new IIIFResourceType(type); } diff --git a/src/ManifestResource.ts b/src/ManifestResource.ts index bb0fa2ae..60800955 100644 --- a/src/ManifestResource.ts +++ b/src/ManifestResource.ts @@ -9,7 +9,7 @@ namespace Manifesto { } getIIIFResourceType(): IIIFResourceType { - return new IIIFResourceType(this.getProperty('@type')); + return new IIIFResourceType(this.getProperty('type')); } getLabel(): TranslationCollection { From ace69996ead6ca9b2633699d294e67b6d881e72c Mon Sep 17 00:00:00 2001 From: edsilv Date: Wed, 30 Aug 2017 16:20:08 +0100 Subject: [PATCH 3/7] return members --- dist/client/manifesto.bundle.js | 9 +++++---- dist/client/manifesto.js | 9 +++++---- dist/server/manifesto.js | 9 +++++---- src/Range.ts | 10 ++++++---- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dist/client/manifesto.bundle.js b/dist/client/manifesto.bundle.js index 4eb60a64..5d2d39be 100644 --- a/dist/client/manifesto.bundle.js +++ b/dist/client/manifesto.bundle.js @@ -1453,10 +1453,11 @@ var Manifesto; return this._canvases = this.members.en().where(function (m) { return m.isCanvas(); }).toArray(); }; Range.prototype.getRanges = function () { - if (this._ranges) { - return this._ranges; - } - return this._ranges = this.members.en().where(function (m) { return m.isRange(); }).toArray(); + return this.members; + // if (this._ranges){ + // return this._ranges; + // } + // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); }; Range.prototype.getViewingDirection = function () { if (this.getProperty('viewingDirection')) { diff --git a/dist/client/manifesto.js b/dist/client/manifesto.js index dd7e0494..df302bbe 100644 --- a/dist/client/manifesto.js +++ b/dist/client/manifesto.js @@ -1380,10 +1380,11 @@ var Manifesto; return this._canvases = this.members.en().where(function (m) { return m.isCanvas(); }).toArray(); }; Range.prototype.getRanges = function () { - if (this._ranges) { - return this._ranges; - } - return this._ranges = this.members.en().where(function (m) { return m.isRange(); }).toArray(); + return this.members; + // if (this._ranges){ + // return this._ranges; + // } + // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); }; Range.prototype.getViewingDirection = function () { if (this.getProperty('viewingDirection')) { diff --git a/dist/server/manifesto.js b/dist/server/manifesto.js index b715a2f5..7bdbfa85 100644 --- a/dist/server/manifesto.js +++ b/dist/server/manifesto.js @@ -1452,10 +1452,11 @@ var Manifesto; return this._canvases = this.members.en().where(function (m) { return m.isCanvas(); }).toArray(); }; Range.prototype.getRanges = function () { - if (this._ranges) { - return this._ranges; - } - return this._ranges = this.members.en().where(function (m) { return m.isRange(); }).toArray(); + return this.members; + // if (this._ranges){ + // return this._ranges; + // } + // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); }; Range.prototype.getViewingDirection = function () { if (this.getProperty('viewingDirection')) { diff --git a/src/Range.ts b/src/Range.ts index 108bbb53..03909825 100644 --- a/src/Range.ts +++ b/src/Range.ts @@ -29,11 +29,13 @@ namespace Manifesto { } getRanges(): IRange[] { - if (this._ranges){ - return this._ranges; - } - return this._ranges = this.members.en().where(m => m.isRange()).toArray(); + return this.members; + // if (this._ranges){ + // return this._ranges; + // } + + // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); } getViewingDirection(): ViewingDirection | null { From 99111a9066a1aea47a6447a18e3a79eb80bd2560 Mon Sep 17 00:00:00 2001 From: edsilv Date: Wed, 30 Aug 2017 16:53:32 +0100 Subject: [PATCH 4/7] updated fixture --- test/fixtures/lunchroom-manners.json | 18 ------------------ test/lunchroommanners.js | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/test/fixtures/lunchroom-manners.json b/test/fixtures/lunchroom-manners.json index df43f48e..048799e2 100644 --- a/test/fixtures/lunchroom-manners.json +++ b/test/fixtures/lunchroom-manners.json @@ -1,4 +1,3 @@ - { "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners", "type": "Manifest", @@ -65,23 +64,6 @@ } ], "structures": [ - { - "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/0", - "type": "Range", - "label": "Table of Contents", - "members": [ - { - "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/1", - "type": "Range", - "label": "Getting Ready for Lunch" - }, - { - "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/3", - "type": "Range", - "label": "In the Lunchroom" - } - ] - }, { "id": "http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/1", "type": "Range", diff --git a/test/lunchroommanners.js b/test/lunchroommanners.js index b0d18bce..75abf50e 100644 --- a/test/lunchroommanners.js +++ b/test/lunchroommanners.js @@ -18,6 +18,6 @@ describe('#loadsMembersRanges', function() { describe('#hasRanges', function() { it('has ranges', function () { topRange = manifest.getTopRanges()[0]; - topRange.members.length.should.equal(3); + topRange.members.length.should.equal(2); }); }); \ No newline at end of file From 1fef2e4625b5ab264bbb2109432b4d75393d82ca Mon Sep 17 00:00:00 2001 From: edsilv Date: Thu, 31 Aug 2017 14:52:23 +0100 Subject: [PATCH 5/7] added Utils.normaliseType --- dist/client/manifesto.bundle.js | 58 ++++++++++++++++----------------- dist/client/manifesto.js | 58 ++++++++++++++++----------------- dist/manifesto.d.ts | 3 +- dist/server/manifesto.js | 58 ++++++++++++++++----------------- src/IIIFResource.ts | 12 ++----- src/IIIFResourceType.ts | 12 +++---- src/IRange.ts | 1 - src/Manifest.ts | 6 ++-- src/ManifestResource.ts | 2 +- src/Range.ts | 24 +++++++------- src/StringValue.ts | 2 +- src/Utils.ts | 11 +++++++ test/chemistdruggist.js | 4 +-- test/nested.js | 4 +-- 14 files changed, 128 insertions(+), 127 deletions(-) diff --git a/dist/client/manifesto.bundle.js b/dist/client/manifesto.bundle.js index 5d2d39be..61da6bfc 100644 --- a/dist/client/manifesto.bundle.js +++ b/dist/client/manifesto.bundle.js @@ -255,12 +255,12 @@ var Manifesto; IIIFResourceType.prototype.sequence = function () { return new IIIFResourceType(IIIFResourceType.SEQUENCE.toString()); }; - IIIFResourceType.ANNOTATION = new IIIFResourceType("oa:annotation"); - IIIFResourceType.CANVAS = new IIIFResourceType("sc:canvas"); - IIIFResourceType.COLLECTION = new IIIFResourceType("sc:collection"); - IIIFResourceType.MANIFEST = new IIIFResourceType("sc:manifest"); - IIIFResourceType.RANGE = new IIIFResourceType("sc:range"); - IIIFResourceType.SEQUENCE = new IIIFResourceType("sc:sequence"); + IIIFResourceType.ANNOTATION = new IIIFResourceType("annotation"); + IIIFResourceType.CANVAS = new IIIFResourceType("canvas"); + IIIFResourceType.COLLECTION = new IIIFResourceType("collection"); + IIIFResourceType.MANIFEST = new IIIFResourceType("manifest"); + IIIFResourceType.RANGE = new IIIFResourceType("range"); + IIIFResourceType.SEQUENCE = new IIIFResourceType("sequence"); return IIIFResourceType; }(Manifesto.StringValue)); Manifesto.IIIFResourceType = IIIFResourceType; @@ -708,7 +708,7 @@ var Manifesto; return _this; } ManifestResource.prototype.getIIIFResourceType = function () { - return new Manifesto.IIIFResourceType(this.getProperty('type')); + return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type'))); }; ManifestResource.prototype.getLabel = function () { return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale); @@ -1030,8 +1030,7 @@ var Manifesto; return []; }; IIIFResource.prototype.getIIIFResourceType = function () { - var type = this.getProperty('type'); - return new Manifesto.IIIFResourceType(type); + return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type'))); }; IIIFResource.prototype.getLogo = function () { var logo = this.getProperty('logo'); @@ -1066,19 +1065,13 @@ var Manifesto; return this.defaultTree; }; IIIFResource.prototype.isCollection = function () { - if (this.getIIIFResourceType().toString().toLowerCase() === 'collection') { - return true; - } - else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { return true; } return false; }; IIIFResource.prototype.isManifest = function () { - if (this.getIIIFResourceType().toString().toLowerCase() === 'manifest') { - return true; - } - else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { return true; } return false; @@ -1179,7 +1172,7 @@ var Manifesto; if (this.__jsonld.structures && this.__jsonld.structures.length) { for (var i = 0; i < this.__jsonld.structures.length; i++) { var r = this.__jsonld.structures[i]; - if (r['@id'] === id) { + if (r['@id'] === id || r.id === id) { return r; } } @@ -1446,18 +1439,17 @@ var Manifesto; } return []; }; - Range.prototype.getCanvases = function () { - if (this._canvases) { - return this._canvases; - } - return this._canvases = this.members.en().where(function (m) { return m.isCanvas(); }).toArray(); - }; + // getCanvases(): ICanvas[] { + // if (this._canvases) { + // return this._canvases; + // } + // return this._canvases = this.members.en().where(m => m.isCanvas()).toArray(); + // } Range.prototype.getRanges = function () { - return this.members; - // if (this._ranges){ - // return this._ranges; - // } - // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); + if (this._ranges) { + return this._ranges; + } + return this._ranges = this.members.en().where(function (m) { return m.isRange(); }).toArray(); }; Range.prototype.getViewingDirection = function () { if (this.getProperty('viewingDirection')) { @@ -2159,6 +2151,14 @@ var Manifesto; Utils.generateTreeNodeIds(n, i); } }; + Utils.normaliseType = function (type) { + type = type.toLowerCase(); + if (type.indexOf(':') !== -1) { + var split = type.split(':'); + return split[1]; + } + return type; + }; Utils.normalisedUrlsMatch = function (url1, url2) { var url1norm = url1.substr(url1.indexOf('://')); var url2norm = url1.substr(url1.indexOf('://')); diff --git a/dist/client/manifesto.js b/dist/client/manifesto.js index df302bbe..9c108d7b 100644 --- a/dist/client/manifesto.js +++ b/dist/client/manifesto.js @@ -182,12 +182,12 @@ var Manifesto; IIIFResourceType.prototype.sequence = function () { return new IIIFResourceType(IIIFResourceType.SEQUENCE.toString()); }; - IIIFResourceType.ANNOTATION = new IIIFResourceType("oa:annotation"); - IIIFResourceType.CANVAS = new IIIFResourceType("sc:canvas"); - IIIFResourceType.COLLECTION = new IIIFResourceType("sc:collection"); - IIIFResourceType.MANIFEST = new IIIFResourceType("sc:manifest"); - IIIFResourceType.RANGE = new IIIFResourceType("sc:range"); - IIIFResourceType.SEQUENCE = new IIIFResourceType("sc:sequence"); + IIIFResourceType.ANNOTATION = new IIIFResourceType("annotation"); + IIIFResourceType.CANVAS = new IIIFResourceType("canvas"); + IIIFResourceType.COLLECTION = new IIIFResourceType("collection"); + IIIFResourceType.MANIFEST = new IIIFResourceType("manifest"); + IIIFResourceType.RANGE = new IIIFResourceType("range"); + IIIFResourceType.SEQUENCE = new IIIFResourceType("sequence"); return IIIFResourceType; }(Manifesto.StringValue)); Manifesto.IIIFResourceType = IIIFResourceType; @@ -635,7 +635,7 @@ var Manifesto; return _this; } ManifestResource.prototype.getIIIFResourceType = function () { - return new Manifesto.IIIFResourceType(this.getProperty('type')); + return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type'))); }; ManifestResource.prototype.getLabel = function () { return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale); @@ -957,8 +957,7 @@ var Manifesto; return []; }; IIIFResource.prototype.getIIIFResourceType = function () { - var type = this.getProperty('type'); - return new Manifesto.IIIFResourceType(type); + return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type'))); }; IIIFResource.prototype.getLogo = function () { var logo = this.getProperty('logo'); @@ -993,19 +992,13 @@ var Manifesto; return this.defaultTree; }; IIIFResource.prototype.isCollection = function () { - if (this.getIIIFResourceType().toString().toLowerCase() === 'collection') { - return true; - } - else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { return true; } return false; }; IIIFResource.prototype.isManifest = function () { - if (this.getIIIFResourceType().toString().toLowerCase() === 'manifest') { - return true; - } - else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { return true; } return false; @@ -1106,7 +1099,7 @@ var Manifesto; if (this.__jsonld.structures && this.__jsonld.structures.length) { for (var i = 0; i < this.__jsonld.structures.length; i++) { var r = this.__jsonld.structures[i]; - if (r['@id'] === id) { + if (r['@id'] === id || r.id === id) { return r; } } @@ -1373,18 +1366,17 @@ var Manifesto; } return []; }; - Range.prototype.getCanvases = function () { - if (this._canvases) { - return this._canvases; - } - return this._canvases = this.members.en().where(function (m) { return m.isCanvas(); }).toArray(); - }; + // getCanvases(): ICanvas[] { + // if (this._canvases) { + // return this._canvases; + // } + // return this._canvases = this.members.en().where(m => m.isCanvas()).toArray(); + // } Range.prototype.getRanges = function () { - return this.members; - // if (this._ranges){ - // return this._ranges; - // } - // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); + if (this._ranges) { + return this._ranges; + } + return this._ranges = this.members.en().where(function (m) { return m.isRange(); }).toArray(); }; Range.prototype.getViewingDirection = function () { if (this.getProperty('viewingDirection')) { @@ -2086,6 +2078,14 @@ var Manifesto; Utils.generateTreeNodeIds(n, i); } }; + Utils.normaliseType = function (type) { + type = type.toLowerCase(); + if (type.indexOf(':') !== -1) { + var split = type.split(':'); + return split[1]; + } + return type; + }; Utils.normalisedUrlsMatch = function (url1, url2) { var url1norm = url1.substr(url1.indexOf('://')); var url2norm = url1.substr(url1.indexOf('://')); diff --git a/dist/manifesto.d.ts b/dist/manifesto.d.ts index 62812744..305c0fc9 100644 --- a/dist/manifesto.d.ts +++ b/dist/manifesto.d.ts @@ -372,7 +372,6 @@ declare namespace Manifesto { treeNode: ITreeNode; constructor(jsonld?: any, options?: IManifestoOptions); getCanvasIds(): string[]; - getCanvases(): ICanvas[]; getRanges(): IRange[]; getViewingDirection(): ViewingDirection | null; getViewingHint(): ViewingHint | null; @@ -529,6 +528,7 @@ declare namespace Manifesto { static getInexactLocale(locale: string): string; static getLocalisedValue(resource: any, locale: string): string | null; static generateTreeNodeIds(treeNode: ITreeNode, index?: number): void; + static normaliseType(type: string): string; static normalisedUrlsMatch(url1: string, url2: string): boolean; static isImageProfile(profile: Manifesto.ServiceProfile): boolean; static isLevel0ImageProfile(profile: Manifesto.ServiceProfile): boolean; @@ -818,7 +818,6 @@ declare namespace Manifesto { declare namespace Manifesto { interface IRange extends IManifestResource { getCanvasIds(): string[]; - getCanvases(): ICanvas[]; getRanges(): IRange[]; getTree(treeRoot: ITreeNode): ITreeNode; getViewingDirection(): ViewingDirection | null; diff --git a/dist/server/manifesto.js b/dist/server/manifesto.js index 7bdbfa85..27b1b3c5 100644 --- a/dist/server/manifesto.js +++ b/dist/server/manifesto.js @@ -254,12 +254,12 @@ var Manifesto; IIIFResourceType.prototype.sequence = function () { return new IIIFResourceType(IIIFResourceType.SEQUENCE.toString()); }; - IIIFResourceType.ANNOTATION = new IIIFResourceType("oa:annotation"); - IIIFResourceType.CANVAS = new IIIFResourceType("sc:canvas"); - IIIFResourceType.COLLECTION = new IIIFResourceType("sc:collection"); - IIIFResourceType.MANIFEST = new IIIFResourceType("sc:manifest"); - IIIFResourceType.RANGE = new IIIFResourceType("sc:range"); - IIIFResourceType.SEQUENCE = new IIIFResourceType("sc:sequence"); + IIIFResourceType.ANNOTATION = new IIIFResourceType("annotation"); + IIIFResourceType.CANVAS = new IIIFResourceType("canvas"); + IIIFResourceType.COLLECTION = new IIIFResourceType("collection"); + IIIFResourceType.MANIFEST = new IIIFResourceType("manifest"); + IIIFResourceType.RANGE = new IIIFResourceType("range"); + IIIFResourceType.SEQUENCE = new IIIFResourceType("sequence"); return IIIFResourceType; }(Manifesto.StringValue)); Manifesto.IIIFResourceType = IIIFResourceType; @@ -707,7 +707,7 @@ var Manifesto; return _this; } ManifestResource.prototype.getIIIFResourceType = function () { - return new Manifesto.IIIFResourceType(this.getProperty('type')); + return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type'))); }; ManifestResource.prototype.getLabel = function () { return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale); @@ -1029,8 +1029,7 @@ var Manifesto; return []; }; IIIFResource.prototype.getIIIFResourceType = function () { - var type = this.getProperty('type'); - return new Manifesto.IIIFResourceType(type); + return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type'))); }; IIIFResource.prototype.getLogo = function () { var logo = this.getProperty('logo'); @@ -1065,19 +1064,13 @@ var Manifesto; return this.defaultTree; }; IIIFResource.prototype.isCollection = function () { - if (this.getIIIFResourceType().toString().toLowerCase() === 'collection') { - return true; - } - else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { return true; } return false; }; IIIFResource.prototype.isManifest = function () { - if (this.getIIIFResourceType().toString().toLowerCase() === 'manifest') { - return true; - } - else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { return true; } return false; @@ -1178,7 +1171,7 @@ var Manifesto; if (this.__jsonld.structures && this.__jsonld.structures.length) { for (var i = 0; i < this.__jsonld.structures.length; i++) { var r = this.__jsonld.structures[i]; - if (r['@id'] === id) { + if (r['@id'] === id || r.id === id) { return r; } } @@ -1445,18 +1438,17 @@ var Manifesto; } return []; }; - Range.prototype.getCanvases = function () { - if (this._canvases) { - return this._canvases; - } - return this._canvases = this.members.en().where(function (m) { return m.isCanvas(); }).toArray(); - }; + // getCanvases(): ICanvas[] { + // if (this._canvases) { + // return this._canvases; + // } + // return this._canvases = this.members.en().where(m => m.isCanvas()).toArray(); + // } Range.prototype.getRanges = function () { - return this.members; - // if (this._ranges){ - // return this._ranges; - // } - // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); + if (this._ranges) { + return this._ranges; + } + return this._ranges = this.members.en().where(function (m) { return m.isRange(); }).toArray(); }; Range.prototype.getViewingDirection = function () { if (this.getProperty('viewingDirection')) { @@ -2158,6 +2150,14 @@ var Manifesto; Utils.generateTreeNodeIds(n, i); } }; + Utils.normaliseType = function (type) { + type = type.toLowerCase(); + if (type.indexOf(':') !== -1) { + var split = type.split(':'); + return split[1]; + } + return type; + }; Utils.normalisedUrlsMatch = function (url1, url2) { var url1norm = url1.substr(url1.indexOf('://')); var url2norm = url1.substr(url1.indexOf('://')); diff --git a/src/IIIFResource.ts b/src/IIIFResource.ts index 8adfb86f..f6da860c 100644 --- a/src/IIIFResource.ts +++ b/src/IIIFResource.ts @@ -40,9 +40,7 @@ namespace Manifesto { } getIIIFResourceType(): IIIFResourceType { - - let type: string = this.getProperty('type'); - return new IIIFResourceType(type); + return new IIIFResourceType(Utils.normaliseType(this.getProperty('type'))); } getLogo(): string | null { @@ -85,18 +83,14 @@ namespace Manifesto { } isCollection(): boolean { - if (this.getIIIFResourceType().toString().toLowerCase() === 'collection') { // todo: use constant - return true; - } else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) { return true; } return false; } isManifest(): boolean { - if (this.getIIIFResourceType().toString().toLowerCase() === 'manifest') { // todo: use constant - return true; - } else if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { + if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.MANIFEST.toString()) { return true; } return false; diff --git a/src/IIIFResourceType.ts b/src/IIIFResourceType.ts index 3f82eaa9..a97a6868 100644 --- a/src/IIIFResourceType.ts +++ b/src/IIIFResourceType.ts @@ -1,11 +1,11 @@ namespace Manifesto { export class IIIFResourceType extends StringValue{ - public static ANNOTATION = new IIIFResourceType("oa:annotation"); - public static CANVAS = new IIIFResourceType("sc:canvas"); - public static COLLECTION = new IIIFResourceType("sc:collection"); - public static MANIFEST = new IIIFResourceType("sc:manifest"); - public static RANGE = new IIIFResourceType("sc:range"); - public static SEQUENCE = new IIIFResourceType("sc:sequence"); + public static ANNOTATION = new IIIFResourceType("annotation"); + public static CANVAS = new IIIFResourceType("canvas"); + public static COLLECTION = new IIIFResourceType("collection"); + public static MANIFEST = new IIIFResourceType("manifest"); + public static RANGE = new IIIFResourceType("range"); + public static SEQUENCE = new IIIFResourceType("sequence"); // todo: use getters when ES3 target is no longer required. diff --git a/src/IRange.ts b/src/IRange.ts index e50e344d..30229cb2 100644 --- a/src/IRange.ts +++ b/src/IRange.ts @@ -1,7 +1,6 @@ namespace Manifesto { export interface IRange extends IManifestResource { getCanvasIds(): string[]; - getCanvases(): ICanvas[]; getRanges(): IRange[]; getTree(treeRoot: ITreeNode): ITreeNode; getViewingDirection(): ViewingDirection | null; diff --git a/src/Manifest.ts b/src/Manifest.ts index 9e833f7f..0372d1d2 100644 --- a/src/Manifest.ts +++ b/src/Manifest.ts @@ -72,7 +72,7 @@ namespace Manifesto { if (this.__jsonld.structures && this.__jsonld.structures.length) { for (let i = 0; i < this.__jsonld.structures.length; i++) { const r = this.__jsonld.structures[i]; - if (r['@id'] === id){ + if (r['@id'] === id || r.id === id) { return r; } } @@ -128,9 +128,7 @@ namespace Manifesto { for (let i = 0; i < r.ranges.length; i++) { this._parseRanges(r.ranges[i], path + '/' + i, range); } - } - - + } } getAllRanges(): IRange[] { diff --git a/src/ManifestResource.ts b/src/ManifestResource.ts index 60800955..f3342bcc 100644 --- a/src/ManifestResource.ts +++ b/src/ManifestResource.ts @@ -9,7 +9,7 @@ namespace Manifesto { } getIIIFResourceType(): IIIFResourceType { - return new IIIFResourceType(this.getProperty('type')); + return new IIIFResourceType(Utils.normaliseType(this.getProperty('type'))); } getLabel(): TranslationCollection { diff --git a/src/Range.ts b/src/Range.ts index 03909825..d3b7153a 100644 --- a/src/Range.ts +++ b/src/Range.ts @@ -13,6 +13,7 @@ namespace Manifesto { } getCanvasIds(): string[] { + if (this.__jsonld.canvases) { return this.__jsonld.canvases; } @@ -20,22 +21,21 @@ namespace Manifesto { return []; } - getCanvases(): ICanvas[] { - if (this._canvases){ - return this._canvases; - } + // getCanvases(): ICanvas[] { + // if (this._canvases) { + // return this._canvases; + // } - return this._canvases = this.members.en().where(m => m.isCanvas()).toArray(); - } + // return this._canvases = this.members.en().where(m => m.isCanvas()).toArray(); + // } getRanges(): IRange[] { + + if (this._ranges) { + return this._ranges; + } - return this.members; - // if (this._ranges){ - // return this._ranges; - // } - - // return this._ranges = this.members.en().where(m => m.isRange()).toArray(); + return this._ranges = this.members.en().where(m => m.isRange()).toArray(); } getViewingDirection(): ViewingDirection | null { diff --git a/src/StringValue.ts b/src/StringValue.ts index 7fa2f66b..424982bf 100644 --- a/src/StringValue.ts +++ b/src/StringValue.ts @@ -4,7 +4,7 @@ namespace Manifesto { public value: string = ""; constructor(value?: string) { - if (value){ + if (value) { this.value = value.toLowerCase(); } } diff --git a/src/Utils.ts b/src/Utils.ts index 8d6726b7..f89805ed 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -93,6 +93,17 @@ namespace Manifesto { } } + static normaliseType(type: string): string { + type = type.toLowerCase(); + + if (type.indexOf(':') !== -1) { + const split: string[] = type.split(':'); + return split[1]; + } + + return type; + } + static normalisedUrlsMatch(url1: string, url2: string): boolean { const url1norm: string = url1.substr(url1.indexOf('://')); const url2norm: string = url1.substr(url1.indexOf('://')); diff --git a/test/chemistdruggist.js b/test/chemistdruggist.js index f382d8c3..41d0cb27 100644 --- a/test/chemistdruggist.js +++ b/test/chemistdruggist.js @@ -18,9 +18,9 @@ describe('#loadsChemistDruggist', function() { }); describe('#hasIIIFResourceType', function() { - it('has a IIIFResourceType property of "sc:collection"', function () { + it('has a IIIFResourceType property of "collection"', function () { var type = collection.getIIIFResourceType(); - type.toString().should.equal('sc:collection'); + type.toString().should.equal('collection'); expect(collection.isManifest()).to.equal(false); expect(collection.isCollection()).to.equal(true); }); diff --git a/test/nested.js b/test/nested.js index c29e6df8..fb3ea25f 100644 --- a/test/nested.js +++ b/test/nested.js @@ -18,9 +18,9 @@ describe('#loadsTopNestedManifest', function() { }); describe('#hasIIIFResourceType', function() { - it('has a IIIFResourceType property of "sc:collection"', function () { + it('has a IIIFResourceType property of "collection"', function () { var type = collection.getIIIFResourceType(); - type.toString().should.equal('sc:collection'); + type.toString().should.equal('collection'); }); }); From 163c7244656c325c0c7d57631a3bf91d1b08e586 Mon Sep 17 00:00:00 2001 From: edsilv Date: Thu, 31 Aug 2017 15:40:39 +0100 Subject: [PATCH 6/7] store canvas ids --- dist/client/manifesto.bundle.js | 18 +++++++++++++----- dist/client/manifesto.js | 18 +++++++++++++----- dist/manifesto.d.ts | 7 ++++--- dist/server/manifesto.js | 18 +++++++++++++----- src/IRange.ts | 1 + src/Manifest.ts | 19 ++++++++++++------- src/Range.ts | 14 ++++++++------ test/https.js | 18 +++++++++--------- test/lunchroommanners.js | 5 +++++ 9 files changed, 78 insertions(+), 40 deletions(-) diff --git a/dist/client/manifesto.bundle.js b/dist/client/manifesto.bundle.js index 61da6bfc..425380f5 100644 --- a/dist/client/manifesto.bundle.js +++ b/dist/client/manifesto.bundle.js @@ -1207,13 +1207,18 @@ var Manifesto; if (r.members) { for (var i = 0; i < r.members.length; i++) { var child = r.members[i]; - // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - // if (range.members.en().where(m => m.id === child.id).first()) { - // continue; - // } + // todo: use constants if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range') { this._parseRanges(child, path + '/' + i, range); } + else if (child['@type'] && child['@type'].toLowerCase() === 'sc:canvas' || child['type'] && child['type'].toLowerCase() === 'canvas') { + // store the ids on the __jsonld object to be used by Range.getCanvasIds() + if (!range.canvases) { + range.canvases = []; + } + var id_1 = child['@id'] || child.id; + range.canvases.push(id_1); + } } } else if (r.ranges) { @@ -1428,8 +1433,8 @@ var Manifesto; __extends(Range, _super); function Range(jsonld, options) { var _this = _super.call(this, jsonld, options) || this; - _this._canvases = null; _this._ranges = null; + _this.canvases = null; _this.members = []; return _this; } @@ -1437,6 +1442,9 @@ var Manifesto; if (this.__jsonld.canvases) { return this.__jsonld.canvases; } + else if (this.canvases) { + return this.canvases; + } return []; }; // getCanvases(): ICanvas[] { diff --git a/dist/client/manifesto.js b/dist/client/manifesto.js index 9c108d7b..d0a10d0a 100644 --- a/dist/client/manifesto.js +++ b/dist/client/manifesto.js @@ -1134,13 +1134,18 @@ var Manifesto; if (r.members) { for (var i = 0; i < r.members.length; i++) { var child = r.members[i]; - // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - // if (range.members.en().where(m => m.id === child.id).first()) { - // continue; - // } + // todo: use constants if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range') { this._parseRanges(child, path + '/' + i, range); } + else if (child['@type'] && child['@type'].toLowerCase() === 'sc:canvas' || child['type'] && child['type'].toLowerCase() === 'canvas') { + // store the ids on the __jsonld object to be used by Range.getCanvasIds() + if (!range.canvases) { + range.canvases = []; + } + var id_1 = child['@id'] || child.id; + range.canvases.push(id_1); + } } } else if (r.ranges) { @@ -1355,8 +1360,8 @@ var Manifesto; __extends(Range, _super); function Range(jsonld, options) { var _this = _super.call(this, jsonld, options) || this; - _this._canvases = null; _this._ranges = null; + _this.canvases = null; _this.members = []; return _this; } @@ -1364,6 +1369,9 @@ var Manifesto; if (this.__jsonld.canvases) { return this.__jsonld.canvases; } + else if (this.canvases) { + return this.canvases; + } return []; }; // getCanvases(): ICanvas[] { diff --git a/dist/manifesto.d.ts b/dist/manifesto.d.ts index 305c0fc9..6300fd0a 100644 --- a/dist/manifesto.d.ts +++ b/dist/manifesto.d.ts @@ -364,11 +364,11 @@ declare namespace Manifesto { declare namespace Manifesto { class Range extends ManifestResource implements IRange { - _canvases: ICanvas[] | null; - _ranges: IRange[] | null; + private _ranges; + canvases: string[] | null; + members: IManifestResource[]; parentRange: Range; path: string; - members: IManifestResource[]; treeNode: ITreeNode; constructor(jsonld?: any, options?: IManifestoOptions); getCanvasIds(): string[]; @@ -817,6 +817,7 @@ declare namespace Manifesto { declare namespace Manifesto { interface IRange extends IManifestResource { + canvases: string[] | null; getCanvasIds(): string[]; getRanges(): IRange[]; getTree(treeRoot: ITreeNode): ITreeNode; diff --git a/dist/server/manifesto.js b/dist/server/manifesto.js index 27b1b3c5..17c73407 100644 --- a/dist/server/manifesto.js +++ b/dist/server/manifesto.js @@ -1206,13 +1206,18 @@ var Manifesto; if (r.members) { for (var i = 0; i < r.members.length; i++) { var child = r.members[i]; - // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - // if (range.members.en().where(m => m.id === child.id).first()) { - // continue; - // } + // todo: use constants if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range') { this._parseRanges(child, path + '/' + i, range); } + else if (child['@type'] && child['@type'].toLowerCase() === 'sc:canvas' || child['type'] && child['type'].toLowerCase() === 'canvas') { + // store the ids on the __jsonld object to be used by Range.getCanvasIds() + if (!range.canvases) { + range.canvases = []; + } + var id_1 = child['@id'] || child.id; + range.canvases.push(id_1); + } } } else if (r.ranges) { @@ -1427,8 +1432,8 @@ var Manifesto; __extends(Range, _super); function Range(jsonld, options) { var _this = _super.call(this, jsonld, options) || this; - _this._canvases = null; _this._ranges = null; + _this.canvases = null; _this.members = []; return _this; } @@ -1436,6 +1441,9 @@ var Manifesto; if (this.__jsonld.canvases) { return this.__jsonld.canvases; } + else if (this.canvases) { + return this.canvases; + } return []; }; // getCanvases(): ICanvas[] { diff --git a/src/IRange.ts b/src/IRange.ts index 30229cb2..739862ae 100644 --- a/src/IRange.ts +++ b/src/IRange.ts @@ -1,5 +1,6 @@ namespace Manifesto { export interface IRange extends IManifestResource { + canvases: string[] | null; getCanvasIds(): string[]; getRanges(): IRange[]; getTree(treeRoot: ITreeNode): ITreeNode; diff --git a/src/Manifest.ts b/src/Manifest.ts index 0372d1d2..d037fe08 100644 --- a/src/Manifest.ts +++ b/src/Manifest.ts @@ -115,20 +115,25 @@ namespace Manifesto { for (let i = 0; i < r.members.length; i++) { const child: any = r.members[i]; - // only add to members if not already parsed from backwards-compatible ranges/canvases arrays - // if (range.members.en().where(m => m.id === child.id).first()) { - // continue; - // } - + // todo: use constants if (child['@type'] && child['@type'].toLowerCase() === 'sc:range' || child['type'] && child['type'].toLowerCase() === 'range'){ this._parseRanges(child, path + '/' + i, range); - } + } else if (child['@type'] && child['@type'].toLowerCase() === 'sc:canvas' || child['type'] && child['type'].toLowerCase() === 'canvas') { + // store the ids on the __jsonld object to be used by Range.getCanvasIds() + if (!range.canvases) { + range.canvases = []; + } + + const id: string = child['@id'] || child.id; + + range.canvases.push(id); + } } } else if (r.ranges) { for (let i = 0; i < r.ranges.length; i++) { this._parseRanges(r.ranges[i], path + '/' + i, range); } - } + } } getAllRanges(): IRange[] { diff --git a/src/Range.ts b/src/Range.ts index d3b7153a..c9148d8e 100644 --- a/src/Range.ts +++ b/src/Range.ts @@ -1,12 +1,12 @@ namespace Manifesto { export class Range extends ManifestResource implements IRange{ - _canvases: ICanvas[] | null = null; - _ranges: IRange[] | null = null; - parentRange: Range; - path: string; - members: IManifestResource[] = []; - treeNode: ITreeNode; + private _ranges: IRange[] | null = null; + public canvases: string[] | null = null; + public members: IManifestResource[] = []; + public parentRange: Range; + public path: string; + public treeNode: ITreeNode; constructor(jsonld?: any, options?: IManifestoOptions){ super(jsonld, options); @@ -16,6 +16,8 @@ namespace Manifesto { if (this.__jsonld.canvases) { return this.__jsonld.canvases; + } else if (this.canvases) { + return this.canvases; } return []; diff --git a/test/https.js b/test/https.js index 728e5946..f739fad4 100644 --- a/test/https.js +++ b/test/https.js @@ -6,12 +6,12 @@ require('./shared'); var manifest, sequence; -describe('#loadsRiksarkivetHTTPS', function() { - this.timeout(20000); - it('loads successfully', function (done) { - manifesto.loadManifest(manifests.https).then(function(data) { - manifest = manifesto.create(data); - done(); - }); - }); -}); \ No newline at end of file +// describe('#loadsRiksarkivetHTTPS', function() { +// this.timeout(20000); +// it('loads successfully', function (done) { +// manifesto.loadManifest(manifests.https).then(function(data) { +// manifest = manifesto.create(data); +// done(); +// }); +// }); +// }); \ No newline at end of file diff --git a/test/lunchroommanners.js b/test/lunchroommanners.js index 75abf50e..d3347fd7 100644 --- a/test/lunchroommanners.js +++ b/test/lunchroommanners.js @@ -19,5 +19,10 @@ describe('#hasRanges', function() { it('has ranges', function () { topRange = manifest.getTopRanges()[0]; topRange.members.length.should.equal(2); + var washingHands = topRange.members[0].members[0]; + expect(washingHands.id).to.equal("http://dlib.indiana.edu/iiif_av/lunchroom_manners/range/2"); + var usingSoap = washingHands.members[0]; + var canvasid = usingSoap.canvases[0]; + expect(canvasid).to.equal("http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=157,160"); }); }); \ No newline at end of file From 9193957db45897977bc15b9f7f6d033d3f05b7dd Mon Sep 17 00:00:00 2001 From: edsilv Date: Thu, 31 Aug 2017 15:56:35 +0100 Subject: [PATCH 7/7] added Utils.normaliseUrl --- dist/client/manifesto.bundle.js | 15 +++++++++++---- dist/client/manifesto.js | 15 +++++++++++---- dist/manifesto.d.ts | 1 + dist/server/manifesto.js | 15 +++++++++++---- src/Sequence.ts | 5 ++++- src/Utils.ts | 15 +++++++++++---- test/lunchroommanners.js | 1 + 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/dist/client/manifesto.bundle.js b/dist/client/manifesto.bundle.js index 425380f5..35f47edb 100644 --- a/dist/client/manifesto.bundle.js +++ b/dist/client/manifesto.bundle.js @@ -1569,7 +1569,9 @@ var Manifesto; Sequence.prototype.getCanvasById = function (id) { for (var i = 0; i < this.getTotalCanvases(); i++) { var canvas = this.getCanvasByIndex(i); - if (canvas.id === id) { + // normalise canvas id + var canvasId = Manifesto.Utils.normaliseUrl(canvas.id); + if (Manifesto.Utils.normaliseUrl(id) === canvasId) { return canvas; } } @@ -2167,10 +2169,15 @@ var Manifesto; } return type; }; + Utils.normaliseUrl = function (url) { + url = url.substr(url.indexOf('://')); + if (url.indexOf('#') !== -1) { + url = url.split('#')[0]; + } + return url; + }; Utils.normalisedUrlsMatch = function (url1, url2) { - var url1norm = url1.substr(url1.indexOf('://')); - var url2norm = url1.substr(url1.indexOf('://')); - return url1norm === url2norm; + return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2); }; Utils.isImageProfile = function (profile) { if (Utils.normalisedUrlsMatch(profile.toString(), Manifesto.ServiceProfile.STANFORDIIIFIMAGECOMPLIANCE0.toString()) || diff --git a/dist/client/manifesto.js b/dist/client/manifesto.js index d0a10d0a..a95ddb45 100644 --- a/dist/client/manifesto.js +++ b/dist/client/manifesto.js @@ -1496,7 +1496,9 @@ var Manifesto; Sequence.prototype.getCanvasById = function (id) { for (var i = 0; i < this.getTotalCanvases(); i++) { var canvas = this.getCanvasByIndex(i); - if (canvas.id === id) { + // normalise canvas id + var canvasId = Manifesto.Utils.normaliseUrl(canvas.id); + if (Manifesto.Utils.normaliseUrl(id) === canvasId) { return canvas; } } @@ -2094,10 +2096,15 @@ var Manifesto; } return type; }; + Utils.normaliseUrl = function (url) { + url = url.substr(url.indexOf('://')); + if (url.indexOf('#') !== -1) { + url = url.split('#')[0]; + } + return url; + }; Utils.normalisedUrlsMatch = function (url1, url2) { - var url1norm = url1.substr(url1.indexOf('://')); - var url2norm = url1.substr(url1.indexOf('://')); - return url1norm === url2norm; + return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2); }; Utils.isImageProfile = function (profile) { if (Utils.normalisedUrlsMatch(profile.toString(), Manifesto.ServiceProfile.STANFORDIIIFIMAGECOMPLIANCE0.toString()) || diff --git a/dist/manifesto.d.ts b/dist/manifesto.d.ts index 6300fd0a..2977c31b 100644 --- a/dist/manifesto.d.ts +++ b/dist/manifesto.d.ts @@ -529,6 +529,7 @@ declare namespace Manifesto { static getLocalisedValue(resource: any, locale: string): string | null; static generateTreeNodeIds(treeNode: ITreeNode, index?: number): void; static normaliseType(type: string): string; + static normaliseUrl(url: string): string; static normalisedUrlsMatch(url1: string, url2: string): boolean; static isImageProfile(profile: Manifesto.ServiceProfile): boolean; static isLevel0ImageProfile(profile: Manifesto.ServiceProfile): boolean; diff --git a/dist/server/manifesto.js b/dist/server/manifesto.js index 17c73407..be7f05af 100644 --- a/dist/server/manifesto.js +++ b/dist/server/manifesto.js @@ -1568,7 +1568,9 @@ var Manifesto; Sequence.prototype.getCanvasById = function (id) { for (var i = 0; i < this.getTotalCanvases(); i++) { var canvas = this.getCanvasByIndex(i); - if (canvas.id === id) { + // normalise canvas id + var canvasId = Manifesto.Utils.normaliseUrl(canvas.id); + if (Manifesto.Utils.normaliseUrl(id) === canvasId) { return canvas; } } @@ -2166,10 +2168,15 @@ var Manifesto; } return type; }; + Utils.normaliseUrl = function (url) { + url = url.substr(url.indexOf('://')); + if (url.indexOf('#') !== -1) { + url = url.split('#')[0]; + } + return url; + }; Utils.normalisedUrlsMatch = function (url1, url2) { - var url1norm = url1.substr(url1.indexOf('://')); - var url2norm = url1.substr(url1.indexOf('://')); - return url1norm === url2norm; + return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2); }; Utils.isImageProfile = function (profile) { if (Utils.normalisedUrlsMatch(profile.toString(), Manifesto.ServiceProfile.STANFORDIIIFIMAGECOMPLIANCE0.toString()) || diff --git a/src/Sequence.ts b/src/Sequence.ts index 6ef8eadd..a43a44f1 100644 --- a/src/Sequence.ts +++ b/src/Sequence.ts @@ -31,7 +31,10 @@ namespace Manifesto { for (let i = 0; i < this.getTotalCanvases(); i++) { const canvas = this.getCanvasByIndex(i); - if (canvas.id === id){ + // normalise canvas id + const canvasId: string = Utils.normaliseUrl(canvas.id); + + if (Utils.normaliseUrl(id) === canvasId){ return canvas; } } diff --git a/src/Utils.ts b/src/Utils.ts index f89805ed..1ee7243a 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -104,11 +104,18 @@ namespace Manifesto { return type; } + static normaliseUrl(url: string): string { + url = url.substr(url.indexOf('://')); + + if (url.indexOf('#') !== -1) { + url = url.split('#')[0]; + } + + return url; + } + static normalisedUrlsMatch(url1: string, url2: string): boolean { - const url1norm: string = url1.substr(url1.indexOf('://')); - const url2norm: string = url1.substr(url1.indexOf('://')); - - return url1norm === url2norm; + return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2); } static isImageProfile(profile: Manifesto.ServiceProfile): boolean { diff --git a/test/lunchroommanners.js b/test/lunchroommanners.js index d3347fd7..1c43dd5e 100644 --- a/test/lunchroommanners.js +++ b/test/lunchroommanners.js @@ -24,5 +24,6 @@ describe('#hasRanges', function() { var usingSoap = washingHands.members[0]; var canvasid = usingSoap.canvases[0]; expect(canvasid).to.equal("http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=157,160"); + // get sequence and use .getCanvasById trimming http/s and hash fragment }); }); \ No newline at end of file