Merge commit 'd711d5ef' into kvt/integratie
@@ -216,10 +216,11 @@ chat met Jonas Ortega en verzonnen kaarten. Besluit: ADR 0024.
216
216
217
217
Zelfde koppeling (app-token, scopes `asclepius ponos daedalus`), geen nieuwe inlog. Besluit: ADR 0024.
218
218
219
- **Ticket maken in Asclepius** (berichtmenu, «Create Asclepius ticket»): opent het nieuw-ticketformulier
220
van Asclepius in de browser met `new_title` (eerste regel, max. 150 tekens) en `new_description`
221
(het bericht als Markdown-citaat, afzender, tijd `15 jan 2026 13:39` en de Teams-link). Geen token
222
of API: de gebruiker kiest zelf de categorie en slaat op in Asclepius.
219
- **Ticket maken in Asclepius** (berichtmenu, «Create Asclepius ticket»): opent het formulier
220
«Nieuw ticket maken» in de app (zie «Asclepius-tegel»), vooraf ingevuld: titel = eerste regel (max.
221
150 tekens), beschrijving = het bericht als Markdown-citaat met afzender, tijd `15 jan 2026 13:39`
222
en de Teams-link. Vermeldingen in het bericht worden `@naam:domein` (adres via het Teams-profiel,
223
best effort), zodat Asclepius ze herkent en die collega's deelnemer worden.
223
224
- **Taak maken in Ponos** (berichtmenu, «Create Ponos task»): dialoog met groepkeuze (groepen waar
224
225
je taken mag maken, laatst gekozen groep onthouden als id in de lokale opslag), titel en
225
226
omschrijving vooraf ingevuld zoals hierboven. Maakt de taak via `ponos_api.php` met de app-token.
@@ -313,12 +314,19 @@ in Asclepius (fase 2).
313
314
die zetten het token in de tekst, zodat Asclepius de vermelding herkent.
314
315
- **Antwoorden** via `add_ticket_message`. Heropenen (op het web een vinkje) blijft in Asclepius;
315
316
bij een afgehandeld ticket staat dat onder het antwoordveld.
317
- **Nieuw ticket maken** (knop in de kop, en vanuit het berichtmenu): de velden van het
318
webformulier: Titel, Categorie (zonder de ICT-categorieën Indiensttreding/Uitdiensttreding),
319
Subcategorie (alleen als de categorie die heeft, optioneel), Beschrijving, de twee vinkjes
320
«Mijn werkzaamheden worden belemmerd» / «Ik kan niet verder werken tot dit opgelost is» (het
321
tweede alleen met het eerste; prioriteit 0–2 zoals `getPriorityFromFlags`), Extra gebruikers
322
(optioneel, adressen gescheiden door komma's) en «Screenshots of documenten» (hooguit 10, elk
323
hooguit 10 MB, als base64 in de JSON). Na indienen opent het nieuwe ticket in de tegel.
316
324
- Elke minuut `ticket_updates` (`updated_since`); bij een wijziging laden lijst en gesprek opnieuw.
317
325
- `--demo`: verzonnen tickets op `example.com`, met een ghost-bericht, een vermelding en een bijlage.
318
326
319
327
| | |
320
328
|---|---|
321
| Eigen bestanden | `crates/kvt-sleutels/src/tickets.rs` (API, vermeldingen, ongelezen).<br>`crates/app/src/kvt/tickets.rs` (tegel, gesprek, demo).<br>`crates/app-base/locales/kvt.yml` (`kvt.rail.asclepius`, `kvt.tickets.*`).<br>`crates/app/assets/symbols/confirmation_number.svg` (Material Symbols, Apache 2.0) |
329
| Eigen bestanden | `crates/kvt-sleutels/src/tickets.rs` (API, vermeldingen, ongelezen).<br>`crates/app/src/kvt/tickets.rs` (tegel, gesprek, demo).<br>`crates/app/src/kvt/ticket_form.rs` (nieuw-ticketformulier).<br>`crates/app/src/kvt/message.rs` (berichtmenu, vermelde personen).<br>`crates/kvt-sleutels/src/asclepius.rs` (`MessageSource` met `mentions`).<br>`crates/app-base/locales/kvt.yml` (`kvt.rail.asclepius`, `kvt.tickets.*`).<br>`crates/app/assets/symbols/confirmation_number.svg` (Material Symbols, Apache 2.0) |
322
330
| Upstream aangeraakt | `crates/app/src/views/rail.rs` (tegel in `with_rail_tiles`).<br>`crates/app/src/views/sidebar.rs` (variant `SidebarTab::Asclepius` in dezelfde armen als Ponos).<br>`crates/app/src/views/shell.rs` (`kvt_tab`: Ponos of Asclepius in het hoofdpaneel).<br>`crates/app-base/src/assets.rs` (symbool `confirmation_number` en `icons/ticket.svg`).<br>`crates/app/src/layout_guard.rs` (uitzondering voor de roze ghost-rand) |
323
331
324
332
Serverkant: `ict/asclepius` — app-tokens (`sat_…`, `asclepius_app_token.php`), gefilterde lijst,
@@ -216,10 +216,11 @@ chat met Jonas Ortega en verzonnen kaarten. Besluit: ADR 0024.216
216
217
Zelfde koppeling (app-token, scopes `asclepius ponos daedalus`), geen nieuwe inlog. Besluit: ADR 0024.217
Zelfde koppeling (app-token, scopes `asclepius ponos daedalus`), geen nieuwe inlog. Besluit: ADR 0024.218
218
219
- **Ticket maken in Asclepius** (berichtmenu, «Create Asclepius ticket»): opent het nieuw-ticketformulier219
- **Ticket maken in Asclepius** (berichtmenu, «Create Asclepius ticket»): opent het formulier220
van Asclepius in de browser met `new_title` (eerste regel, max. 150 tekens) en `new_description`220
«Nieuw ticket maken» in de app (zie «Asclepius-tegel»), vooraf ingevuld: titel = eerste regel (max.221
(het bericht als Markdown-citaat, afzender, tijd `15 jan 2026 13:39` en de Teams-link). Geen token221
150 tekens), beschrijving = het bericht als Markdown-citaat met afzender, tijd `15 jan 2026 13:39`222
of API: de gebruiker kiest zelf de categorie en slaat op in Asclepius.222
en de Teams-link. Vermeldingen in het bericht worden `@naam:domein` (adres via het Teams-profiel,223
best effort), zodat Asclepius ze herkent en die collega's deelnemer worden.223
- **Taak maken in Ponos** (berichtmenu, «Create Ponos task»): dialoog met groepkeuze (groepen waar224
- **Taak maken in Ponos** (berichtmenu, «Create Ponos task»): dialoog met groepkeuze (groepen waar224
je taken mag maken, laatst gekozen groep onthouden als id in de lokale opslag), titel en225
je taken mag maken, laatst gekozen groep onthouden als id in de lokale opslag), titel en225
omschrijving vooraf ingevuld zoals hierboven. Maakt de taak via `ponos_api.php` met de app-token.226
omschrijving vooraf ingevuld zoals hierboven. Maakt de taak via `ponos_api.php` met de app-token.@@ -313,12 +314,19 @@ in Asclepius (fase 2).313
die zetten het token in de tekst, zodat Asclepius de vermelding herkent.314
die zetten het token in de tekst, zodat Asclepius de vermelding herkent.314
- **Antwoorden** via `add_ticket_message`. Heropenen (op het web een vinkje) blijft in Asclepius;315
- **Antwoorden** via `add_ticket_message`. Heropenen (op het web een vinkje) blijft in Asclepius;315
bij een afgehandeld ticket staat dat onder het antwoordveld.316
bij een afgehandeld ticket staat dat onder het antwoordveld.317
- **Nieuw ticket maken** (knop in de kop, en vanuit het berichtmenu): de velden van het318
webformulier: Titel, Categorie (zonder de ICT-categorieën Indiensttreding/Uitdiensttreding),319
Subcategorie (alleen als de categorie die heeft, optioneel), Beschrijving, de twee vinkjes320
«Mijn werkzaamheden worden belemmerd» / «Ik kan niet verder werken tot dit opgelost is» (het321
tweede alleen met het eerste; prioriteit 0–2 zoals `getPriorityFromFlags`), Extra gebruikers322
(optioneel, adressen gescheiden door komma's) en «Screenshots of documenten» (hooguit 10, elk323
hooguit 10 MB, als base64 in de JSON). Na indienen opent het nieuwe ticket in de tegel.316
- Elke minuut `ticket_updates` (`updated_since`); bij een wijziging laden lijst en gesprek opnieuw.324
- Elke minuut `ticket_updates` (`updated_since`); bij een wijziging laden lijst en gesprek opnieuw.317
- `--demo`: verzonnen tickets op `example.com`, met een ghost-bericht, een vermelding en een bijlage.325
- `--demo`: verzonnen tickets op `example.com`, met een ghost-bericht, een vermelding en een bijlage.318
326
319
| | |327
| | |320
|---|---|328
|---|---|321
| Eigen bestanden | `crates/kvt-sleutels/src/tickets.rs` (API, vermeldingen, ongelezen).<br>`crates/app/src/kvt/tickets.rs` (tegel, gesprek, demo).<br>`crates/app-base/locales/kvt.yml` (`kvt.rail.asclepius`, `kvt.tickets.*`).<br>`crates/app/assets/symbols/confirmation_number.svg` (Material Symbols, Apache 2.0) |329
| Eigen bestanden | `crates/kvt-sleutels/src/tickets.rs` (API, vermeldingen, ongelezen).<br>`crates/app/src/kvt/tickets.rs` (tegel, gesprek, demo).<br>`crates/app/src/kvt/ticket_form.rs` (nieuw-ticketformulier).<br>`crates/app/src/kvt/message.rs` (berichtmenu, vermelde personen).<br>`crates/kvt-sleutels/src/asclepius.rs` (`MessageSource` met `mentions`).<br>`crates/app-base/locales/kvt.yml` (`kvt.rail.asclepius`, `kvt.tickets.*`).<br>`crates/app/assets/symbols/confirmation_number.svg` (Material Symbols, Apache 2.0) |322
| Upstream aangeraakt | `crates/app/src/views/rail.rs` (tegel in `with_rail_tiles`).<br>`crates/app/src/views/sidebar.rs` (variant `SidebarTab::Asclepius` in dezelfde armen als Ponos).<br>`crates/app/src/views/shell.rs` (`kvt_tab`: Ponos of Asclepius in het hoofdpaneel).<br>`crates/app-base/src/assets.rs` (symbool `confirmation_number` en `icons/ticket.svg`).<br>`crates/app/src/layout_guard.rs` (uitzondering voor de roze ghost-rand) |330
| Upstream aangeraakt | `crates/app/src/views/rail.rs` (tegel in `with_rail_tiles`).<br>`crates/app/src/views/sidebar.rs` (variant `SidebarTab::Asclepius` in dezelfde armen als Ponos).<br>`crates/app/src/views/shell.rs` (`kvt_tab`: Ponos of Asclepius in het hoofdpaneel).<br>`crates/app-base/src/assets.rs` (symbool `confirmation_number` en `icons/ticket.svg`).<br>`crates/app/src/layout_guard.rs` (uitzondering voor de roze ghost-rand) |323
331
324
Serverkant: `ict/asclepius` — app-tokens (`sat_…`, `asclepius_app_token.php`), gefilterde lijst,332
Serverkant: `ict/asclepius` — app-tokens (`sat_…`, `asclepius_app_token.php`), gefilterde lijst,@@ -398,6 +398,95 @@ kvt:
398
398
en: Attachments are not available in the demo
399
399
de: Anhänge sind in der Demo nicht verfügbar
400
400
nl: Bijlagen zijn niet beschikbaar in de demo
401
new:
402
en: "New ticket"
403
de: "Neues Ticket"
404
nl: "Nieuw ticket"
405
form:
406
heading:
407
en: "Create new ticket"
408
de: "Neues Ticket erstellen"
409
nl: "Nieuw ticket maken"
410
title:
411
en: "Title"
412
de: "Titel"
413
nl: "Titel"
414
title_placeholder:
415
en: "For example: New scanner needed"
416
de: "Zum Beispiel: Neuer Scanner benötigt"
417
nl: "Bijvoorbeeld: Nieuwe scanner nodig"
418
category:
419
en: "Category"
420
de: "Kategorie"
421
nl: "Categorie"
422
subcategory:
423
en: "Subcategory"
424
de: "Unterkategorie"
425
nl: "Subcategorie"
426
description:
427
en: "Description"
428
de: "Beschreibung"
429
nl: "Beschrijving"
430
description_placeholder:
431
en: "Describe the problem or request as clearly as possible."
432
de: "Beschreibe das Problem oder die Anfrage so genau wie möglich."
433
nl: "Beschrijf het probleem of de aanvraag zo duidelijk mogelijk."
434
blocked:
435
en: "My work is being impeded"
436
de: "Meine Arbeit wird behindert"
437
nl: "Mijn werkzaamheden worden belemmerd"
438
fully_blocked:
439
en: "I cannot continue working until this is resolved"
440
de: "Ich kann nicht weiterarbeiten, bis das gelöst ist"
441
nl: "Ik kan niet verder werken tot dit opgelost is"
442
participants:
443
en: "Additional users"
444
de: "Weitere Benutzer"
445
nl: "Extra gebruikers"
446
participants_placeholder:
447
en: "name1@kvt.nl, name2@kvt.nl"
448
de: "name1@kvt.nl, name2@kvt.nl"
449
nl: "naam1@kvt.nl, naam2@kvt.nl"
450
participants_hint:
451
en: "Add colleagues who should also see this ticket under My tickets."
452
de: "Füge Kollegen hinzu, die dieses Ticket auch unter Meine Tickets sehen sollen."
453
nl: "Voeg collega's toe die dit ticket ook onder Mijn tickets moeten zien."
454
attachments:
455
en: "Screenshots or documents"
456
de: "Screenshots oder Dokumente"
457
nl: "Screenshots of documenten"
458
add_files:
459
en: "Add files"
460
de: "Dateien hinzufügen"
461
nl: "Bestanden toevoegen"
462
submit:
463
en: "Submit ticket"
464
de: "Ticket einreichen"
465
nl: "Ticket indienen"
466
pick_category:
467
en: "Choose a category"
468
de: "Kategorie wählen"
469
nl: "Kies een categorie"
470
fill_in:
471
en: "Fill in a title and a description"
472
de: "Titel und Beschreibung ausfüllen"
473
nl: "Vul een titel en een beschrijving in"
474
bad_email:
475
en: "Not a valid e-mail address: %{email}"
476
de: "Keine gültige E-Mail-Adresse: %{email}"
477
nl: "Geen geldig e-mailadres: %{email}"
478
too_many_files:
479
en: "At most %{max} files"
480
de: "Höchstens %{max} Dateien"
481
nl: "Hooguit %{max} bestanden"
482
file_too_large:
483
en: "%{name} is larger than 10 MB"
484
de: "%{name} ist größer als 10 MB"
485
nl: "%{name} is groter dan 10 MB"
486
created:
487
en: "Ticket #%{id} created in Asclepius"
488
de: "Ticket #%{id} in Asclepius erstellt"
489
nl: "Ticket #%{id} aangemaakt in Asclepius"
401
490
status:
402
491
ingediend:
403
492
en: Submitted
@@ -398,6 +398,95 @@ kvt:398
en: Attachments are not available in the demo398
en: Attachments are not available in the demo399
de: Anhänge sind in der Demo nicht verfügbar399
de: Anhänge sind in der Demo nicht verfügbar400
nl: Bijlagen zijn niet beschikbaar in de demo400
nl: Bijlagen zijn niet beschikbaar in de demo401
new:402
en: "New ticket"403
de: "Neues Ticket"404
nl: "Nieuw ticket"405
form:406
heading:407
en: "Create new ticket"408
de: "Neues Ticket erstellen"409
nl: "Nieuw ticket maken"410
title:411
en: "Title"412
de: "Titel"413
nl: "Titel"414
title_placeholder:415
en: "For example: New scanner needed"416
de: "Zum Beispiel: Neuer Scanner benötigt"417
nl: "Bijvoorbeeld: Nieuwe scanner nodig"418
category:419
en: "Category"420
de: "Kategorie"421
nl: "Categorie"422
subcategory:423
en: "Subcategory"424
de: "Unterkategorie"425
nl: "Subcategorie"426
description:427
en: "Description"428
de: "Beschreibung"429
nl: "Beschrijving"430
description_placeholder:431
en: "Describe the problem or request as clearly as possible."432
de: "Beschreibe das Problem oder die Anfrage so genau wie möglich."433
nl: "Beschrijf het probleem of de aanvraag zo duidelijk mogelijk."434
blocked:435
en: "My work is being impeded"436
de: "Meine Arbeit wird behindert"437
nl: "Mijn werkzaamheden worden belemmerd"438
fully_blocked:439
en: "I cannot continue working until this is resolved"440
de: "Ich kann nicht weiterarbeiten, bis das gelöst ist"441
nl: "Ik kan niet verder werken tot dit opgelost is"442
participants:443
en: "Additional users"444
de: "Weitere Benutzer"445
nl: "Extra gebruikers"446
participants_placeholder:447
en: "name1@kvt.nl, name2@kvt.nl"448
de: "name1@kvt.nl, name2@kvt.nl"449
nl: "naam1@kvt.nl, naam2@kvt.nl"450
participants_hint:451
en: "Add colleagues who should also see this ticket under My tickets."452
de: "Füge Kollegen hinzu, die dieses Ticket auch unter Meine Tickets sehen sollen."453
nl: "Voeg collega's toe die dit ticket ook onder Mijn tickets moeten zien."454
attachments:455
en: "Screenshots or documents"456
de: "Screenshots oder Dokumente"457
nl: "Screenshots of documenten"458
add_files:459
en: "Add files"460
de: "Dateien hinzufügen"461
nl: "Bestanden toevoegen"462
submit:463
en: "Submit ticket"464
de: "Ticket einreichen"465
nl: "Ticket indienen"466
pick_category:467
en: "Choose a category"468
de: "Kategorie wählen"469
nl: "Kies een categorie"470
fill_in:471
en: "Fill in a title and a description"472
de: "Titel und Beschreibung ausfüllen"473
nl: "Vul een titel en een beschrijving in"474
bad_email:475
en: "Not a valid e-mail address: %{email}"476
de: "Keine gültige E-Mail-Adresse: %{email}"477
nl: "Geen geldig e-mailadres: %{email}"478
too_many_files:479
en: "At most %{max} files"480
de: "Höchstens %{max} Dateien"481
nl: "Hooguit %{max} bestanden"482
file_too_large:483
en: "%{name} is larger than 10 MB"484
de: "%{name} ist größer als 10 MB"485
nl: "%{name} is groter dan 10 MB"486
created:487
en: "Ticket #%{id} created in Asclepius"488
de: "Ticket #%{id} in Asclepius erstellt"489
nl: "Ticket #%{id} aangemaakt in Asclepius"401
status:490
status:402
ingediend:491
ingediend:403
en: Submitted492
en: Submitted@@ -1,4 +1,5 @@
1
//! Berichtmenu: «Ticket maken in Asclepius» en «Taak maken in Ponos».
1
//! Berichtmenu: «Ticket maken in Asclepius» en «Taak maken in Ponos» (beide een
2
//! dialoog in de app, vooraf ingevuld met het bericht).
2
3
//!
3
4
//! Upstream-haak: `views/message_actions.rs` (veld `kvt` in `MessageMenu`) en
4
5
//! `views/conversation.rs` (`message_menu`).
@@ -8,10 +9,10 @@ use std::rc::Rc;
8
9
use chrono::Local;
9
10
use gpui_kit::assets::IconName;
10
11
use gpui_kit::*;
11
use kvt_sleutels::asclepius::{MessageSource, new_ticket_url};
12
use kvt_sleutels::asclepius::MessageSource;
12
13
use kvt_sleutels::format::date_time_nl;
13
14
14
use super::{base_url, installed, open_external};
15
use super::installed;
15
16
use crate::app_state::AppHandle;
16
17
use crate::i18n::tr;
17
18
use crate::runtime;
@@ -52,7 +53,7 @@ pub fn menu_entries(conversation_id: Option<String>, message_id: &str, cx: &App)
52
53
entry(
53
54
"kvt.message.asclepius",
54
55
IconName::Ticket,
55
|source, _, cx| open_external(&new_ticket_url(&base_url(), &source), cx),
56
|source, window, cx| super::ticket_form::open_new(Some(source), window, cx),
56
57
),
57
58
entry(
58
59
"kvt.message.ponos",
@@ -82,7 +83,9 @@ fn with_source(
82
83
sender: record.sender_name.clone().unwrap_or_default(),
83
84
sent_at: date_time_nl(record.created_at.with_timezone(&Local).naive_local()),
84
85
link: None,
86
mentions: Vec::new(),
85
87
};
88
let mentioned = mentioned_users(&record.mentions_json);
86
89
let Some(engine) = state.engine.clone() else {
87
90
let link = state
88
91
.mode
@@ -92,11 +95,79 @@ fn with_source(
92
95
return;
93
96
};
94
97
let (conversation_id, message_id) = (conversation_id.to_owned(), message_id.to_owned());
95
let linking =
96
runtime::spawn(async move { engine.message_link(&conversation_id, &message_id).await });
98
let linking = runtime::spawn(async move {
99
let link = engine
100
.message_link(&conversation_id, &message_id)
101
.await
102
.ok();
103
// Vermeldingen: het adres via het profiel (best effort), voor `@naam:domein` in Asclepius.
104
let mut mentions = Vec::new();
105
for (name, user_id) in mentioned {
106
if let Ok(profile) = engine.person_profile(&user_id).await
107
&& let Some(email) = profile.email.filter(|email| email.contains('@'))
108
{
109
mentions.push((name, email));
110
}
111
}
112
(link, mentions)
113
});
97
114
cx.spawn(async move |cx| {
98
let link = linking.await.ok().and_then(Result::ok);
99
cx.update(|cx| then(MessageSource { link, ..source }, cx));
115
let (link, mentions) = linking.await.unwrap_or_default();
116
cx.update(|cx| {
117
then(
118
MessageSource {
119
link,
120
mentions,
121
..source
122
},
123
cx,
124
)
125
});
100
126
})
101
127
.detach();
102
128
}
129
130
/// Vermelde personen (naam, Teams-id) uit het bericht; groepen en dubbelen niet.
131
fn mentioned_users(mentions_json: &str) -> Vec<(String, String)> {
132
let infos: Vec<teams_core::MentionInfo> =
133
serde_json::from_str(mentions_json).unwrap_or_default();
134
let mut users: Vec<(String, String)> = Vec::new();
135
for info in infos.into_iter().filter(|info| !info.group) {
136
let Some(user_id) = info.user_id.filter(|id| !id.is_empty()) else {
137
continue;
138
};
139
let name = info.name.trim().to_owned();
140
if name.is_empty() || users.iter().any(|(_, known)| *known == user_id) {
141
continue;
142
}
143
users.push((name, user_id));
144
}
145
users.truncate(MENTIONS_MAX);
146
users
147
}
148
149
/// Zoveel profielen halen we hooguit op voor één bericht.
150
const MENTIONS_MAX: usize = 10;
151
152
#[cfg(test)]
153
mod tests {
154
use super::mentioned_users;
155
156
#[test]
157
fn mentioned_users_skips_groups_and_duplicates() {
158
let json = r#"[
159
{"user_id":"8:orgid:a","name":"Jonas Ortega","id":0},
160
{"user_id":"8:orgid:a","name":"Jonas","id":1},
161
{"user_id":null,"name":"Iedereen","id":2,"group":true},
162
{"user_id":"8:orgid:b","name":"Mara","id":3}
163
]"#;
164
assert_eq!(
165
mentioned_users(json),
166
[
167
("Jonas Ortega".to_owned(), "8:orgid:a".to_owned()),
168
("Mara".to_owned(), "8:orgid:b".to_owned())
169
]
170
);
171
assert!(mentioned_users("geen json").is_empty());
172
}
173
}
@@ -1,4 +1,5 @@1
//! Berichtmenu: «Ticket maken in Asclepius» en «Taak maken in Ponos».1
//! Berichtmenu: «Ticket maken in Asclepius» en «Taak maken in Ponos» (beide een2
//! dialoog in de app, vooraf ingevuld met het bericht).2
//!3
//!3
//! Upstream-haak: `views/message_actions.rs` (veld `kvt` in `MessageMenu`) en4
//! Upstream-haak: `views/message_actions.rs` (veld `kvt` in `MessageMenu`) en4
//! `views/conversation.rs` (`message_menu`).5
//! `views/conversation.rs` (`message_menu`).@@ -8,10 +9,10 @@ use std::rc::Rc;8
use chrono::Local;9
use chrono::Local;9
use gpui_kit::assets::IconName;10
use gpui_kit::assets::IconName;10
use gpui_kit::*;11
use gpui_kit::*;11
use kvt_sleutels::asclepius::{MessageSource, new_ticket_url};12
use kvt_sleutels::asclepius::MessageSource;12
use kvt_sleutels::format::date_time_nl;13
use kvt_sleutels::format::date_time_nl;13
14
14
use super::{base_url, installed, open_external};15
use super::installed;15
use crate::app_state::AppHandle;16
use crate::app_state::AppHandle;16
use crate::i18n::tr;17
use crate::i18n::tr;17
use crate::runtime;18
use crate::runtime;@@ -52,7 +53,7 @@ pub fn menu_entries(conversation_id: Option<String>, message_id: &str, cx: &App)52
entry(53
entry(53
"kvt.message.asclepius",54
"kvt.message.asclepius",54
IconName::Ticket,55
IconName::Ticket,55
|source, _, cx| open_external(&new_ticket_url(&base_url(), &source), cx),56
|source, window, cx| super::ticket_form::open_new(Some(source), window, cx),56
),57
),57
entry(58
entry(58
"kvt.message.ponos",59
"kvt.message.ponos",@@ -82,7 +83,9 @@ fn with_source(82
sender: record.sender_name.clone().unwrap_or_default(),83
sender: record.sender_name.clone().unwrap_or_default(),83
sent_at: date_time_nl(record.created_at.with_timezone(&Local).naive_local()),84
sent_at: date_time_nl(record.created_at.with_timezone(&Local).naive_local()),84
link: None,85
link: None,86
mentions: Vec::new(),85
};87
};88
let mentioned = mentioned_users(&record.mentions_json);86
let Some(engine) = state.engine.clone() else {89
let Some(engine) = state.engine.clone() else {87
let link = state90
let link = state88
.mode91
.mode@@ -92,11 +95,79 @@ fn with_source(92
return;95
return;93
};96
};94
let (conversation_id, message_id) = (conversation_id.to_owned(), message_id.to_owned());97
let (conversation_id, message_id) = (conversation_id.to_owned(), message_id.to_owned());95
let linking =98
let linking = runtime::spawn(async move {96
runtime::spawn(async move { engine.message_link(&conversation_id, &message_id).await });99
let link = engine100
.message_link(&conversation_id, &message_id)101
.await102
.ok();103
// Vermeldingen: het adres via het profiel (best effort), voor `@naam:domein` in Asclepius.104
let mut mentions = Vec::new();105
for (name, user_id) in mentioned {106
if let Ok(profile) = engine.person_profile(&user_id).await107
&& let Some(email) = profile.email.filter(|email| email.contains('@'))108
{109
mentions.push((name, email));110
}111
}112
(link, mentions)113
});97
cx.spawn(async move |cx| {114
cx.spawn(async move |cx| {98
let link = linking.await.ok().and_then(Result::ok);115
let (link, mentions) = linking.await.unwrap_or_default();99
cx.update(|cx| then(MessageSource { link, ..source }, cx));116
cx.update(|cx| {117
then(118
MessageSource {119
link,120
mentions,121
..source122
},123
cx,124
)125
});100
})126
})101
.detach();127
.detach();102
}128
}129
130
/// Vermelde personen (naam, Teams-id) uit het bericht; groepen en dubbelen niet.131
fn mentioned_users(mentions_json: &str) -> Vec<(String, String)> {132
let infos: Vec<teams_core::MentionInfo> =133
serde_json::from_str(mentions_json).unwrap_or_default();134
let mut users: Vec<(String, String)> = Vec::new();135
for info in infos.into_iter().filter(|info| !info.group) {136
let Some(user_id) = info.user_id.filter(|id| !id.is_empty()) else {137
continue;138
};139
let name = info.name.trim().to_owned();140
if name.is_empty() || users.iter().any(|(_, known)| *known == user_id) {141
continue;142
}143
users.push((name, user_id));144
}145
users.truncate(MENTIONS_MAX);146
users147
}148
149
/// Zoveel profielen halen we hooguit op voor één bericht.150
const MENTIONS_MAX: usize = 10;151
152
#[cfg(test)]153
mod tests {154
use super::mentioned_users;155
156
#[test]157
fn mentioned_users_skips_groups_and_duplicates() {158
let json = r#"[159
{"user_id":"8:orgid:a","name":"Jonas Ortega","id":0},160
{"user_id":"8:orgid:a","name":"Jonas","id":1},161
{"user_id":null,"name":"Iedereen","id":2,"group":true},162
{"user_id":"8:orgid:b","name":"Mara","id":3}163
]"#;164
assert_eq!(165
mentioned_users(json),166
[167
("Jonas Ortega".to_owned(), "8:orgid:a".to_owned()),168
("Mara".to_owned(), "8:orgid:b".to_owned())169
]170
);171
assert!(mentioned_users("geen json").is_empty());172
}173
}@@ -27,6 +27,7 @@ mod modal;
27
27
mod picker;
28
28
mod session;
29
29
mod tasks;
30
mod ticket_form;
30
31
mod tickets;
31
32
pub mod window_controls;
32
33
@@ -95,6 +96,8 @@ pub(crate) struct Kvt {
95
96
board: Option<Entity<board::PonosBoard>>,
96
97
/// Asclepius-tickets in het hoofdpaneel (ook voor de badge op de tegel).
97
98
tickets: Option<Entity<tickets::TicketsPage>>,
99
/// «Nieuw ticket maken» (ook vanuit een bericht).
100
ticket_form: Option<Entity<ticket_form::TicketForm>>,
98
101
/// Daedalus-planning in de agenda (instelling).
99
102
planning: bool,
100
103
/// Token waarmee de agendabron nu staat (zie `calendar::sync`).
@@ -129,6 +132,7 @@ pub fn install(demo: bool, cx: &mut App) {
129
132
ponos_dialog: None,
130
133
board: None,
131
134
tickets: None,
135
ticket_form: None,
132
136
planning: true,
133
137
calendar_source: None,
134
138
});
@@ -531,7 +535,10 @@ pub fn with_rail_tiles<T>(mut items: Vec<T>, tile: impl Fn(RailTile, String) ->
531
535
/// Telt mee voor de modale lagen van de shell.
532
536
pub fn dialog_open(cx: &App) -> bool {
533
537
read(cx, |kvt| {
534
kvt.modal.is_some() || kvt.picker.is_some() || kvt.ponos_dialog.is_some()
538
kvt.modal.is_some()
539
|| kvt.picker.is_some()
540
|| kvt.ponos_dialog.is_some()
541
|| kvt.ticket_form.is_some()
535
542
})
536
543
.unwrap_or(false)
537
544
}
@@ -548,6 +555,9 @@ pub fn overlay(cx: &App) -> Vec<AnyElement> {
548
555
if let Some(dialog) = read(cx, |kvt| kvt.ponos_dialog.clone()).flatten() {
549
556
layers.push(dialog.into_any_element());
550
557
}
558
if let Some(form) = read(cx, |kvt| kvt.ticket_form.clone()).flatten() {
559
layers.push(form.into_any_element());
560
}
551
561
layers
552
562
}
553
563
@@ -27,6 +27,7 @@ mod modal;27
mod picker;27
mod picker;28
mod session;28
mod session;29
mod tasks;29
mod tasks;30
mod ticket_form;30
mod tickets;31
mod tickets;31
pub mod window_controls;32
pub mod window_controls;32
33
@@ -95,6 +96,8 @@ pub(crate) struct Kvt {95
board: Option<Entity<board::PonosBoard>>,96
board: Option<Entity<board::PonosBoard>>,96
/// Asclepius-tickets in het hoofdpaneel (ook voor de badge op de tegel).97
/// Asclepius-tickets in het hoofdpaneel (ook voor de badge op de tegel).97
tickets: Option<Entity<tickets::TicketsPage>>,98
tickets: Option<Entity<tickets::TicketsPage>>,99
/// «Nieuw ticket maken» (ook vanuit een bericht).100
ticket_form: Option<Entity<ticket_form::TicketForm>>,98
/// Daedalus-planning in de agenda (instelling).101
/// Daedalus-planning in de agenda (instelling).99
planning: bool,102
planning: bool,100
/// Token waarmee de agendabron nu staat (zie `calendar::sync`).103
/// Token waarmee de agendabron nu staat (zie `calendar::sync`).@@ -129,6 +132,7 @@ pub fn install(demo: bool, cx: &mut App) {129
ponos_dialog: None,132
ponos_dialog: None,130
board: None,133
board: None,131
tickets: None,134
tickets: None,135
ticket_form: None,132
planning: true,136
planning: true,133
calendar_source: None,137
calendar_source: None,134
});138
});@@ -531,7 +535,10 @@ pub fn with_rail_tiles<T>(mut items: Vec<T>, tile: impl Fn(RailTile, String) ->531
/// Telt mee voor de modale lagen van de shell.535
/// Telt mee voor de modale lagen van de shell.532
pub fn dialog_open(cx: &App) -> bool {536
pub fn dialog_open(cx: &App) -> bool {533
read(cx, |kvt| {537
read(cx, |kvt| {534
kvt.modal.is_some() || kvt.picker.is_some() || kvt.ponos_dialog.is_some()538
kvt.modal.is_some()539
|| kvt.picker.is_some()540
|| kvt.ponos_dialog.is_some()541
|| kvt.ticket_form.is_some()535
})542
})536
.unwrap_or(false)543
.unwrap_or(false)537
}544
}@@ -548,6 +555,9 @@ pub fn overlay(cx: &App) -> Vec<AnyElement> {548
if let Some(dialog) = read(cx, |kvt| kvt.ponos_dialog.clone()).flatten() {555
if let Some(dialog) = read(cx, |kvt| kvt.ponos_dialog.clone()).flatten() {549
layers.push(dialog.into_any_element());556
layers.push(dialog.into_any_element());550
}557
}558
if let Some(form) = read(cx, |kvt| kvt.ticket_form.clone()).flatten() {559
layers.push(form.into_any_element());560
}551
layers561
layers552
}562
}553
563
@@ -0,0 +1,680 @@
1
//! Asclepius: «Nieuw ticket maken» in de app, met de velden van het webformulier.
2
//! Ook voor «Ticket maken in Asclepius» in het berichtmenu, dan vooraf ingevuld
3
//! met het bericht; vermeldingen worden `@naam:domein` zoals Asclepius ze kent.
4
5
use std::path::PathBuf;
6
7
use gpui_kit::component::checkbox::Checkbox;
8
use gpui_kit::component::input::{Input, InputState, Textarea, TextareaState};
9
use gpui_kit::component::{Disableable as _, h_flex, v_flex};
10
use gpui_kit::prelude::FluentBuilder as _;
11
use gpui_kit::*;
12
use kvt_sleutels::ClientError;
13
use kvt_sleutels::asclepius::MessageSource;
14
use kvt_sleutels::tickets::{
15
ATTACHMENT_MAX_BYTES, ATTACHMENTS_MAX, DESCRIPTION_MAX, Lookups, NewAttachment, NewTicket,
16
TITLE_MAX, mentions_to_asclepius, mime_for, parse_participants, priority_from_flags,
17
};
18
19
use super::modal::{primary_button, secondary_button};
20
use super::tasks::{chip, field, label, muted, not_linked};
21
use super::tickets::ticket_error;
22
use super::{Link, forget_token, installed, is_demo, link, notice, token_and_client, update};
23
use crate::i18n::{tr, tr_args};
24
use crate::runtime;
25
use crate::theme::{self, ElevatedSurface as _};
26
use crate::views::widgets::symbol;
27
28
pub const KVT_TICKET_FORM_TAG: &str = "kvt-asclepius-form";
29
const BACKDROP_OPACITY: f32 = 0.55;
30
const PANEL_WIDTH: f32 = 560.;
31
const PANEL_MARGIN: f32 = 32.;
32
const PANEL_RADIUS: f32 = 10.;
33
const PANEL_PADDING: f32 = 16.;
34
const SECTION_GAP: f32 = 10.;
35
const CLOSE_SIZE: f32 = 28.;
36
37
#[derive(Clone)]
38
enum LookupState {
39
Loading,
40
Loaded(Lookups),
41
Failed(ClientError),
42
}
43
44
struct PickedFile {
45
name: String,
46
size: usize,
47
attachment: NewAttachment,
48
}
49
50
pub struct TicketForm {
51
source: Option<MessageSource>,
52
lookups: LookupState,
53
category: Option<String>,
54
subcategory: Option<String>,
55
title: Entity<InputState>,
56
description: Entity<TextareaState>,
57
participants: Entity<InputState>,
58
blocked: bool,
59
fully_blocked: bool,
60
files: Vec<PickedFile>,
61
saving: bool,
62
error: Option<String>,
63
}
64
65
/// Opent het formulier; `source` is het bericht bij «Ticket maken in Asclepius».
66
pub(super) fn open_new(source: Option<MessageSource>, window: &mut Window, cx: &mut App) {
67
if !installed(cx) {
68
return;
69
}
70
let form = cx.new(|cx| TicketForm::new(source, window, cx));
71
update(cx, |kvt| kvt.ticket_form = Some(form.clone()));
72
if is_demo(cx) {
73
form.update(cx, |form, cx| form.set_lookups(Ok(demo_lookups()), cx));
74
return;
75
}
76
let Some((token, client)) = token_and_client(cx) else {
77
return;
78
};
79
let loading = runtime::spawn(async move { client.asclepius_lookups(&token).await });
80
let weak = form.downgrade();
81
cx.spawn(async move |cx| {
82
let result = loading.await.unwrap_or(Err(ClientError::Unavailable));
83
cx.update(|cx| {
84
if result == Err(ClientError::Unauthorized) {
85
forget_token(cx);
86
}
87
weak.update(cx, |form, cx| form.set_lookups(result, cx))
88
.ok();
89
});
90
})
91
.detach();
92
}
93
94
fn tr_with(key: &str, name: &str, value: String) -> String {
95
tr_args(
96
key,
97
&std::collections::HashMap::from([(name.to_owned(), value)]),
98
)
99
}
100
101
fn close(cx: &mut App) {
102
update(cx, |kvt| kvt.ticket_form = None);
103
}
104
105
/// Knop «Nieuw ticket» in de kop van de tegel.
106
pub(super) fn new_ticket_button<T: 'static>(cx: &mut Context<T>) -> Option<Stateful<Div>> {
107
matches!(link(cx), Link::Linked(_)).then(|| {
108
primary_button("kvt-tickets-new", tr("kvt.tickets.new"))
109
.on_click(|_, window, cx| open_new(None, window, cx))
110
})
111
}
112
113
/// Beschrijving uit het bericht, met de vermeldingen als Asclepius-token.
114
fn prefilled_description(source: &MessageSource) -> String {
115
mentions_to_asclepius(&source.description(DESCRIPTION_MAX), &source.mentions)
116
}
117
118
impl TicketForm {
119
fn new(source: Option<MessageSource>, window: &mut Window, cx: &mut Context<Self>) -> Self {
120
let title_text = source
121
.as_ref()
122
.map(|source| source.title(TITLE_MAX))
123
.unwrap_or_default();
124
let description_text = source
125
.as_ref()
126
.map(prefilled_description)
127
.unwrap_or_default();
128
let title = cx.new(|cx| {
129
InputState::new(window, cx)
130
.placeholder(tr("kvt.tickets.form.title_placeholder"))
131
.default_value(title_text)
132
});
133
let description = cx.new(|cx| {
134
TextareaState::new(window, cx)
135
.auto_grow(4, 10)
136
.placeholder(tr("kvt.tickets.form.description_placeholder"))
137
.default_value(description_text)
138
});
139
let participants = cx.new(|cx| {
140
InputState::new(window, cx).placeholder(tr("kvt.tickets.form.participants_placeholder"))
141
});
142
title.update(cx, |input, cx| input.focus(window, cx));
143
TicketForm {
144
source,
145
lookups: LookupState::Loading,
146
category: None,
147
subcategory: None,
148
title,
149
description,
150
participants,
151
blocked: false,
152
fully_blocked: false,
153
files: Vec::new(),
154
saving: false,
155
error: None,
156
}
157
}
158
159
fn set_lookups(&mut self, result: Result<Lookups, ClientError>, cx: &mut Context<Self>) {
160
self.lookups = match result {
161
Ok(lookups) => LookupState::Loaded(lookups),
162
Err(error) => LookupState::Failed(error),
163
};
164
cx.notify();
165
}
166
167
fn pick_files(&mut self, cx: &mut Context<Self>) {
168
let receiver = cx.prompt_for_paths(PathPromptOptions {
169
files: true,
170
directories: false,
171
multiple: true,
172
prompt: None,
173
});
174
cx.spawn(async move |this, cx| {
175
let Ok(Ok(Some(paths))) = receiver.await else {
176
return;
177
};
178
let reading = runtime::spawn(async move { read_files(paths) });
179
let read = reading.await.unwrap_or_default();
180
this.update(cx, |this, cx| {
181
for file in read {
182
match file {
183
Ok(file) if this.files.len() < ATTACHMENTS_MAX => this.files.push(file),
184
Ok(_) => {
185
this.error = Some(tr_with(
186
"kvt.tickets.form.too_many_files",
187
"max",
188
ATTACHMENTS_MAX.to_string(),
189
))
190
}
191
Err(name) => {
192
this.error =
193
Some(tr_with("kvt.tickets.form.file_too_large", "name", name))
194
}
195
}
196
}
197
cx.notify();
198
})
199
.ok();
200
})
201
.detach();
202
}
203
204
fn save(&mut self, cx: &mut Context<Self>) {
205
if self.saving {
206
return;
207
}
208
let title = self.title.read(cx).value().trim().to_owned();
209
let description = self.description.read(cx).value().trim().to_owned();
210
let participants_text = self.participants.read(cx).value().to_string();
211
let Some(category) = self.category.clone() else {
212
self.error = Some(tr("kvt.tickets.form.pick_category"));
213
cx.notify();
214
return;
215
};
216
if title.is_empty() || description.is_empty() {
217
self.error = Some(tr("kvt.tickets.form.fill_in"));
218
cx.notify();
219
return;
220
}
221
let participant_emails = match parse_participants(&participants_text) {
222
Ok(emails) => emails,
223
Err(bad) => {
224
self.error = Some(tr_with("kvt.tickets.form.bad_email", "email", bad));
225
cx.notify();
226
return;
227
}
228
};
229
let ticket = NewTicket {
230
title,
231
category,
232
subcategory: self.subcategory.clone(),
233
description,
234
priority: priority_from_flags(self.blocked, self.fully_blocked),
235
participant_emails,
236
attachments: self
237
.files
238
.iter()
239
.map(|file| file.attachment.clone())
240
.collect(),
241
};
242
if is_demo(cx) {
243
close(cx);
244
notice(
245
tr_with("kvt.tickets.form.created", "id", "4103".to_owned()),
246
cx,
247
);
248
return;
249
}
250
let Some((token, client)) = token_and_client(cx) else {
251
return;
252
};
253
self.saving = true;
254
self.error = None;
255
cx.notify();
256
let creating =
257
runtime::spawn(async move { client.asclepius_create(&token, &ticket).await });
258
cx.spawn(async move |this, cx| {
259
let result = creating.await.unwrap_or(Err(ClientError::Unavailable));
260
cx.update(|cx| match result {
261
Ok(id) => {
262
close(cx);
263
notice(
264
tr_with("kvt.tickets.form.created", "id", id.to_string()),
265
cx,
266
);
267
super::tickets::created(id, cx);
268
}
269
Err(error) => {
270
if error == ClientError::Unauthorized {
271
forget_token(cx);
272
}
273
this.update(cx, |this, cx| {
274
this.saving = false;
275
this.error = Some(ticket_error(&error));
276
cx.notify();
277
})
278
.ok();
279
}
280
});
281
})
282
.detach();
283
}
284
285
fn categories(&self, cx: &mut Context<Self>) -> AnyElement {
286
let lookups = match &self.lookups {
287
LookupState::Loading => return muted(tr("kvt.card.loading")).into_any_element(),
288
LookupState::Failed(error) => return muted(ticket_error(error)).into_any_element(),
289
LookupState::Loaded(lookups) => lookups,
290
};
291
let categories = h_flex().w_full().flex_wrap().gap(px(6.)).children(
292
lookups
293
.form_categories()
294
.into_iter()
295
.enumerate()
296
.map(|(index, category)| {
297
let selected = self.category.as_deref() == Some(category.as_str());
298
chip(
299
format!("kvt-ticket-category-{index}").into(),
300
category.clone(),
301
selected,
302
)
303
.on_click(cx.listener(move |this, _, _, cx| {
304
if this.category.as_deref() != Some(category.as_str()) {
305
this.category = Some(category.clone());
306
this.subcategory = None;
307
}
308
this.error = None;
309
cx.notify();
310
}))
311
}),
312
);
313
let subcategories = self
314
.category
315
.as_deref()
316
.map(|category| lookups.subcategories_of(category).to_vec())
317
.unwrap_or_default();
318
v_flex()
319
.w_full()
320
.gap(px(SECTION_GAP))
321
.child(categories)
322
.when(!subcategories.is_empty(), |column| {
323
column
324
.child(label(tr("kvt.tickets.form.subcategory")))
325
.child(
326
h_flex().w_full().flex_wrap().gap(px(6.)).children(
327
subcategories
328
.into_iter()
329
.enumerate()
330
.map(|(index, subcategory)| {
331
let selected =
332
self.subcategory.as_deref() == Some(subcategory.as_str());
333
chip(
334
format!("kvt-ticket-subcategory-{index}").into(),
335
subcategory.clone(),
336
selected,
337
)
338
.on_click(cx.listener(
339
move |this, _, _, cx| {
340
// Nogmaals klikken haalt de keuze weg (subcategorie is optioneel).
341
this.subcategory =
342
(!selected).then(|| subcategory.clone());
343
cx.notify();
344
},
345
))
346
}),
347
),
348
)
349
})
350
.into_any_element()
351
}
352
353
fn files(&self, cx: &mut Context<Self>) -> Div {
354
h_flex()
355
.w_full()
356
.flex_wrap()
357
.gap(px(6.))
358
.items_center()
359
.children(self.files.iter().enumerate().map(|(index, file)| {
360
h_flex()
361
.id(ElementId::Name(format!("kvt-ticket-file-{index}").into()))
362
.h(px(28.))
363
.pl(px(10.))
364
.pr(px(4.))
365
.gap(px(6.))
366
.items_center()
367
.rounded(px(6.))
368
.bg(theme::popup_hover())
369
.text_size(px(12.))
370
.child(symbol("attach_file", 14., theme::text_muted()))
371
.child(format!("{} ({})", file.name, size_label(file.size)))
372
.child(
373
div()
374
.id(ElementId::Name(
375
format!("kvt-ticket-file-remove-{index}").into(),
376
))
377
.size(px(20.))
378
.flex()
379
.items_center()
380
.justify_center()
381
.rounded_full()
382
.cursor_pointer()
383
.hover(|button| button.bg(theme::row_hover()))
384
.on_click(cx.listener(move |this, _, _, cx| {
385
if index < this.files.len() {
386
this.files.remove(index);
387
}
388
cx.notify();
389
}))
390
.child(symbol("close", 12., theme::text_muted())),
391
)
392
}))
393
.when(self.files.len() < ATTACHMENTS_MAX, |row| {
394
row.child(
395
secondary_button(
396
"kvt-ticket-add-file",
397
"attach_file",
398
tr("kvt.tickets.form.add_files"),
399
)
400
.on_click(cx.listener(|this, _, _, cx| this.pick_files(cx))),
401
)
402
})
403
}
404
}
405
406
fn read_files(paths: Vec<PathBuf>) -> Vec<Result<PickedFile, String>> {
407
paths
408
.into_iter()
409
.filter_map(|path| {
410
let name = path.file_name()?.to_string_lossy().into_owned();
411
let size = std::fs::metadata(&path).ok()?.len() as usize;
412
if size > ATTACHMENT_MAX_BYTES {
413
return Some(Err(name));
414
}
415
let data = std::fs::read(&path).ok()?;
416
Some(Ok(PickedFile {
417
size: data.len(),
418
attachment: NewAttachment {
419
mime: mime_for(&name).to_owned(),
420
filename: name.clone(),
421
data,
422
},
423
name,
424
}))
425
})
426
.collect()
427
}
428
429
fn size_label(bytes: usize) -> String {
430
if bytes >= 1024 * 1024 {
431
format!("{:.1} MB", bytes as f64 / (1024. * 1024.)).replace('.', ",")
432
} else {
433
format!("{} kB", bytes.div_ceil(1024).max(1))
434
}
435
}
436
437
impl Render for TicketForm {
438
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
439
let linked = matches!(link(cx), Link::Linked(_));
440
let ready = linked && matches!(self.lookups, LookupState::Loaded(_));
441
let detail = self
442
.source
443
.as_ref()
444
.filter(|source| !source.sender.is_empty())
445
.map(|source| format!("{} · {}", source.sender, source.sent_at))
446
.unwrap_or_default();
447
let blocked = self.blocked;
448
let body = if !linked {
449
v_flex().w_full().child(not_linked())
450
} else {
451
v_flex()
452
.w_full()
453
.gap(px(SECTION_GAP))
454
.child(label(tr("kvt.tickets.form.title")))
455
.child(
456
field().child(
457
div()
458
.flex_1()
459
.child(Input::new(&self.title).appearance(false).bordered(false)),
460
),
461
)
462
.child(label(tr("kvt.tickets.form.category")))
463
.child(self.categories(cx))
464
.child(label(tr("kvt.tickets.form.description")))
465
.child(Textarea::new(&self.description))
466
.child(
467
Checkbox::new("kvt-ticket-blocked")
468
.label(tr("kvt.tickets.form.blocked"))
469
.checked(self.blocked)
470
.on_click(cx.listener(|this, checked: &bool, _, cx| {
471
this.blocked = *checked;
472
if !*checked {
473
this.fully_blocked = false;
474
}
475
cx.notify();
476
})),
477
)
478
.child(
479
Checkbox::new("kvt-ticket-fully-blocked")
480
.label(tr("kvt.tickets.form.fully_blocked"))
481
.checked(self.fully_blocked)
482
.disabled(!blocked)
483
.on_click(cx.listener(|this, checked: &bool, _, cx| {
484
this.fully_blocked = *checked && this.blocked;
485
cx.notify();
486
})),
487
)
488
.child(label(tr("kvt.tickets.form.participants")))
489
.child(
490
field().child(
491
div().flex_1().child(
492
Input::new(&self.participants)
493
.appearance(false)
494
.bordered(false),
495
),
496
),
497
)
498
.child(
499
div()
500
.text_size(px(12.))
501
.text_color(theme::text_muted())
502
.child(tr("kvt.tickets.form.participants_hint")),
503
)
504
.child(label(tr("kvt.tickets.form.attachments")))
505
.child(self.files(cx))
506
};
507
div()
508
.id("kvt-ticket-form-layer")
509
.absolute()
510
.top_0()
511
.left_0()
512
.size_full()
513
.flex()
514
.items_center()
515
.justify_center()
516
.child(
517
div()
518
.id("kvt-ticket-form-backdrop")
519
.absolute()
520
.top_0()
521
.left_0()
522
.size_full()
523
.bg(black().opacity(BACKDROP_OPACITY))
524
.occlude()
525
.on_click(|_, _, cx| close(cx)),
526
)
527
.child(
528
v_flex()
529
.id("kvt-ticket-form-panel")
530
.debug_selector(|| KVT_TICKET_FORM_TAG.into())
531
.w(px(PANEL_WIDTH))
532
.max_w(relative(1.))
533
.max_h(relative(0.92))
534
.m(px(PANEL_MARGIN))
535
.p(px(PANEL_PADDING))
536
.gap(px(SECTION_GAP))
537
.rounded(px(PANEL_RADIUS))
538
.dialog_surface()
539
.text_color(theme::text())
540
.overflow_y_scroll()
541
.occlude()
542
.on_key_down(cx.listener(|_, event: &KeyDownEvent, _, cx| {
543
if event.keystroke.key == "escape" {
544
close(cx);
545
}
546
}))
547
.child(
548
h_flex()
549
.w_full()
550
.items_center()
551
.gap(px(SECTION_GAP))
552
.child(
553
v_flex()
554
.flex_1()
555
.min_w_0()
556
.child(
557
div()
558
.text_size(px(15.))
559
.font_weight(FontWeight::SEMIBOLD)
560
.child(tr("kvt.tickets.form.heading")),
561
)
562
.when(!detail.is_empty(), |column| {
563
column.child(
564
div()
565
.truncate()
566
.text_size(px(12.))
567
.text_color(theme::text_muted())
568
.child(detail),
569
)
570
}),
571
)
572
.child(
573
div()
574
.id("kvt-ticket-form-close")
575
.size(px(CLOSE_SIZE))
576
.flex_none()
577
.flex()
578
.items_center()
579
.justify_center()
580
.rounded_full()
581
.cursor_pointer()
582
.hover(|button| button.bg(theme::popup_hover()))
583
.on_click(|_, _, cx| close(cx))
584
.child(symbol("close", 16., theme::text_muted())),
585
),
586
)
587
.child(body)
588
.children(self.error.clone().map(|error| {
589
div()
590
.text_size(px(13.))
591
.text_color(theme::red_soft())
592
.child(error)
593
}))
594
.child(
595
h_flex()
596
.w_full()
597
.gap(px(8.))
598
.justify_end()
599
.child(
600
secondary_button(
601
"kvt-ticket-form-cancel",
602
"close",
603
tr("common.cancel"),
604
)
605
.on_click(|_, _, cx| close(cx)),
606
)
607
.when(ready, |row| {
608
row.child(
609
primary_button(
610
"kvt-ticket-form-submit",
611
tr(if self.saving {
612
"kvt.tickets.sending"
613
} else {
614
"kvt.tickets.form.submit"
615
}),
616
)
617
.on_click(cx.listener(|this, _, _, cx| this.save(cx))),
618
)
619
}),
620
),
621
)
622
}
623
}
624
625
pub(super) fn demo_lookups() -> Lookups {
626
let mut lookups = Lookups {
627
categories: [
628
"Hardware",
629
"Hardware bestellen",
630
"Software",
631
"Rechten en toegang",
632
"Indiensttreding",
633
]
634
.map(str::to_owned)
635
.to_vec(),
636
..Lookups::default()
637
};
638
lookups.subcategories.insert(
639
"Hardware".to_owned(),
640
["Laptop", "Monitor", "Printer"].map(str::to_owned).to_vec(),
641
);
642
lookups
643
}
644
645
#[cfg(test)]
646
mod tests {
647
use super::{demo_lookups, prefilled_description, size_label};
648
use kvt_sleutels::asclepius::MessageSource;
649
650
#[test]
651
fn message_mentions_become_asclepius_tokens() {
652
let source = MessageSource {
653
text: "@Jonas Ortega kun jij hiernaar kijken?".to_owned(),
654
sender: "Dana Demo".to_owned(),
655
sent_at: "15 jan 2026 13:39".to_owned(),
656
link: None,
657
mentions: vec![(
658
"Jonas Ortega".to_owned(),
659
"jonas.ortega@example.com".to_owned(),
660
)],
661
};
662
let description = prefilled_description(&source);
663
assert!(description.starts_with("> @jonas.ortega:examplecom kun jij"));
664
}
665
666
#[test]
667
fn ict_only_categories_are_not_offered() {
668
assert!(
669
!demo_lookups()
670
.form_categories()
671
.contains(&"Indiensttreding".to_owned())
672
);
673
}
674
675
#[test]
676
fn sizes_are_short_and_dutch() {
677
assert_eq!(size_label(500), "1 kB");
678
assert_eq!(size_label(3 * 1024 * 1024 + 512 * 1024), "3,5 MB");
679
}
680
}
@@ -0,0 +1,680 @@1
//! Asclepius: «Nieuw ticket maken» in de app, met de velden van het webformulier.2
//! Ook voor «Ticket maken in Asclepius» in het berichtmenu, dan vooraf ingevuld3
//! met het bericht; vermeldingen worden `@naam:domein` zoals Asclepius ze kent.4
5
use std::path::PathBuf;6
7
use gpui_kit::component::checkbox::Checkbox;8
use gpui_kit::component::input::{Input, InputState, Textarea, TextareaState};9
use gpui_kit::component::{Disableable as _, h_flex, v_flex};10
use gpui_kit::prelude::FluentBuilder as _;11
use gpui_kit::*;12
use kvt_sleutels::ClientError;13
use kvt_sleutels::asclepius::MessageSource;14
use kvt_sleutels::tickets::{15
ATTACHMENT_MAX_BYTES, ATTACHMENTS_MAX, DESCRIPTION_MAX, Lookups, NewAttachment, NewTicket,16
TITLE_MAX, mentions_to_asclepius, mime_for, parse_participants, priority_from_flags,17
};18
19
use super::modal::{primary_button, secondary_button};20
use super::tasks::{chip, field, label, muted, not_linked};21
use super::tickets::ticket_error;22
use super::{Link, forget_token, installed, is_demo, link, notice, token_and_client, update};23
use crate::i18n::{tr, tr_args};24
use crate::runtime;25
use crate::theme::{self, ElevatedSurface as _};26
use crate::views::widgets::symbol;27
28
pub const KVT_TICKET_FORM_TAG: &str = "kvt-asclepius-form";29
const BACKDROP_OPACITY: f32 = 0.55;30
const PANEL_WIDTH: f32 = 560.;31
const PANEL_MARGIN: f32 = 32.;32
const PANEL_RADIUS: f32 = 10.;33
const PANEL_PADDING: f32 = 16.;34
const SECTION_GAP: f32 = 10.;35
const CLOSE_SIZE: f32 = 28.;36
37
#[derive(Clone)]38
enum LookupState {39
Loading,40
Loaded(Lookups),41
Failed(ClientError),42
}43
44
struct PickedFile {45
name: String,46
size: usize,47
attachment: NewAttachment,48
}49
50
pub struct TicketForm {51
source: Option<MessageSource>,52
lookups: LookupState,53
category: Option<String>,54
subcategory: Option<String>,55
title: Entity<InputState>,56
description: Entity<TextareaState>,57
participants: Entity<InputState>,58
blocked: bool,59
fully_blocked: bool,60
files: Vec<PickedFile>,61
saving: bool,62
error: Option<String>,63
}64
65
/// Opent het formulier; `source` is het bericht bij «Ticket maken in Asclepius».66
pub(super) fn open_new(source: Option<MessageSource>, window: &mut Window, cx: &mut App) {67
if !installed(cx) {68
return;69
}70
let form = cx.new(|cx| TicketForm::new(source, window, cx));71
update(cx, |kvt| kvt.ticket_form = Some(form.clone()));72
if is_demo(cx) {73
form.update(cx, |form, cx| form.set_lookups(Ok(demo_lookups()), cx));74
return;75
}76
let Some((token, client)) = token_and_client(cx) else {77
return;78
};79
let loading = runtime::spawn(async move { client.asclepius_lookups(&token).await });80
let weak = form.downgrade();81
cx.spawn(async move |cx| {82
let result = loading.await.unwrap_or(Err(ClientError::Unavailable));83
cx.update(|cx| {84
if result == Err(ClientError::Unauthorized) {85
forget_token(cx);86
}87
weak.update(cx, |form, cx| form.set_lookups(result, cx))88
.ok();89
});90
})91
.detach();92
}93
94
fn tr_with(key: &str, name: &str, value: String) -> String {95
tr_args(96
key,97
&std::collections::HashMap::from([(name.to_owned(), value)]),98
)99
}100
101
fn close(cx: &mut App) {102
update(cx, |kvt| kvt.ticket_form = None);103
}104
105
/// Knop «Nieuw ticket» in de kop van de tegel.106
pub(super) fn new_ticket_button<T: 'static>(cx: &mut Context<T>) -> Option<Stateful<Div>> {107
matches!(link(cx), Link::Linked(_)).then(|| {108
primary_button("kvt-tickets-new", tr("kvt.tickets.new"))109
.on_click(|_, window, cx| open_new(None, window, cx))110
})111
}112
113
/// Beschrijving uit het bericht, met de vermeldingen als Asclepius-token.114
fn prefilled_description(source: &MessageSource) -> String {115
mentions_to_asclepius(&source.description(DESCRIPTION_MAX), &source.mentions)116
}117
118
impl TicketForm {119
fn new(source: Option<MessageSource>, window: &mut Window, cx: &mut Context<Self>) -> Self {120
let title_text = source121
.as_ref()122
.map(|source| source.title(TITLE_MAX))123
.unwrap_or_default();124
let description_text = source125
.as_ref()126
.map(prefilled_description)127
.unwrap_or_default();128
let title = cx.new(|cx| {129
InputState::new(window, cx)130
.placeholder(tr("kvt.tickets.form.title_placeholder"))131
.default_value(title_text)132
});133
let description = cx.new(|cx| {134
TextareaState::new(window, cx)135
.auto_grow(4, 10)136
.placeholder(tr("kvt.tickets.form.description_placeholder"))137
.default_value(description_text)138
});139
let participants = cx.new(|cx| {140
InputState::new(window, cx).placeholder(tr("kvt.tickets.form.participants_placeholder"))141
});142
title.update(cx, |input, cx| input.focus(window, cx));143
TicketForm {144
source,145
lookups: LookupState::Loading,146
category: None,147
subcategory: None,148
title,149
description,150
participants,151
blocked: false,152
fully_blocked: false,153
files: Vec::new(),154
saving: false,155
error: None,156
}157
}158
159
fn set_lookups(&mut self, result: Result<Lookups, ClientError>, cx: &mut Context<Self>) {160
self.lookups = match result {161
Ok(lookups) => LookupState::Loaded(lookups),162
Err(error) => LookupState::Failed(error),163
};164
cx.notify();165
}166
167
fn pick_files(&mut self, cx: &mut Context<Self>) {168
let receiver = cx.prompt_for_paths(PathPromptOptions {169
files: true,170
directories: false,171
multiple: true,172
prompt: None,173
});174
cx.spawn(async move |this, cx| {175
let Ok(Ok(Some(paths))) = receiver.await else {176
return;177
};178
let reading = runtime::spawn(async move { read_files(paths) });179
let read = reading.await.unwrap_or_default();180
this.update(cx, |this, cx| {181
for file in read {182
match file {183
Ok(file) if this.files.len() < ATTACHMENTS_MAX => this.files.push(file),184
Ok(_) => {185
this.error = Some(tr_with(186
"kvt.tickets.form.too_many_files",187
"max",188
ATTACHMENTS_MAX.to_string(),189
))190
}191
Err(name) => {192
this.error =193
Some(tr_with("kvt.tickets.form.file_too_large", "name", name))194
}195
}196
}197
cx.notify();198
})199
.ok();200
})201
.detach();202
}203
204
fn save(&mut self, cx: &mut Context<Self>) {205
if self.saving {206
return;207
}208
let title = self.title.read(cx).value().trim().to_owned();209
let description = self.description.read(cx).value().trim().to_owned();210
let participants_text = self.participants.read(cx).value().to_string();211
let Some(category) = self.category.clone() else {212
self.error = Some(tr("kvt.tickets.form.pick_category"));213
cx.notify();214
return;215
};216
if title.is_empty() || description.is_empty() {217
self.error = Some(tr("kvt.tickets.form.fill_in"));218
cx.notify();219
return;220
}221
let participant_emails = match parse_participants(&participants_text) {222
Ok(emails) => emails,223
Err(bad) => {224
self.error = Some(tr_with("kvt.tickets.form.bad_email", "email", bad));225
cx.notify();226
return;227
}228
};229
let ticket = NewTicket {230
title,231
category,232
subcategory: self.subcategory.clone(),233
description,234
priority: priority_from_flags(self.blocked, self.fully_blocked),235
participant_emails,236
attachments: self237
.files238
.iter()239
.map(|file| file.attachment.clone())240
.collect(),241
};242
if is_demo(cx) {243
close(cx);244
notice(245
tr_with("kvt.tickets.form.created", "id", "4103".to_owned()),246
cx,247
);248
return;249
}250
let Some((token, client)) = token_and_client(cx) else {251
return;252
};253
self.saving = true;254
self.error = None;255
cx.notify();256
let creating =257
runtime::spawn(async move { client.asclepius_create(&token, &ticket).await });258
cx.spawn(async move |this, cx| {259
let result = creating.await.unwrap_or(Err(ClientError::Unavailable));260
cx.update(|cx| match result {261
Ok(id) => {262
close(cx);263
notice(264
tr_with("kvt.tickets.form.created", "id", id.to_string()),265
cx,266
);267
super::tickets::created(id, cx);268
}269
Err(error) => {270
if error == ClientError::Unauthorized {271
forget_token(cx);272
}273
this.update(cx, |this, cx| {274
this.saving = false;275
this.error = Some(ticket_error(&error));276
cx.notify();277
})278
.ok();279
}280
});281
})282
.detach();283
}284
285
fn categories(&self, cx: &mut Context<Self>) -> AnyElement {286
let lookups = match &self.lookups {287
LookupState::Loading => return muted(tr("kvt.card.loading")).into_any_element(),288
LookupState::Failed(error) => return muted(ticket_error(error)).into_any_element(),289
LookupState::Loaded(lookups) => lookups,290
};291
let categories = h_flex().w_full().flex_wrap().gap(px(6.)).children(292
lookups293
.form_categories()294
.into_iter()295
.enumerate()296
.map(|(index, category)| {297
let selected = self.category.as_deref() == Some(category.as_str());298
chip(299
format!("kvt-ticket-category-{index}").into(),300
category.clone(),301
selected,302
)303
.on_click(cx.listener(move |this, _, _, cx| {304
if this.category.as_deref() != Some(category.as_str()) {305
this.category = Some(category.clone());306
this.subcategory = None;307
}308
this.error = None;309
cx.notify();310
}))311
}),312
);313
let subcategories = self314
.category315
.as_deref()316
.map(|category| lookups.subcategories_of(category).to_vec())317
.unwrap_or_default();318
v_flex()319
.w_full()320
.gap(px(SECTION_GAP))321
.child(categories)322
.when(!subcategories.is_empty(), |column| {323
column324
.child(label(tr("kvt.tickets.form.subcategory")))325
.child(326
h_flex().w_full().flex_wrap().gap(px(6.)).children(327
subcategories328
.into_iter()329
.enumerate()330
.map(|(index, subcategory)| {331
let selected =332
self.subcategory.as_deref() == Some(subcategory.as_str());333
chip(334
format!("kvt-ticket-subcategory-{index}").into(),335
subcategory.clone(),336
selected,337
)338
.on_click(cx.listener(339
move |this, _, _, cx| {340
// Nogmaals klikken haalt de keuze weg (subcategorie is optioneel).341
this.subcategory =342
(!selected).then(|| subcategory.clone());343
cx.notify();344
},345
))346
}),347
),348
)349
})350
.into_any_element()351
}352
353
fn files(&self, cx: &mut Context<Self>) -> Div {354
h_flex()355
.w_full()356
.flex_wrap()357
.gap(px(6.))358
.items_center()359
.children(self.files.iter().enumerate().map(|(index, file)| {360
h_flex()361
.id(ElementId::Name(format!("kvt-ticket-file-{index}").into()))362
.h(px(28.))363
.pl(px(10.))364
.pr(px(4.))365
.gap(px(6.))366
.items_center()367
.rounded(px(6.))368
.bg(theme::popup_hover())369
.text_size(px(12.))370
.child(symbol("attach_file", 14., theme::text_muted()))371
.child(format!("{} ({})", file.name, size_label(file.size)))372
.child(373
div()374
.id(ElementId::Name(375
format!("kvt-ticket-file-remove-{index}").into(),376
))377
.size(px(20.))378
.flex()379
.items_center()380
.justify_center()381
.rounded_full()382
.cursor_pointer()383
.hover(|button| button.bg(theme::row_hover()))384
.on_click(cx.listener(move |this, _, _, cx| {385
if index < this.files.len() {386
this.files.remove(index);387
}388
cx.notify();389
}))390
.child(symbol("close", 12., theme::text_muted())),391
)392
}))393
.when(self.files.len() < ATTACHMENTS_MAX, |row| {394
row.child(395
secondary_button(396
"kvt-ticket-add-file",397
"attach_file",398
tr("kvt.tickets.form.add_files"),399
)400
.on_click(cx.listener(|this, _, _, cx| this.pick_files(cx))),401
)402
})403
}404
}405
406
fn read_files(paths: Vec<PathBuf>) -> Vec<Result<PickedFile, String>> {407
paths408
.into_iter()409
.filter_map(|path| {410
let name = path.file_name()?.to_string_lossy().into_owned();411
let size = std::fs::metadata(&path).ok()?.len() as usize;412
if size > ATTACHMENT_MAX_BYTES {413
return Some(Err(name));414
}415
let data = std::fs::read(&path).ok()?;416
Some(Ok(PickedFile {417
size: data.len(),418
attachment: NewAttachment {419
mime: mime_for(&name).to_owned(),420
filename: name.clone(),421
data,422
},423
name,424
}))425
})426
.collect()427
}428
429
fn size_label(bytes: usize) -> String {430
if bytes >= 1024 * 1024 {431
format!("{:.1} MB", bytes as f64 / (1024. * 1024.)).replace('.', ",")432
} else {433
format!("{} kB", bytes.div_ceil(1024).max(1))434
}435
}436
437
impl Render for TicketForm {438
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {439
let linked = matches!(link(cx), Link::Linked(_));440
let ready = linked && matches!(self.lookups, LookupState::Loaded(_));441
let detail = self442
.source443
.as_ref()444
.filter(|source| !source.sender.is_empty())445
.map(|source| format!("{} · {}", source.sender, source.sent_at))446
.unwrap_or_default();447
let blocked = self.blocked;448
let body = if !linked {449
v_flex().w_full().child(not_linked())450
} else {451
v_flex()452
.w_full()453
.gap(px(SECTION_GAP))454
.child(label(tr("kvt.tickets.form.title")))455
.child(456
field().child(457
div()458
.flex_1()459
.child(Input::new(&self.title).appearance(false).bordered(false)),460
),461
)462
.child(label(tr("kvt.tickets.form.category")))463
.child(self.categories(cx))464
.child(label(tr("kvt.tickets.form.description")))465
.child(Textarea::new(&self.description))466
.child(467
Checkbox::new("kvt-ticket-blocked")468
.label(tr("kvt.tickets.form.blocked"))469
.checked(self.blocked)470
.on_click(cx.listener(|this, checked: &bool, _, cx| {471
this.blocked = *checked;472
if !*checked {473
this.fully_blocked = false;474
}475
cx.notify();476
})),477
)478
.child(479
Checkbox::new("kvt-ticket-fully-blocked")480
.label(tr("kvt.tickets.form.fully_blocked"))481
.checked(self.fully_blocked)482
.disabled(!blocked)483
.on_click(cx.listener(|this, checked: &bool, _, cx| {484
this.fully_blocked = *checked && this.blocked;485
cx.notify();486
})),487
)488
.child(label(tr("kvt.tickets.form.participants")))489
.child(490
field().child(491
div().flex_1().child(492
Input::new(&self.participants)493
.appearance(false)494
.bordered(false),495
),496
),497
)498
.child(499
div()500
.text_size(px(12.))501
.text_color(theme::text_muted())502
.child(tr("kvt.tickets.form.participants_hint")),503
)504
.child(label(tr("kvt.tickets.form.attachments")))505
.child(self.files(cx))506
};507
div()508
.id("kvt-ticket-form-layer")509
.absolute()510
.top_0()511
.left_0()512
.size_full()513
.flex()514
.items_center()515
.justify_center()516
.child(517
div()518
.id("kvt-ticket-form-backdrop")519
.absolute()520
.top_0()521
.left_0()522
.size_full()523
.bg(black().opacity(BACKDROP_OPACITY))524
.occlude()525
.on_click(|_, _, cx| close(cx)),526
)527
.child(528
v_flex()529
.id("kvt-ticket-form-panel")530
.debug_selector(|| KVT_TICKET_FORM_TAG.into())531
.w(px(PANEL_WIDTH))532
.max_w(relative(1.))533
.max_h(relative(0.92))534
.m(px(PANEL_MARGIN))535
.p(px(PANEL_PADDING))536
.gap(px(SECTION_GAP))537
.rounded(px(PANEL_RADIUS))538
.dialog_surface()539
.text_color(theme::text())540
.overflow_y_scroll()541
.occlude()542
.on_key_down(cx.listener(|_, event: &KeyDownEvent, _, cx| {543
if event.keystroke.key == "escape" {544
close(cx);545
}546
}))547
.child(548
h_flex()549
.w_full()550
.items_center()551
.gap(px(SECTION_GAP))552
.child(553
v_flex()554
.flex_1()555
.min_w_0()556
.child(557
div()558
.text_size(px(15.))559
.font_weight(FontWeight::SEMIBOLD)560
.child(tr("kvt.tickets.form.heading")),561
)562
.when(!detail.is_empty(), |column| {563
column.child(564
div()565
.truncate()566
.text_size(px(12.))567
.text_color(theme::text_muted())568
.child(detail),569
)570
}),571
)572
.child(573
div()574
.id("kvt-ticket-form-close")575
.size(px(CLOSE_SIZE))576
.flex_none()577
.flex()578
.items_center()579
.justify_center()580
.rounded_full()581
.cursor_pointer()582
.hover(|button| button.bg(theme::popup_hover()))583
.on_click(|_, _, cx| close(cx))584
.child(symbol("close", 16., theme::text_muted())),585
),586
)587
.child(body)588
.children(self.error.clone().map(|error| {589
div()590
.text_size(px(13.))591
.text_color(theme::red_soft())592
.child(error)593
}))594
.child(595
h_flex()596
.w_full()597
.gap(px(8.))598
.justify_end()599
.child(600
secondary_button(601
"kvt-ticket-form-cancel",602
"close",603
tr("common.cancel"),604
)605
.on_click(|_, _, cx| close(cx)),606
)607
.when(ready, |row| {608
row.child(609
primary_button(610
"kvt-ticket-form-submit",611
tr(if self.saving {612
"kvt.tickets.sending"613
} else {614
"kvt.tickets.form.submit"615
}),616
)617
.on_click(cx.listener(|this, _, _, cx| this.save(cx))),618
)619
}),620
),621
)622
}623
}624
625
pub(super) fn demo_lookups() -> Lookups {626
let mut lookups = Lookups {627
categories: [628
"Hardware",629
"Hardware bestellen",630
"Software",631
"Rechten en toegang",632
"Indiensttreding",633
]634
.map(str::to_owned)635
.to_vec(),636
..Lookups::default()637
};638
lookups.subcategories.insert(639
"Hardware".to_owned(),640
["Laptop", "Monitor", "Printer"].map(str::to_owned).to_vec(),641
);642
lookups643
}644
645
#[cfg(test)]646
mod tests {647
use super::{demo_lookups, prefilled_description, size_label};648
use kvt_sleutels::asclepius::MessageSource;649
650
#[test]651
fn message_mentions_become_asclepius_tokens() {652
let source = MessageSource {653
text: "@Jonas Ortega kun jij hiernaar kijken?".to_owned(),654
sender: "Dana Demo".to_owned(),655
sent_at: "15 jan 2026 13:39".to_owned(),656
link: None,657
mentions: vec![(658
"Jonas Ortega".to_owned(),659
"jonas.ortega@example.com".to_owned(),660
)],661
};662
let description = prefilled_description(&source);663
assert!(description.starts_with("> @jonas.ortega:examplecom kun jij"));664
}665
666
#[test]667
fn ict_only_categories_are_not_offered() {668
assert!(669
!demo_lookups()670
.form_categories()671
.contains(&"Indiensttreding".to_owned())672
);673
}674
675
#[test]676
fn sizes_are_short_and_dutch() {677
assert_eq!(size_label(500), "1 kB");678
assert_eq!(size_label(3 * 1024 * 1024 + 512 * 1024), "3,5 MB");679
}680
}@@ -729,6 +729,26 @@ fn refresh_list(cx: &mut App) {
729
729
}
730
730
}
731
731
732
/// Net aangemaakt: lijst opnieuw en het nieuwe ticket openen (als de tegel bestaat).
733
pub(super) fn created(id: u64, cx: &mut App) {
734
let Some(page) = super::read(cx, |kvt| kvt.tickets.clone()).flatten() else {
735
return;
736
};
737
let Some(window) = cx.active_window() else {
738
page.update(cx, |page, cx| page.reload(cx));
739
return;
740
};
741
window
742
.update(cx, |_, window, cx| {
743
page.update(cx, |page, cx| {
744
page.filter = TicketFilter::Open;
745
page.selected = Some(cx.new(|cx| TicketThread::new(id, window, cx)));
746
page.reload(cx);
747
})
748
})
749
.ok();
750
}
751
732
752
/// Een ticket is bekeken (tegel of ticketvenster): niet meer ongelezen.
733
753
pub(super) fn ticket_seen(ticket: &Ticket, cx: &mut App) {
734
754
if let Some(page) = super::read(cx, |kvt| kvt.tickets.clone()).flatten() {
@@ -918,6 +938,7 @@ impl TicketsPage {
918
938
.text_color(theme::text())
919
939
.child(tr("kvt.tickets.title")),
920
940
)
941
.children(super::ticket_form::new_ticket_button(cx))
921
942
.child(
922
943
secondary_button("kvt-tickets-refresh", "refresh", tr("kvt.card.refresh"))
923
944
.on_click(cx.listener(|this, _, _, cx| this.reload(cx))),
@@ -729,6 +729,26 @@ fn refresh_list(cx: &mut App) {729
}729
}730
}730
}731
731
732
/// Net aangemaakt: lijst opnieuw en het nieuwe ticket openen (als de tegel bestaat).733
pub(super) fn created(id: u64, cx: &mut App) {734
let Some(page) = super::read(cx, |kvt| kvt.tickets.clone()).flatten() else {735
return;736
};737
let Some(window) = cx.active_window() else {738
page.update(cx, |page, cx| page.reload(cx));739
return;740
};741
window742
.update(cx, |_, window, cx| {743
page.update(cx, |page, cx| {744
page.filter = TicketFilter::Open;745
page.selected = Some(cx.new(|cx| TicketThread::new(id, window, cx)));746
page.reload(cx);747
})748
})749
.ok();750
}751
732
/// Een ticket is bekeken (tegel of ticketvenster): niet meer ongelezen.752
/// Een ticket is bekeken (tegel of ticketvenster): niet meer ongelezen.733
pub(super) fn ticket_seen(ticket: &Ticket, cx: &mut App) {753
pub(super) fn ticket_seen(ticket: &Ticket, cx: &mut App) {734
if let Some(page) = super::read(cx, |kvt| kvt.tickets.clone()).flatten() {754
if let Some(page) = super::read(cx, |kvt| kvt.tickets.clone()).flatten() {@@ -918,6 +938,7 @@ impl TicketsPage {918
.text_color(theme::text())938
.text_color(theme::text())919
.child(tr("kvt.tickets.title")),939
.child(tr("kvt.tickets.title")),920
)940
)941
.children(super::ticket_form::new_ticket_button(cx))921
.child(942
.child(922
secondary_button("kvt-tickets-refresh", "refresh", tr("kvt.card.refresh"))943
secondary_button("kvt-tickets-refresh", "refresh", tr("kvt.card.refresh"))923
.on_click(cx.listener(|this, _, _, cx| this.reload(cx))),944
.on_click(cx.listener(|this, _, _, cx| this.reload(cx))),@@ -19,6 +19,8 @@ pub struct MessageSource {
19
19
pub sent_at: String,
20
20
/// Link naar het bericht in Teams, als die er is.
21
21
pub link: Option<String>,
22
/// Vermelde personen in het bericht (naam zoals in de tekst, e-mailadres), als bekend.
23
pub mentions: Vec<(String, String)>,
22
24
}
23
25
24
26
impl MessageSource {
@@ -90,6 +92,7 @@ mod tests {
90
92
sender: "Mara Lindqvist".into(),
91
93
sent_at: "15 jan 2026 13:39".into(),
92
94
link: Some("https://teams.microsoft.com/l/message/19:x/1".into()),
95
mentions: Vec::new(),
93
96
}
94
97
}
95
98
@@ -19,6 +19,8 @@ pub struct MessageSource {19
pub sent_at: String,19
pub sent_at: String,20
/// Link naar het bericht in Teams, als die er is.20
/// Link naar het bericht in Teams, als die er is.21
pub link: Option<String>,21
pub link: Option<String>,22
/// Vermelde personen in het bericht (naam zoals in de tekst, e-mailadres), als bekend.23
pub mentions: Vec<(String, String)>,22
}24
}23
25
24
impl MessageSource {26
impl MessageSource {@@ -90,6 +92,7 @@ mod tests {90
sender: "Mara Lindqvist".into(),92
sender: "Mara Lindqvist".into(),91
sent_at: "15 jan 2026 13:39".into(),93
sent_at: "15 jan 2026 13:39".into(),92
link: Some("https://teams.microsoft.com/l/message/19:x/1".into()),94
link: Some("https://teams.microsoft.com/l/message/19:x/1".into()),95
mentions: Vec::new(),93
}96
}94
}97
}95
98
@@ -275,6 +275,32 @@ pub fn is_closed(status: &str) -> bool {
275
275
}
276
276
277
277
/// Zelfde als `getPriorityFromFlags` op het web: het tweede vinkje telt alleen met het eerste.
278
/// MIME-type uit de extensie (Asclepius controleert de inhoud zelf ook).
279
pub fn mime_for(filename: &str) -> &'static str {
280
let extension = filename
281
.rsplit_once('.')
282
.map(|(_, extension)| extension.to_ascii_lowercase())
283
.unwrap_or_default();
284
match extension.as_str() {
285
"png" => "image/png",
286
"jpg" | "jpeg" => "image/jpeg",
287
"gif" => "image/gif",
288
"webp" => "image/webp",
289
"pdf" => "application/pdf",
290
"txt" | "log" => "text/plain",
291
"csv" => "text/csv",
292
"doc" => "application/msword",
293
"docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
294
"xls" => "application/vnd.ms-excel",
295
"xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
296
"ppt" => "application/vnd.ms-powerpoint",
297
"pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
298
"zip" => "application/zip",
299
"eml" => "message/rfc822",
300
_ => "application/octet-stream",
301
}
302
}
303
278
304
pub fn priority_from_flags(blocked: bool, fully_blocked: bool) -> u8 {
279
305
match (blocked, fully_blocked) {
280
306
(true, true) => 2,
@@ -988,4 +1014,11 @@ mod tests {
988
1014
let restored = SeenTickets::from_json(&seen.to_json());
989
1015
assert_eq!(restored, seen);
990
1016
}
1017
1018
#[test]
1019
fn mime_comes_from_the_extension() {
1020
assert_eq!(mime_for("Scherm.PNG"), "image/png");
1021
assert_eq!(mime_for("rapport.pdf"), "application/pdf");
1022
assert_eq!(mime_for("geen-extensie"), "application/octet-stream");
1023
}
991
1024
}
@@ -275,6 +275,32 @@ pub fn is_closed(status: &str) -> bool {275
}275
}276
276
277
/// Zelfde als `getPriorityFromFlags` op het web: het tweede vinkje telt alleen met het eerste.277
/// Zelfde als `getPriorityFromFlags` op het web: het tweede vinkje telt alleen met het eerste.278
/// MIME-type uit de extensie (Asclepius controleert de inhoud zelf ook).279
pub fn mime_for(filename: &str) -> &'static str {280
let extension = filename281
.rsplit_once('.')282
.map(|(_, extension)| extension.to_ascii_lowercase())283
.unwrap_or_default();284
match extension.as_str() {285
"png" => "image/png",286
"jpg" | "jpeg" => "image/jpeg",287
"gif" => "image/gif",288
"webp" => "image/webp",289
"pdf" => "application/pdf",290
"txt" | "log" => "text/plain",291
"csv" => "text/csv",292
"doc" => "application/msword",293
"docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",294
"xls" => "application/vnd.ms-excel",295
"xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",296
"ppt" => "application/vnd.ms-powerpoint",297
"pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",298
"zip" => "application/zip",299
"eml" => "message/rfc822",300
_ => "application/octet-stream",301
}302
}303
278
pub fn priority_from_flags(blocked: bool, fully_blocked: bool) -> u8 {304
pub fn priority_from_flags(blocked: bool, fully_blocked: bool) -> u8 {279
match (blocked, fully_blocked) {305
match (blocked, fully_blocked) {280
(true, true) => 2,306
(true, true) => 2,@@ -988,4 +1014,11 @@ mod tests {988
let restored = SeenTickets::from_json(&seen.to_json());1014
let restored = SeenTickets::from_json(&seen.to_json());989
assert_eq!(restored, seen);1015
assert_eq!(restored, seen);990
}1016
}1017
1018
#[test]1019
fn mime_comes_from_the_extension() {1020
assert_eq!(mime_for("Scherm.PNG"), "image/png");1021
assert_eq!(mime_for("rapport.pdf"), "application/pdf");1022
assert_eq!(mime_for("geen-extensie"), "application/octet-stream");1023
}991
}1024
}