« get me outta code hell

group 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 15:13:56 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-01 15:13:56 -0400
commitf6cd5a19f3171e1a4117aa47559df22d8bbb1de9 (patch)
tree4030f6d64dd625455a55d1d75e2f499d13236746 /src/thing
parentbd5527c46b2538fd8a114f1f9bb13ecba6894d05 (diff)
group data
Diffstat (limited to 'src/thing')
-rw-r--r--src/thing/group.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/thing/group.js b/src/thing/group.js
new file mode 100644
index 00000000..3b92e957
--- /dev/null
+++ b/src/thing/group.js
@@ -0,0 +1,73 @@
+import CacheableObject from './cacheable-object.js';
+import Thing from './thing.js';
+
+import {
+    isColor,
+    isDirectory,
+    isName,
+    isString,
+    isURL,
+    validateArrayItems,
+    validateReferenceList,
+} from './validators.js';
+
+export class GroupCategory extends CacheableObject {
+    static propertyDescriptors = {
+        // Update & expose
+
+        name: {
+            flags: {update: true, expose: true},
+            update: {default: 'Unnamed Group Category', validate: isName}
+        },
+
+        color: {
+            flags: {update: true, expose: true},
+            update: {validate: isColor}
+        },
+
+        groupsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: validateReferenceList('group')}
+        },
+    };
+}
+
+export default class Group extends Thing {
+    static [Thing.referenceType] = 'group';
+
+    static propertyDescriptors = {
+        // Update & expose
+
+        name: {
+            flags: {update: true, expose: true},
+            update: {default: 'Unnamed Group', validate: isName}
+        },
+
+        directory: {
+            flags: {update: true, expose: true},
+            update: {validate: isDirectory},
+            expose: Thing.directoryExpose
+        },
+
+        description: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        urls: {
+            flags: {update: true, expose: true},
+            update: {validate: validateArrayItems(isURL)}
+        },
+
+        // Expose only
+
+        descriptionShort: {
+            flags: {expose: true},
+
+            expose: {
+                dependencies: ['description'],
+                compute: ({ description }) => description.split('<hr class="split">')[0]
+            }
+        }
+    };
+}