« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing/album.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing/album.js')
-rw-r--r--src/thing/album.js255
1 files changed, 249 insertions, 6 deletions
diff --git a/src/thing/album.js b/src/thing/album.js
index e99cfc36..7be092e0 100644
--- a/src/thing/album.js
+++ b/src/thing/album.js
@@ -1,28 +1,267 @@
 import Thing from './thing.js';
 
 import {
-    validateDirectory,
-    validateReference
-} from './structures.js';
+    isBoolean,
+    isColor,
+    isCommentary,
+    isContributionList,
+    isDate,
+    isDimensions,
+    isDirectory,
+    isName,
+    isURL,
+    isString,
+    validateArrayItems,
+    validateReference,
+    validateReferenceList,
+} from './validators.js';
 
 import {
+    aggregateThrows,
     showAggregate,
     withAggregate
 } from '../util/sugar.js';
 
 export default class Album extends Thing {
+    /*
+    #name = 'Unnamed Album';
+
+    #color = null;
     #directory = null;
+    #urls = [];
+
+    #artists = [];
+    #coverArtists = [];
+    #trackCoverArtists = [];
+
+    #wallpaperArtists = [];
+    #wallpaperStyle = '';
+    #wallpaperFileExtension = 'jpg';
+
+    #bannerArtists = [];
+    #bannerStyle = '';
+    #bannerFileExtension = 'jpg';
+    #bannerDimensions = [0, 0];
+
+    #date = null;
+    #trackArtDate = null;
+    #coverArtDate = null;
+    #dateAddedToWiki = null;
+
+    #hasTrackArt = true;
+    #isMajorRelease = false;
+    #isListedOnHomepage = true;
+
+    #aka = '';
+    #groups = [];
+    #artTags = [];
+    #commentary = '';
+
     #tracks = [];
 
-    static updateError = {
+    static propertyError = {
+        name: Thing.extendPropertyError('name'),
         directory: Thing.extendPropertyError('directory'),
         tracks: Thing.extendPropertyError('tracks')
     };
+    */
+
+    static propertyDescriptors = {
+        // Update & expose
+
+        name: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: 'Unnamed Album',
+                validate: isName
+            }
+        },
+
+        color: {
+            flags: {update: true, expose: true},
+            update: {validate: isColor}
+        },
+
+        directory: {
+            flags: {update: true, expose: true},
+            update: {validate: isDirectory}
+        },
+
+        urls: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateArrayItems(isURL)
+            }
+        },
+
+        date: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
+
+        coverArtDate: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
+
+        trackArtDate: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
+
+        dateAddedToWiki: {
+            flags: {update: true, expose: true},
+
+            update: {validate: isDate}
+        },
+
+        artistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        coverArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        trackCoverArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        wallpaperArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        bannerArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        groupsByRef: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateReferenceList('group')
+            }
+        },
+
+        artTagsByRef: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateReferenceList('tag')
+            }
+        },
 
+        tracksByRef: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateReferenceList('track')
+            }
+        },
+
+        wallpaperStyle: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        wallpaperFileExtension: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        bannerStyle: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        bannerFileExtension: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        bannerDimensions: {
+            flags: {update: true, expose: true},
+            update: {validate: isDimensions}
+        },
+
+        hasTrackArt: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: true,
+                validate: isBoolean
+            }
+        },
+
+        isMajorRelease: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: false,
+                validate: isBoolean
+            }
+        },
+
+        isListedOnHomepage: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: true,
+                validate: isBoolean
+            }
+        },
+
+        commentary: {
+            flags: {update: true, expose: true},
+            update: {validate: isCommentary}
+        },
+
+        // Expose only
+
+        tracks: {
+            flags: {expose: true},
+
+            expose: {
+                dependencies: ['trackReferences', 'wikiData'],
+                compute: ({trackReferences, wikiData}) => (
+                    trackReferences.map(ref => find.track(ref, {wikiData})))
+            }
+        },
+
+        // Update only
+
+        wikiData: {
+            flags: {update: true}
+        }
+    };
+
+    /*
     update(source) {
-        const err = this.constructor.updateError;
+        const err = this.constructor.propertyError;
+
+        withAggregate(aggregateThrows(Thing.UpdateError), ({ nest, filter, throws }) => {
+            if (source.name) {
+                nest(throws(err.name), ({ call }) => {
+                    if (call(validateName, source.name)) {
+                        this.#name = source.name;
+                    }
+                });
+            }
 
-        withAggregate(({ nest, filter, throws }) => {
+            if (source.color) {
+                nest(throws(err.color), ({ call }) => {
+                    if (call(validateColor, source.color)) {
+                        this.#color = source.color;
+                    }
+                });
+            }
 
             if (source.directory) {
                 nest(throws(err.directory), ({ call }) => {
@@ -37,10 +276,13 @@ export default class Album extends Thing {
         });
     }
 
+    get name() { return this.#name; }
     get directory() { return this.#directory; }
     get tracks() { return this.#tracks; }
+    */
 }
 
+/*
 const album = new Album();
 
 console.log('tracks (before):', album.tracks);
@@ -60,3 +302,4 @@ try {
 }
 
 console.log('tracks (after):', album.tracks);
+*/