Skip to content

Commit

Permalink
reloading works
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Sep 8, 2015
1 parent d6f74aa commit e737f6c
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 79 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"utils": "edsilv/utils#~0.0.23",
"uv-cy-GB-theme": "universalviewer/uv-cy-GB-theme",
"uv-en-GB-theme": "universalviewer/uv-en-GB-theme",
"manifesto": "universalviewer/manifesto#dev",
"manifesto": "universalviewer/manifesto#tree",
"lodash-compat": "~3.10.0"
},
"devDependencies": {
Expand Down
37 changes: 19 additions & 18 deletions src/BootstrapParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BootstrapParams {
locales: any[];
manifestIndex: number;
manifestUri: string;
paramMap: string[] = ['c', 'm', 's', 'cv', 'z', 'r'];
paramMap: string[] = ['c', 'm', 's', 'cv', 'z', 'r']; // todo: remove z, r
sequenceIndex: number;

constructor() {
Expand All @@ -40,23 +40,6 @@ class BootstrapParams {
this.canvasIndex = this.getParam(Params.canvasIndex);
}

// parse string 'en-GB' or 'en-GB:English,cy-GB:Welsh' into array
setLocale(locale: string): void {
this.locale = locale;
this.locales = [];
var l = this.locale.split(',');

for (var i = 0; i < l.length; i++) {
var v = l[i].split(':');
this.locales.push({
name: v[0].trim(),
label: (v[1]) ? v[1].trim() : ""
});
}

this.localeName = this.locales[0].name;
}

getLocaleName(): string {
return this.localeName;
}
Expand All @@ -72,8 +55,26 @@ class BootstrapParams {
}

hashParamsAvailable(): boolean {
// if reloading,
return (this.isHomeDomain && !this.isReload);
}

// parse string 'en-GB' or 'en-GB:English,cy-GB:Welsh' into array
setLocale(locale: string): void {
this.locale = locale;
this.locales = [];
var l = this.locale.split(',');

for (var i = 0; i < l.length; i++) {
var v = l[i].split(':');
this.locales.push({
name: v[0].trim(),
label: (v[1]) ? v[1].trim() : ""
});
}

this.localeName = this.locales[0].name;
}
}

export = BootstrapParams;
7 changes: 7 additions & 0 deletions src/Bootstrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ class Bootstrapper{
var manifest: Manifesto.IManifest;

if (this.iiifResource.getIIIFResourceType().toString() === manifesto.IIIFResourceType.collection().toString()){
// if it's a collection and has child collections, get the collection by index
if ((<Manifesto.ICollection>this.iiifResource).collections && (<Manifesto.ICollection>this.iiifResource).collections.length){
var collection = (<Manifesto.ICollection>this.iiifResource).collections[this.params.collectionIndex];

if (!collection){
this.notFound();
return;
}

manifest = collection.getManifestByIndex(this.params.manifestIndex);
} else {
manifest = (<Manifesto.ICollection>this.iiifResource).getManifestByIndex(this.params.manifestIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/uv-seadragon-extension/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class Extension extends BaseExtension {
if (!data.type) return;

if (data.type === 'manifest') {
//this.viewManifest(data);
this.viewManifest(data);
} else {
this.viewRange(data.path);
}
Expand Down
11 changes: 11 additions & 0 deletions src/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ String.format = function () {
}
return s;
};
String.prototype.hashCode = function () {
var hash = 0, i, chr, len;
if (this.length == 0)
return hash;
for (i = 0, len = this.length; i < len; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash.toString();
};
String.prototype.ltrim = function () {
return this.replace(/^\s+/, '');
};
Expand Down
84 changes: 51 additions & 33 deletions src/lib/manifesto.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ var Manifesto;
}
return metadata;
};
// todo: once UV download menu uses manifesto parsed objects, this can be moved back from Utils
ManifestResource.prototype.getRendering = function (format) {
return Manifesto.Utils.getRendering(this, format);
};
// todo: once UV download menu uses manifesto parsed objects, this can be moved back from Utils
ManifestResource.prototype.getRenderings = function () {
return Manifesto.Utils.getRenderings(this);
};
Expand Down Expand Up @@ -394,6 +396,7 @@ var Manifesto;
__extends(IIIFResource, _super);
function IIIFResource(jsonld, options) {
_super.call(this, jsonld, options);
this.index = 0;
this.isLoaded = false;
var defaultOptions = {
defaultLabel: '-',
Expand Down Expand Up @@ -423,6 +426,11 @@ var Manifesto;
IIIFResource.prototype.getTitle = function () {
return Manifesto.Utils.getLocalisedValue(this.getProperty('label'), this.options.locale);
};
IIIFResource.prototype.getTree = function () {
this.treeRoot = new Manifesto.TreeNode('root');
this.treeRoot.data = this;
return this.treeRoot;
};
IIIFResource.prototype.load = function () {
var that = this;
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -450,39 +458,10 @@ var Manifesto;
__extends(Manifest, _super);
function Manifest(jsonld, options) {
_super.call(this, jsonld, options);
this.index = 0;
this.sequences = [];
jsonld.__manifest = this;
}
//getMetadata(): any {
// var metadata = this.getMetadata();
//
// if (this.getLicense()){
// metadata.unshift({
// "label": "license",
// "value": this.getLicense()
// });
// }
//
// if (this.getAttribution()){
// metadata.unshift({
// "label": "attribution",
// "value": this.getAttribution()
// });
// }
//
// if (this.getDescription()){
// metadata.unshift({
// "label": "description",
// "value": this.getDescription()
// });
// }
//
// if (this.getLogo()){
// metadata.pop({
// "label": "logo",
// "value": '<img src="' + this.getLogo() + '"/>'});
// }
//}
// todo: use jmespath to flatten tree?
// https://github.com/jmespath/jmespath.js/issues/6
// using r.__parsed in the meantime
Expand Down Expand Up @@ -524,12 +503,14 @@ var Manifesto;
return this.sequences.length;
};
Manifest.prototype.getTree = function () {
this.treeRoot = new Manifesto.TreeNode('root');
this.treeRoot.label = 'root';
_super.prototype.getTree.call(this);
this.treeRoot.data.type = 'manifest';
if (!this.isLoaded) {
return this.treeRoot;
}
if (!this.rootRange)
return this.treeRoot;
this.treeRoot.data = this.rootRange;
this.treeRoot.data.type = 'manifest';
this.rootRange.treeNode = this.treeRoot;
if (this.rootRange.ranges) {
for (var i = 0; i < this.rootRange.ranges.length; i++) {
Expand Down Expand Up @@ -587,6 +568,39 @@ var Manifesto;
Collection.prototype.getTotalManifests = function () {
return this.manifests.length;
};
Collection.prototype.getTree = function () {
_super.prototype.getTree.call(this);
this.treeRoot.data.type = 'collection';
this._parseManifests(this);
this._parseCollections(this);
return this.treeRoot;
};
Collection.prototype._parseManifests = function (parentCollection) {
if (parentCollection.manifests && parentCollection.manifests.length) {
for (var i = 0; i < parentCollection.manifests.length; i++) {
var manifest = parentCollection.manifests[i];
//manifest.parentCollection = parentCollection;
//manifest.index = i;
var tree = manifest.getTree();
tree.label = manifest.getTitle() || 'manifest ' + (i + 1);
parentCollection.treeRoot.addNode(tree);
}
}
};
Collection.prototype._parseCollections = function (parentCollection) {
if (parentCollection.collections && parentCollection.collections.length) {
for (var i = 0; i < parentCollection.collections.length; i++) {
var collection = parentCollection.collections[i];
//collection.parentCollection = parentCollection;
//collection.index = i;
var tree = collection.getTree();
tree.label = collection.getTitle() || 'collection ' + (i + 1);
parentCollection.treeRoot.addNode(tree);
this._parseManifests(collection);
this._parseCollections(collection);
}
}
};
return Collection;
})(Manifesto.IIIFResource);
Manifesto.Collection = Collection;
Expand Down Expand Up @@ -873,6 +887,8 @@ var Manifesto;
if (children) {
for (var i = 0; i < children.length; i++) {
var child = this.parseCollection(children[i], options);
child.index = i;
child.parentCollection = collection;
collection.collections.push(child);
}
}
Expand All @@ -890,6 +906,8 @@ var Manifesto;
if (children) {
for (var i = 0; i < children.length; i++) {
var child = this.parseManifest(children[i], options);
child.index = i;
child.parentCollection = collection;
collection.manifests.push(child);
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/modules/uv-shared-module/BaseExtension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BaseCommands = require("./BaseCommands");
import BaseProvider = require("./BaseProvider");
import BootStrapper = require("../../Bootstrapper");
import BootstrapParams = require("../../BootstrapParams");
import ClickThroughDialogue = require("../../modules/uv-dialogues-module/ClickThroughDialogue");
import ExternalResource = require("./ExternalResource");
import IExtension = require("./IExtension");
Expand Down Expand Up @@ -226,8 +227,10 @@ class BaseExtension implements IExtension {
setParams(): void{
if (!this.provider.isHomeDomain) return;

// set sequenceIndex hash param.
this.setParam(Params.collectionIndex, this.provider.collectionIndex);
this.setParam(Params.manifestIndex, this.provider.manifestIndex);
this.setParam(Params.sequenceIndex, this.provider.sequenceIndex);
this.setParam(Params.canvasIndex, this.provider.canvasIndex);
}

setDefaultFocus(): void {
Expand Down Expand Up @@ -369,17 +372,12 @@ class BaseExtension implements IExtension {
return Shell.$overlays.is(':visible');
}

viewManifest(manifestIndex: number): void{
//var seeAlsoUri = this.provider.getManifestSeeAlsoUri(manifest);
//if (seeAlsoUri){
// window.open(seeAlsoUri, '_blank');
//} else {
if (this.isFullScreen()) {
$.publish(BaseCommands.TOGGLE_FULLSCREEN);
}
viewManifest(manifest: Manifesto.IManifest): void{
var p = new BootstrapParams();
p.collectionIndex = this.provider.getCollectionIndex(manifest);
p.manifestIndex = manifest.index;

//this.triggerSocket(BaseCommands.SEQUENCE_INDEX_CHANGED, manifest.assetSequence);
//}
this.provider.reload(p);
}

inIframe(): boolean {
Expand Down
9 changes: 8 additions & 1 deletion src/modules/uv-shared-module/BaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BaseProvider implements IProvider{

bootstrapper: BootStrapper;
canvasIndex: number;
collectionIndex: number;
config: any;
domain: string;
embedDomain: string;
Expand Down Expand Up @@ -58,6 +59,7 @@ class BaseProvider implements IProvider{
this.domain = this.bootstrapper.params.domain;
this.isLightbox = this.bootstrapper.params.isLightbox;

this.collectionIndex = this.bootstrapper.params.collectionIndex;
this.manifestIndex = this.bootstrapper.params.manifestIndex;
this.sequenceIndex = this.bootstrapper.params.sequenceIndex;
this.canvasIndex = this.bootstrapper.params.canvasIndex;
Expand All @@ -78,6 +80,11 @@ class BaseProvider implements IProvider{
this.bootstrapper.bootStrap(p);
}

getCollectionIndex(iiifResource: Manifesto.IIIIFResource): number {
// todo: support nested collections. walk up parents adding to array and return csv string.
return iiifResource.parentCollection.index;
}

getManifestType(): Manifesto.ManifestType{
var manifestType = this.manifest.getManifestType();

Expand Down Expand Up @@ -293,7 +300,7 @@ class BaseProvider implements IProvider{
}

getTree(): Manifesto.TreeNode{
return this.manifest.getTree();
return this.iiifResource.getTree();
}

getDomain(): string{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/uv-shared-module/IExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface IExtension{
tabbing: boolean;
triggerSocket(eventName: string, eventObject: any): void;
viewCanvas(canvasIndex): void;
viewManifest(manifestIndex: number): void
viewManifest(manifest: Manifesto.IManifest): void;
width(): number;
}

Expand Down
3 changes: 3 additions & 0 deletions src/modules/uv-shared-module/IProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import ExternalResource = require("./ExternalResource");
// interacting with the IIIF data model.
interface IProvider{
canvasIndex: number;
collectionIndex: number;
manifest: Manifesto.IIIIFResource;
manifestIndex: number;
resources: Manifesto.IExternalResource[];
sequenceIndex: number;

Expand All @@ -17,6 +19,7 @@ interface IProvider{
getCanvasIndexByLabel(label: string): number;
getCanvasIndexParam(): number;
getCanvasType(canvas?: Manifesto.ICanvas): Manifesto.CanvasType;
getCollectionIndex(iiifResource: Manifesto.IIIIFResource): number;
getCurrentCanvas(): Manifesto.ICanvas;
getCurrentSequence(): Manifesto.ISequence;
getFirstPageIndex(): number;
Expand Down
1 change: 1 addition & 0 deletions src/typings/extensions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface String {
b64_to_utf8(str: string): string;
contains(str: string): boolean;
endsWith(text: string): boolean;
hashCode(): string;
ltrim(): string;
rtrim(): string;
startsWith(text: string): boolean;
Expand Down
Loading

0 comments on commit e737f6c

Please sign in to comment.