@rcsb/rcsb-documentation 0.0.3 → 0.0.5

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 +100 -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.05",
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,95 @@ 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 = schema_name.substring(0, 1).toUpperCase() + schema_name.substring(1) + ' 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
+
321
+ let { nested_attribute, nested_attribute_value, units, range } = si;
322
+
323
+ // assign values from selectorItem
324
+ obj.nested_attribute = nested_attribute;
325
+
326
+ if (units) obj.units = UNITS[units];
327
+ if (range) {
328
+ obj.min = range.min;
329
+ obj.max = range.max;
330
+ }
331
+
332
+ const { nestedAttribute } = attrObj
333
+ , context = nestedAttribute.contexts[nested_attribute_value]
334
+ , { detail, examples } = context;
335
+
336
+ // these values are not available in selectorItem, so assign from attrObj
337
+ if (detail) obj.detail = detail;
338
+ if (examples) obj.examples = examples;
339
+
340
+ } else {
341
+ const { units, examples, enumeration, is_iterable } = attrObj;
342
+ let { min, max } = attrObj;
343
+
344
+ if (units) obj.units = UNITS[units];
345
+ if (examples) obj.examples = examples;
346
+ if (enumeration) obj.enumeration = enumeration;
347
+ if (is_iterable) obj.is_iterable = is_iterable;
348
+
349
+ // check min, max for 0 otherwise they will not display in ui
350
+ if (typeof min !== 'undefined' && typeof max !== 'undefined') {
351
+ obj.min = '' + min;
352
+ obj.max = '' + max;
353
+ }
354
+ }
355
+
356
+ headers[headers.length - 1].attributes.push(obj);
357
+ }
358
+ }
359
+ });
360
+ });
361
+
362
+ item.attributeDetails = attributeDetails;
363
+ item.lastUpdatedStr = metadata['structure'].lastReleaseDate.long;
364
+ }
365
+
270
366
  // Set parent group state for rendering
271
367
  function setParentGroupState(groupMap, o) {
272
368
  if (o.show) {
@@ -295,5 +391,6 @@ module.exports = {
295
391
  getMenuPath,
296
392
  returnData,
297
393
  getMenuObj,
394
+ setAttributeDetails,
298
395
  setParentGroupState,
299
396
  };