« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/group.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/group.js')
-rw-r--r--src/data/things/group.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/data/things/group.js b/src/data/things/group.js
new file mode 100644
index 0000000..26fe9a5
--- /dev/null
+++ b/src/data/things/group.js
@@ -0,0 +1,94 @@
+import Thing from './thing.js';
+
+import find from '../../util/find.js';
+
+export class Group extends Thing {
+  static [Thing.referenceType] = 'group';
+
+  static [Thing.getPropertyDescriptors] = ({
+    Album,
+  }) => ({
+    // Update & expose
+
+    name: Thing.common.name('Unnamed Group'),
+    directory: Thing.common.directory(),
+
+    description: Thing.common.simpleString(),
+
+    urls: Thing.common.urls(),
+
+    // Update only
+
+    albumData: Thing.common.wikiData(Album),
+    groupCategoryData: Thing.common.wikiData(GroupCategory),
+
+    // Expose only
+
+    descriptionShort: {
+      flags: {expose: true},
+
+      expose: {
+        dependencies: ['description'],
+        compute: ({description}) => description.split('<hr class="split">')[0],
+      },
+    },
+
+    albums: {
+      flags: {expose: true},
+
+      expose: {
+        dependencies: ['albumData'],
+        compute: ({albumData, [Group.instance]: group}) =>
+          albumData?.filter((album) => album.groups.includes(group)) ?? [],
+      },
+    },
+
+    color: {
+      flags: {expose: true},
+
+      expose: {
+        dependencies: ['groupCategoryData'],
+
+        compute: ({groupCategoryData, [Group.instance]: group}) =>
+          groupCategoryData.find((category) => category.groups.includes(group))
+            ?.color,
+      },
+    },
+
+    category: {
+      flags: {expose: true},
+
+      expose: {
+        dependencies: ['groupCategoryData'],
+        compute: ({groupCategoryData, [Group.instance]: group}) =>
+          groupCategoryData.find((category) => category.groups.includes(group)) ??
+          null,
+      },
+    },
+  });
+}
+
+export class GroupCategory extends Thing {
+  static [Thing.getPropertyDescriptors] = ({
+    Group,
+  }) => ({
+    // Update & expose
+
+    name: Thing.common.name('Unnamed Group Category'),
+    color: Thing.common.color(),
+
+    groupsByRef: Thing.common.referenceList(Group),
+
+    // Update only
+
+    groupData: Thing.common.wikiData(Group),
+
+    // Expose only
+
+    groups: Thing.common.dynamicThingsFromReferenceList(
+      'groupsByRef',
+      'groupData',
+      find.group
+    ),
+  });
+}