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, 0, 'Eleanor Edgeworth'),
|
||||||
(3, 1, 'Eleanor');
|
(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
|
insert into journal_entries(id, date, value) values
|
||||||
(0, '2020-02-27', 'Lunch with [[Bazel Bagend]] and his wife'),
|
(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 id: DbId,
|
||||||
pub birthday: Option<Birthday>,
|
pub birthday: Option<Birthday>,
|
||||||
pub manually_freshened_at: Option<DateTime<Utc>>,
|
pub manually_freshened_at: Option<DateTime<Utc>>,
|
||||||
|
pub lives_with: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -55,10 +56,13 @@ impl FromRow<'_, SqliteRow> for Contact {
|
||||||
.map(|d| d.to_utc())
|
.map(|d| d.to_utc())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let lives_with: String = row.try_get("lives_with")?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
birthday,
|
birthday,
|
||||||
manually_freshened_at,
|
manually_freshened_at,
|
||||||
|
lives_with,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,12 @@ mod get {
|
||||||
) -> Result<Markup, AppError> {
|
) -> Result<Markup, AppError> {
|
||||||
let pool = &state.db(&auth_session.user.unwrap()).pool;
|
let pool = &state.db(&auth_session.user.unwrap()).pool;
|
||||||
let contact: HydratedContact = sqlx::query_as(
|
let contact: HydratedContact = sqlx::query_as(
|
||||||
"select id, birthday, manually_freshened_at, (
|
"select *, (
|
||||||
select string_agg(name,'\x1c' order by sort)
|
select string_agg(name,'\x1c' order by sort)
|
||||||
from names where contact_id = c.id
|
from names where contact_id = c.id
|
||||||
) as names
|
) as names
|
||||||
from contacts c
|
from contacts c
|
||||||
where c.id = $1",
|
where c.id = $1",
|
||||||
)
|
)
|
||||||
.bind(contact_id)
|
.bind(contact_id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
|
|
@ -156,6 +156,12 @@ mod get {
|
||||||
"(never)"
|
"(never)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if contact.lives_with.len() > 0 {
|
||||||
|
label { "lives with" }
|
||||||
|
div { (contact.lives_with) }
|
||||||
|
}
|
||||||
|
|
||||||
@if addresses.len() == 1 {
|
@if addresses.len() == 1 {
|
||||||
label { "address" }
|
label { "address" }
|
||||||
#addresses {
|
#addresses {
|
||||||
|
|
@ -207,16 +213,21 @@ mod get {
|
||||||
) -> Result<Markup, AppError> {
|
) -> Result<Markup, AppError> {
|
||||||
let pool = &state.db(&auth_session.user.unwrap()).pool;
|
let pool = &state.db(&auth_session.user.unwrap()).pool;
|
||||||
let contact: HydratedContact = sqlx::query_as(
|
let contact: HydratedContact = sqlx::query_as(
|
||||||
"select id, birthday, manually_freshened_at, (
|
"select *, (
|
||||||
select string_agg(name,'\x1c' order by sort)
|
select string_agg(name,'\x1c' order by sort)
|
||||||
from names where contact_id = c.id
|
from names where contact_id = c.id
|
||||||
) as names, (
|
) as names, (
|
||||||
select jes.date from journal_entries jes
|
select jes.date from journal_entries jes
|
||||||
join journal_mentions cms on cms.entry_id = jes.id
|
join journal_mentions cms on cms.entry_id = jes.id
|
||||||
where cms.url = '/contact/'||c.id
|
where cms.url = '/contact/'||c.id
|
||||||
order by jes.date desc limit 1
|
or cms.url in (
|
||||||
) as last_mention_date from contacts c
|
select '/group/'||name
|
||||||
where c.id = $1",
|
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",
|
||||||
)
|
)
|
||||||
.bind(contact_id)
|
.bind(contact_id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
|
|
@ -289,6 +300,10 @@ mod get {
|
||||||
span x-text="date.length ? date.split('T')[0] : '(never)'" {}
|
span x-text="date.length ? date.split('T')[0] : '(never)'" {}
|
||||||
input type="button" value="Mark fresh now" x-on:click="date = new Date().toISOString()";
|
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" }
|
label { "addresses" }
|
||||||
div x-data=(json!({ "addresses": addresses, "new_label": "", "new_address": "" })) {
|
div x-data=(json!({ "addresses": addresses, "new_label": "", "new_address": "" })) {
|
||||||
template x-for="(address, index) in addresses" x-bind:key="index" {
|
template x-for="(address, index) in addresses" x-bind:key="index" {
|
||||||
|
|
@ -361,6 +376,7 @@ mod put {
|
||||||
name: Option<Vec<String>>,
|
name: Option<Vec<String>>,
|
||||||
birthday: String,
|
birthday: String,
|
||||||
manually_freshened_at: String,
|
manually_freshened_at: String,
|
||||||
|
lives_with: String,
|
||||||
address_label: Option<Vec<String>>,
|
address_label: Option<Vec<String>>,
|
||||||
address_value: Option<Vec<String>>,
|
address_value: Option<Vec<String>>,
|
||||||
group: Option<Vec<String>>,
|
group: Option<Vec<String>>,
|
||||||
|
|
@ -400,9 +416,10 @@ mod put {
|
||||||
};
|
};
|
||||||
|
|
||||||
sqlx::query!(
|
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,
|
birthday,
|
||||||
manually_freshened_at,
|
manually_freshened_at,
|
||||||
|
payload.lives_with,
|
||||||
text_body,
|
text_body,
|
||||||
contact_id
|
contact_id
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue