@isrd-isi-edu/ermrestjs 2.7.0 → 2.9.0

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.
@@ -7,7 +7,7 @@ import { Reference, Tuple } from '@isrd-isi-edu/ermrestjs/src/models/reference';
7
7
 
8
8
  // utils
9
9
  import { renderMarkdown } from '@isrd-isi-edu/ermrestjs/src/utils/markdown-utils';
10
- import { isStringAndNotEmpty } from '@isrd-isi-edu/ermrestjs/src/utils/type-utils';
10
+ import { isValidVisibleCellHeight, isStringAndNotEmpty } from '@isrd-isi-edu/ermrestjs/src/utils/type-utils';
11
11
  import { buildSelfTemplateVariables } from '@isrd-isi-edu/ermrestjs/src/utils/template-utils';
12
12
 
13
13
  // legacy
@@ -227,6 +227,10 @@ export class KeyPseudoColumn extends ReferenceColumn {
227
227
  sourceDisplay.hideColumnHeader = this.sourceObject.hide_column_header;
228
228
  }
229
229
 
230
+ if (this.sourceObject && isValidVisibleCellHeight(this.sourceObject.visible_cell_height)) {
231
+ sourceDisplay.visibleCellHeight = this.sourceObject.visible_cell_height;
232
+ }
233
+
230
234
  Object.assign(res, keyDisplay, sourceDisplay);
231
235
  this._display_cached = res;
232
236
  }
@@ -12,7 +12,12 @@ import $log from '@isrd-isi-edu/ermrestjs/src/services/logger';
12
12
 
13
13
  // utils
14
14
  import { renderMarkdown } from '@isrd-isi-edu/ermrestjs/src/utils/markdown-utils';
15
- import { isObjectAndKeyExists, isObjectAndNotNull, isStringAndNotEmpty } from '@isrd-isi-edu/ermrestjs/src/utils/type-utils';
15
+ import {
16
+ isValidVisibleCellHeight,
17
+ isObjectAndKeyExists,
18
+ isObjectAndNotNull,
19
+ isStringAndNotEmpty,
20
+ } from '@isrd-isi-edu/ermrestjs/src/utils/type-utils';
16
21
  import { _annotations, _contexts } from '@isrd-isi-edu/ermrestjs/src/utils/constants';
17
22
  import { buildSelfTemplateVariables } from '@isrd-isi-edu/ermrestjs/src/utils/template-utils';
18
23
  import ActiveListCondition from '@isrd-isi-edu/ermrestjs/src/models/active-list-condition';
@@ -385,6 +390,10 @@ export class ReferenceColumn {
385
390
  sourceDisplay.hideColumnHeader = this.sourceObject.hide_column_header;
386
391
  }
387
392
 
393
+ if (this.sourceObject && isValidVisibleCellHeight(this.sourceObject.visible_cell_height)) {
394
+ sourceDisplay.visibleCellHeight = this.sourceObject.visible_cell_height;
395
+ }
396
+
388
397
  // Using assign to avoid changing the original colDisplay
389
398
  Object.assign(res, colDisplay, sourceDisplay);
390
399
  this._display_cached = res;
@@ -12,11 +12,11 @@ import {
12
12
  _addErmrestVarsToTemplate,
13
13
  _addTemplateVars,
14
14
  _escapeMarkdownCharacters,
15
- _formatUtils,
16
15
  _getPath,
17
16
  encodeFacet,
18
17
  encodeFacetString,
19
18
  } from '@isrd-isi-edu/ermrestjs/js/utils/helpers';
19
+ import { _formatUtils } from '@isrd-isi-edu/ermrestjs/src/utils/format-utils';
20
20
  import AuthnService from '@isrd-isi-edu/ermrestjs/src/services/authn';
21
21
  import { isObjectAndNotNull } from '@isrd-isi-edu/ermrestjs/src/utils/type-utils';
22
22
  import { fixedEncodeURIComponent } from '@isrd-isi-edu/ermrestjs/src/utils/value-utils';
@@ -403,6 +403,28 @@ export default class HandlebarsService {
403
403
  return _formatUtils.humanizeBytes(value, mode, precision, tooltip);
404
404
  },
405
405
 
