« 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/group.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing/group.js')
-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]
+            }
+        }
+    };
+}