Skip to content

Commit

Permalink
moved clickthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Jul 31, 2015
1 parent 8e5d1c8 commit befef96
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 84 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manifesto",
"version": "0.1.5",
"version": "0.1.6",
"homepage": "https://github.com/edsilv/manifesto",
"authors": [
"edsilv <[email protected]>"
Expand Down
54 changes: 30 additions & 24 deletions dist/client/manifesto.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,35 +597,35 @@ var Manifesto;
if (storedAccessToken) {
// try using the stored access token
resource.getData(storedAccessToken).then(function () {
// if the resource has a click through service, use that.
if (resource.clickThroughService) {
resolve(clickThrough(resource));
// if the info.json loaded using the stored access token
if (resource.status === 200) {
resolve(handleResourceResponse(resource));
}
else {
// if the info.json loaded using the stored access token
if (resource.status === 200) {
// otherwise, load the resource data to determine the correct access control services.
// if access controlled, do login.
_this.authorize(resource, clickThrough, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
}
else {
// otherwise, load the resource data to determine the correct access control services.
// if access controlled, do login.
_this.authorize(resource, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
});
}
});
}
});
}
else {
_this.authorize(resource, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
});
// if the resource has a click through service, use that.
if (resource.clickThroughService) {
resolve(clickThrough(resource));
}
else {
_this.authorize(resource, clickThrough, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
});
}
}
});
}
});
};
Manifest.prototype.authorize = function (resource, login, getAccessToken, storeAccessToken, getStoredAccessToken) {
Manifest.prototype.authorize = function (resource, clickThrough, login, getAccessToken, storeAccessToken, getStoredAccessToken) {
return new Promise(function (resolve, reject) {
resource.getData().then(function () {
if (resource.isAccessControlled) {
Expand All @@ -637,16 +637,22 @@ var Manifesto;
});
}
else {
// get an access token
login(resource.loginService).then(function () {
getAccessToken(resource.tokenService).then(function (accessToken) {
storeAccessToken(resource, accessToken).then(function () {
resource.getData(accessToken).then(function () {
resolve(resource);
// if the resource has a click through service, use that.
if (resource.clickThroughService) {
clickThrough(resource);
}
else {
// get an access token
login(resource.loginService).then(function () {
getAccessToken(resource.tokenService).then(function (accessToken) {
storeAccessToken(resource, accessToken).then(function () {
resource.getData(accessToken).then(function () {
resolve(resource);
});
});
});
});
});
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/manifesto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ declare module Manifesto {
private _parseTreeNode(node, range);
isMultiSequence(): boolean;
loadResource(resource: IResource, clickThrough: (resource: IResource) => void, login: (loginService: string) => Promise<void>, getAccessToken: (tokenServiceUrl: string) => Promise<IAccessToken>, storeAccessToken: (resource: IResource, token: IAccessToken) => Promise<void>, getStoredAccessToken: (tokenService: string) => Promise<IAccessToken>, handleResourceResponse: (resource: IResource) => Promise<any>): Promise<any>;
authorize(resource: IResource, login: (loginService: string) => Promise<void>, getAccessToken: (tokenServiceUrl: string) => Promise<IAccessToken>, storeAccessToken: (resource: IResource, token: IAccessToken) => Promise<void>, getStoredAccessToken: (tokenService: string) => Promise<IAccessToken>): Promise<IResource>;
authorize(resource: IResource, clickThrough: (resource: IResource) => void, login: (loginService: string) => Promise<void>, getAccessToken: (tokenServiceUrl: string) => Promise<IAccessToken>, storeAccessToken: (resource: IResource, token: IAccessToken) => Promise<void>, getStoredAccessToken: (tokenService: string) => Promise<IAccessToken>): Promise<IResource>;
loadResources(resources: IResource[], clickThrough: (resource: IResource) => void, login: (loginService: string) => Promise<void>, getAccessToken: (tokenServiceUrl: string) => Promise<IAccessToken>, storeAccessToken: (resource: IResource, token: IAccessToken) => Promise<void>, getStoredAccessToken: (tokenService: string) => Promise<IAccessToken>, handleResourceResponse: (resource: IResource) => Promise<any>): Promise<IResource[]>;
}
}
Expand Down
54 changes: 30 additions & 24 deletions dist/server/manifesto.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,35 +596,35 @@ var Manifesto;
if (storedAccessToken) {
// try using the stored access token
resource.getData(storedAccessToken).then(function () {
// if the resource has a click through service, use that.
if (resource.clickThroughService) {
resolve(clickThrough(resource));
// if the info.json loaded using the stored access token
if (resource.status === 200) {
resolve(handleResourceResponse(resource));
}
else {
// if the info.json loaded using the stored access token
if (resource.status === 200) {
// otherwise, load the resource data to determine the correct access control services.
// if access controlled, do login.
_this.authorize(resource, clickThrough, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
}
else {
// otherwise, load the resource data to determine the correct access control services.
// if access controlled, do login.
_this.authorize(resource, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
});
}
});
}
});
}
else {
_this.authorize(resource, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
});
// if the resource has a click through service, use that.
if (resource.clickThroughService) {
resolve(clickThrough(resource));
}
else {
_this.authorize(resource, clickThrough, login, getAccessToken, storeAccessToken, getStoredAccessToken).then(function () {
resolve(handleResourceResponse(resource));
});
}
}
});
}
});
};
Manifest.prototype.authorize = function (resource, login, getAccessToken, storeAccessToken, getStoredAccessToken) {
Manifest.prototype.authorize = function (resource, clickThrough, login, getAccessToken, storeAccessToken, getStoredAccessToken) {
return new Promise(function (resolve, reject) {
resource.getData().then(function () {
if (resource.isAccessControlled) {
Expand All @@ -636,16 +636,22 @@ var Manifesto;
});
}
else {
// get an access token
login(resource.loginService).then(function () {
getAccessToken(resource.tokenService).then(function (accessToken) {
storeAccessToken(resource, accessToken).then(function () {
resource.getData(accessToken).then(function () {
resolve(resource);
// if the resource has a click through service, use that.
if (resource.clickThroughService) {
clickThrough(resource);
}
else {
// get an access token
login(resource.loginService).then(function () {
getAccessToken(resource.tokenService).then(function (accessToken) {
storeAccessToken(resource, accessToken).then(function () {
resource.getData(accessToken).then(function () {
resolve(resource);
});
});
});
});
});
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manifesto",
"version": "0.1.5",
"version": "0.1.6",
"description": "IIIF Presentation API utility library for client and server",
"main": "dist/server/manifesto.js",
"scripts": {
Expand Down
75 changes: 42 additions & 33 deletions src/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,43 +366,47 @@ module Manifesto {
if (storedAccessToken) {
// try using the stored access token
resource.getData(storedAccessToken).then(() => {
// if the resource has a click through service, use that.
if (resource.clickThroughService){
resolve(clickThrough(resource));
// if the info.json loaded using the stored access token
if (resource.status === 200) {
resolve(handleResourceResponse(resource));
} else {
// if the info.json loaded using the stored access token
if (resource.status === 200) {
resolve(handleResourceResponse(resource));
} else {
// otherwise, load the resource data to determine the correct access control services.
// if access controlled, do login.
this.authorize(
resource,
login,
getAccessToken,
storeAccessToken,
getStoredAccessToken).then(() => {
resolve(handleResourceResponse(resource));
});
}
// otherwise, load the resource data to determine the correct access control services.
// if access controlled, do login.
this.authorize(
resource,
clickThrough,
login,
getAccessToken,
storeAccessToken,
getStoredAccessToken).then(() => {
resolve(handleResourceResponse(resource));
});
}

});
} else {
this.authorize(
resource,
login,
getAccessToken,
storeAccessToken,
getStoredAccessToken).then(() => {
resolve(handleResourceResponse(resource));
});
// if the resource has a click through service, use that.
if (resource.clickThroughService){
resolve(clickThrough(resource));
} else {
this.authorize(
resource,
clickThrough,
login,
getAccessToken,
storeAccessToken,
getStoredAccessToken).then(() => {
resolve(handleResourceResponse(resource));
});
}
}
});
}
});
}

authorize(resource: IResource,
clickThrough: (resource: IResource) => void,
login: (loginService: string) => Promise<void>,
getAccessToken: (tokenServiceUrl: string) => Promise<IAccessToken>,
storeAccessToken: (resource: IResource, token: IAccessToken) => Promise<void>,
Expand All @@ -419,16 +423,21 @@ module Manifesto {
resolve(resource);
});
} else {
// get an access token
login(resource.loginService).then(() => {
getAccessToken(resource.tokenService).then((accessToken) => {
storeAccessToken(resource, accessToken).then(() => {
resource.getData(accessToken).then(() => {
resolve(resource);
// if the resource has a click through service, use that.
if (resource.clickThroughService){
clickThrough(resource);
} else {
// get an access token
login(resource.loginService).then(() => {
getAccessToken(resource.tokenService).then((accessToken) => {
storeAccessToken(resource, accessToken).then(() => {
resource.getData(accessToken).then(() => {
resolve(resource);
});
});
});
});
});
}
}
});
} else {
Expand Down

0 comments on commit befef96

Please sign in to comment.