« 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.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things.js')
-rw-r--r--src/data/things.js74
1 files changed, 70 insertions, 4 deletions
diff --git a/src/data/things.js b/src/data/things.js
index 4f4c290..90d09b9 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -20,6 +20,7 @@ import {
     isNumber,
     isURL,
     isString,
+    isWholeNumber,
     oneOf,
     validateArrayItems,
     validateInstanceOf,
@@ -270,7 +271,7 @@ Thing.common = {
         expose: {
             dependencies: ['artistData', contribsByRefProperty],
             compute: ({ artistData, [contribsByRefProperty]: contribsByRef }) => (
-                (contribsByRef && artistData
+                ((contribsByRef && artistData)
                     ? (contribsByRef
                         .map(({ who: ref, what }) => ({
                             who: find.artist(ref, {wikiData: {artistData}}),
@@ -329,7 +330,10 @@ Thing.common = {
             dependencies: [wikiDataProperty],
 
             compute: ({ [wikiDataProperty]: wikiData, [Thing.instance]: thing }) => (
-                wikiData?.filter(t => t[referencerRefListProperty]?.includes(thing)))
+                (wikiData
+                    ? wikiData.filter(t => t[referencerRefListProperty]?.includes(thing))
+                    : [])
+            )
         }
     }),
 
@@ -466,7 +470,25 @@ TrackGroup.propertyDescriptors = {
     // Update & expose
 
     name: Thing.common.name('Unnamed Track Group'),
-    color: Thing.common.color(),
+
+    color: {
+        flags: {update: true, expose: true},
+
+        update: {validate: isColor},
+
+        expose: {
+            dependencies: ['album'],
+
+            transform(color, { album }) {
+                return color ?? album?.color ?? null;
+            }
+        }
+    },
+
+    startIndex: {
+        flags: {update: true, expose: true},
+        update: {validate: isWholeNumber}
+    },
 
     dateOriginallyReleased: Thing.common.simpleDate(),
 
@@ -476,6 +498,11 @@ TrackGroup.propertyDescriptors = {
 
     // Update only
 
+    album: {
+        flags: {update: true},
+        update: {validate: validateInstanceOf(Album)}
+    },
+
     trackData: Thing.common.wikiData(Track),
 
     // Expose only
@@ -544,6 +571,7 @@ Track.propertyDescriptors = {
     albumData: Thing.common.wikiData(Album),
     artistData: Thing.common.wikiData(Artist),
     artTagData: Thing.common.wikiData(ArtTag),
+    flashData: Thing.common.wikiData(Flash),
     trackData: Thing.common.wikiData(Track),
 
     // Expose only
@@ -565,12 +593,26 @@ Track.propertyDescriptors = {
             dependencies: ['albumData', 'dateFirstReleased'],
             compute: ({ albumData, dateFirstReleased, [Track.instance]: track }) => (
                 dateFirstReleased ??
-                Track.findAlbum(track)?.date ??
+                Track.findAlbum(track, albumData)?.date ??
                 null
             )
         }
     },
 
+    color: {
+        flags: {expose: true},
+
+        expose: {
+            dependencies: ['albumData', 'trackData'],
+
+            compute: ({ albumData, trackData, [Track.instance]: track }) => (
+                (Track.findAlbum(track, albumData)?.trackGroups
+                    .find(tg => tg.tracks.includes(track))?.color)
+                ?? null
+            )
+        }
+    },
+
     coverArtDate: {
         flags: {update: true, expose: true},
 
@@ -588,6 +630,30 @@ Track.propertyDescriptors = {
         }
     },
 
+    otherReleases: {
+        flags: {expose: true},
+
+        expose: {
+            dependencies: ['originalReleaseTrackByRef', 'trackData'],
+
+            compute: ({ originalReleaseTrackByRef: ref1, trackData, [Track.instance]: t1 }) => (
+                (ref1 && trackData
+                    ? [
+                        find.track(ref1, {wikiData: {trackData}}),
+                        ...trackData.filter(t2 => {
+                            const { originalReleaseTrackByRef: ref2 } = t2;
+                            return (
+                                t2 !== t1 &&
+                                ref2 &&
+                                (
+                                    find.track(ref2, {wikiData: {trackData}}) ===
+                                    find.track(ref1, {wikiData: {trackData}})))
+                        })]
+                    : [])
+            )
+        }
+    },
+
     // Previously known as: (track).artists
     artistContribs: Thing.common.dynamicInheritContribs('artistContribsByRef', 'artistContribsByRef', 'albumData', Track.findAlbum),