« get me outta code hell

generateCommentaryEntryDate.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateCommentaryEntryDate.js
blob: f1cf5cb3db6e52ad2509975be9f3394dd9c3886e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
export default {
  contentDependencies: ['generateTextWithTooltip', 'generateTooltip'],
  extraDependencies: ['html', 'language'],

  relations: (relation, _entry) => ({
    textWithTooltip:
      relation('generateTextWithTooltip'),

    tooltip:
      relation('generateTooltip'),
  }),

  data: (entry) => ({
    date: entry.date,
    secondDate: entry.secondDate,
    dateKind: entry.dateKind,

    accessDate: entry.accessDate,
    accessKind: entry.accessKind,
  }),

  generate(data, relations, {html, language}) {
    const titleCapsule = language.encapsulate('misc.artistCommentary.entry.title');

    const willDisplayTooltip =
      !!(data.accessKind && data.accessDate);

    const topAttributes =
      {class: 'commentary-date'};

    const time =
      html.tag('time',
        {[html.onlyIfContent]: true},

        (willDisplayTooltip
          ? {class: 'text-with-tooltip-interaction-cue'}
          : topAttributes),

        language.encapsulate(titleCapsule, 'date', workingCapsule => {
          const workingOptions = {};

          if (!data.date) {
            return html.blank();
          }

          const rangeNeeded =
            data.dateKind === 'sometime' ||
            data.dateKind === 'throughout';

          if (rangeNeeded && !data.secondDate) {
            workingOptions.date = language.formatDate(data.date);
            return language.$(workingCapsule, workingOptions);
          }

          if (data.dateKind) {
            workingCapsule += '.' + data.dateKind;
          }

          if (data.secondDate) {
            workingCapsule += '.range';
            workingOptions.dateRange =
              language.formatDateRange(data.date, data.secondDate);
          } else {
            workingOptions.date =
              language.formatDate(data.date);
          }

          return language.$(workingCapsule, workingOptions);
        }));

    if (willDisplayTooltip) {
      return relations.textWithTooltip.slots({
        customInteractionCue: true,

        attributes: topAttributes,
        text: time,

        tooltip:
          relations.tooltip.slots({
            attributes: {class: 'commentary-date-tooltip'},

            content:
              language.$(titleCapsule, 'date', data.accessKind, {
                date:
                  language.formatDate(data.accessDate),
              }),
          }),
      });
    } else {
      return time;
    }
  },
}