This commit is contained in:
parent
a0afb6dfd3
commit
fd5f1899c1
4 changed files with 53 additions and 17 deletions
|
|
@ -30,6 +30,20 @@ insert into names(contact_id, sort, name) values
|
|||
(3, 0, 'Eleanor Edgeworth'),
|
||||
(3, 1, 'Eleanor');
|
||||
|
||||
insert into contacts(id, lives_with) values (4, 'Henrietta');
|
||||
insert into names(contact_id, sort, name) values
|
||||
(4, 0, 'Felicia Homeowner');
|
||||
|
||||
insert into contacts(id, lives_with) values (5, 'Henrietta');
|
||||
insert into names(contact_id, sort, name) values
|
||||
(5, 0, 'Gregory Homeowner');
|
||||
|
||||
insert into contacts(id) values (6);
|
||||
insert into names(contact_id, sort, name) values
|
||||
(6, 0, 'Henrietta Homeowner');
|
||||
|
||||
insert into addresses(contact_id, label, value) values
|
||||
(6, null, '123 Main St., Realville, WI 99999');
|
||||
|
||||
insert into journal_entries(id, date, value) values
|
||||
(0, '2020-02-27', 'Lunch with [[Bazel Bagend]] and his wife'),
|
||||
|
|
|
|||
1
migrations/each_user/0009_contact-lives-with.sql
Normal file
1
migrations/each_user/0009_contact-lives-with.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
alter table contacts add column lives_with text not null default '';
|
||||
|
|
@ -11,6 +11,7 @@ pub struct Contact {
|
|||
pub id: DbId,
|
||||
pub birthday: Option<Birthday>,
|
||||
pub manually_freshened_at: Option<DateTime<Utc>>,
|
||||
pub lives_with: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -55,10 +56,13 @@ impl FromRow<'_, SqliteRow> for Contact {
|
|||
.map(|d| d.to_utc())
|
||||
});
|
||||
|
||||
let lives_with: String = row.try_get("lives_with")?;
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
birthday,
|
||||
manually_freshened_at,
|
||||
lives_with,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ mod get {
|
|||
) -> Result<Markup, AppError> {
|
||||
let pool = &state.db(&auth_session.user.unwrap()).pool;
|
||||
let contact: HydratedContact = sqlx::query_as(
|
||||
"select id, birthday, manually_freshened_at, (
|
||||
"select *, (
|
||||
select string_agg(name,'\x1c' order by sort)
|
||||
from names where contact_id = c.id
|
||||
) as names
|
||||
|
|
@ -156,6 +156,12 @@ mod get {
|
|||
"(never)"
|
||||
}
|
||||
}
|
||||
|
||||
@if contact.lives_with.len() > 0 {
|
||||
label { "lives with" }
|
||||
div { (contact.lives_with) }
|
||||
}
|
||||
|
||||
@if addresses.len() == 1 {
|
||||
label { "address" }
|
||||
#addresses {
|
||||
|
|
@ -207,13 +213,18 @@ mod get {
|
|||
) -> Result<Markup, AppError> {
|
||||
let pool = &state.db(&auth_session.user.unwrap()).pool;
|
||||
let contact: HydratedContact = sqlx::query_as(
|
||||
"select id, birthday, manually_freshened_at, (
|
||||
"select *, (
|
||||
select string_agg(name,'\x1c' order by sort)
|
||||
from names where contact_id = c.id
|
||||
) as names, (
|
||||
select jes.date from journal_entries jes
|
||||
join journal_mentions cms on cms.entry_id = jes.id
|
||||
where cms.url = '/contact/'||c.id
|
||||
or cms.url in (
|
||||
select '/group/'||name
|
||||
from groups
|
||||
where contact_id = c.id
|
||||
)
|
||||
order by jes.date desc limit 1
|
||||
) as last_mention_date from contacts c
|
||||
where c.id = $1",
|
||||
|
|
@ -289,6 +300,10 @@ mod get {
|
|||
span x-text="date.length ? date.split('T')[0] : '(never)'" {}
|
||||
input type="button" value="Mark fresh now" x-on:click="date = new Date().toISOString()";
|
||||
}
|
||||
label { "lives with" }
|
||||
div {
|
||||
input name="lives_with" value=(contact.lives_with);
|
||||
}
|
||||
label { "addresses" }
|
||||
div x-data=(json!({ "addresses": addresses, "new_label": "", "new_address": "" })) {
|
||||
template x-for="(address, index) in addresses" x-bind:key="index" {
|
||||
|
|
@ -361,6 +376,7 @@ mod put {
|
|||
name: Option<Vec<String>>,
|
||||
birthday: String,
|
||||
manually_freshened_at: String,
|
||||
lives_with: String,
|
||||
address_label: Option<Vec<String>>,
|
||||
address_value: Option<Vec<String>>,
|
||||
group: Option<Vec<String>>,
|
||||
|
|
@ -400,9 +416,10 @@ mod put {
|
|||
};
|
||||
|
||||
sqlx::query!(
|
||||
"update contacts set (birthday, manually_freshened_at, text_body) = ($1, $2, $3) where id = $4",
|
||||
"update contacts set (birthday, manually_freshened_at, lives_with, text_body) = ($1, $2, $3, $4) where id = $5",
|
||||
birthday,
|
||||
manually_freshened_at,
|
||||
payload.lives_with,
|
||||
text_body,
|
||||
contact_id
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue