From c56a1eb78b76b52cbeeed6fe16d3511c1fd41147 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Feb 2022 09:46:22 -0400 Subject: super basic album ↔ track linking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thing/track.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/thing/track.js') diff --git a/src/thing/track.js b/src/thing/track.js index 75df109a..d0e88acf 100644 --- a/src/thing/track.js +++ b/src/thing/track.js @@ -16,6 +16,11 @@ import { validateReferenceList, } from './validators.js'; +import Album from './album.js'; +import ArtTag from './art-tag.js'; + +import find from '../util/find.js'; + export default class Track extends Thing { static [Thing.referenceType] = 'track'; @@ -112,6 +117,55 @@ export default class Track extends Thing { // Update only + albumData: { + flags: {update: true}, + update: {validate: validateArrayItems(x => x instanceof Album)} + }, + + artTagData: { + flags: {update: true}, + update: {validate: validateArrayItems(x => x instanceof ArtTag)} + }, + // Expose only + + album: { + flags: {expose: true}, + + expose: { + dependencies: ['albumData'], + compute: ({ [this.instance]: track, albumData }) => ( + albumData?.find(album => album.tracks.includes(track)) ?? null) + } + }, + + date: { + flags: {expose: true}, + + expose: { + dependencies: ['albumData', 'dateFirstReleased'], + compute: ({ albumData, dateFirstReleased, [this.instance]: track }) => ( + dateFirstReleased ?? + albumData?.find(album => album.tracks.includes(track))?.date ?? + null + ) + } + }, + + artTags: { + flags: {expose: true}, + + expose: { + dependencies: ['artTagsByRef', 'artTagData'], + + compute: ({ artTagsByRef, artTagData }) => ( + (artTagsByRef && artTagData + ? (artTagsByRef + .map(ref => find.tag(ref, {wikiData: {tagData: artTagData}})) + .filter(Boolean)) + : []) + ) + } + } }; } -- cgit 1.3.0-6-gf8a5