« get me outta code hell

homepage layout data - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-02-01 16:23:16 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-01 16:23:16 -0400
commite17bf53b3f17d8d8aa62869d4fc97883acc5c1fa (patch)
tree541fab09213494f34c3e859a018ef88ea5be1575 /src/thing
parente64d210cf0a798ae99bec89ca37cffcc1599411d (diff)
homepage layout data
Diffstat (limited to 'src/thing')
-rw-r--r--src/thing/homepage-layout.js99
-rw-r--r--src/thing/validators.js7
2 files changed, 106 insertions, 0 deletions
diff --git a/src/thing/homepage-layout.js b/src/thing/homepage-layout.js
new file mode 100644
index 00000000..47173917
--- /dev/null
+++ b/src/thing/homepage-layout.js
@@ -0,0 +1,99 @@
+import CacheableObject from './cacheable-object.js';
+
+import {
+    isColor,
+    isCountingNumber,
+    isName,
+    isString,
+    oneOf,
+    validateArrayItems,
+    validateInstanceOf,
+    validateReference,
+    validateReferenceList,
+} from './validators.js';
+
+export class HomepageLayoutRow extends CacheableObject {
+    static propertyDescriptors = {
+        // Update & expose
+
+        name: {
+            flags: {update: true, expose: true},
+            update: {validate: isName}
+        },
+
+        type: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate(value) {
+                    throw new Error(`'type' property validator must be overridden`);
+                }
+            }
+        },
+
+        color: {
+            flags: {update: true, expose: true},
+            update: {validate: isColor}
+        },
+    };
+}
+
+export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
+    static propertyDescriptors = {
+        ...HomepageLayoutRow.propertyDescriptors,
+
+        // Update & expose
+
+        type: {
+            flags: {update: true, expose: true},
+            update: {
+                validate(value) {
+                    if (value !== 'albums') {
+                        throw new TypeError(`Expected 'albums'`);
+                    }
+
+                    return true;
+                }
+            }
+        },
+
+        sourceGroupByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: validateReference('group')}
+        },
+
+        sourceAlbumsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: validateReferenceList('album')}
+        },
+
+        countAlbumsFromGroup: {
+            flags: {update: true, expose: true},
+            update: {validate: isCountingNumber}
+        },
+
+        actionLinks: {
+            flags: {update: true, expose: true},
+            update: {validate: validateArrayItems(isString)}
+        },
+    }
+}
+
+export default class HomepageLayout extends CacheableObject {
+    static propertyDescriptors = {
+        // Update & expose
+
+        sidebarContent: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        rows: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateArrayItems(validateInstanceOf(HomepageLayoutRow))
+            }
+        },
+    };
+}
diff --git a/src/thing/validators.js b/src/thing/validators.js
index a465e9d1..49463473 100644
--- a/src/thing/validators.js
+++ b/src/thing/validators.js
@@ -74,6 +74,13 @@ export function isInteger(number) {
     return true;
 }
 
+export function isCountingNumber(number) {
+    isInteger(number);
+    isPositive(number);
+
+    return true;
+}
+
 export function isString(value) {
     return isType(value, 'string');
 }