| 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 super::DEFAULT_COMPANY as COMPANY; |
| 9 | |
| 10 | pub(super) fn token() -> StoredToken { |
| 11 | StoredToken { |
| 12 | token: String::new(), |
| 13 | expires_at: i64::MAX, |
| 14 | email: "dana.demo@example.com".to_owned(), |
| 15 | name: "Dana Demo".to_owned(), |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | pub(super) fn companies() -> Vec<String> { |
| 20 | vec![COMPANY.to_owned(), "KVT Germany".to_owned()] |
| 21 | } |
| 22 | |
| 23 | fn field(key: &str, label: &str, value: &str) -> CardField { |
| 24 | CardField { |
| 25 | key: key.to_owned(), |
| 26 | label: label.to_owned(), |
| 27 | value: value.to_owned(), |
| 28 | date: None, |
| 29 | reference: None, |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn reference(key: &str, label: &str, kind: CardKind, company: &str, no: &str) -> CardField { |
| 34 | CardField { |
| 35 | reference: Some(FieldRef { |
| 36 | kind: kind.api_name().to_owned(), |
| 37 | no: no.to_owned(), |
| 38 | bc_url: bc_url(kind, company, no, None), |
| 39 | }), |
| 40 | ..field(key, label, no) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | struct Entry { |
| 45 | kind: CardKind, |
| 46 | no: &'static str, |
| 47 | title: &'static str, |
| 48 | subtitle: &'static str, |
| 49 | } |
| 50 | |
| 51 | const ENTRIES: [Entry; 5] = [ |
| 52 | Entry { |
| 53 | kind: CardKind::Werkorder, |
| 54 | no: "WO2699001", |
| 55 | title: "Onderhoud 500 uur", |
| 56 | subtitle: "MS Voorbeeld", |
| 57 | }, |
| 58 | Entry { |
| 59 | kind: CardKind::Werkorder, |
| 60 | no: "WO2699002", |
| 61 | title: "Inspectie generator", |
| 62 | subtitle: "Pontveer Demo", |
| 63 | }, |
| 64 | Entry { |
| 65 | kind: CardKind::Project, |
| 66 | no: "PRJ2699001", |
| 67 | title: "Nieuwbouw aandrijving", |
| 68 | subtitle: "Rederij Voorbeeld", |
| 69 | }, |
| 70 | Entry { |
| 71 | kind: CardKind::Project, |
| 72 | no: "PRJ2699002", |
| 73 | title: "Retrofit noodstroom", |
| 74 | subtitle: "Haven Demo", |
| 75 | }, |
| 76 | Entry { |
| 77 | kind: CardKind::Contract, |
| 78 | no: "CT2699001", |
| 79 | title: "Onderhoudscontract vloot", |
| 80 | subtitle: "Rederij Voorbeeld", |
| 81 | }, |
| 82 | ]; |
| 83 | |
| 84 | pub(super) fn card(reference_to: &CardRef) -> Option<Card> { |
| 85 | let entry = ENTRIES |
| 86 | .iter() |
| 87 | .find(|entry| entry.kind == reference_to.kind && entry.no == reference_to.no)?; |
| 88 | let company = reference_to.company.as_str(); |
| 89 | let fields = match entry.kind { |
| 90 | CardKind::Werkorder => vec![ |
| 91 | field("Main_Entity_Description", "Object", entry.subtitle), |
| 92 | field("Sell_to_Name", "Klant", "Rederij Voorbeeld"), |
| 93 | field("Component_Description", "Component", "Hoofdmotor"), |
| 94 | field("Task_Code", "Taakcode", "OH-500"), |
| 95 | field("Status", "Status", "Gepland"), |
| 96 | field("Start_Date", "Begindatum", "15 jan 2026"), |
| 97 | field("End_Date", "Einddatum", "16 jan 2026"), |
| 98 | field("Resource_Name", "Monteur", "Mara Lindqvist"), |
| 99 | field( |
| 100 | "KVT_Service_Coordinator", |
| 101 | "Servicecoördinator", |
| 102 | "Jonas Ortega", |
| 103 | ), |
| 104 | reference( |
| 105 | "Job_No", |
| 106 | "Project", |
| 107 | CardKind::Project, |
| 108 | company, |
| 109 | "PRJ2699001", |
| 110 | ), |
| 111 | reference( |
| 112 | "Contract_No", |
| 113 | "Contract", |
| 114 | CardKind::Contract, |
| 115 | company, |
| 116 | "CT2699001", |
| 117 | ), |
| 118 | ], |
| 119 | CardKind::Project => vec![ |
| 120 | field("Sell_to_Customer_Name", "Klant", entry.subtitle), |
| 121 | field("Status", "Status", "Open"), |
| 122 | field("Starting_Date", "Begindatum", "2 feb 2026"), |
| 123 | field("Ending_Date", "Einddatum", "30 jun 2026"), |
| 124 | field("Project_Manager", "Projectleider", "Priya Nair"), |
| 125 | reference( |
| 126 | "KVT_Contract_No", |
| 127 | "Contract", |
| 128 | CardKind::Contract, |
| 129 | company, |
| 130 | "CT2699001", |
| 131 | ), |
| 132 | ], |
| 133 | CardKind::Contract => vec![ |
| 134 | field("Name", "Klant", entry.subtitle), |
| 135 | field("Contract_Type", "Soort", "Onderhoud"), |
| 136 | field("Document_Status", "Status", "Getekend"), |
| 137 | field("Starting_Date", "Begindatum", "1 jan 2026"), |
| 138 | field("End_Date", "Einddatum", "31 dec 2028"), |
| 139 | field( |
| 140 | "KVT_Service_Coordinator", |
| 141 | "Servicecoördinator", |
| 142 | "Jonas Ortega", |
| 143 | ), |
| 144 | ], |
| 145 | }; |
| 146 | Some(Card { |
| 147 | kind: entry.kind.api_name().to_owned(), |
| 148 | type_label: entry.kind.label_nl().to_owned(), |
| 149 | company: company.to_owned(), |
| 150 | no: entry.no.to_owned(), |
| 151 | title: entry.title.to_owned(), |
| 152 | subtitle: entry.subtitle.to_owned(), |
| 153 | fields, |
| 154 | links: CardLinks { |
| 155 | bc: bc_url(entry.kind, company, entry.no, None), |
| 156 | daedalus: (entry.kind == CardKind::Werkorder).then(|| { |
| 157 | format!( |
| 158 | "https://sleutels.kvt.nl/daedalus/index.php?workorder={}", |
| 159 | entry.no |
| 160 | ) |
| 161 | }), |
| 162 | }, |
| 163 | }) |
| 164 | } |
| 165 | |
| 166 | pub(super) fn search(kind: CardKind, company: &str, query: &str) -> Vec<SearchResult> { |
| 167 | let query = query.trim().to_lowercase(); |
| 168 | ENTRIES |
| 169 | .iter() |
| 170 | .filter(|entry| entry.kind == kind) |
| 171 | .filter(|entry| { |
| 172 | entry.no.to_lowercase().contains(&query) || entry.title.to_lowercase().contains(&query) |
| 173 | }) |
| 174 | .map(|entry| SearchResult { |
| 175 | kind: kind.api_name().to_owned(), |
| 176 | company: company.to_owned(), |
| 177 | no: entry.no.to_owned(), |
| 178 | title: entry.title.to_owned(), |
| 179 | subtitle: entry.subtitle.to_owned(), |
| 180 | bc_url: bc_url(kind, company, entry.no, None), |
| 181 | }) |
| 182 | .collect() |
| 183 | } |