-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
services/ucd-lib-client/client/public/lib/models/FcAppConfigModel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |