@rcsb/rcsb-documentation
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "@rcsb/rcsb-documentation", | ||
"private": false, | ||
"version": "0.0.03", | ||
"version": "0.0.04", | ||
"main": "build/bundle.js", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -111,5 +111,12 @@ // Check if fetch is available; otherwise, use node-fetch | ||
const item = await fetchItem(env, _id); | ||
const imgPath = getImagePath(env, item, _id); | ||
item.html = item.html.replace(/<IMG_PATH>/g, imgPath).replace(/https:\/\/www.rcsb.org/g, ''); | ||
item.lastUpdatedStr = new Date(item.lastUpdated).toLocaleDateString('en-US'); | ||
// Special case: Set attribute details if the URL matches | ||
if (reqUrl === '/docs/search-and-browse/advanced-search/attribute-details') { | ||
setAttributeDetails(req, item); | ||
} else { | ||
const imgPath = getImagePath(env, item, _id); | ||
item.html = item.html.replace(/<IMG_PATH>/g, imgPath).replace(/https:\/\/www.rcsb.org/g, ''); | ||
item.lastUpdatedStr = new Date(item.lastUpdated).toLocaleDateString('en-US'); | ||
} | ||
item.href = hrefMap[_id]; | ||
@@ -271,2 +278,92 @@ itemMap[_id] = item; | ||
function setAttributeDetails(req, item) { | ||
const metadata = req.app.locals.metadata | ||
, UNITS = { // see definition in lib/js/search/src/constants.js | ||
angstroms: 'Å' | ||
, angstroms_cubed_per_dalton: 'ų/Da' | ||
, angstroms_squared: 'Ų' | ||
, kelvins: 'K' | ||
, kilodaltons: 'kDa' | ||
, kilojoule_per_mole: 'kJ/mol' | ||
, megahertz: 'MHz' | ||
, daltons: 'Da' | ||
, degrees: '°' | ||
, nanomole: 'nM' | ||
, per_mole: 'M\u207B\u00B9' // unicode <sup>-1</sup> - TODO replace other unicode chars with unicode equivalent | ||
} | ||
, attributeDetails = { | ||
schemas: [ | ||
{ schema_name: 'structure', headers: [] } | ||
, { schema_name: 'chemical', headers: [] } | ||
] | ||
}; | ||
//u.logJson(metadata.structure, 'setAttributeDetails: metadata.structure') | ||
attributeDetails.schemas.forEach(schema => { | ||
const { headers, schema_name } = schema; | ||
schema.display_name = u.ucFirst(schema_name) + ' Attributes'; | ||
const selectorItems = metadata[schema_name].selectorItems; | ||
selectorItems.forEach(si => { | ||
if (si.type === 'header') { | ||
headers.push({ name: si.name, attributes: [] }); | ||
} else { | ||
const attrObj = metadata[schema_name].uiAttrMap[si.attribute]; // attrObj from metadata, where 'name' is schema name | ||
if (attrObj) { | ||
const { attribute, description, type } = attrObj | ||
, obj = { attribute, description, type }; | ||
obj.name = si.name; | ||
if (si.type === 'item-nested') { | ||
//if (si.attribute === 'rcsb_binding_affinity.value') u.logJson({ selectorItem: si, attrObj }, 'setAttributeDetails') | ||
let { nested_attribute, nested_attribute_value, units, range } = si; | ||
// assign values from selectorItem | ||
obj.nested_attribute = nested_attribute; | ||
if (units) obj.units = UNITS[units]; | ||
if (range) { | ||
obj.min = range.min; | ||
obj.max = range.max; | ||
} | ||
const { nestedAttribute } = attrObj | ||
, context = nestedAttribute.contexts[nested_attribute_value] | ||
, { detail, examples } = context; | ||
// these values are not available in selectorItem, so assign from attrObj | ||
if (detail) obj.detail = detail; | ||
if (examples) obj.examples = examples; | ||
} else { | ||
const { units, examples, enumeration, is_iterable } = attrObj; | ||
let { min, max } = attrObj; | ||
if (units) obj.units = UNITS[units]; | ||
if (examples) obj.examples = examples; | ||
if (enumeration) obj.enumeration = enumeration; | ||
if (is_iterable) obj.is_iterable = is_iterable; | ||
// check min, max for 0 otherwise they will not display in ui | ||
if (typeof min !== 'undefined' && typeof max !== 'undefined') { | ||
obj.min = '' + min; | ||
obj.max = '' + max; | ||
} | ||
} | ||
headers[headers.length - 1].attributes.push(obj); | ||
} | ||
} | ||
}); | ||
}); | ||
item.attributeDetails = attributeDetails; | ||
item.lastUpdatedStr = metadata['structure'].lastReleaseDate.long; | ||
} | ||
// Set parent group state for rendering | ||
@@ -300,3 +397,4 @@ function setParentGroupState(groupMap, o) { | ||
getMenuObj, | ||
setAttributeDetails, | ||
setParentGroupState, | ||
}; |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1228111
1054