« get me outta code hell

data: TrackSection.directory, find.trackSection, etc - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-19 22:55:15 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-19 22:55:15 -0300
commit0db3ac0e5e7e80f2268bf94f897ff442a4c8c855 (patch)
tree75d173a893348a6250a5d52df124f9b6fc704905 /src/data/things
parent83911a3abab88aef7548d95c769eced5d2af821a (diff)
data: TrackSection.directory, find.trackSection, etc
Diffstat (limited to 'src/data/things')
-rw-r--r--src/data/things/album.js80
1 files changed, 65 insertions, 15 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 78ecb294..253c6641 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -121,17 +121,11 @@ export class Album extends Thing {
     commentary: commentary(),
     additionalFiles: additionalFiles(),
 
-    trackSections: {
-      flags: {update: true, expose: true},
-
-      update: {
-        validate:
-          validateWikiData({
-            referenceType:
-              TrackSection[Thing.referenceType],
-          }),
-      },
-    },
+    trackSections: referenceList({
+      referenceType: input.value('unqualified-track-section'),
+      data: 'ownTrackSectionData',
+      find: input.value(find.unqualifiedTrackSection),
+    }),
 
     artistContribs: contributionList(),
     coverArtistContribs: contributionList(),
@@ -172,6 +166,10 @@ export class Album extends Thing {
       class: input.value(Group),
     }),
 
+    ownTrackSectionData: wikiData({
+      class: input.value(TrackSection),
+    }),
+
     // Expose only
 
     commentatorArtists: commentatorArtists(),
@@ -360,6 +358,7 @@ export class Album extends Thing {
 
     save(results) {
       const albumData = [];
+      const trackSectionData = [];
       const trackData = [];
 
       for (const {header: album, entries} of results) {
@@ -376,7 +375,10 @@ export class Album extends Thing {
         const albumRef = Thing.getReference(album);
 
         const closeCurrentTrackSection = () => {
-          if (empty(currentTrackSectionTracks)) {
+          if (
+            currentTrackSection.isDefaultTrackSection &&
+            empty(currentTrackSectionTracks)
+          ) {
             return;
           }
 
@@ -391,6 +393,7 @@ export class Album extends Thing {
             [album];
 
           trackSections.push(currentTrackSection);
+          trackSectionData.push(currentTrackSection);
         };
 
         for (const entry of entries) {
@@ -402,7 +405,6 @@ export class Album extends Thing {
           }
 
           currentTrackSectionTracks.push(entry);
-
           trackData.push(entry);
 
           entry.dataSourceAlbum = albumRef;
@@ -412,10 +414,16 @@ export class Album extends Thing {
 
         albumData.push(album);
 
-        album.trackSections = trackSections;
+        album.trackSections =
+          trackSections
+            .map(trackSection =>
+              `unqualified-track-section:` +
+              trackSection.unqualifiedDirectory);
+
+        album.ownTrackSectionData = trackSections;
       }
 
-      return {albumData, trackData};
+      return {albumData, trackSectionData, trackData};
     },
 
     sort({albumData, trackData}) {
@@ -478,6 +486,34 @@ export class TrackSection extends Thing {
 
     // Expose only
 
+    directory: [
+      withAlbum(),
+
+      exitWithoutDependency({
+        dependency: '#album',
+      }),
+
+      withPropertyFromObject({
+        object: '#album',
+        property: input.value('directory'),
+      }),
+
+      withDirectory({
+        directory: 'unqualifiedDirectory',
+      }).outputs({
+        '#directory': '#unqualifiedDirectory',
+      }),
+
+      {
+        dependencies: ['#album.directory', '#unqualifiedDirectory'],
+        compute: ({
+          ['#album.directory']: albumDirectory,
+          ['#unqualifiedDirectory']: unqualifiedDirectory,
+        }) =>
+          albumDirectory + '/' + unqualifiedDirectory,
+      },
+    ],
+
     startIndex: [
       withAlbum(),
 
@@ -517,6 +553,20 @@ export class TrackSection extends Thing {
     ],
   });
 
+  static [Thing.findSpecs] = {
+    trackSection: {
+      referenceTypes: ['track-section'],
+      bindTo: 'trackSectionData',
+    },
+
+    unqualifiedTrackSection: {
+      referenceTypes: ['unqualified-track-section'],
+
+      getMatchableDirectories: trackSection =>
+        [trackSection.unqualifiedDirectory],
+    },
+  };
+
   static [Thing.yamlDocumentSpec] = {
     fields: {
       'Section': {property: 'name'},