From 71de050864a42afcaeb409c11b9c792653cf2f1b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 20 Feb 2022 00:24:56 -0400 Subject: basic page writes --- src/data/things.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) (limited to 'src/data/things.js') diff --git a/src/data/things.js b/src/data/things.js index 4f4c2908..90d09b9c 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), -- cgit 1.3.0-6-gf8a5