kahuna/public/js/services/image-accessor.js (81 lines of code) (raw):
import angular from 'angular';
export const imageAccessor = angular.module('kahuna.services.image-accessor', []);
/**
* Accessor helpers to read information out of image resources.
*/
imageAccessor.factory('imageAccessor', function() {
/* == Extractors == (return embedded Resources) */
function extractUserMetadata(image) {
return image.data.userMetadata;
}
/* == Readers == (return data) */
function readId(image) {
return image.data.id;
}
function readCost(image) {
return image.data.cost;
}
function readLabels(image) {
const userMetadata = extractUserMetadata(image);
return userMetadata.data.labels.data;
}
function readPeopleInImage(image) {
return image.data.metadata.peopleInImage;
}
function readLeases(image) {
return image.data.leases.data;
}
function readMetadata(image) {
return image.data.metadata;
}
function readExtraInfo(image) {
return {
filename: image.data.uploadInfo && image.data.uploadInfo.filename,
uploadedBy: image.data.uploadedBy
};
}
function readUsageRights(image) {
return image.data.usageRights;
}
function readPersistedReasons(image) {
return image.data.persisted.reasons;
}
function isPersisted(image) {
return image.data.persisted.value;
}
function isArchived(image) {
const userMetadata = extractUserMetadata(image);
return userMetadata.data.archived.data;
}
function readCollections(image) {
return image.data.collections;
}
function readSyndicationStatus(image) {
return image.data.syndicationStatus;
}
function getCollectionsIds(image) {
const collections = readCollections(image);
return collections.map(col => col.data.pathId);
}
function getPhotoshoot(image) {
const userMetadata = extractUserMetadata(image);
return userMetadata.data.photoshoot;
}
function getSyndicationRights(image) {
return image.data.syndicationRights;
}
return {
readId,
readCost,
readLabels,
readLeases,
readMetadata,
readExtraInfo,
readUsageRights,
readPersistedReasons,
readPeopleInImage,
isPersisted,
isArchived,
readCollections,
getCollectionsIds,
getPhotoshoot,
readSyndicationStatus,
getSyndicationRights
};
});
export default imageAccessor;