Add checkboxes to turn off sorting and validation

This commit is contained in:
Joscha 2024-11-04 15:57:35 +01:00
parent d30cd79229
commit 14622a1fb2
6 changed files with 61 additions and 15 deletions

View file

@ -27,9 +27,7 @@ label {
grid-column: 2; grid-column: 2;
text-align: center; text-align: center;
} }
#i-name, .twocol {
#i-department,
#mhhr {
grid-column: 2 / 4; grid-column: 2 / 4;
} }
#gfub { #gfub {
@ -57,6 +55,12 @@ label {
justify-content: end; justify-content: end;
align-items: baseline; align-items: baseline;
} }
#check {
grid-column: 2;
}
#validate {
text-align: right;
}
#table { #table {
display: grid; display: grid;
grid: auto-flow / 3fr 1fr 1fr 1fr 1fr 1fr; grid: auto-flow / 3fr 1fr 1fr 1fr 1fr 1fr;

View file

@ -47,7 +47,7 @@ pub async fn get() -> Markup {
input #i-month name="month" type="month" placeholder=(month) value=(month) {} input #i-month name="month" type="month" placeholder=(month) value=(month) {}
label #l-name for="i-name" { "Name, Vorname des/r Beschäftigten:" } label #l-name for="i-name" { "Name, Vorname des/r Beschäftigten:" }
input #i-name name="name" type="text" placeholder="McStudentface, Student" {} input #i-name .twocol name="name" type="text" placeholder="McStudentface, Student" {}
label #l-staffid for="i-staffid" { "Personalnummer:" } label #l-staffid for="i-staffid" { "Personalnummer:" }
input #i-staffid name="staff_id" type="text" placeholder="1337420" {} input #i-staffid name="staff_id" type="text" placeholder="1337420" {}
@ -63,10 +63,10 @@ pub async fn get() -> Markup {
} }
label #l-department for="i-department" title="Organisationseinheit" { "OE:" } label #l-department for="i-department" title="Organisationseinheit" { "OE:" }
input #i-department name="department" type="text" placeholder="Institut für Informatik" value="Institut für Informatik" {} input #i-department .twocol name="department" type="text" placeholder="Institut für Informatik" value="Institut für Informatik" {}
label #l-monthlyhours for="i-monthlyhours" { "Vertraglich vereinbarte Arbeitszeit:" } label #l-monthlyhours for="i-monthlyhours" { "Vertraglich vereinbarte Arbeitszeit:" }
div #mhhr { div #mhhr .twocol {
span { span {
input #i-monthlyhours name="monthly_hours" type="number" value="40" min="0" {} input #i-monthlyhours name="monthly_hours" type="number" value="40" min="0" {}
" Std." " Std."
@ -78,12 +78,22 @@ pub async fn get() -> Markup {
} }
} }
div #carry { div #carry .twocol {
span { span {
label #l-carry for="i-carry" { "Übertrag vom Vormonat: " } label #l-carry for="i-carry" { "Übertrag vom Vormonat: " }
input #i-carry .i-dur name="carry_prev_month" type="text" placeholder="00:00" {} input #i-carry .i-dur name="carry_prev_month" type="text" placeholder="00:00" {}
} }
} }
label #check title="Die Tabelleneinträge werden chronologisch sortiert, anstatt dass ihre Reihenfolge beibehalten wird." {
"Einträge sortieren "
input name="sort" type="checkbox" value="true" checked {}
}
label #validate title="Die Tabelleneinträge werden auf Konsistenz und Korrektheit überprüft, bevor das Dokument generiert wird." {
"Einträge validieren "
input name="validate" type="checkbox" value="true" checked {}
}
} }
div #table { div #table {
@ -133,6 +143,10 @@ pub struct PostForm {
monthly_hours: u32, monthly_hours: u32,
hourly_wage: String, hourly_wage: String,
carry_prev_month: String, carry_prev_month: String,
#[serde(default)]
sort: bool,
#[serde(default)]
validate: bool,
task: Vec<String>, task: Vec<String>,
day: Vec<Option<u32>>, day: Vec<Option<u32>>,
start: Vec<String>, start: Vec<String>,
@ -229,7 +243,8 @@ pub async fn post(form: Form<PostForm>) -> Response {
working_area, working_area,
monthly_hours: form.monthly_hours, monthly_hours: form.monthly_hours,
hourly_wage: form.hourly_wage, hourly_wage: form.hourly_wage,
validate: true, validate: form.validate,
sort: form.sort,
carry_prev_month, carry_prev_month,
year, year,
month, month,

View file

@ -18,7 +18,6 @@ h1 {
label { label {
display: block; display: block;
font-weight: bold; font-weight: bold;
margin-top: 4mm;
} }
textarea { textarea {
display: block; display: block;

View file

@ -44,7 +44,14 @@ submit.addEventListener("click", async () => {
return; return;
} }
const dataJson = JSON.stringify({ global, month }); let sort = data.get("sort") !== null;
let validate = data.get("validate") !== null;
console.log("data", data)
console.log("sort", sort)
console.log("validate", validate)
const dataJson = JSON.stringify({ global, month, sort, validate });
try { try {
const response = await fetch(".", { const response = await fetch(".", {

View file

@ -30,11 +30,27 @@ pub async fn get() -> Markup {
" eingeben." " eingeben."
} }
p {
label for="i-global" { "Global.json" } label for="i-global" { "Global.json" }
textarea #i-global name="global" placeholder="{}" {} textarea #i-global name="global" placeholder="{}" {}
}
p {
label for="i-month" { "Month.json" } label for="i-month" { "Month.json" }
textarea #i-month name="month" placeholder="{}" {} textarea #i-month name="month" placeholder="{}" {}
}
p {
label title="Die Einträge werden chronologisch sortiert, anstatt dass ihre Reihenfolge beibehalten wird." {
input name="sort" type="checkbox" checked {}
" Einträge sortieren"
}
label title="Die Einträge werden auf Konsistenz und Korrektheit überprüft, bevor das Dokument generiert wird." {
input name="validate" type="checkbox" checked {}
" Einträge validieren"
}
}
button #submit type="button" { "Arbeitszeitdokumentation generieren" } button #submit type="button" { "Arbeitszeitdokumentation generieren" }
@ -82,6 +98,8 @@ pub struct MonthJson {
pub struct PostJson { pub struct PostJson {
global: GlobalJson, global: GlobalJson,
month: MonthJson, month: MonthJson,
sort: bool,
validate: bool,
} }
fn error_response<S: ToString>(msg: S) -> Response { fn error_response<S: ToString>(msg: S) -> Response {
@ -149,7 +167,8 @@ pub async fn post(json: Json<PostJson>) -> Response {
working_area, working_area,
monthly_hours, monthly_hours,
hourly_wage: json.global.wage.to_string(), hourly_wage: json.global.wage.to_string(),
validate: true, validate: json.validate,
sort: json.sort,
carry_prev_month: json.month.pred_transfer, carry_prev_month: json.month.pred_transfer,
year: json.month.year, year: json.month.year,
month: json.month.month, month: json.month.month,

View file

@ -51,6 +51,7 @@ pub struct Timesheet {
pub monthly_hours: u32, pub monthly_hours: u32,
pub hourly_wage: String, pub hourly_wage: String,
pub validate: bool, pub validate: bool,
pub sort: bool,
pub carry_prev_month: Option<String>, pub carry_prev_month: Option<String>,
pub year: u32, pub year: u32,
pub month: u32, pub month: u32,
@ -137,6 +138,7 @@ fn fmt_timesheet(ts: Timesheet) -> String {
lines.push(format!(" monthly_hours: {},", fmt_int(ts.monthly_hours))); lines.push(format!(" monthly_hours: {},", fmt_int(ts.monthly_hours)));
lines.push(format!(" hourly_wage: {},", fmt_str(&ts.hourly_wage))); lines.push(format!(" hourly_wage: {},", fmt_str(&ts.hourly_wage)));
lines.push(format!(" validate: {},", fmt_bool(ts.validate))); lines.push(format!(" validate: {},", fmt_bool(ts.validate)));
lines.push(format!(" sort: {},", fmt_bool(ts.sort)));
if let Some(carry) = ts.carry_prev_month { if let Some(carry) = ts.carry_prev_month {
lines.push(format!(" carry_prev_month: {},", fmt_str(&carry))); lines.push(format!(" carry_prev_month: {},", fmt_str(&carry)));
} }