A company's office: its GPS position and a photo
The company form has a field for the office's GPS position (migration 0004, column companies.office_gps). It takes what people have at hand: the numbers Google Maps copies, a link to the place on Google Maps or OpenStreetMap, a geo: URI, or degrees, minutes and seconds. It keeps decimal degrees with six decimals and refuses a position outside Thailand, which catches a swapped pair; a short maps.app.goo.gl link is refused with a hint, as it holds no position (src/gps.rs, with unit tests). The company's page has an Office card: the position with links that open it on OpenStreetMap and Google Maps, the newest photo of the office, and a strip that uploads a photo (kind "Photo of the office") and returns to the card. The photos are documents like any other: encrypted on the server and audited. A refused photo shows its errors on the card only; office photos that are PDFs are counted under Company documents. The demo company has a position. Tests: the position read from a link, from degrees, minutes and seconds, the three refusals, the audit entry and its removal; a photo uploaded from the card, shown, and its errors placed.
This commit is contained in:
1 parent
e88bb74e1e
commit
2a6e972b68
14 files changed
+642
-8
No files matched your search
+15
-1
@@ -16,6 +16,7 @@ use sqlx::{PgConnection, PgPool, Postgres, QueryBuilder, Row};
|
||||
use crate::audit::Entity;
|
||||
use crate::dates::{self, Status};
|
||||
use crate::forms::{Errors, Fields, compact_upper, err};
|
||||
use crate::gps;
|
||||
|
||||
/// A record's values as text by field name: what the form shows and the
|
||||
/// checks read. Dates are `YYYY-MM-DD`; references are ids.
|
||||
@@ -39,6 +40,8 @@ pub enum Input {
|
||||
Visa,
|
||||
/// One of the companies.
|
||||
Company,
|
||||
/// A GPS position, kept as "18.796500, 99.008200" (`gps`).
|
||||
Gps,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -438,6 +441,11 @@ const COMPANY_FIELDS: &[Field] = &[
|
||||
field("district", "District (amphoe)", Input::Text),
|
||||
field("province", "Province", Input::Text).suggest("provinces"),
|
||||
field("postal_code", "Postal code", Input::Digits),
|
||||
field("office_gps", "GPS position of the office", Input::Gps)
|
||||
.hint(
|
||||
"As Google Maps copies it: right-click the office on the map and click the numbers. A link to the place works too.",
|
||||
)
|
||||
.wide(),
|
||||
field("phone", "Phone", Input::Text),
|
||||
field("email", "Email", Input::Text),
|
||||
field("signatory", "Authorized director", Input::Text)
|
||||
@@ -643,6 +651,7 @@ pub fn read(kind: &Kind, f: &Fields) -> Values {
|
||||
Input::Digits => raw.trim().replace([' ', '-'], ""),
|
||||
Input::Money => raw.trim().replace([',', ' '], ""),
|
||||
Input::Area => raw.trim().replace("\r\n", "\n"),
|
||||
Input::Gps => gps::parse(raw).map_or_else(|| raw.trim().to_string(), |p| p.text()),
|
||||
_ => raw.trim().to_string(),
|
||||
};
|
||||
(fl.name.to_string(), v)
|
||||
@@ -694,6 +703,11 @@ pub fn validate(kind: &Kind, v: &Values, opts: &Options) -> Errors {
|
||||
err(&mut e, fl.name, "Choose from the list.");
|
||||
}
|
||||
}
|
||||
Input::Gps => {
|
||||
if let Some(msg) = gps::problem(value) {
|
||||
err(&mut e, fl.name, msg);
|
||||
}
|
||||
}
|
||||
Input::Text | Input::Code | Input::Area => {}
|
||||
}
|
||||
}
|
||||
@@ -946,7 +960,7 @@ pub fn form_fields(kind: &Kind, opts: &Options) -> Vec<FormField> {
|
||||
Input::Passport | Input::Visa | Input::Company => {
|
||||
("select", opts.list(fl.input).to_vec())
|
||||
}
|
||||
Input::Text | Input::Code | Input::Digits => ("text", vec![]),
|
||||
Input::Text | Input::Code | Input::Digits | Input::Gps => ("text", vec![]),
|
||||
};
|
||||
FormField {
|
||||
name: fl.name,
|
||||
|
||||
Reference in new issue
Block a user