| 1 | //! Verzonnen kaarten voor `--demo` (geen echte BC-gegevens, geen echte personen). |
| 2 | |
| 3 | use kvt_sleutels::links::bc_url; |
| 4 | use kvt_sleutels::{ |
| 5 | Card, CardField, CardKind, CardLinks, CardRef, FieldRef, SearchResult, StoredToken, |
| 6 | }; |
| 7 | |
| 8 | use std::collections::HashMap; |
| 9 | |
| 10 | use kvt_sleutels::ponos::{MY_TASKS_GROUP, PonosGroup, PonosNavigation, PonosTask}; |
| 11 | |
| 12 | use super::DEFAULT_COMPANY as COMPANY; |
| 13 | |
| 14 | pub(super) fn token() -> StoredToken { |
| 15 | StoredToken { |
| 16 | token: String::new(), |
| 17 | expires_at: i64::MAX, |
| 18 | email: "dana.demo@example.com".to_owned(), |
| 19 | name: "Dana Demo".to_owned(), |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | pub(super) fn companies() -> Vec<String> { |
| 24 | vec![COMPANY.to_owned(), "KVT Germany".to_owned()] |
| 25 | } |
| 26 | |
| 27 | fn field(key: &str, label: &str, value: &str) -> CardField { |
| 28 | CardField { |
| 29 | key: key.to_owned(), |
| 30 | label: label.to_owned(), |
| 31 | value: value.to_owned(), |
| 32 | date: None, |
| 33 | reference: None, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | fn reference(key: &str, label: &str, kind: CardKind, company: &str, no: &str) -> CardField { |
| 38 | CardField { |
| 39 | reference: Some(FieldRef { |
| 40 | kind: kind.api_name().to_owned(), |
| 41 | no: no.to_owned(), |
| 42 | bc_url: bc_url(kind, company, no, None), |
| 43 | }), |
| 44 | ..field(key, label, no) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | struct Entry { |
| 49 | kind: CardKind, |
| 50 | no: &'static str, |
| 51 | title: &'static str, |
| 52 | subtitle: &'static str, |
| 53 | } |
| 54 | |
| 55 | const ENTRIES: [Entry; 8] = [ |
| 56 | Entry { |
| 57 | kind: CardKind::Werkorder, |
| 58 | no: "WO2699001", |
| 59 | title: "Onderhoud 500 uur", |
| 60 | subtitle: "MS Voorbeeld", |
| 61 | }, |
| 62 | Entry { |
| 63 | kind: CardKind::Werkorder, |
| 64 | no: "WO2699002", |
| 65 | title: "Inspectie generator", |
| 66 | subtitle: "Pontveer Demo", |
| 67 | }, |
| 68 | Entry { |
| 69 | kind: CardKind::Project, |
| 70 | no: "PRJ2699001", |
| 71 | title: "Nieuwbouw aandrijving", |
| 72 | subtitle: "Rederij Voorbeeld", |
| 73 | }, |
| 74 | Entry { |
| 75 | kind: CardKind::Project, |
| 76 | no: "PRJ2699002", |
| 77 | title: "Retrofit noodstroom", |
| 78 | subtitle: "Haven Demo", |
| 79 | }, |
| 80 | Entry { |
| 81 | kind: CardKind::Contract, |
| 82 | no: "CT2699001", |
| 83 | title: "Onderhoudscontract vloot", |
| 84 | subtitle: "Rederij Voorbeeld", |
| 85 | }, |
| 86 | Entry { |
| 87 | kind: CardKind::Klant, |
| 88 | no: "269901", |
| 89 | title: "Rederij Voorbeeld", |
| 90 | subtitle: "Rotterdam", |
| 91 | }, |
| 92 | Entry { |
| 93 | kind: CardKind::Component, |
| 94 | no: "COM2699001", |
| 95 | title: "Hoofdmotor bakboord", |
| 96 | subtitle: "MS Voorbeeld", |
| 97 | }, |
| 98 | Entry { |
| 99 | kind: CardKind::Artikel, |
| 100 | no: "2699001", |
| 101 | title: "Brandstoffilter 12 µm", |
| 102 | subtitle: "Filters", |
| 103 | }, |
| 104 | ]; |
| 105 | |
| 106 | pub(super) fn card(reference_to: &CardRef) -> Option<Card> { |
| 107 | let entry = ENTRIES |
| 108 | .iter() |
| 109 | .find(|entry| entry.kind == reference_to.kind && entry.no == reference_to.no)?; |
| 110 | let company = reference_to.company.as_str(); |
| 111 | let fields = match entry.kind { |
| 112 | CardKind::Werkorder => vec![ |
| 113 | field("Main_Entity_Description", "Object", entry.subtitle), |
| 114 | field("Sell_to_Name", "Klant", "Rederij Voorbeeld"), |
| 115 | field("Component_Description", "Component", "Hoofdmotor"), |
| 116 | field("Task_Code", "Taakcode", "OH-500"), |
| 117 | field("Status", "Status", "Gepland"), |
| 118 | field("Start_Date", "Begindatum", "15 jan 2026"), |
| 119 | field("End_Date", "Einddatum", "16 jan 2026"), |
| 120 | field("Resource_Name", "Monteur", "Mara Lindqvist"), |
| 121 | field( |
| 122 | "KVT_Service_Coordinator", |
| 123 | "Servicecoördinator", |
| 124 | "Jonas Ortega", |
| 125 | ), |
| 126 | reference( |
| 127 | "Job_No", |
| 128 | "Project", |
| 129 | CardKind::Project, |
| 130 | company, |
| 131 | "PRJ2699001", |
| 132 | ), |
| 133 | reference( |
| 134 | "Contract_No", |
| 135 | "Contract", |
| 136 | CardKind::Contract, |
| 137 | company, |
| 138 | "CT2699001", |
| 139 | ), |
| 140 | ], |
| 141 | CardKind::Project => vec![ |
| 142 | field("Sell_to_Customer_Name", "Klant", entry.subtitle), |
| 143 | field("Status", "Status", "Open"), |
| 144 | field("Starting_Date", "Begindatum", "2 feb 2026"), |
| 145 | field("Ending_Date", "Einddatum", "30 jun 2026"), |
| 146 | field("Project_Manager", "Projectleider", "Priya Nair"), |
| 147 | reference( |
| 148 | "KVT_Contract_No", |
| 149 | "Contract", |
| 150 | CardKind::Contract, |
| 151 | company, |
| 152 | "CT2699001", |
| 153 | ), |
| 154 | ], |
| 155 | CardKind::Contract => vec![ |
| 156 | field("Name", "Klant", entry.subtitle), |
| 157 | field("Contract_Type", "Soort", "Onderhoud"), |
| 158 | field("Document_Status", "Status", "Getekend"), |
| 159 | field("Starting_Date", "Begindatum", "1 jan 2026"), |
| 160 | field("End_Date", "Einddatum", "31 dec 2028"), |
| 161 | field( |
| 162 | "KVT_Service_Coordinator", |
| 163 | "Servicecoördinator", |
| 164 | "Jonas Ortega", |
| 165 | ), |
| 166 | ], |
| 167 | CardKind::Klant => vec![ |
| 168 | field("City", "Plaats", entry.subtitle), |
| 169 | field("Country_Region_Code", "Land", "NL"), |
| 170 | field("Salesperson_Code", "Verkoper", "DEMO"), |
| 171 | field("Service_Zone_Code", "Servicezone", "ZUID"), |
| 172 | ], |
| 173 | CardKind::Component => vec![ |
| 174 | field("Main_Entity_Description", "Object", entry.subtitle), |
| 175 | field("Serial_No", "Serienummer", "SN-DEMO-0001"), |
| 176 | reference( |
| 177 | "Sell_to_Customer_No", |
| 178 | "Klant", |
| 179 | CardKind::Klant, |
| 180 | company, |
| 181 | "269901", |
| 182 | ), |
| 183 | field("Manufacturer_Code", "Fabrikant", "DEMO"), |
| 184 | reference( |
| 185 | "Part_Item_No", |
| 186 | "Artikel", |
| 187 | CardKind::Artikel, |
| 188 | company, |
| 189 | "2699001", |
| 190 | ), |
| 191 | ], |
| 192 | CardKind::Artikel => vec![ |
| 193 | field("Item_Category_Code", "Categorie", entry.subtitle), |
| 194 | field("Base_Unit_of_Measure", "Eenheid", "STUK"), |
| 195 | field("LVS_Manufacturer_Code", "Fabrikant", "DEMO"), |
| 196 | field("Inventory", "Voorraad", "12"), |
| 197 | ], |
| 198 | }; |
| 199 | Some(Card { |
| 200 | kind: entry.kind.api_name().to_owned(), |
| 201 | type_label: entry.kind.label_nl().to_owned(), |
| 202 | company: company.to_owned(), |
| 203 | no: entry.no.to_owned(), |
| 204 | title: entry.title.to_owned(), |
| 205 | subtitle: entry.subtitle.to_owned(), |
| 206 | fields, |
| 207 | links: CardLinks { |
| 208 | bc: bc_url(entry.kind, company, entry.no, None), |
| 209 | daedalus: (entry.kind == CardKind::Werkorder).then(|| { |
| 210 | format!( |
| 211 | "https://sleutels.kvt.nl/daedalus/index.php?workorder={}", |
| 212 | entry.no |
| 213 | ) |
| 214 | }), |
| 215 | }, |
| 216 | }) |
| 217 | } |
| 218 | |
| 219 | pub(super) fn search(kind: CardKind, company: &str, query: &str) -> Vec<SearchResult> { |
| 220 | let query = query.trim().to_lowercase(); |
| 221 | ENTRIES |
| 222 | .iter() |
| 223 | .filter(|entry| entry.kind == kind) |
| 224 | .filter(|entry| { |
| 225 | entry.no.to_lowercase().contains(&query) || entry.title.to_lowercase().contains(&query) |
| 226 | }) |
| 227 | .map(|entry| SearchResult { |
| 228 | kind: kind.api_name().to_owned(), |
| 229 | company: company.to_owned(), |
| 230 | no: entry.no.to_owned(), |
| 231 | title: entry.title.to_owned(), |
| 232 | subtitle: entry.subtitle.to_owned(), |
| 233 | bc_url: bc_url(kind, company, entry.no, None), |
| 234 | }) |
| 235 | .collect() |
| 236 | } |
| 237 | |
| 238 | pub(super) fn ponos_groups() -> Vec<kvt_sleutels::ponos::PonosGroup> { |
| 239 | ["ICT", "Service Noord", "Werkplaats"] |
| 240 | .into_iter() |
| 241 | .enumerate() |
| 242 | .map(|(index, name)| kvt_sleutels::ponos::PonosGroup { |
| 243 | id: format!("demo-group-{index}"), |
| 244 | name: name.to_owned(), |
| 245 | is_virtual: false, |
| 246 | can_create_tasks: true, |
| 247 | has_task_access: true, |
| 248 | task_count: 0, |
| 249 | }) |
| 250 | .collect() |
| 251 | } |
| 252 | |
| 253 | /// Verzonnen gebruiker van het demobord (geen echt adres). |
| 254 | pub(super) const BOARD_USER: &str = "dana.demo@example.com"; |
| 255 | |
| 256 | pub(super) fn empty_task() -> PonosTask { |
| 257 | PonosTask { |
| 258 | id: String::new(), |
| 259 | group_id: String::new(), |
| 260 | home_group_id: String::new(), |
| 261 | home_group_name: String::new(), |
| 262 | title: String::new(), |
| 263 | status: "todo".to_owned(), |
| 264 | due_date: String::new(), |
| 265 | description: String::new(), |
| 266 | assignee_email: String::new(), |
| 267 | category_label: String::new(), |
| 268 | checklist_total: 0, |
| 269 | checklist_done: 0, |
| 270 | can_edit: true, |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /// Verzonnen taken per groep voor het Ponos-bord in `--demo`. |
| 275 | pub(super) fn board_tasks() -> HashMap<String, Vec<PonosTask>> { |
| 276 | let today = chrono::Local::now().date_naive(); |
| 277 | let groups = ponos_groups(); |
| 278 | let mut board: HashMap<String, Vec<PonosTask>> = HashMap::new(); |
| 279 | #[allow(clippy::type_complexity)] |
| 280 | let rows: [(usize, &str, &str, Option<i64>, &str, &str, (u32, u32)); 13] = [ |
| 281 | ( |
| 282 | 0, |
| 283 | "Laptop klaarzetten voor nieuwe collega", |
| 284 | "todo", |
| 285 | Some(-1), |
| 286 | BOARD_USER, |
| 287 | "Hardware", |
| 288 | (1, 4), |
| 289 | ), |
| 290 | ( |
| 291 | 0, |
| 292 | "Printer receptie controleren", |
| 293 | "todo", |
| 294 | None, |
| 295 | BOARD_USER, |
| 296 | "", |
| 297 | (0, 0), |
| 298 | ), |
| 299 | ( |
| 300 | 0, |
| 301 | "Wifi in hal 3 meten", |
| 302 | "todo", |
| 303 | Some(6), |
| 304 | "", |
| 305 | "Netwerk", |
| 306 | (0, 0), |
| 307 | ), |
| 308 | ( |
| 309 | 0, |
| 310 | "Teams-koppeling testen", |
| 311 | "in_progress", |
| 312 | Some(1), |
| 313 | BOARD_USER, |
| 314 | "", |
| 315 | (2, 3), |
| 316 | ), |
| 317 | ( |
| 318 | 0, |
| 319 | "Back-up NAS nakijken", |
| 320 | "in_progress", |
| 321 | None, |
| 322 | "jonas.ortega@example.com", |
| 323 | "", |
| 324 | (0, 0), |
| 325 | ), |
| 326 | ( |
| 327 | 0, |
| 328 | "Licenties verlengd", |
| 329 | "done", |
| 330 | None, |
| 331 | BOARD_USER, |
| 332 | "", |
| 333 | (0, 0), |
| 334 | ), |
| 335 | ( |
| 336 | 1, |
| 337 | "Rapport WO2699001 nakijken", |
| 338 | "in_progress", |
| 339 | Some(2), |
| 340 | BOARD_USER, |
| 341 | "Rapport", |
| 342 | (0, 0), |
| 343 | ), |
| 344 | ( |
| 345 | 1, |
| 346 | "Onderdelen bestellen voor PRJ2600140", |
| 347 | "todo", |
| 348 | Some(4), |
| 349 | "mila.van.der.berg@example.com", |
| 350 | "", |
| 351 | (0, 0), |
| 352 | ), |
| 353 | ( |
| 354 | 1, |
| 355 | "Klant terugbellen over storing", |
| 356 | "todo", |
| 357 | Some(0), |
| 358 | BOARD_USER, |
| 359 | "", |
| 360 | (0, 0), |
| 361 | ), |
| 362 | (1, "Servicebus ingepland", "done", None, "", "", (0, 0)), |
| 363 | ( |
| 364 | 2, |
| 365 | "Brandstoffilters bestellen", |
| 366 | "todo", |
| 367 | Some(9), |
| 368 | BOARD_USER, |
| 369 | "Inkoop", |
| 370 | (0, 0), |
| 371 | ), |
| 372 | (2, "Hefbrug keuren", "in_progress", Some(12), "", "", (0, 0)), |
| 373 | ( |
| 374 | 2, |
| 375 | "Gereedschapskist aangevuld", |
| 376 | "done", |
| 377 | None, |
| 378 | "", |
| 379 | "", |
| 380 | (0, 0), |
| 381 | ), |
| 382 | ]; |
| 383 | for (index, (group, title, status, due, assignee, category, (done, total))) in |
| 384 | rows.into_iter().enumerate() |
| 385 | { |
| 386 | let group = &groups[group]; |
| 387 | board.entry(group.id.clone()).or_default().push(PonosTask { |
| 388 | id: format!("demo-board-task-{index}"), |
| 389 | group_id: group.id.clone(), |
| 390 | home_group_id: group.id.clone(), |
| 391 | home_group_name: group.name.clone(), |
| 392 | title: title.to_owned(), |
| 393 | status: status.to_owned(), |
| 394 | due_date: due |
| 395 | .map(|days| { |
| 396 | (today + chrono::Duration::days(days)) |
| 397 | .format("%Y-%m-%d") |
| 398 | .to_string() |
| 399 | }) |
| 400 | .unwrap_or_default(), |
| 401 | description: "Verzonnen taak voor de demo.".to_owned(), |
| 402 | assignee_email: assignee.to_owned(), |
| 403 | category_label: category.to_owned(), |
| 404 | checklist_total: total, |
| 405 | checklist_done: done, |
| 406 | ..empty_task() |
| 407 | }); |
| 408 | } |
| 409 | board |
| 410 | } |
| 411 | |
| 412 | /// Groepen zoals Ponos ze geeft: eerst «Mijn Taken», met open taken geteld. |
| 413 | pub(super) fn board_navigation(board: &HashMap<String, Vec<PonosTask>>) -> PonosNavigation { |
| 414 | let open = |tasks: &mut dyn Iterator<Item = &PonosTask>| { |
| 415 | tasks.filter(|task| task.status != "done").count() as u32 |
| 416 | }; |
| 417 | let mut groups = vec![PonosGroup { |
| 418 | id: MY_TASKS_GROUP.to_owned(), |
| 419 | name: "Mijn Taken".to_owned(), |
| 420 | is_virtual: true, |
| 421 | can_create_tasks: false, |
| 422 | has_task_access: true, |
| 423 | task_count: open( |
| 424 | &mut board |
| 425 | .values() |
| 426 | .flatten() |
| 427 | .filter(|task| task.assignee_email == BOARD_USER), |
| 428 | ), |
| 429 | }]; |
| 430 | groups.extend(ponos_groups().into_iter().map(|mut group| { |
| 431 | group.task_count = open(&mut board.get(&group.id).into_iter().flatten()); |
| 432 | group |
| 433 | })); |
| 434 | PonosNavigation { |
| 435 | groups, |
| 436 | status_labels: [ |
| 437 | ("todo", "Nog te doen"), |
| 438 | ("in_progress", "Onderhanden"), |
| 439 | ("done", "Afgerond"), |
| 440 | ] |
| 441 | .into_iter() |
| 442 | .map(|(status, label)| (status.to_owned(), label.to_owned())) |
| 443 | .collect(), |
| 444 | user_email: BOARD_USER.to_owned(), |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /// Twee verzonnen werkorders in de zichtbare periode. |
| 449 | pub(super) fn planning( |
| 450 | from: chrono::DateTime<chrono::Utc>, |
| 451 | to: chrono::DateTime<chrono::Utc>, |
| 452 | ) -> Vec<chatsvc::CalendarEvent> { |
| 453 | use chrono::Duration; |
| 454 | let day = |offset: i64| { |
| 455 | (from.with_timezone(&chrono::Local).date_naive() + Duration::days(offset)) |
| 456 | .format("%Y-%m-%d") |
| 457 | .to_string() |
| 458 | }; |
| 459 | let at = |offset: i64, hour: u32| { |
| 460 | let date = from.with_timezone(&chrono::Local).date_naive() + Duration::days(offset); |
| 461 | date.and_hms_opt(hour, 0, 0) |
| 462 | .and_then(|moment| moment.and_local_timezone(chrono::Local).single()) |
| 463 | .map(|moment| moment.to_rfc3339()) |
| 464 | .unwrap_or_default() |
| 465 | }; |
| 466 | let event = |no: &str, title: &str, object: &str, all_day: bool, start: String, end: String| { |
| 467 | kvt_sleutels::planning::PlanningEvent { |
| 468 | id: format!("{no}@{COMPANY}"), |
| 469 | workorder: no.to_owned(), |
| 470 | company: COMPANY.to_owned(), |
| 471 | title: format!("{no} · {title}"), |
| 472 | object: object.to_owned(), |
| 473 | component: "Hoofdmotor".to_owned(), |
| 474 | status: "Gepland".to_owned(), |
| 475 | all_day, |
| 476 | start, |
| 477 | end, |
| 478 | url: format!("https://sleutels.kvt.nl/daedalus/index.php?workorder={no}"), |
| 479 | } |
| 480 | }; |
| 481 | [ |
| 482 | event( |
| 483 | "WO2699001", |
| 484 | "Onderhoud 500 uur", |
| 485 | "MS Voorbeeld", |
| 486 | true, |
| 487 | day(1), |
| 488 | day(3), |
| 489 | ), |
| 490 | event( |
| 491 | "WO2699002", |
| 492 | "Inspectie generator", |
| 493 | "Pontveer Demo", |
| 494 | false, |
| 495 | at(3, 8), |
| 496 | at(3, 12), |
| 497 | ), |
| 498 | ] |
| 499 | .iter() |
| 500 | .filter_map(super::calendar::calendar_event) |
| 501 | .filter(|event| event.end > from && event.start < to) |
| 502 | .collect() |
| 503 | } |