« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/artwork.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/artwork.js')
-rw-r--r--src/data/things/artwork.js274
1 files changed, 107 insertions, 167 deletions
diff --git a/src/data/things/artwork.js b/src/data/things/artwork.js
index ac70159c..c1aafa8f 100644
--- a/src/data/things/artwork.js
+++ b/src/data/things/artwork.js
@@ -1,6 +1,7 @@
 import {inspect} from 'node:util';
 
-import {input} from '#composite';
+import {colors} from '#cli';
+import {input, V} from '#composite';
 import find from '#find';
 import Thing from '#thing';
 
@@ -24,17 +25,25 @@ import {
   parseDimensions,
 } from '#yaml';
 
-import {withIndexInList, withPropertyFromObject} from '#composite/data';
-
 import {
   exitWithoutDependency,
   exposeConstant,
   exposeDependency,
   exposeDependencyOrContinue,
   exposeUpdateValueOrContinue,
+  flipFilter,
 } from '#composite/control-flow';
 
 import {
+  withFilteredList,
+  withNearbyItemFromList,
+  withPropertyFromList,
+  withPropertyFromObject,
+} from '#composite/data';
+
+import {
+  constituteFrom,
+  constituteOrContinue,
   withRecontextualizedContributionList,
   withResolvedAnnotatedReferenceList,
   withResolvedContribs,
@@ -53,21 +62,18 @@ import {
   wikiData,
 } from '#composite/wiki-properties';
 
-import {
-  withAttachedArtwork,
-  withContainingArtworkList,
-  withContribsFromAttachedArtwork,
-  withPropertyFromAttachedArtwork,
-  withDate,
-} from '#composite/things/artwork';
+import {withContainingArtworkList} from '#composite/things/artwork';
 
 export class Artwork extends Thing {
   static [Thing.referenceType] = 'artwork';
+  static [Thing.wikiData] = 'artworkData';
+
+  static [Thing.constitutibleProperties] = [
+    // Contributions currently aren't being observed for constitution.
+    // 'artistContribs', // from attached artwork or thing
+  ];
 
-  static [Thing.getPropertyDescriptors] = ({
-    ArtTag,
-    Contribution,
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({ArtTag}) => ({
     // Update & expose
 
     unqualifiedDirectory: directory({
@@ -79,51 +85,28 @@ export class Artwork extends Thing {
 
     label: simpleString(),
     source: contentString(),
+    originDetails: contentString(),
+    showFilename: simpleString(),
 
     dateFromThingProperty: simpleString(),
 
     date: [
-      withDate({
-        from: input.updateValue({validate: isDate}),
+      exposeUpdateValueOrContinue({
+        validate: input.value(isDate),
       }),
 
-      exposeDependency({dependency: '#date'}),
+      constituteFrom('thing', 'dateFromThingProperty'),
     ],
 
     fileExtensionFromThingProperty: simpleString(),
 
     fileExtension: [
-      {
-        compute: (continuation) => continuation({
-          ['#default']: 'jpg',
-        }),
-      },
-
       exposeUpdateValueOrContinue({
         validate: input.value(isFileExtension),
       }),
 
-      exitWithoutDependency({
-        dependency: 'thing',
-        value: '#default',
-      }),
-
-      exitWithoutDependency({
-        dependency: 'fileExtensionFromThingProperty',
-        value: '#default',
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
-        property: 'fileExtensionFromThingProperty',
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#value',
-      }),
-
-      exposeDependency({
-        dependency: '#default',
+      constituteFrom('thing', 'fileExtensionFromThingProperty', {
+        else: input.value('jpg'),
       }),
     ],
 
@@ -134,78 +117,40 @@ export class Artwork extends Thing {
         validate: input.value(isDimensions),
       }),
 
-      exitWithoutDependency({
-        dependency: 'dimensionsFromThingProperty',
-        value: input.value(null),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
-        property: 'dimensionsFromThingProperty',
-      }).outputs({
-        ['#value']: '#dimensionsFromThing',
-      }),
-
-      exitWithoutDependency({
-        dependency: 'dimensionsFromThingProperty',
-        value: input.value(null),
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#dimensionsFromThing',
-      }),
-
-      exposeConstant({
-        value: input.value(null),
-      }),
+      constituteFrom('thing', 'dimensionsFromThingProperty'),
     ],
 
-    attachAbove: flag(false),
+    attachAbove: flag(V(false)),
 
     artistContribsFromThingProperty: simpleString(),
     artistContribsArtistProperty: simpleString(),
 
     artistContribs: [
-      withDate(),
-
       withResolvedContribs({
         from: input.updateValue({validate: isContributionList}),
-        date: '#date',
+        date: 'date',
+        thingProperty: input.thisProperty(),
         artistProperty: 'artistContribsArtistProperty',
       }),
 
-      exposeDependencyOrContinue({
-        dependency: '#resolvedContribs',
-        mode: input.value('empty'),
-      }),
-
-      withContribsFromAttachedArtwork(),
+      exposeDependencyOrContinue('#resolvedContribs', V('empty')),
 
-      exposeDependencyOrContinue({
-        dependency: '#attachedArtwork.artistContribs',
-      }),
+      withPropertyFromObject('attachedArtwork', V('artistContribs')),
 
-      exitWithoutDependency({
-        dependency: 'artistContribsFromThingProperty',
-        value: input.value([]),
-      }),
+      withRecontextualizedContributionList('#attachedArtwork.artistContribs'),
+      exposeDependencyOrContinue('#attachedArtwork.artistContribs'),
 
-      withPropertyFromObject({
-        object: 'thing',
-        property: 'artistContribsFromThingProperty',
-      }).outputs({
-        ['#value']: '#artistContribs',
-      }),
+      exitWithoutDependency('artistContribsFromThingProperty', V([])),
 
-      withRecontextualizedContributionList({
-        list: '#artistContribs',
-      }),
+      withPropertyFromObject('thing', 'artistContribsFromThingProperty')
+        .outputs({'#value': '#artistContribsFromThing'}),
 
-      exposeDependency({
-        dependency: '#artistContribs',
-      }),
+      withRecontextualizedContributionList('#artistContribsFromThing'),
+      exposeDependency('#artistContribsFromThing'),
     ],
 
+    style: simpleString(),
+
     artTagsFromThingProperty: simpleString(),
 
     artTags: [
@@ -214,42 +159,14 @@ export class Artwork extends Thing {
           validate:
             validateReferenceList(ArtTag[Thing.referenceType]),
         }),
-
         find: soupyFind.input('artTag'),
       }),
 
-      exposeDependencyOrContinue({
-        dependency: '#resolvedReferenceList',
-        mode: input.value('empty'),
-      }),
+      exposeDependencyOrContinue('#resolvedReferenceList', V('empty')),
 
-      withPropertyFromAttachedArtwork({
-        property: input.value('artTags'),
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#attachedArtwork.artTags',
-      }),
+      constituteOrContinue('attachedArtwork', V('artTags'), V('empty')),
 
-      exitWithoutDependency({
-        dependency: 'artTagsFromThingProperty',
-        value: input.value([]),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
-        property: 'artTagsFromThingProperty',
-      }).outputs({
-        ['#value']: '#artTags',
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#artTags',
-      }),
-
-      exposeConstant({
-        value: input.value([]),
-      }),
+      constituteFrom('thing', 'artTagsFromThingProperty', V([])),
     ],
 
     referencedArtworksFromThingProperty: simpleString(),
@@ -279,35 +196,16 @@ export class Artwork extends Thing {
               })),
         }),
 
-        data: 'artworkData',
+        data: '_artworkData',
         find: '#find',
 
         thing: input.value('artwork'),
       }),
 
-      exposeDependencyOrContinue({
-        dependency: '#resolvedAnnotatedReferenceList',
-        mode: input.value('empty'),
-      }),
-
-      exitWithoutDependency({
-        dependency: 'referencedArtworksFromThingProperty',
-        value: input.value([]),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
-        property: 'referencedArtworksFromThingProperty',
-      }).outputs({
-        ['#value']: '#referencedArtworks',
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#referencedArtworks',
-      }),
+      exposeDependencyOrContinue('#resolvedAnnotatedReferenceList', V('empty')),
 
-      exposeConstant({
-        value: input.value([]),
+      constituteFrom('thing', 'referencedArtworksFromThingProperty', {
+        else: input.value([]),
       }),
     ],
 
@@ -317,23 +215,19 @@ export class Artwork extends Thing {
     reverse: soupyReverse(),
 
     // used for referencedArtworks (mixedFind)
-    artworkData: wikiData({
-      class: input.value(Artwork),
-    }),
+    artworkData: wikiData(V(Artwork)),
 
     // Expose only
 
+    isArtwork: exposeConstant(V(true)),
+
     referencedByArtworks: reverseReferenceList({
       reverse: soupyReverse.input('artworksWhichReference'),
     }),
 
     isMainArtwork: [
       withContainingArtworkList(),
-
-      exitWithoutDependency({
-        dependency: '#containingArtworkList',
-        value: input.value(null),
-      }),
+      exitWithoutDependency('#containingArtworkList'),
 
       {
         dependencies: [input.myself(), '#containingArtworkList'],
@@ -347,11 +241,7 @@ export class Artwork extends Thing {
 
     mainArtwork: [
       withContainingArtworkList(),
-
-      exitWithoutDependency({
-        dependency: '#containingArtworkList',
-        value: input.value(null),
-      }),
+      exitWithoutDependency('#containingArtworkList'),
 
       {
         dependencies: ['#containingArtworkList'],
@@ -361,16 +251,50 @@ export class Artwork extends Thing {
     ],
 
     attachedArtwork: [
-      withAttachedArtwork(),
+      exitWithoutDependency('attachAbove', {
+        value: input.value(null),
+        mode: input.value('falsy'),
+      }),
+
+      withContainingArtworkList(),
+
+      withPropertyFromList('#containingArtworkList', V('attachAbove')),
+
+      flipFilter('#containingArtworkList.attachAbove')
+        .outputs({'#containingArtworkList.attachAbove': '#filterNotAttached'}),
 
-      exposeDependency({
-        dependency: '#attachedArtwork',
+      withNearbyItemFromList({
+        list: '#containingArtworkList',
+        item: input.myself(),
+        offset: input.value(-1),
+        filter: '#filterNotAttached',
       }),
+
+      exposeDependency('#nearbyItem'),
     ],
 
     attachingArtworks: reverseReferenceList({
       reverse: soupyReverse.input('artworksWhichAttach'),
     }),
+
+    groups: [
+      withPropertyFromObject('thing', V('groups')),
+      exposeDependencyOrContinue('#thing.groups'),
+
+      exposeConstant(V([])),
+    ],
+
+    contentWarningArtTags: [
+      withPropertyFromList('artTags', V('isContentWarning')),
+      withFilteredList('artTags', '#artTags.isContentWarning'),
+      exposeDependency('#filteredList'),
+    ],
+
+    contentWarnings: [
+      withPropertyFromList('contentWarningArtTags', V('name')),
+      exposeDependency('#contentWarningArtTags.name'),
+    ],
+
   });
 
   static [Thing.yamlDocumentSpec] = {
@@ -385,6 +309,8 @@ export class Artwork extends Thing {
 
       'Label': {property: 'label'},
       'Source': {property: 'source'},
+      'Origin Details': {property: 'originDetails'},
+      'Show Filename': {property: 'showFilename'},
 
       'Date': {
         property: 'date',
@@ -398,6 +324,8 @@ export class Artwork extends Thing {
         transform: parseContributors,
       },
 
+      'Style': {property: 'style'},
+
       'Tags': {property: 'artTags'},
 
       'Referenced Artworks': {
@@ -456,6 +384,18 @@ export class Artwork extends Thing {
     return this.thing.getOwnArtworkPath(this);
   }
 
+  countOwnContributionInContributionTotals(contrib) {
+    if (this.attachAbove) {
+      return false;
+    }
+
+    if (contrib.annotation?.startsWith('edits for wiki')) {
+      return false;
+    }
+
+    return true;
+  }
+
   [inspect.custom](depth, options, inspect) {
     const parts = [];