Skip to content

Commit

Permalink
added getRequiredStatement, renamed MetadataItem to LabelValuePair
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Aug 21, 2018
1 parent d3c63a0 commit 320bca3
Show file tree
Hide file tree
Showing 14 changed files with 1,041 additions and 186 deletions.
112 changes: 60 additions & 52 deletions dist/client/manifesto.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ var Manifesto;
return metadata;
for (var i = 0; i < _metadata.length; i++) {
var item = _metadata[i];
var metadataItem = new Manifesto.MetadataItem(this.options.locale);
var metadataItem = new Manifesto.LabelValuePair(this.options.locale);
metadataItem.parse(item);
metadata.push(metadataItem);
}
Expand Down Expand Up @@ -1167,6 +1167,14 @@ var Manifesto;
this.defaultTree.data = this;
return this.defaultTree;
};
IIIFResource.prototype.getRequiredStatement = function () {
var _requiredStatement = this.getProperty('requiredStatement');
if (!_requiredStatement)
return null;
var requiredStatement = new Manifesto.LabelValuePair(this.options.locale);
requiredStatement.parse(_requiredStatement);
return requiredStatement;
};
IIIFResource.prototype.isCollection = function () {
if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) {
return true;
Expand Down Expand Up @@ -3054,56 +3062,6 @@ var Manifesto;
Manifesto.Utils = Utils;
})(Manifesto || (Manifesto = {}));

