« 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/wiki-data/helpers/withSimpleDirectory.js52
-rw-r--r--src/data/composite/wiki-data/withDirectory.js41
-rw-r--r--src/data/composite/wiki-properties/directory.js6
-rw-r--r--src/data/things/album.js13
-rw-r--r--src/data/things/track.js27
5 files changed, 118 insertions, 21 deletions
diff --git a/src/data/composite/wiki-data/helpers/withSimpleDirectory.js b/src/data/composite/wiki-data/helpers/withSimpleDirectory.js
new file mode 100644
index 00000000..08ca3bfc
--- /dev/null
+++ b/src/data/composite/wiki-data/helpers/withSimpleDirectory.js
@@ -0,0 +1,52 @@
+// A "simple" directory, based only on the already-provided directory, if
+// available, or the provided name.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {isDirectory, isName} from '#validators';
+
+import {withResultOfAvailabilityCheck} from '#composite/control-flow';
+
+import withDirectoryFromName from './withDirectoryFromName.js';
+
+export default templateCompositeFrom({
+  annotation: `withSimpleDirectory`,
+
+  inputs: {
+    directory: input({
+      validate: isDirectory,
+      defaultDependency: 'directory',
+      acceptsNull: true,
+    }),
+
+    name: input({
+      validate: isName,
+      acceptsNull: true,
+    }),
+  },
+
+  outputs: ['#directory'],
+
+  steps: () => [
+    withResultOfAvailabilityCheck({
+      from: input('directory'),
+    }),
+
+    {
+      dependencies: ['#availability', input('directory')],
+      compute: (continuation, {
+        ['#availability']: availability,
+        [input('directory')]: directory,
+      }) =>
+        (availability
+          ? continuation.raiseOutput({
+              ['#directory']: directory
+            })
+          : continuation()),
+    },
+
+    withDirectoryFromName({
+      name: input('name'),
+    }),
+  ],
+});
diff --git a/src/data/composite/wiki-data/withDirectory.js b/src/data/composite/wiki-data/withDirectory.js
index a3f4ceda..f3bedf2e 100644
--- a/src/data/composite/wiki-data/withDirectory.js
+++ b/src/data/composite/wiki-data/withDirectory.js
@@ -7,9 +7,9 @@ import {input, templateCompositeFrom} from '#composite';
 
 import {isDirectory, isName} from '#validators';
 
-import {withResultOfAvailabilityCheck} from '#composite/control-flow';
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
 
-import withDirectoryFromName from './helpers/withDirectoryFromName.js';
+import withSimpleDirectory from './helpers/withSimpleDirectory.js';
 
 export default templateCompositeFrom({
   annotation: `withDirectory`,
@@ -26,30 +26,37 @@ export default templateCompositeFrom({
       defaultDependency: 'name',
       acceptsNull: true,
     }),
+
+    suffix: input({
+      validate: isDirectory,
+      defaultValue: null,
+    }),
   },
 
   outputs: ['#directory'],
 
   steps: () => [
-    withResultOfAvailabilityCheck({
-      from: input('directory'),
+    withSimpleDirectory({
+      directory: input('directory'),
+      name: input('name'),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#directory',
+      output: input.value({['#directory']: null}),
     }),
 
     {
-      dependencies: ['#availability', input('directory')],
+      dependencies: ['#directory', input('suffix')],
       compute: (continuation, {
-        ['#availability']: availability,
-        [input('directory')]: directory,
-      }) =>
-        (availability
-          ? continuation.raiseOutput({
-              ['#directory']: directory
-            })
-          : continuation()),
+        ['#directory']: directory,
+        [input('suffix')]: suffix,
+      }) => continuation({
+        ['#directory']:
+          (suffix
+            ? directory + '-' + suffix
+            : directory),
+      }),
     },
-
-    withDirectoryFromName({
-      name: input('name'),
-    }),
   ],
 });
diff --git a/src/data/composite/wiki-properties/directory.js b/src/data/composite/wiki-properties/directory.js
index 843958d7..9ca2a204 100644
--- a/src/data/composite/wiki-properties/directory.js
+++ b/src/data/composite/wiki-properties/directory.js
@@ -19,12 +19,18 @@ export default templateCompositeFrom({
       validate: isName,
       defaultDependency: 'name',
     }),
+
+    suffix: input({
+      validate: isDirectory,
+      defaultValue: null,
+    }),
   },
 
   steps: () => [
     withDirectory({
       directory: input.updateValue({validate: isDirectory}),
       name: input('name'),
+      suffix: input('suffix'),
     }),
 
     exposeDependency({
diff --git a/src/data/things/album.js b/src/data/things/album.js
index b8009063..9cbab427 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -11,7 +11,7 @@ import {traverse} from '#node-utils';
 import {sortAlbumsTracksChronologically, sortChronologically} from '#sort';
 import {accumulateSum, empty} from '#sugar';
 import Thing from '#thing';
-import {isColor, isDate, validateWikiData} from '#validators';
+import {isColor, isDate, isDirectory, validateWikiData} from '#validators';
 
 import {
   parseAdditionalFiles,
@@ -75,12 +75,18 @@ export class Album extends Thing {
     // Update & expose
 
     name: name('Unnamed Album'),
-    color: color(),
     directory: directory(),
-    urls: urls(),
+
+    directorySuffix: {
+      flags: {update: true, expose: true},
+      update: {validate: isDirectory},
+    },
 
     alwaysReferenceTracksByDirectory: flag(false),
 
+    color: color(),
+    urls: urls(),
+
     additionalNames: additionalNameList(),
 
     bandcampAlbumIdentifier: simpleString(),
@@ -328,6 +334,7 @@ export class Album extends Thing {
     fields: {
       'Album': {property: 'name'},
       'Directory': {property: 'directory'},
+      'Directory Suffix': {property: 'directorySuffix'},
 
       'Always Reference Tracks By Directory': {
         property: 'alwaysReferenceTracksByDirectory',
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 078ad11b..2ee42fdf 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -88,7 +88,31 @@ export class Track extends Thing {
     // Update & expose
 
     name: name('Unnamed Track'),
-    directory: directory(),
+
+    directory: [
+      withPropertyFromAlbum({
+        property: input.value('directorySuffix'),
+      }),
+
+      {
+        dependencies: ['suffixDirectory', '#album.directorySuffix'],
+        compute: (continuation, {
+          ['suffixDirectory']: suffixDirectory,
+          ['#album.directorySuffix']: directorySuffix,
+        }) => continuation({
+          ['#suffix']:
+            (suffixDirectory
+              ? directorySuffix
+              : null),
+        }),
+      },
+
+      directory({
+        suffix: '#suffix',
+      }),
+    ],
+
+    suffixDirectory: flag(false),
 
     additionalNames: additionalNameList(),
 
@@ -434,6 +458,7 @@ export class Track extends Thing {
     fields: {
       'Track': {property: 'name'},
       'Directory': {property: 'directory'},
+      'Suffix Directory': {property: 'suffixDirectory'},
 
       'Additional Names': {
         property: 'additionalNames',