Skip to content

Commit

Permalink
adding FcAppConfigModel, #76
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmerz committed Mar 10, 2021
1 parent 6566481 commit 367b257
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class AppHome extends Mixin(PolymerElement)
constructor() {
super();
this.active = true;

this._injectModel('FcAppConfigModel');
console.log(this.FcAppConfigModel.getFeaturedImages());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions services/ucd-lib-client/client/public/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
MediaModel : require('./models/MediaModel'),
CitationModel : require('./models/CitationsModel'),
SeoModel : require('./models/SeoModel'),
FiltersModel : require('./models/FiltersModel')
}
FiltersModel : require('./models/FiltersModel'),
FcAppConfigModel : require('./models/FcAppConfigModel')
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const {BaseModel} = require('@ucd-lib/cork-app-utils');

/**
* @class FcAppConfigModel
* @description a wrapper class around APP_CONFIG.fcAppConfig which contains
* the /application/ucd-lib-client graph from fcrepo. Adds nice accessor
* methods
*/
class FcAppConfigModel extends BaseModel {

constructor() {
super();

this.TYPES = {
APPLICATION_CONTAINER : 'http://digital.ucdavis.edu/schema#ApplicationContainer'
}

this.byId = {};
(APP_CONFIG.fcAppConfig || []).forEach(item => this.byId[item['@id']] = item);

this.register('FcAppConfigModel');
}

/**
* @method getFeaturedCollections
* @description return any defined featured collections
*
* @returns {Array}
*/
getFeaturedCollections() {
let appContainer = this.getApplicationContainer();
return asArray(appContainer.featuredCollection)
.map(item => {
return this.byId[item['@id']];
});
}

/**
* @method getFeaturedImages
* @description return any defined featured images
*
* @returns {Array}
*/
getFeaturedImages() {
let appContainer = this.getApplicationContainer();
return asArray(appContainer.featuredImage)
.map(item => {
return this.byId[item['@id']];
});
}

/**
* @method getApplicationContainer
* @description return the main application container from the app graph
*
* @returns {Object}
*/
getApplicationContainer() {
return (APP_CONFIG.fcAppConfig || [])
.find(item => item['@type'].includes(this.TYPES.APPLICATION_CONTAINER));
}

}

function asArray(val) {
if( val === undefined ) return [];
if( Array.isArray(val) ) return val;
return [val];
}

module.exports = new FcAppConfigModel();

0 comments on commit 367b257

Please sign in to comment.