aboutsummaryrefslogtreecommitdiff
path: root/www/framework/event.nix
blob: 2daa4a2bf3374489a361feaae8fed44d52ece6b6 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
{ config, ... }:
{
  config.types.event =
    event@{ lib, events, ... }:
    let
      inherit (lib) mkOption types;
      cfg = event.config;
      sort-key = e: "${e.date.start} ${e.time.start}";
      prior =
        let
          candidates = lib.filter (
            e:
            e.venue != null && e.venue == cfg.venue && sort-key e < sort-key cfg && !e.address.once
          ) (lib.attrValues events);
          sorted = lib.sortOn sort-key candidates;
        in
        if sorted == [ ] then
          throw "Kein vorheriger Termin mit gleichem Veranstaltungsort gefunden."
        else
          lib.last sorted;
    in
    {
      imports = [ config.types.document ];
      options = {
        title = mkOption {
          description = ''
            Übeschrift für den Termin
          '';
          type = types.singleLineStr;
        };
        summary = mkOption {
          description = ''
            Kurzbeschreibung des Termins
          '';
          type = with types; nullOr singleLineStr;
          default = null;
        };
        aside = mkOption {
          description = ''
            Anmerkung zur Beschreibung
          '';
          type = with types; nullOr singleLineStr;
          default = null;
        };
        description = mkOption {
          description = ''
            Beschreibung des Termins als Freitext
          '';
          type = with types; nullOr str;
          default = null;
        };
        data = mkOption {
          description = ''
            Semistrukturierte Daten über den Termin
          '';
          type =
            with types;
            listOf (submodule {
              options = {
                name = mkOption {
                  type = singleLineStr;
                };
                value = mkOption {
                  type = singleLineStr;
                };
              };
            });
          example = [
            {
              name = "Eintritt";
              value = "frei &ndash; um Spenden wird gebeten";
            }
          ];
          default = [ ];
        };
        links = mkOption {
          description = ''
            Links zu weiteren Informationen
          '';
          type =
            with types;
            listOf (submodule {
              options = {
                text = mkOption {
                  type = singleLineStr;
                };
                url = mkOption {
                  type = strMatching "^(([^:/?#]+):)(//([^/?#]*))([^?#]*)(\\?([^#]*))?(#(.*))?";
                };
                external = mkOption {
                  type = bool;
                  default = true;
                };
              };
            });
          default = [ ];
          example = {
            text = "Details beim Veranstalter";
            url = "https://examle.org/event/123";
          };
        };
        hosts = mkOption {
          description = ''
            Veranstalter
          '';
          type =
            with types;
            listOf (submodule {
              options = {
                name = mkOption {
                  type = singleLineStr;
                };
                url = mkOption {
                  type = strMatching "^(([^:/?#]+):)(//([^/?#]*))([^?#]*)(\\?([^#]*))?(#(.*))?";
                };
              };
            });
          default = [ ];
          example = {
            name = "Stadtteilbeirat Heimfeld";
            url = "https://heimfeld.harburg";
          };
        };
        date.start = mkOption {
          description = ''
            Datum des Termins
          '';
          type = types.strMatching "[0-9]{4}-[0-9]{2}-[0-9]{2}";
          example = "2025-12-20";
        };
        date.end = mkOption {
          description = ''
            Enddatum des Termins
          '';
          type = with types; nullOr (strMatching "[0-9]{4}-[0-9]{2}-[0-9]{2}");
          example = "2025-12-21";
          default = null;
        };
        time.start = mkOption {
          description = ''
            Startzeit des Termins
          '';
          type = types.strMatching "[0-9]{2}:[0-9]{2}";
          example = "17:00";
        };
        time.end = mkOption {
          description = ''
            Endzeit des Termins
          '';
          type = with types; nullOr (strMatching "[0-9]{2}:[0-9]{2}");
          example = "19:00";
          default = null;
        };
        datetime-range-text = mkOption {
          description = ''
            Zeitraum des Termins in Textform
          '';
          type = types.str;
          example = "Samstag, 20.12.2025 von 15:00 bis 17:00 Uhr";
        };
        venue = mkOption {
          description = ''
            Kennzeichen des Veranstaltungsorts zum Wiederverwenden von Angaben in nachfolgenden Terminen.
          '';
          type = with types; nullOr singleLineStr;
          default = null;
        };
        address.name = mkOption {
          description = ''
            Eigenname des Veranstaltungsorts
          '';
          type = with types; nullOr str;
          example = "Treffpunkthaus";
          default = if cfg.venue == null then null else prior.address.name;
          defaultText = lib.literalMD "Adresse des vorherigen Termins mit gleichem Veranstaltungsort, falls vorhanden.";
        };
        address.text = mkOption {
          description = ''
            Ort in Textform
          '';
          type = types.lines;
          default =
            if cfg.venue == null then
              throw "Ohne Veranstaltungsort-Kennzeichen muss die Adresse vollständig angegeben werden."
            else
              prior.address.text;
          defaultText = lib.literalMD "Adresse des vorherigen Termins mit gleichem Veranstaltungsort.";
        };
        address.openstreetmap = mkOption {
          description = ''
            Ort auf OpenStreetMap
          '';
          type =
            with types;
            attrTag {
              way = mkOption {
                type = ints.positive;
              };
              node = mkOption {
                type = ints.positive;
              };
            };
          example = {
            node = 6549438363;
          };
          default =
            if cfg.venue == null then
              throw "Ohne Veranstaltungsort-Kennzeichen muss die Adresse vollständig angegeben werden."
            else
              prior.address.openstreetmap;
          defaultText = lib.literalMD "Adresse des vorherigen Termins mit gleichem Veranstaltungsort.";
        };
        address.once = mkOption {
          description = ''
            Wenn gesetzt, wird die Adresse nicht in nachfolgende Termine vererbt.
          '';
          type = types.bool;
          default = false;
        };
      };
    };
}