« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/contribution/index.js1
-rw-r--r--src/data/composite/things/contribution/inheritFromContributionPresets.js76
-rw-r--r--src/data/things/contribution.js18
-rw-r--r--src/data/validators.js3
-rw-r--r--src/data/yaml.js3
5 files changed, 101 insertions, 0 deletions
diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js
index e912dadc..2cc69254 100644
--- a/src/data/composite/things/contribution/index.js
+++ b/src/data/composite/things/contribution/index.js
@@ -1,3 +1,4 @@
+export {default as inheritFromContributionPresets} from './inheritFromContributionPresets.js';
 export {default as withContributionArtist} from './withContributionArtist.js';
 export {default as withContributionContext} from './withContributionContext.js';
 export {default as withMatchingContributionPresets} from './withMatchingContributionPresets.js';
diff --git a/src/data/composite/things/contribution/inheritFromContributionPresets.js b/src/data/composite/things/contribution/inheritFromContributionPresets.js
new file mode 100644
index 00000000..72642957
--- /dev/null
+++ b/src/data/composite/things/contribution/inheritFromContributionPresets.js
@@ -0,0 +1,76 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withPropertyFromList, withPropertyFromObject} from '#composite/data';
+
+import withMatchingContributionPresets
+  from './withMatchingContributionPresets.js';
+
+export default templateCompositeFrom({
+  annotation: `inheritFromContributionPresets`,
+
+  inputs: {
+    property: input({type: 'string'}),
+  },
+
+  steps: () => [
+    withMatchingContributionPresets().outputs({
+      '#matchingContributionPresets': '#presets',
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#presets',
+      mode: input.value('empty'),
+    }),
+
+    withPropertyFromList({
+      list: '#presets',
+      property: input('property'),
+    }),
+
+    {
+      dependencies: ['#values'],
+
+      compute: (continuation, {
+        ['#values']: values,
+      }) => continuation({
+        ['#presetIndex']:
+          values.findIndex(value =>
+            value !== undefined &&
+            value !== null),
+      }),
+    },
+
+    raiseOutputWithoutDependency({
+      dependency: '#presetIndex',
+      mode: input.value('index'),
+    }),
+
+    {
+      dependencies: ['#presets', '#presetIndex'],
+
+      compute: (continuation, {
+        ['#presets']: presets,
+        ['#presetIndex']: presetIndex,
+      }) => continuation({
+        ['#preset']:
+          presets[presetIndex],
+      }),
+    },
+
+    withPropertyFromObject({
+      object: '#preset',
+      property: input('property'),
+    }),
+
+    // Can't use exposeDependency here since it doesn't compose, and so looks
+    // unfit to serve as the composition's base - even though we'll have raised
+    // out of this composition in the relevant cases already!
+    {
+      dependencies: ['#value'],
+      compute: (continuation, {
+        ['#value']: value,
+      }) => continuation.exit(value),
+    },
+  ],
+});
diff --git a/src/data/things/contribution.js b/src/data/things/contribution.js
index 6b7f050f..5594055c 100644
--- a/src/data/things/contribution.js
+++ b/src/data/things/contribution.js
@@ -9,8 +9,10 @@ import {isStringNonEmpty, isThing, validateReference} from '#validators';
 
 import {exposeDependency} from '#composite/control-flow';
 import {withResolvedReference} from '#composite/wiki-data';
+import {flag} from '#composite/wiki-properties';
 
 import {
+  inheritFromContributionPresets,
   withContributionArtist,
   withContributionContext,
   withMatchingContributionPresets,
@@ -47,6 +49,22 @@ export class Contribution extends Thing {
       update: {validate: isStringNonEmpty},
     },
 
+    countInContributionTotals: [
+      inheritFromContributionPresets({
+        property: input.thisProperty(),
+      }),
+
+      flag(true),
+    ],
+
+    countInDurationTotals: [
+      inheritFromContributionPresets({
+        property: input.thisProperty(),
+      }),
+
+      flag(true),
+    ],
+
     // Expose only
 
     context: [
diff --git a/src/data/validators.js b/src/data/validators.js
index 0f1d2e62..354de6fa 100644
--- a/src/data/validators.js
+++ b/src/data/validators.js
@@ -636,6 +636,9 @@ export function isThing(thing) {
 export const isContribution = validateProperties({
   artist: isArtistRef,
   annotation: optional(isStringNonEmpty),
+
+  countInDurationTotals: optional(isBoolean),
+  countInContributionTotals: optional(isBoolean),
 });
 
 export const isContributionList = validateArrayItems(isContribution);
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 3f096e8a..7a16341b 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -416,6 +416,9 @@ export function parseContributors(entries) {
       return {
         artist: item['Artist'],
         annotation: item['Annotation'] ?? null,
+
+        countInContributionTotals: item['Count In Contribution Totals'] ?? null,
+        countInDurationTotals: item['Count In Duration Totals'] ?? null,
       };
 
     if (typeof item !== 'string') return item;