Skip to content

Instantly share code, notes, and snippets.

@rosiegrant
Last active April 8, 2021 19:40
Show Gist options
  • Save rosiegrant/8207bc274dcf886f29b7d97029dc42b4 to your computer and use it in GitHub Desktop.
Save rosiegrant/8207bc274dcf886f29b7d97029dc42b4 to your computer and use it in GitHub Desktop.
document-standard component.js file
{{> cards/card_component componentName='document-standard' }}
class document-standardCardComponent extends BaseCard['document-standard'] {
constructor(config = {}, systemConfig = {}) {
super(config, systemConfig);
}
/**
* This returns an object that will be called `card`
* in the template. Put all mapping logic here.
*
* @param profile profile of the entity in the card
*/
dataForRender(profile) {
var detailsData = "";
if (profile.d_highlightedFields && profile.d_highlightedFields.s_snippet) {
detailsData = Formatter.highlightField(profile.d_highlightedFields.s_snippet.value, profile.d_highlightedFields.s_snippet.matchedSubstrings);
} else if (profile.s_snippet) {
detailsData = profile.s_snippet;
}
return {
title: profile.name, // The header text of the card
url: profile.website || profile.landingPageUrl, // If the card title is a clickable link, set URL here
target: '_top', // If the title's URL should open in a new tab, etc.
titleEventOptions: this.addDefaultEventOptions(),
subtitle: profile.externalArticleUpdateDate ? `Last Updated on ${profile.externalArticleUpdateDate}` : '', // The sub-header text of the card
details: detailsData
};
}
/**
* The template to render
* @returns {string}
* @override
*/
static defaultTemplateName (config) {
return 'cards/document-standard';
}
}
ANSWERS.registerTemplate(
'cards/document-standard',
{{{stringifyPartial (read 'cards/document-standard/template') }}}
);
ANSWERS.registerComponentType(document-standardCardComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment