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
+14
-2
@@ -195,7 +195,19 @@ pub async fn company_page(
|
||||
let candidates = companies::candidates(&st.db, id).await?;
|
||||
let owner = Owner::Company(id);
|
||||
let docs = documents::views(st, owner, &HashMap::new()).await?;
|
||||
let upload = documents::upload_context(st, owner, values, errors, &[]);
|
||||
let office = documents::office_context(st, &docs, values, errors);
|
||||
// a refused office photo shows its errors on the office card only
|
||||
let upload = if values.from_office() {
|
||||
documents::upload_context(
|
||||
st,
|
||||
owner,
|
||||
&documents::Values::default(),
|
||||
&Errors::new(),
|
||||
&[],
|
||||
)
|
||||
} else {
|
||||
documents::upload_context(st, owner, values, errors, &[])
|
||||
};
|
||||
let title = c.name.clone();
|
||||
Ok(page(
|
||||
st,
|
||||
@@ -204,7 +216,7 @@ pub async fn company_page(
|
||||
&title,
|
||||
"companies",
|
||||
status,
|
||||
context! { c, employees, candidates, docs, upload },
|
||||
context! { c, employees, candidates, docs, upload, office },
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
+48
-1
@@ -51,6 +51,9 @@ pub struct Values {
|
||||
pub link: String,
|
||||
pub dated_on: String,
|
||||
pub note: String,
|
||||
/// Where an upload came from: "office" for the office card of a
|
||||
/// company's page, which it returns to.
|
||||
pub back: String,
|
||||
}
|
||||
|
||||
impl Values {
|
||||
@@ -60,6 +63,7 @@ impl Values {
|
||||
link: documents::link_value(d.link()),
|
||||
dated_on: d.dated_on.map(|d| d.to_string()).unwrap_or_default(),
|
||||
note: d.note.clone(),
|
||||
back: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,14 +73,21 @@ impl Values {
|
||||
link: forms::get(f, "link"),
|
||||
dated_on: forms::get(f, "dated_on"),
|
||||
note: forms::get(f, "note"),
|
||||
back: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The upload came from the office card of a company's page.
|
||||
pub fn from_office(&self) -> bool {
|
||||
self.back == "office"
|
||||
}
|
||||
}
|
||||
|
||||
/// A document as the pages show it.
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct DocView {
|
||||
pub id: i64,
|
||||
pub kind: String,
|
||||
pub kind_label: String,
|
||||
pub link_label: String,
|
||||
pub link_href: String,
|
||||
@@ -209,6 +220,7 @@ fn view(d: &Document, names: &HashMap<String, (String, String)>) -> DocView {
|
||||
.unwrap_or_default();
|
||||
DocView {
|
||||
id: d.id,
|
||||
kind: d.kind.clone(),
|
||||
kind_label: documents::kind_label(owner, &d.kind),
|
||||
link_label,
|
||||
link_href,
|
||||
@@ -265,6 +277,36 @@ fn kinds(owner: Owner) -> Vec<(&'static str, &'static str)> {
|
||||
owner.kinds().iter().map(|k| (k.slug, k.label)).collect()
|
||||
}
|
||||
|
||||
/// The office card of a company's page: the newest photo of the office that
|
||||
/// is an image, how many more there are, and the strip that adds one (with
|
||||
/// its errors when an upload from it was refused).
|
||||
pub fn office_context(
|
||||
st: &AppState,
|
||||
docs: &[DocView],
|
||||
values: &Values,
|
||||
errors: &Errors,
|
||||
) -> minijinja::Value {
|
||||
let all = docs.iter().filter(|d| d.kind == "office-photo").count();
|
||||
let photo = docs
|
||||
.iter()
|
||||
.filter(|d| d.kind == "office-photo" && d.image)
|
||||
.max_by_key(|d| d.id);
|
||||
let errors = if values.from_office() {
|
||||
errors.clone()
|
||||
} else {
|
||||
Errors::new()
|
||||
};
|
||||
context! {
|
||||
files_on => st.files.is_some(),
|
||||
photo,
|
||||
// the other photos of the office, PDFs among them
|
||||
more => all - usize::from(photo.is_some()),
|
||||
errors,
|
||||
file_limit_mb => FILE_LIMIT / (1024 * 1024),
|
||||
file_limit => FILE_LIMIT,
|
||||
}
|
||||
}
|
||||
|
||||
/// The upload part of a page: on the Documents tab and the company's page.
|
||||
pub fn upload_context(
|
||||
st: &AppState,
|
||||
@@ -475,6 +517,7 @@ async fn read_upload(
|
||||
"link" => up.values.link = text,
|
||||
"dated_on" => up.values.dated_on = text,
|
||||
"note" => up.values.note = text,
|
||||
"back" => up.values.back = text,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -704,7 +747,11 @@ pub async fn upload(st: Arc<AppState>, user: User, owner: Owner, mp: Multipart)
|
||||
};
|
||||
}
|
||||
let first = save(&st, &user, &store, owner, &meta, checked).await?;
|
||||
Ok(Redirect::to(&format!("{}#doc-{first}", list_page(owner))).into_response())
|
||||
let to = match owner {
|
||||
Owner::Company(id) if values.from_office() => format!("/companies/{id}#office"),
|
||||
_ => format!("{}#doc-{first}", list_page(owner)),
|
||||
};
|
||||
Ok(Redirect::to(&to).into_response())
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
||||
Reference in new issue
Block a user