var Manifesto;
(function (Manifesto) {
var MetadataItem = /** @class */ (function () {
function MetadataItem(defaultLocale) {
this.defaultLocale = defaultLocale;
}
MetadataItem.prototype.parse = function (resource) {
this.resource = resource;
this.label = Manifesto.TranslationCollection.parse(this.resource.label, this.defaultLocale);
this.value = Manifesto.TranslationCollection.parse(this.resource.value, this.defaultLocale);
};
// shortcuts to get/set values based on default locale
MetadataItem.prototype.getLabel = function () {
if (this.label) {
return Manifesto.TranslationCollection.getValue(this.label, this.defaultLocale);
}
return null;
};
MetadataItem.prototype.setLabel = function (value) {
var _this = this;
if (this.label && this.label.length) {
var t = this.label.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
MetadataItem.prototype.getValue = function () {
if (this.value) {
var locale = this.defaultLocale;
// if the label has a locale, prefer that to the default locale
if (this.label.length && this.label[0].locale) {
locale = this.label[0].locale;
}
return Manifesto.TranslationCollection.getValue(this.value, locale);
}
return null;
};
MetadataItem.prototype.setValue = function (value) {
var _this = this;
if (this.value && this.value.length) {
var t = this.value.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
return MetadataItem;
}());
Manifesto.MetadataItem = MetadataItem;
})(Manifesto || (Manifesto = {}));

var Manifesto;
(function (Manifesto) {
var Translation = /** @class */ (function () {
Expand Down Expand Up @@ -3227,7 +3185,7 @@ global.manifesto = global.Manifesto = module.exports = {
IIIFResourceType: new Manifesto.IIIFResourceType(),
ManifestType: new Manifesto.ManifestType(),
MediaType: new Manifesto.MediaType(),
MetadataItem: Manifesto.MetadataItem,
LabelValuePair: Manifesto.LabelValuePair,
RenderingFormat: new Manifesto.RenderingFormat(),
ResourceType: new Manifesto.ResourceType(),
ServiceProfile: new Manifesto.ServiceProfile(),
Expand Down Expand Up @@ -3464,6 +3422,56 @@ var Manifesto;




var Manifesto;
(function (Manifesto) {
var LabelValuePair = /** @class */ (function () {
function LabelValuePair(defaultLocale) {
this.defaultLocale = defaultLocale;
}
LabelValuePair.prototype.parse = function (resource) {
this.resource = resource;
this.label = Manifesto.TranslationCollection.parse(this.resource.label, this.defaultLocale);
this.value = Manifesto.TranslationCollection.parse(this.resource.value, this.defaultLocale);
};
// shortcuts to get/set values based on default locale
LabelValuePair.prototype.getLabel = function () {
if (this.label) {
return Manifesto.TranslationCollection.getValue(this.label, this.defaultLocale);
}
return null;
};
LabelValuePair.prototype.setLabel = function (value) {
var _this = this;
if (this.label && this.label.length) {
var t = this.label.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
LabelValuePair.prototype.getValue = function () {
if (this.value) {
var locale = this.defaultLocale;
// if the label has a locale, prefer that to the default locale
if (this.label.length && this.label[0].locale) {
locale = this.label[0].locale;
}
return Manifesto.TranslationCollection.getValue(this.value, locale);
}
return null;
};
LabelValuePair.prototype.setValue = function (value) {
var _this = this;
if (this.value && this.value.length) {
var t = this.value.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
return LabelValuePair;
}());
Manifesto.LabelValuePair = LabelValuePair;
})(Manifesto || (Manifesto = {}));

var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
Expand Down
114 changes: 61 additions & 53 deletions dist/client/manifesto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// manifesto v2.2.32 https://github.com/iiif-commons/manifesto
// manifesto v2.3.0 https://github.com/iiif-commons/manifesto
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.manifesto = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function (global){

Expand Down Expand Up @@ -665,7 +665,7 @@ var Manifesto;
return metadata;
for (var i = 0; i < _metadata.length; i++) {
var item = _metadata[i];
var metadataItem = new Manifesto.MetadataItem(this.options.locale);
var metadataItem = new Manifesto.LabelValuePair(this.options.locale);
metadataItem.parse(item);
metadata.push(metadataItem);
}
Expand Down Expand Up @@ -1095,6 +1095,14 @@ var Manifesto;
this.defaultTree.data = this;
return this.defaultTree;
};
IIIFResource.prototype.getRequiredStatement = function () {
var _requiredStatement = this.getProperty('requiredStatement');
if (!_requiredStatement)
return null;
var requiredStatement = new Manifesto.LabelValuePair(this.options.locale);
requiredStatement.parse(_requiredStatement);
return requiredStatement;
};
IIIFResource.prototype.isCollection = function () {
if (this.getIIIFResourceType().toString() === Manifesto.IIIFResourceType.COLLECTION.toString()) {
return true;
Expand Down Expand Up @@ -2982,56 +2990,6 @@ var Manifesto;
Manifesto.Utils = Utils;
})(Manifesto || (Manifesto = {}));

var Manifesto;
(function (Manifesto) {
var MetadataItem = /** @class */ (function () {
function MetadataItem(defaultLocale) {
this.defaultLocale = defaultLocale;
}
MetadataItem.prototype.parse = function (resource) {
this.resource = resource;
this.label = Manifesto.TranslationCollection.parse(this.resource.label, this.defaultLocale);
this.value = Manifesto.TranslationCollection.parse(this.resource.value, this.defaultLocale);
};
// shortcuts to get/set values based on default locale
MetadataItem.prototype.getLabel = function () {
if (this.label) {
return Manifesto.TranslationCollection.getValue(this.label, this.defaultLocale);
}
return null;
};
MetadataItem.prototype.setLabel = function (value) {
var _this = this;
if (this.label && this.label.length) {
var t = this.label.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
MetadataItem.prototype.getValue = function () {
if (this.value) {
var locale = this.defaultLocale;
// if the label has a locale, prefer that to the default locale
if (this.label.length && this.label[0].locale) {
locale = this.label[0].locale;
}
return Manifesto.TranslationCollection.getValue(this.value, locale);
}
return null;
};
MetadataItem.prototype.setValue = function (value) {
var _this = this;
if (this.value && this.value.length) {
var t = this.value.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
return MetadataItem;
}());
Manifesto.MetadataItem = MetadataItem;
})(Manifesto || (Manifesto = {}));

var Manifesto;
(function (Manifesto) {
var Translation = /** @class */ (function () {
Expand Down Expand Up @@ -3155,7 +3113,7 @@ global.manifesto = global.Manifesto = module.exports = {
IIIFResourceType: new Manifesto.IIIFResourceType(),
ManifestType: new Manifesto.ManifestType(),
MediaType: new Manifesto.MediaType(),
MetadataItem: Manifesto.MetadataItem,
LabelValuePair: Manifesto.LabelValuePair,
RenderingFormat: new Manifesto.RenderingFormat(),
ResourceType: new Manifesto.ResourceType(),
ServiceProfile: new Manifesto.ServiceProfile(),
Expand Down Expand Up @@ -3392,6 +3350,56 @@ var Manifesto;




var Manifesto;
(function (Manifesto) {
var LabelValuePair = /** @class */ (function () {
function LabelValuePair(defaultLocale) {
this.defaultLocale = defaultLocale;
}
LabelValuePair.prototype.parse = function (resource) {
this.resource = resource;
this.label = Manifesto.TranslationCollection.parse(this.resource.label, this.defaultLocale);
this.value = Manifesto.TranslationCollection.parse(this.resource.value, this.defaultLocale);
};
// shortcuts to get/set values based on default locale
LabelValuePair.prototype.getLabel = function () {
if (this.label) {
return Manifesto.TranslationCollection.getValue(this.label, this.defaultLocale);
}
return null;
};
LabelValuePair.prototype.setLabel = function (value) {
var _this = this;
if (this.label && this.label.length) {
var t = this.label.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
LabelValuePair.prototype.getValue = function () {
if (this.value) {
var locale = this.defaultLocale;
// if the label has a locale, prefer that to the default locale
if (this.label.length && this.label[0].locale) {
locale = this.label[0].locale;
}
return Manifesto.TranslationCollection.getValue(this.value, locale);
}
return null;
};
LabelValuePair.prototype.setValue = function (value) {
var _this = this;
if (this.value && this.value.length) {
var t = this.value.en().where(function (x) { return x.locale === _this.defaultLocale || x.locale === Manifesto.Utils.getInexactLocale(_this.defaultLocale); }).first();
if (t)
t.value = value;
}
};
return LabelValuePair;
}());
Manifesto.LabelValuePair = LabelValuePair;
})(Manifesto || (Manifesto = {}));

var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
Expand Down
39 changes: 20 additions & 19 deletions dist/manifesto.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// manifesto v2.2.32 https://github.com/iiif-commons/manifesto
// manifesto v2.3.0 https://github.com/iiif-commons/manifesto

declare namespace Manifesto {
class StringValue {
Expand Down Expand Up @@ -260,7 +260,7 @@ declare namespace Manifesto {
constructor(jsonld: any, options?: IManifestoOptions);
getIIIFResourceType(): IIIFResourceType;
getLabel(): TranslationCollection;
getMetadata(): MetadataItem[];
getMetadata(): LabelValuePair[];
getRendering(format: RenderingFormat | string): IRendering | null;
getRenderings(): IRendering[];
getService(profile: ServiceProfile | string): IService | null;
Expand Down Expand Up @@ -324,6 +324,7 @@ declare namespace Manifesto {
getLabel(): TranslationCollection;
getDefaultLabel(): string | null;
getDefaultTree(): ITreeNode;
getRequiredStatement(): LabelValuePair | null;
isCollection(): boolean;
isManifest(): boolean;
load(): Promise<IIIIFResource>;
Expand Down Expand Up @@ -581,21 +582,6 @@ declare namespace Manifesto {
}
}

declare namespace Manifesto {
class MetadataItem {
label: TranslationCollection;
value: TranslationCollection;
defaultLocale: string;
resource: any;
constructor(defaultLocale: string);
parse(resource: any): void;
getLabel(): string | null;
setLabel(value: string): void;
getValue(): string | null;
setValue(value: string): void;
}
}

declare namespace Manifesto {
class Translation {
value: string;
Expand Down Expand Up @@ -831,10 +817,10 @@ interface IManifesto {
Behavior: Manifesto.Behavior;
create: (manifest: string, options?: Manifesto.IManifestoOptions) => Manifesto.IIIIFResource;
IIIFResourceType: Manifesto.IIIFResourceType;
LabelValuePair: any;
loadManifest: (uri: string) => Promise<string>;
ManifestType: Manifesto.ManifestType;
MediaType: Manifesto.MediaType;
MetadataItem: any;
RenderingFormat: Manifesto.RenderingFormat;
ResourceType: Manifesto.ResourceType;
ServiceProfile: Manifesto.ServiceProfile;
Expand Down Expand Up @@ -865,7 +851,7 @@ declare namespace Manifesto {
externalResource: Manifesto.IExternalResource;
options: IManifestoOptions;
getLabel(): TranslationCollection;
getMetadata(): MetadataItem[];
getMetadata(): LabelValuePair[];
getRendering(format: RenderingFormat | string): IRendering | null;
getRenderings(): IRendering[];
getService(profile: ServiceProfile | string): IService | null;
Expand Down Expand Up @@ -972,6 +958,21 @@ declare namespace Manifesto {
}
}

declare namespace Manifesto {
class LabelValuePair {
label: TranslationCollection;
value: TranslationCollection;
defaultLocale: string;
resource: any;
constructor(defaultLocale: string);
parse(resource: any): void;
getLabel(): string | null;
setLabel(value: string): void;
getValue(): string | null;
setValue(value: string): void;
}
}

declare namespace Manifesto {
class Thumbnail extends Resource implements IThumbnail {
constructor(jsonld: any, options: IManifestoOptions);
Expand Down
114 changes: 61 additions & 53 deletions dist/server/manifesto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manifesto.js",
"version": "2.2.32",
"version": "2.3.0",
"description": "IIIF Presentation API utility library for client and server",
"main": "./dist/server/manifesto.js",
"types": "./dist/manifesto.d.ts",
Expand Down
Loading

0 comments on commit 320bca3

Please sign in to comment.