« get me outta code hell

group.js « thing « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing/group.js
blob: 3b92e957cf25cbc2df32e96b9449d015095a1bc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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]
            }
        }
    };
}