diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-11-03 13:22:08 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-11-14 07:59:22 -0400 |
commit | 60f007a20db3547c57b1b1f84510707b38a4076a (patch) | |
tree | b401118bc40ce493fe5fd243a3472cf6986e9053 | |
parent | 163c541f4b8244f3c2fd8568ab3ef5cc4ed114a2 (diff) |
data: Album.suffixTrackDirectories
-rw-r--r-- | src/data/composite/things/track/index.js | 2 | ||||
-rw-r--r-- | src/data/composite/things/track/withDirectorySuffix.js | 36 | ||||
-rw-r--r-- | src/data/composite/things/track/withSuffixDirectoryFromAlbum.js | 53 | ||||
-rw-r--r-- | src/data/things/album.js | 18 | ||||
-rw-r--r-- | src/data/things/track.js | 37 |
5 files changed, 127 insertions, 19 deletions
diff --git a/src/data/composite/things/track/index.js b/src/data/composite/things/track/index.js index 63ede4cf..05ccaaba 100644 --- a/src/data/composite/things/track/index.js +++ b/src/data/composite/things/track/index.js @@ -6,9 +6,11 @@ export {default as withAlbum} from './withAlbum.js'; export {default as withAlwaysReferenceByDirectory} from './withAlwaysReferenceByDirectory.js'; export {default as withContainingTrackSection} from './withContainingTrackSection.js'; export {default as withDate} from './withDate.js'; +export {default as withDirectorySuffix} from './withDirectorySuffix.js'; export {default as withHasUniqueCoverArt} from './withHasUniqueCoverArt.js'; export {default as withOriginalRelease} from './withOriginalRelease.js'; export {default as withOtherReleases} from './withOtherReleases.js'; export {default as withPropertyFromAlbum} from './withPropertyFromAlbum.js'; export {default as withPropertyFromOriginalRelease} from './withPropertyFromOriginalRelease.js'; +export {default as withSuffixDirectoryFromAlbum} from './withSuffixDirectoryFromAlbum.js'; export {default as withTrackArtDate} from './withTrackArtDate.js'; diff --git a/src/data/composite/things/track/withDirectorySuffix.js b/src/data/composite/things/track/withDirectorySuffix.js new file mode 100644 index 00000000..c063e158 --- /dev/null +++ b/src/data/composite/things/track/withDirectorySuffix.js @@ -0,0 +1,36 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + +import withPropertyFromAlbum from './withPropertyFromAlbum.js'; +import withSuffixDirectoryFromAlbum from './withSuffixDirectoryFromAlbum.js'; + +export default templateCompositeFrom({ + annotation: `withDirectorySuffix`, + + outputs: ['#directorySuffix'], + + steps: () => [ + withSuffixDirectoryFromAlbum(), + + raiseOutputWithoutDependency({ + dependency: '#suffixDirectoryFromAlbum', + mode: input.value('falsy'), + output: input.value({['#directorySuffix']: null}), + }), + + withPropertyFromAlbum({ + property: input.value('directorySuffix'), + }), + + { + dependencies: ['#album.directorySuffix'], + compute: (continuation, { + ['#album.directorySuffix']: directorySuffix, + }) => continuation({ + ['#directorySuffix']: + directorySuffix, + }), + }, + ], +}); diff --git a/src/data/composite/things/track/withSuffixDirectoryFromAlbum.js b/src/data/composite/things/track/withSuffixDirectoryFromAlbum.js new file mode 100644 index 00000000..7159a3f4 --- /dev/null +++ b/src/data/composite/things/track/withSuffixDirectoryFromAlbum.js @@ -0,0 +1,53 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {withResultOfAvailabilityCheck} from '#composite/control-flow'; + +import withPropertyFromAlbum from './withPropertyFromAlbum.js'; + +export default templateCompositeFrom({ + annotation: `withSuffixDirectoryFromAlbum`, + + inputs: { + flagValue: input({ + defaultDependency: 'suffixDirectoryFromAlbum', + acceptsNull: true, + }), + }, + + outputs: ['#suffixDirectoryFromAlbum'], + + steps: () => [ + withResultOfAvailabilityCheck({ + from: 'suffixDirectoryFromAlbum', + }), + + { + dependencies: [ + '#availability', + 'suffixDirectoryFromAlbum' + ], + + compute: (continuation, { + ['#availability']: availability, + ['suffixDirectoryFromAlbum']: flagValue, + }) => + (availability + ? continuation.raiseOutput({['#suffixDirectoryFromAlbum']: flagValue}) + : continuation()), + }, + + withPropertyFromAlbum({ + property: input.value('suffixTrackDirectories'), + }), + + { + dependencies: ['#album.suffixTrackDirectories'], + compute: (continuation, { + ['#album.suffixTrackDirectories']: suffixTrackDirectories, + }) => continuation({ + ['#suffixDirectoryFromAlbum']: + suffixTrackDirectories, + }), + }, + ], +}); diff --git a/src/data/things/album.js b/src/data/things/album.js index 9cbab427..4a714361 100644 --- a/src/data/things/album.js +++ b/src/data/things/album.js @@ -77,12 +77,20 @@ export class Album extends Thing { name: name('Unnamed Album'), directory: directory(), - directorySuffix: { - flags: {update: true, expose: true}, - update: {validate: isDirectory}, - }, + directorySuffix: [ + exposeUpdateValueOrContinue({ + validate: input.value(isDirectory), + }), + + withDirectory(), + + exposeDependency({ + dependency: '#directory', + }), + ], alwaysReferenceTracksByDirectory: flag(false), + suffixTrackDirectories: flag(false), color: color(), urls: urls(), @@ -333,8 +341,10 @@ export class Album extends Thing { static [Thing.yamlDocumentSpec] = { fields: { 'Album': {property: 'name'}, + 'Directory': {property: 'directory'}, 'Directory Suffix': {property: 'directorySuffix'}, + 'Suffix Track Directories': {property: 'suffixTrackDirectories'}, 'Always Reference Tracks By Directory': { property: 'alwaysReferenceTracksByDirectory', diff --git a/src/data/things/track.js b/src/data/things/track.js index 2ee42fdf..a1740f87 100644 --- a/src/data/things/track.js +++ b/src/data/things/track.js @@ -5,7 +5,7 @@ import {colors} from '#cli'; import {input} from '#composite'; import find from '#find'; import Thing from '#thing'; -import {isColor, isContributionList, isDate, isFileExtension} +import {isBoolean, isColor, isContributionList, isDate, isFileExtension} from '#validators'; import { @@ -67,10 +67,12 @@ import { withAlwaysReferenceByDirectory, withContainingTrackSection, withDate, + withDirectorySuffix, withHasUniqueCoverArt, withOriginalRelease, withOtherReleases, withPropertyFromAlbum, + withSuffixDirectoryFromAlbum, withTrackArtDate, } from '#composite/things/track'; @@ -90,29 +92,34 @@ export class Track extends Thing { name: name('Unnamed Track'), directory: [ - withPropertyFromAlbum({ - property: input.value('directorySuffix'), + withDirectorySuffix(), + + directory({ + suffix: '#directorySuffix', }), + ], + suffixDirectoryFromAlbum: [ { - dependencies: ['suffixDirectory', '#album.directorySuffix'], + dependencies: [ + input.updateValue({validate: isBoolean}), + ], + compute: (continuation, { - ['suffixDirectory']: suffixDirectory, - ['#album.directorySuffix']: directorySuffix, + [input.updateValue()]: value, }) => continuation({ - ['#suffix']: - (suffixDirectory - ? directorySuffix - : null), + ['#flagValue']: value ?? false, }), }, - directory({ - suffix: '#suffix', + withSuffixDirectoryFromAlbum({ + flagValue: '#flagValue', }), - ], - suffixDirectory: flag(false), + exposeDependency({ + dependency: '#suffixDirectoryFromAlbum', + }) + ], additionalNames: additionalNameList(), @@ -458,7 +465,7 @@ export class Track extends Thing { fields: { 'Track': {property: 'name'}, 'Directory': {property: 'directory'}, - 'Suffix Directory': {property: 'suffixDirectory'}, + 'Suffix Directory': {property: 'suffixDirectoryFromAlbum'}, 'Additional Names': { property: 'additionalNames', |