@rcsb/rcsb-documentation 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/docsApi.js +101 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rcsb/rcsb-documentation",
3
3
  "private": false,
4
- "version": "0.0.03",
4
+ "version": "0.0.04",
5
5
  "main": "build/bundle.js",
6
6
  "files": [
7
7
  "build",
package/server/docsApi.js CHANGED
@@ -108,9 +108,16 @@ async function getItem(req, res, env) {
108
108
 
109
109
  if (loadItem) {
110
110
  const item = await fetchItem(env, _id);
111
- const imgPath = getImagePath(env, item, _id);
112
- item.html = item.html.replace(/<IMG_PATH>/g, imgPath).replace(/https:\/\/www.rcsb.org/g, '');
113
- item.lastUpdatedStr = new Date(item.lastUpdated).toLocaleDateString('en-US');
111
+
112
+ // Special case: Set attribute details if the URL matches
113
+ if (reqUrl === '/docs/search-and-browse/advanced-search/attribute-details') {
114
+ setAttributeDetails(req, item);
115
+ } else {
116
+ const imgPath = getImagePath(env, item, _id);
117
+ item.html = item.html.replace(/<IMG_PATH>/g, imgPath).replace(/https:\/\/www.rcsb.org/g, '');
118
+ item.lastUpdatedStr = new Date(item.lastUpdated).toLocaleDateString('en-US');
119
+ }
120
+
114
121
  item.href = hrefMap[_id];
115
122
  itemMap[_id] = item;
116
123
 
@@ -267,6 +274,96 @@ function getMenuObj(item) {
267
274
  return { groupMap, menu };
268
275
  }
269
276
 
277
+ function setAttributeDetails(req, item) {
278
+ const metadata = req.app.locals.metadata
279
+ , UNITS = { // see definition in lib/js/search/src/constants.js
280
+ angstroms: 'Å'
281
+ , angstroms_cubed_per_dalton: 'ų/Da'
282
+ , angstroms_squared: 'Ų'
283
+ , kelvins: 'K'
284
+ , kilodaltons: 'kDa'
285
+ , kilojoule_per_mole: 'kJ/mol'
286
+ , megahertz: 'MHz'
287
+ , daltons: 'Da'
288
+ , degrees: '°'
289
+ , nanomole: 'nM'
290
+ , per_mole: 'M\u207B\u00B9' // unicode <sup>-1</sup> - TODO replace other unicode chars with unicode equivalent
291
+ }
292
+ , attributeDetails = {
293
+ schemas: [
294
+ { schema_name: 'structure', headers: [] }
295
+ , { schema_name: 'chemical', headers: [] }
296
+ ]
297
+ };
298
+
299
+ //u.logJson(metadata.structure, 'setAttributeDetails: metadata.structure')
300
+
301
+ attributeDetails.schemas.forEach(schema => {
302
+ const { headers, schema_name } = schema;
303
+
304
+ schema.display_name = u.ucFirst(schema_name) + ' Attributes';
305
+ const selectorItems = metadata[schema_name].selectorItems;
306
+
307
+ selectorItems.forEach(si => {
308
+ if (si.type === 'header') {
309
+ headers.push({ name: si.name, attributes: [] });
310
+ } else {
311
+ const attrObj = metadata[schema_name].uiAttrMap[si.attribute]; // attrObj from metadata, where 'name' is schema name
312
+
313
+ if (attrObj) {
314
+ const { attribute, description, type } = attrObj
315
+ , obj = { attribute, description, type };
316
+
317
+ obj.name = si.name;
318
+
319
+ if (si.type === 'item-nested') {
320
+ //if (si.attribute === 'rcsb_binding_affinity.value') u.logJson({ selectorItem: si, attrObj }, 'setAttributeDetails')
321
+
322
+ let { nested_attribute, nested_attribute_value, units, range } = si;
323
+
324
+ // assign values from selectorItem
325
+ obj.nested_attribute = nested_attribute;
326
+
327
+ if (units) obj.units = UNITS[units];
328
+ if (range) {
329
+ obj.min = range.min;
330
+ obj.max = range.max;
331
+ }
332
+
333
+ const { nestedAttribute } = attrObj
334
+ , context = nestedAttribute.contexts[nested_attribute_value]
335
+ , { detail, examples } = context;
336
+
337
+ // these values are not available in selectorItem, so assign from attrObj
338
+ if (detail) obj.detail = detail;
339
+ if (examples) obj.examples = examples;
340
+
341
+ } else {
342
+ const { units, examples, enumeration, is_iterable } = attrObj;
343
+ let { min, max } = attrObj;
344
+
345
+ if (units) obj.units = UNITS[units];
346
+ if (examples) obj.examples = examples;
347
+ if (enumeration) obj.enumeration = enumeration;
348
+ if (is_iterable) obj.is_iterable = is_iterable;
349
+
350
+ // check min, max for 0 otherwise they will not display in ui
351
+ if (typeof min !== 'undefined' && typeof max !== 'undefined') {
352
+ obj.min = '' + min;
353
+ obj.max = '' + max;
354
+ }
355
+ }
356
+
357
+ headers[headers.length - 1].attributes.push(obj);
358
+ }
359
+ }
360
+ });
361
+ });
362
+
363
+ item.attributeDetails = attributeDetails;
364
+ item.lastUpdatedStr = metadata['structure'].lastReleaseDate.long;
365
+ }
366
+
270
367
  // Set parent group state for rendering
271
368
  function setParentGroupState(groupMap, o) {
272
369
  if (o.show) {
@@ -295,5 +392,6 @@ module.exports = {
295
392
  getMenuPath,
296
393
  returnData,
297
394
  getMenuObj,
395
+ setAttributeDetails,
298
396
  setParentGroupState,
299
397
  };