406
+ /**
407
+ * {{datetimeDuration start end}}
408
+ * {{datetimeDuration start end unit="month"}}
409
+ * {{datetimeDuration start end unit="auto" fraction=2}}
410
+ * {{datetimeDuration start end unit="multi"}}
411
+ * {{datetimeDuration start end unit="calendar"}}
412
+ * {{datetimeDuration start end direction="before/after"}}
413
+ * {{datetimeDuration start end unit="month" tooltip=true}}
414
+ * @ignore
415
+ * @returns human-readable duration between `start` and `end`
416
+ */
417
+ datetimeDuration: function (start: any, end: any, options: Handlebars.HelperOptions) {
418
+ let unit, fraction, direction, tooltip;
419
+ if (options && isObjectAndNotNull(options.hash)) {
420
+ unit = options.hash.unit;
421
+ fraction = options.hash.fraction;
422
+ direction = options.hash.direction;
423
+ tooltip = options.hash.tooltip;
424
+ }
425
+ return _formatUtils.datetimeDuration(start, end, unit, fraction, direction, tooltip);
426
+ },
427
+
406
428
  /**
407
429
  * {{stringLength value }}
408
430
  * @ignore
@@ -18,12 +18,12 @@ import { isDefinedAndNotNull } from '@isrd-isi-edu/ermrestjs/src/utils/type-util
18
18
 
19
19
  // legacy
20
20
  import {
21
- _formatUtils,
22
21
  _generateRowPresentation,
23
22
  _getRowTemplateVariables,
24
23
  _processColumnOrderList,
25
24
  _renderTemplate,
26
25
  } from '@isrd-isi-edu/ermrestjs/js/utils/helpers';
26
+ import { _formatUtils } from '@isrd-isi-edu/ermrestjs/src/utils/format-utils';
27
27
 
28
28
  /**
29
29
  * Convert the raw value of an aggregate column to a formatted value.
@@ -286,6 +286,7 @@ export const _handlebarsHelpersList = [
286
286
  'toTitleCase',
287
287
  'replace',
288
288
  'humanizeBytes',
289
+ 'datetimeDuration',
289
290
  'printf',
290
291
  'stringLength',
291
292
  'isUserInAcl',
@@ -529,6 +530,83 @@ export const _sourceProperties = Object.freeze({
529
530
 
530
531
  export const _exportKnownAPIs = ['entity', 'attribute', 'attributegroup', 'aggregate'];
531
532
 
533
+ /**
534
+ * Named constants for the `unit` argument of `datetimeDuration`. Source of
535
+ * truth for valid unit values — `_datetimeDuration.VALID_UNITS` and
536
+ * `UNIT_ORDER` are derived from this object below.
537
+ *
538
+ * Includes the three pseudo-units (`AUTO`, `MULTI`, `CALENDAR`) alongside the
539
+ * seven real time units. Use `DurationRealUnit` for the real-unit subset.
540
+ */
541
+ export const DURATION_UNIT = Object.freeze({
542
+ AUTO: 'auto',
543
+ MULTI: 'multi',
544
+ CALENDAR: 'calendar',
545
+ YEAR: 'year',
546
+ MONTH: 'month',
547
+ DAY: 'day',
548
+ HOUR: 'hour',
549
+ MINUTE: 'minute',
550
+ SECOND: 'second',
551
+ MILLISECOND: 'millisecond',
552
+ } as const);
553
+ export type DurationUnit = (typeof DURATION_UNIT)[keyof typeof DURATION_UNIT];
554
+
555
+ /**
556
+ * Named constants for the `direction` argument of `datetimeDuration`. Source
557
+ * of truth for valid direction values — `_datetimeDuration.VALID_DIRECTIONS`
558
+ * is derived from this object below.
559
+ */
560
+ export const DURATION_DIRECTION = Object.freeze({
561
+ SIGN: 'sign',
562
+ BEFORE_AFTER: 'before/after',
563
+ EARLIER_LATER: 'earlier/later',
564
+ UNSIGNED: 'unsigned',
565
+ } as const);
566
+ export type DurationDirection = (typeof DURATION_DIRECTION)[keyof typeof DURATION_DIRECTION];
567
+
568
+ export const _datetimeDuration = Object.freeze({
569
+ // Real units in walking order (largest first). The source of truth for what
570
+ // counts as a "real" (non-pseudo) duration unit.
571
+ UNIT_ORDER: [
572
+ DURATION_UNIT.YEAR,
573
+ DURATION_UNIT.MONTH,
574
+ DURATION_UNIT.DAY,
575
+ DURATION_UNIT.HOUR,
576
+ DURATION_UNIT.MINUTE,
577
+ DURATION_UNIT.SECOND,
578
+ DURATION_UNIT.MILLISECOND,
579
+ ] as const,
580
+ ABBREVIATIONS: {
581
+ [DURATION_UNIT.YEAR]: 'Y',
582
+ [DURATION_UNIT.MONTH]: 'M',
583
+ [DURATION_UNIT.DAY]: 'D',
584
+ [DURATION_UNIT.HOUR]: 'h',
585
+ [DURATION_UNIT.MINUTE]: 'm',
586
+ [DURATION_UNIT.SECOND]: 's',
587
+ [DURATION_UNIT.MILLISECOND]: 'ms',
588
+ },
589
+ // Julian fixed-math constants (1Y = 365.25d, 1M = 365.25/12d).
590
+ // Self-consistent (12 * MONTH === YEAR), matches moment.js / date-fns / astronomy.
591
+ CONVERSION_RATES: {
592
+ [DURATION_UNIT.MILLISECOND]: 1,
593
+ [DURATION_UNIT.SECOND]: 1000,
594
+ [DURATION_UNIT.MINUTE]: 60 * 1000,
595
+ [DURATION_UNIT.HOUR]: 60 * 60 * 1000,
596
+ [DURATION_UNIT.DAY]: 24 * 60 * 60 * 1000,
597
+ [DURATION_UNIT.MONTH]: (365.25 / 12) * 24 * 60 * 60 * 1000, // 2,629,800,000
598
+ [DURATION_UNIT.YEAR]: 365.25 * 24 * 60 * 60 * 1000, // 31,557,600,000
599
+ },
600
+ VALID_UNITS: Object.values(DURATION_UNIT) as readonly DurationUnit[],
601
+ VALID_DIRECTIONS: Object.values(DURATION_DIRECTION) as readonly DurationDirection[],
602
+ });
603
+
604
+ /**
605
+ * The real (non-pseudo) subset of `DurationUnit`, derived from `UNIT_ORDER`
606
+ * so it stays in sync automatically.
607
+ */
608
+ export type DurationRealUnit = (typeof _datetimeDuration.UNIT_ORDER)[number];
609
+
532
610
  export const FILTER_TYPES = Object.freeze({
533
611
  BINARYPREDICATE: 'BinaryPredicate',
534
612
  CONJUNCTION: 'Conjunction',