« get me outta code hell

additional-file.js « things « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/additional-file.js
blob: 2ddc688a0dccdee88f60346d6837de05ae99dbcd (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
import {input} from '#composite';
import Thing from '#thing';
import {isString, validateArrayItems} from '#validators';

import {contentString, simpleString, thing} from '#composite/wiki-properties';

import {exposeConstant, exposeUpdateValueOrContinue}
  from '#composite/control-flow';

export class AdditionalFile extends Thing {
  static [Thing.getPropertyDescriptors] = ({}) => ({
    // Update & expose

    thing: thing(),

    title: simpleString(),

    description: contentString(),

    filenames: [
      exposeUpdateValueOrContinue({
        validate: input.value(validateArrayItems(isString)),
      }),

      exposeConstant({
        value: input.value([]),
      }),
    ],
  });

  static [Thing.yamlDocumentSpec] = {
    fields: {
      'Title': {property: 'title'},
      'Description': {property: 'description'},
      'Files': {property: 'filenames'},
    },
  };

  get paths() {
    if (!this.thing) return null;
    if (!this.thing.getOwnAdditionalFilePath) return null;

    return (
      this.filenames.map(filename =>
        this.thing.getOwnAdditionalFilePath(this, filename)));
  }
}