initial commit

11b17d3 · gmorell · 2025-01-01 02:00

25 files +738 -150

Files changed

modified Cargo.lock
+87 −10
@@ -727,6 +727,27 @@ dependencies = [
727 727 "subtle",
728 728 ]
729 729
730 +[[package]]
731 +name = "directories"
732 +version = "5.0.1"
733 +source = "registry+https://github.com/rust-lang/crates.io-index"
734 +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35"
735 +dependencies = [
736 + "dirs-sys",
737 +]
738 +
739 +[[package]]
740 +name = "dirs-sys"
741 +version = "0.4.1"
742 +source = "registry+https://github.com/rust-lang/crates.io-index"
743 +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
744 +dependencies = [
745 + "libc",
746 + "option-ext",
747 + "redox_users",
748 + "windows-sys 0.48.0",
749 +]
750 +
730 751 [[package]]
731 752 name = "displaydoc"
732 753 version = "0.2.5"
@@ -858,7 +879,7 @@ checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095"
858 879 dependencies = [
859 880 "futures-core",
860 881 "futures-sink",
861 − "spin 0.9.8",
882 + "spin",
862 883 ]
863 884
864 885 [[package]]
@@ -1379,11 +1400,11 @@ dependencies = [
1379 1400
1380 1401 [[package]]
1381 1402 name = "lazy_static"
1382 −version = "1.4.0"
1403 +version = "1.5.0"
1383 1404 source = "registry+https://github.com/rust-lang/crates.io-index"
1384 −checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
1405 +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
1385 1406 dependencies = [
1386 − "spin 0.5.2",
1407 + "spin",
1387 1408 ]
1388 1409
1389 1410 [[package]]
@@ -1398,6 +1419,16 @@ version = "0.2.11"
1398 1419 source = "registry+https://github.com/rust-lang/crates.io-index"
1399 1420 checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
1400 1421
1422 +[[package]]
1423 +name = "libredox"
1424 +version = "0.1.3"
1425 +source = "registry+https://github.com/rust-lang/crates.io-index"
1426 +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
1427 +dependencies = [
1428 + "bitflags 2.4.2",
1429 + "libc",
1430 +]
1431 +
1401 1432 [[package]]
1402 1433 name = "libsqlite3-sys"
1403 1434 version = "0.30.1"
@@ -1556,6 +1587,16 @@ dependencies = [
1556 1587 "minimal-lexical",
1557 1588 ]
1558 1589
1590 +[[package]]
1591 +name = "nu-ansi-term"
1592 +version = "0.46.0"
1593 +source = "registry+https://github.com/rust-lang/crates.io-index"
1594 +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
1595 +dependencies = [
1596 + "overload",
1597 + "winapi",
1598 +]
1599 +
1559 1600 [[package]]
1560 1601 name = "num"
1561 1602 version = "0.4.1"
@@ -1667,6 +1708,12 @@ version = "1.19.0"
1667 1708 source = "registry+https://github.com/rust-lang/crates.io-index"
1668 1709 checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
1669 1710
1711 +[[package]]
1712 +name = "option-ext"
1713 +version = "0.2.0"
1714 +source = "registry+https://github.com/rust-lang/crates.io-index"
1715 +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
1716 +
1670 1717 [[package]]
1671 1718 name = "ordered-float"
1672 1719 version = "3.9.2"
@@ -1701,6 +1748,12 @@ dependencies = [
1701 1748 "syn 2.0.90",
1702 1749 ]
1703 1750
1751 +[[package]]
1752 +name = "overload"
1753 +version = "0.1.1"
1754 +source = "registry+https://github.com/rust-lang/crates.io-index"
1755 +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
1756 +
1704 1757 [[package]]
1705 1758 name = "owo-colors"
1706 1759 version = "3.5.0"
@@ -1812,15 +1865,20 @@ dependencies = [
1812 1865 "color-eyre",
1813 1866 "crossterm",
1814 1867 "dateparser",
1868 + "directories",
1815 1869 "enum-iterator",
1816 1870 "env_logger",
1817 1871 "futures",
1818 1872 "interim",
1873 + "lazy_static",
1819 1874 "log",
1820 1875 "ratatui",
1821 1876 "sea-orm",
1822 1877 "sea-orm-migration",
1823 1878 "tokio",
1879 + "tracing",
1880 + "tracing-error",
1881 + "tracing-subscriber",
1824 1882 "tui-input",
1825 1883 "wealthy",
1826 1884 ]
@@ -2001,6 +2059,17 @@ dependencies = [
2001 2059 "bitflags 2.4.2",
2002 2060 ]
2003 2061
2062 +[[package]]
2063 +name = "redox_users"
2064 +version = "0.4.6"
2065 +source = "registry+https://github.com/rust-lang/crates.io-index"
2066 +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
2067 +dependencies = [
2068 + "getrandom",
2069 + "libredox",
2070 + "thiserror",
2071 +]
2072 +
2004 2073 [[package]]
2005 2074 name = "regex"
2006 2075 version = "1.10.3"
@@ -2482,12 +2551,6 @@ dependencies = [
2482 2551 "windows-sys 0.52.0",
2483 2552 ]
2484 2553
2485 −[[package]]
2486 −name = "spin"
2487 −version = "0.5.2"
2488 −source = "registry+https://github.com/rust-lang/crates.io-index"
2489 −checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
2490 −
2491 2554 [[package]]
2492 2555 name = "spin"
2493 2556 version = "0.9.8"
@@ -3029,6 +3092,17 @@ dependencies = [
3029 3092 "tracing-subscriber",
3030 3093 ]
3031 3094
3095 +[[package]]
3096 +name = "tracing-log"
3097 +version = "0.2.0"
3098 +source = "registry+https://github.com/rust-lang/crates.io-index"
3099 +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
3100 +dependencies = [
3101 + "log",
3102 + "once_cell",
3103 + "tracing-core",
3104 +]
3105 +
3032 3106 [[package]]
3033 3107 name = "tracing-subscriber"
3034 3108 version = "0.3.19"
@@ -3036,12 +3110,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
3036 3110 checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
3037 3111 dependencies = [
3038 3112 "matchers",
3113 + "nu-ansi-term",
3039 3114 "once_cell",
3040 3115 "regex",
3041 3116 "sharded-slab",
3117 + "smallvec",
3042 3118 "thread_local",
3043 3119 "tracing",
3044 3120 "tracing-core",
3121 + "tracing-log",
3045 3122 ]
3046 3123
3047 3124 [[package]]
modified Cargo.toml
+5 −0
@@ -23,3 +23,8 @@ enum-iterator = "2.1.0"
23 23 dateparser = "0.2.1"
24 24 interim = { version = "0.1.2", features = ["chrono"] }
25 25 chrono = "0.4.39"
26 +tracing-error = "0.2.1"
27 +tracing = "0.1.41"
28 +tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
29 +directories = "5.0.1"
30 +lazy_static = "1.5.0"
modified src/db.rs
+2 −2
@@ -8,7 +8,7 @@ pub async fn check_migrations(db: &DatabaseConnection) -> Result<(), PplError> {
8 8
9 9 // let be = db.get_database_backend();
10 10 // let schema_manager = SchemaManager::new(db);
11 − Migrator::refresh(db).await?;
12 − info!("migrations run");
11 + // Migrator::refresh(db).await?;
12 + Migrator::up(db, None).await?;
13 13 Ok(())
14 14 }
modified src/do_init.rs
+389 −66
@@ -1,19 +1,28 @@
1 −use crate::Commands::Tiers;
1 +use crate::entities::prelude::Ppl;
2 +use crate::entities::prelude::Traits;
3 +use crate::entities::prelude::{Entitys, TierDefaults, TraitDefaults};
4 +use crate::entities::sig_date::Model;
5 +use crate::entities::{
6 + contact, entitys, ppl, relation, sig_date, tier, tier_defaults, trait_defaults, traits,
7 +};
2 8 use crate::PplError;
3 9 use chrono::NaiveDate;
4 10 use crossterm::event;
5 −use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
6 −use dateparser::{parse, DateTimeUtc};
11 +use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
7 12 use enum_iterator::{all, cardinality, first, last, next, previous, reverse_all, Sequence};
8 13 use interim::{parse_date_string, Dialect};
14 +use log::{info, warn};
9 15 use ratatui::{
10 16 prelude::*,
11 17 style::{palette::tailwind::*, Color, Modifier, Style, Stylize},
12 18 widgets::*,
13 19 DefaultTerminal,
14 20 };
15 −use sea_orm::sqlx::types::chrono;
21 +use sea_orm::prelude::Date;
16 22 use sea_orm::sqlx::types::chrono::Local;
23 +use sea_orm::sqlx::types::{chrono, time};
24 +use sea_orm::ActiveValue::Set;
25 +use sea_orm::{ActiveModelTrait, DatabaseConnection, DbErr, EntityTrait, InsertResult};
17 26 use std::collections::{BTreeMap, HashMap};
18 27 use std::fmt;
19 28 use std::string::String;
@@ -49,15 +58,17 @@ struct Init {
49 58 /// Name
50 59 name: String,
51 60 /// Nicks
52 − nicks: Vec<String>,
61 + aliases: Vec<String>,
53 62 /// bday
54 63 bday: NaiveDate,
55 64 /// bday-parse-error
56 65 bday_parse: String,
57 − /// bplace
58 − birthplace: String,
66 + /// c-place
67 + place: String,
59 68 /// of-parents
60 69 of_ppl: Vec<String>,
70 + /// with-ppl
71 + with_ppl: Vec<String>,
61 72 /// list state for the tier
62 73 tier_state: ListState,
63 74 /// tier storage
@@ -70,6 +81,8 @@ struct Init {
70 81 trait_list: Vec<TraitSelect>,
71 82 /// editing/not
72 83 trait_editing: Selection,
84 + /// debuy msgs
85 + debugmsgs: Vec<(String, String)>,
73 86 }
74 87
75 88 impl Default for Init {
@@ -77,12 +90,13 @@ impl Default for Init {
77 90 Init {
78 91 step: Steps::Welcome,
79 92 input: Input::default(),
80 − nicks: Vec::<String>::default(),
93 + aliases: Vec::<String>::default(),
81 94 name: "".to_string(),
82 95 bday: NaiveDate::default(),
83 96 bday_parse: "".to_string(),
84 − birthplace: "".to_string(),
97 + place: "".to_string(),
85 98 of_ppl: Vec::<String>::default(),
99 + with_ppl: Vec::<String>::default(),
86 100 tier_state: ListState::default(),
87 101 tier_list: all::<DefaultTiers>()
88 102 .map(|e| TierSelect {
@@ -99,7 +113,7 @@ impl Default for Init {
99 113 selection: Selection::Selected,
100 114 symbol: "🏷️".to_string(),
101 115 color: "VIOLET".to_string(),
102 − name: "Nickname".to_string(),
116 + name: "alias".to_string(),
103 117 is_date: false,
104 118 is_contact: false,
105 119 },
@@ -107,7 +121,7 @@ impl Default for Init {
107 121 selection: Selection::Selected,
108 122 symbol: "🎂".to_string(),
109 123 color: "GOLD".to_string(),
110 − name: "Birthday".to_string(),
124 + name: "birthday".to_string(),
111 125 is_date: true,
112 126 is_contact: false,
113 127 },
@@ -115,7 +129,7 @@ impl Default for Init {
115 129 selection: Selection::Selected,
116 130 symbol: "💒".to_string(),
117 131 color: "WHITE".to_string(),
118 − name: "Wedding".to_string(),
132 + name: "wedding".to_string(),
119 133 is_date: true,
120 134 is_contact: false,
121 135 },
@@ -123,7 +137,7 @@ impl Default for Init {
123 137 selection: Selection::Selected,
124 138 symbol: "🤝".to_string(),
125 139 color: "PINK".to_string(),
126 − name: "Met".to_string(),
140 + name: "met".to_string(),
127 141 is_date: true,
128 142 is_contact: false,
129 143 },
@@ -131,7 +145,7 @@ impl Default for Init {
131 145 selection: Selection::Selected,
132 146 symbol: "📞".to_string(),
133 147 color: "TEAL".to_string(),
134 − name: "Phone".to_string(),
148 + name: "phone".to_string(),
135 149 is_date: false,
136 150 is_contact: true,
137 151 },
@@ -139,7 +153,7 @@ impl Default for Init {
139 153 selection: Selection::Selected,
140 154 symbol: "📬".to_string(),
141 155 color: "RED".to_string(),
142 − name: "Mailing".to_string(),
156 + name: "mailing".to_string(),
143 157 is_date: false,
144 158 is_contact: true,
145 159 },
@@ -147,11 +161,12 @@ impl Default for Init {
147 161 selection: Selection::Selected,
148 162 symbol: "📧".to_string(),
149 163 color: "GREEN".to_string(),
150 − name: "eMail".to_string(),
164 + name: "email".to_string(),
151 165 is_date: false,
152 166 is_contact: true,
153 167 },
154 168 ],
169 + debugmsgs: vec![],
155 170 }
156 171 }
157 172 }
@@ -224,8 +239,9 @@ enum Steps {
224 239 Welcome,
225 240 Name,
226 241 Birthday,
227 − Birthplace,
242 + Place,
228 243 Of,
244 + With,
229 245 Tiers,
230 246 Traits,
231 247 Review,
@@ -248,7 +264,10 @@ impl fmt::Display for DefaultTiers {
248 264
249 265 fn handle_key_event(key_event: KeyEvent) {}
250 266
251 −pub fn run_init(mut terminal: DefaultTerminal) -> Result<(), PplError> {
267 +pub async fn run_init(
268 + mut terminal: DefaultTerminal,
269 + db: DatabaseConnection,
270 +) -> Result<(), PplError> {
252 271 let mut app = Init::default();
253 272 loop {
254 273 terminal.draw(|f| render(f, &mut app))?;
@@ -274,7 +293,7 @@ pub fn run_init(mut terminal: DefaultTerminal) -> Result<(), PplError> {
274 293 split.reverse();
275 294 app.name = split.pop().unwrap().to_string();
276 295 split.reverse();
277 − app.nicks = split
296 + app.aliases = split
278 297 .iter()
279 298 .map(|s| s.to_string())
280 299 .collect::<Vec<String>>();
@@ -302,9 +321,9 @@ pub fn run_init(mut terminal: DefaultTerminal) -> Result<(), PplError> {
302 321 }
303 322 }
304 323 }
305 − Steps::Birthplace => {
324 + Steps::Place => {
306 325 if app.input.value() != "".to_string() {
307 − app.birthplace = app.input.value().into();
326 + app.place = app.input.value().into();
308 327 app.input.reset();
309 328 app.step = next(&app.step).unwrap();
310 329 }
@@ -322,6 +341,17 @@ pub fn run_init(mut terminal: DefaultTerminal) -> Result<(), PplError> {
322 341 app.step = next(&app.step).unwrap();
323 342 }
324 343 }
344 + Steps::With => {
345 + app.with_ppl = app
346 + .input
347 + .value()
348 + .to_string()
349 + .split(",")
350 + .map(|s| s.trim().to_string())
351 + .collect::<Vec<String>>();
352 + app.input.reset();
353 + app.step = next(&app.step).unwrap();
354 + }
325 355 Steps::Tiers => match app.tier_editing {
326 356 Selection::Selected => {
327 357 app.tier_add(app.input.value().to_string());
@@ -336,7 +366,274 @@ pub fn run_init(mut terminal: DefaultTerminal) -> Result<(), PplError> {
336 366 app.input.reset();
337 367 app.step = next(&app.step).unwrap();
338 368 }
339 − Steps::Review => {}
369 + Steps::Review => {
370 + if key_event.modifiers.contains(KeyModifiers::ALT) {
371 + // let rt = tokio::runtime::Builder::new_current_thread()
372 + // .enable_all()
373 + // .build()?;
374 + // Ppl::insert()
375 + app.debugmsgs.push(("---".to_string(), "---".to_string()));
376 + let p = ppl::ActiveModel {
377 + id: Default::default(),
378 + name: Set(app.name.clone()),
379 + me: Set(true),
380 + date_ins: Set(Local::today().naive_local()),
381 + date_up: Set(Local::today().naive_local()),
382 + };
383 + let pp: ppl::Model = p.insert(&db).await?;
384 + app.debugmsgs.push(("ppid".to_string(), pp.id.to_string()));
385 +
386 + if !app.aliases.is_empty() {
387 + let alias_am = app
388 + .aliases
389 + .iter()
390 + .map(|alias| traits::ActiveModel {
391 + id: Default::default(),
392 + ppl_id: Set(pp.id.clone()),
393 + key: Set("alias".to_string()),
394 + value: Set(alias.clone()),
395 + hidden: Set(false),
396 + date_ins: Set(Local::today().naive_local()),
397 + date_up: Set(Local::today().naive_local()),
398 + })
399 + .collect::<Vec<traits::ActiveModel>>();
400 + let aliases = Traits::insert_many(alias_am).exec(&db).await;
401 + match aliases {
402 + Ok(res) => app.debugmsgs.push((
403 + "alias-ok.".to_string(),
404 + res.last_insert_id.to_string(),
405 + )),
406 + Err(err) => {
407 + app.debugmsgs
408 + .push(("alias-err".to_string(), err.to_string()));
409 + }
410 + }
411 + }
412 +
413 + let b = sig_date::ActiveModel {
414 + id: Default::default(),
415 + ppl_id: Set(pp.id.clone()),
416 + date: Set(app.bday.clone()),
417 + event: Set("birthday".to_string()),
418 + do_remind: Set(true),
419 + with_ppl: Default::default(),
420 + date_ins: Set(Local::today().naive_local()),
421 + date_up: Set(Local::today().naive_local()),
422 + };
423 +
424 + let bb = b.insert(&db).await;
425 + match bb {
426 + Ok(res) => app
427 + .debugmsgs
428 + .push(("bd-ok.".to_string(), res.id.to_string())),
429 + Err(err) => {
430 + app.debugmsgs.push(("bd-err".to_string(), err.to_string()));
431 + }
432 + }
433 + //
434 + let pl = contact::ActiveModel {
435 + id: Default::default(),
436 + ppl_id: Set(pp.id.clone()),
437 + r#type: Set("address".to_string()),
438 + designator: Default::default(),
439 + value: Set(app.place.clone()),
440 + date_acq: Set(Local::today().naive_local()),
441 + date_ins: Set(Local::today().naive_local()),
442 + date_up: Set(Local::today().naive_local()),
443 + };
444 + //
445 + let plpl = pl.insert(&db).await;
446 + match plpl {
447 + Ok(res) => app
448 + .debugmsgs
449 + .push(("ct-ok.".to_string(), res.id.to_string())),
450 + Err(err) => {
451 + app.debugmsgs.push(("ct-err".to_string(), err.to_string()));
452 + }
453 + }
454 + if !app.of_ppl.is_empty() {
455 + for ofppl in &app.of_ppl {
456 + let of = ppl::ActiveModel {
457 + id: Default::default(),
458 + name: Set(ofppl.clone()),
459 + me: Set(false),
460 + date_ins: Set(Local::today().naive_local()),
461 + date_up: Set(Local::today().naive_local()),
462 + };
463 + let ofof = of.insert(&db).await;
464 + match ofof {
465 + Ok(res) => {
466 + app.debugmsgs.push((
467 + "ofppl-ok.".to_string(),
468 + res.id.to_string(),
469 + ));
470 +
471 + let r = relation::ActiveModel {
472 + id: Default::default(),
473 + ppl_id_a: Set(pp.id),
474 + ppl_id_b: Set(res.id),
475 + r#type: Set("parent".to_string()),
476 + date_entered: Set(Option::from(app.bday)),
477 + date_ended: Default::default(),
478 + superseded: Set(false),
479 + date_ins: Set(Local::today().naive_local()),
480 + date_up: Set(Local::today().naive_local()),
481 + };
482 +
483 + let rr = r.insert(&db).await;
484 + match rr {
485 + Ok(res) => app.debugmsgs.push((
486 + "ofppl-rel-ok.".to_string(),
487 + res.id.to_string(),
488 + )),
489 + Err(err) => {
490 + app.debugmsgs.push((
491 + "ofppl-rel-err".to_string(),
492 + err.to_string(),
493 + ));
494 + }
495 + }
496 + }
497 + Err(err) => {
498 + app.debugmsgs.push((
499 + "ofppl-err".to_string(),
500 + err.to_string(),
501 + ));
502 + }
503 + }
504 + }
505 + }
506 +
507 + if !app.with_ppl.is_empty() {
508 + for ofppl in &app.with_ppl {
509 + let of = ppl::ActiveModel {
510 + id: Default::default(),
511 + name: Set(ofppl.clone()),
512 + me: Set(false),
513 + date_ins: Set(Local::today().naive_local()),
514 + date_up: Set(Local::today().naive_local()),
515 + };
516 + let ofof = of.insert(&db).await;
517 + match ofof {
518 + Ok(res) => {
519 + app.debugmsgs.push((
520 + "wppl-ok.".to_string(),
521 + res.id.to_string(),
522 + ));
523 +
524 + let r = relation::ActiveModel {
525 + id: Default::default(),
526 + ppl_id_a: Set(pp.id),
527 + ppl_id_b: Set(res.id),
528 + r#type: Set("sibling".to_string()),
529 + date_entered: Set(None),
530 + date_ended: Default::default(),
531 + superseded: Set(false),
532 + date_ins: Set(Local::today().naive_local()),
533 + date_up: Set(Local::today().naive_local()),
534 + };
535 +
536 + let rr = r.insert(&db).await;
537 + match rr {
538 + Ok(res) => app.debugmsgs.push((
539 + "wppl-rel-ok.".to_string(),
540 + res.id.to_string(),
541 + )),
542 + Err(err) => {
543 + app.debugmsgs.push((
544 + "wppl-rel-err".to_string(),
545 + err.to_string(),
546 + ));
547 + }
548 + }
549 + }
550 + Err(err) => {
551 + app.debugmsgs.push((
552 + "wppl-err".to_string(),
553 + err.to_string(),
554 + ));
555 + }
556 + }
557 + }
558 + }
559 +
560 + //
561 + if !app.tier_list.is_empty() {
562 + let tier_am = app
563 + .tier_list
564 + .iter()
565 + .filter(|t| t.selection == Selection::Selected)
566 + .map(|tier| tier_defaults::ActiveModel {
567 + id: Default::default(),
568 + key: Set(tier.name.clone()),
569 + default: Set(true),
570 + enabled: Set(true),
571 + color: Default::default(),
572 + symbol: Default::default(),
573 + date_ins: Set(Local::today().naive_local()),
574 + date_up: Set(Local::today().naive_local()),
575 + })
576 + .collect::<Vec<tier_defaults::ActiveModel>>();
577 +
578 + let tttt = TierDefaults::insert_many(tier_am).exec(&db).await;
579 + match tttt {
580 + Ok(res) => app.debugmsgs.push((
581 + "tl-ok.".to_string(),
582 + res.last_insert_id.to_string(),
583 + )),
584 + Err(err) => {
585 + app.debugmsgs
586 + .push(("tl-err".to_string(), err.to_string()));
587 + }
588 + }
589 + }
590 +
591 + if !app.trait_list.is_empty() {
592 + let trait_am = app.trait_list.iter().map(|dtrait|
593 + trait_defaults::ActiveModel {
594 + id: Default::default(),
595 + key: Set(dtrait.name.clone()),
596 + default: Set(true),
597 + enabled: Set(true),
598 + is_date: Set(dtrait.is_date),
599 + is_contact: Set(dtrait.is_contact),
600 + color: Set(dtrait.color.clone()),
601 + symbol: Set(dtrait.symbol.clone()),
602 + date_ins: Set(Local::today().naive_local()),
603 + date_up: Set(Local::today().naive_local()),
604 + }).collect::<Vec<trait_defaults::ActiveModel>>();
605 +
606 + let trtr = TraitDefaults::insert_many(trait_am).exec(&db).await;
607 + match trtr {
608 + Ok(res) => app.debugmsgs.push((
609 + "tr-ok.".to_string(),
610 + res.last_insert_id.to_string(),
611 + )),
612 + Err(err) => {
613 + app.debugmsgs
614 + .push(("tr-err".to_string(), err.to_string()));
615 + }
616 + }
617 + }
618 + //
619 + // for dtrait in &app.trait_list {
620 + // let trt = trait_default::ActiveModel {
621 + // id: Default::default(),
622 + // key: Set(dtrait.name.clone()),
623 + // default: Set(true),
624 + // enabled: Set(true),
625 + // is_date: Set(dtrait.is_date),
626 + // is_contact: Set(dtrait.is_contact),
627 + // color: Set(dtrait.color.clone()),
628 + // symbol: Set(dtrait.symbol.clone()),
629 + // date_ins: Set(Local::today().naive_local()),
630 + // date_up: Set(Local::today().naive_local()),
631 + // };
632 + //
633 + // let trttrt: trait_default::Model = trt.insert(&db).await?;
634 + // }
635 + }
636 + }
340 637 },
341 638 KeyCode::Backspace => {
342 639 if app.input.value() == "" {
@@ -347,25 +644,30 @@ pub fn run_init(mut terminal: DefaultTerminal) -> Result<(), PplError> {
347 644 }
348 645 Steps::Birthday => {
349 646 app.name = "".to_string();
350 − app.nicks = vec![];
647 + app.aliases = vec![];
351 648 app.input.reset();
352 649 app.step = previous(&app.step).unwrap();
353 650 }
354 − Steps::Birthplace => {
651 + Steps::Place => {
355 652 app.bday = NaiveDate::default();
356 653 app.input.reset();
357 654 app.step = previous(&app.step).unwrap();
358 655 }
359 656 Steps::Of => {
360 − app.birthplace = "".to_string();
657 + app.place = "".to_string();
361 658 app.input.reset();
362 659 app.step = previous(&app.step).unwrap();
363 660 }
364 − Steps::Tiers => {
661 + Steps::With => {
365 662 app.of_ppl = vec![];
366 663 app.input.reset();
367 664 app.step = previous(&app.step).unwrap();
368 665 }
666 + Steps::Tiers => {
667 + app.with_ppl = vec![];
668 + app.input.reset();
669 + app.step = previous(&app.step).unwrap();
670 + }
369 671 Steps::Traits => {
370 672 app.input.reset();
371 673 app.step = previous(&app.step).unwrap();
@@ -480,67 +782,77 @@ fn render(f: &mut Frame, app: &mut Init) {
480 782 .block(Block::default().borders(Borders::ALL).title("Input"));
481 783
482 784 let mname: String = app.name.clone();
483 − let mnicks: String = app.nicks.join(", ");
785 + let mnicks: String = app.aliases.join(", ");
484 786 let mbday = app.bday.clone();
485 − let mplace = app.birthplace.clone();
787 + let mplace = app.place.clone();
486 788 let mut messages = vec![
487 − ("name", mname),
488 − ("nicks", mnicks),
489 − ("bday", mbday.to_string()),
490 − ("place", mplace),
789 + ("name".to_string(), mname),
790 + ("nicks".to_string(), mnicks),
791 + ("bday".to_string(), mbday.to_string()),
792 + ("place".to_string(), mplace),
491 793 ];
492 794
795 + // display elements
796 + let oflist = &app
797 + .of_ppl
798 + .iter()
799 + .map(|x| x.to_string())
800 + .collect::<Vec<String>>()
801 + .join(",");
802 + let withlist = &app
803 + .with_ppl
804 + .iter()
805 + .map(|x| x.to_string())
806 + .collect::<Vec<String>>()
807 + .join(",");
808 + let tierlist = &app
809 + .tier_list
810 + .iter()
811 + .filter(|t| t.selection == Selection::Selected)
812 + .map(|t| t.name.as_str())
813 + .collect::<Vec<_>>()
814 + .join(",");
815 + let traitlist = &app
816 + .trait_list
817 + .iter()
818 + .filter(|t| t.selection == Selection::Selected)
819 + .map(|t| t.name.as_str())
820 + .collect::<Vec<_>>()
821 + .join(",");
493 822 match app.step {
494 823 Steps::Welcome => {}
495 824 Steps::Name => {}
496 825 Steps::Birthday => {}
497 − Steps::Birthplace => {}
826 + Steps::Place => {}
498 827 Steps::Of => {}
828 + Steps::With => {
829 + messages.push(("of".to_string(), oflist.clone()));
830 + }
499 831 Steps::Tiers => {
500 − let oflist = &app.of_ppl.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(",");;
501 − messages.push(("of", oflist.clone()))
832 + messages.push(("of".to_string(), oflist.clone()));
833 + messages.push(("with".to_string(), withlist.clone()));
502 834 }
503 835 Steps::Traits => {
504 − let oflist = &app.of_ppl.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(",");;
505 − messages.push(("of", oflist.clone()));
506 − let tierlist = &app
507 − .tier_list
508 − .iter()
509 − .filter(|t| t.selection == Selection::Selected)
510 − .map(|t| t.name.as_str())
511 − .collect::<Vec<_>>()
512 − .join(",");
513 − messages.push(("circles", tierlist.clone()))
836 + messages.push(("of".to_string(), oflist.clone()));
837 + messages.push(("with".to_string(), withlist.clone()));
838 + messages.push(("circles".to_string(), tierlist.clone()))
514 839 }
515 840 Steps::Review => {
516 − let oflist = &app.of_ppl.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(",");;
517 − messages.push(("of", oflist.clone()));
518 − let tierlist = &app
519 − .tier_list
520 − .iter()
521 − .filter(|t| t.selection == Selection::Selected)
522 − .map(|t| t.name.as_str())
523 − .collect::<Vec<_>>()
524 − .join(",");
525 − messages.push(("circles", tierlist.clone()));
526 − let traitlist = &app
527 − .trait_list
528 − .iter()
529 − .filter(|t| t.selection == Selection::Selected)
530 − .map(|t| t.name.as_str())
531 − .collect::<Vec<_>>()
532 − .join(",");
533 − messages.push(("traits", traitlist.clone()))
841 + messages.push(("of".to_string(), oflist.clone()));
842 + messages.push(("with".to_string(), withlist.clone()));
843 + messages.push(("circles".to_string(), tierlist.clone()));
844 + messages.push(("traits".to_string(), traitlist.clone()))
534 845 }
535 846 }
536 847
848 + messages.extend(app.debugmsgs.clone());
537 849 let messages_v: Vec<ListItem> = messages
538 850 .iter()
539 851 .filter(|(t, i)| **i != "".to_string())
540 852 .enumerate()
541 853 .map(|(i, (t, m))| {
542 854 let content = vec![Line::from(vec![
543 − Span::styled(*t, Style::default().add_modifier(Modifier::BOLD)),
855 + Span::styled(t, Style::default().add_modifier(Modifier::BOLD)),
544 856 Span::raw(format!(": {}", m)),
545 857 ])];
546 858 ListItem::new(content)
@@ -608,10 +920,10 @@ fn render(f: &mut Frame, app: &mut Init) {
608 920 f.render_widget(input, chunks[3]);
609 921 f.render_widget(messages, chunks[4]);
610 922 }
611 − Steps::Birthplace => {
923 + Steps::Place => {
612 924 f.render_widget(
613 925 Span::styled(
614 − "> born where?",
926 + "> where are you at?",
615 927 Style::default().add_modifier(Modifier::BOLD).fg(WHITE),
616 928 ),
617 929 chunks[2],
@@ -630,6 +942,17 @@ fn render(f: &mut Frame, app: &mut Init) {
630 942 f.render_widget(input, chunks[3]);
631 943 f.render_widget(messages, chunks[4]);
632 944 }
945 + Steps::With => {
946 + f.render_widget(
947 + Span::styled(
948 + "> born with? (comma seperated, optional)",
949 + Style::default().add_modifier(Modifier::BOLD).fg(WHITE),
950 + ),
951 + chunks[2],
952 + );
953 + f.render_widget(input, chunks[3]);
954 + f.render_widget(messages, chunks[4]);
955 + }
633 956 Steps::Tiers => {
634 957 let tcs = app.tier_count_string();
635 958 let msg = vec![
modified src/entities/contact.rs
+1 −1
@@ -9,7 +9,7 @@ pub struct Model {
9 9 pub id: i32,
10 10 pub ppl_id: i32,
11 11 pub r#type: String,
12 − pub designator: String,
12 + pub designator: Option<String>,
13 13 pub value: String,
14 14 pub date_acq: Date,
15 15 pub date_ins: Date,
renamed src/entities/entity.rs → src/entities/entitys.rs
+1 −1

Click to load diff…

modified src/entities/mod.rs
+4 −2

Click to load diff…

modified src/entities/prelude.rs
+4 −2

Click to load diff…

modified src/entities/relation.rs
+2 −2

Click to load diff…

modified src/entities/sig_date.rs
+1 −1

Click to load diff…

added src/entities/tier_defaults.rs
+22 −0

Click to load diff…

added src/entities/trait_defaults.rs
+24 −0

Click to load diff…

renamed src/entities/trait.rs → src/entities/traits.rs
+2 −1

Click to load diff…

modified src/main.rs
+78 −16

Click to load diff…

modified src/migrator/m20241220_000002_create_contact.rs
+3 −3

Click to load diff…

modified src/migrator/m20241220_000003_create_entity.rs
+10 −10

Click to load diff…

modified src/migrator/m20241220_000004_create_sig_date.rs
+1 −1

Click to load diff…

modified src/migrator/m20241220_000005_create_trait.rs
+11 −9

Click to load diff…

modified src/migrator/m20241220_000006_create_relation.rs
+2 −2

Click to load diff…

modified src/migrator/m20241222_000008_create_traitsettings.rs
+13 −15

Click to load diff…

added src/migrator/m20241222_000009_create_tiersettings.rs
+68 −0

Click to load diff…

modified src/migrator/mod.rs
+2 −0

Click to load diff…

Parents: 3eb5b38