diff --git a/src/main.rs b/src/main.rs index 678969a..3abad41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,7 @@ fn route_index(store: State>, page: Option) -> Template { let mut page = page.unwrap_or_default(); let n_pages = (rg.data.cards.len() as f64 / PER_PAGE as f64).ceil() as usize; - if page >= n_pages { + if page >= n_pages && page != 0 { page = n_pages - 1; } diff --git a/src/store/form.rs b/src/store/form.rs index 1a8a6df..6532ed7 100644 --- a/src/store/form.rs +++ b/src/store/form.rs @@ -23,6 +23,7 @@ pub struct RenderedField<'a> { pub max: String, pub all_tags_json: String, pub tags_json: String, + pub tags: Option>, pub options: Option>, pub value: Cow<'a, str>, pub checked: bool, @@ -118,7 +119,6 @@ impl<'a> RenderedField<'a> { FieldKind::Tags { options } => { rendered.kind = "tags"; rendered.options = Some(options.iter().collect()); - rendered.all_tags_json = serde_json::to_string(options).unwrap(); } FieldKind::FreeTags { tag_group } => { @@ -145,12 +145,12 @@ impl<'a> RenderedField<'a> { } FieldKind::Tags { .. } | FieldKind::FreeTags { .. } => { if let Some(v) = value { - rendered.value = serde_json::from_value::>(v.clone()) - .unwrap() - .join(" ") - .into(); + let tags = serde_json::from_value::>(v.clone()).unwrap(); + rendered.value = tags.join(",").into(); + rendered.tags = Some(tags); rendered.tags_json = serde_json::to_string(v).unwrap(); } else { + rendered.tags = Some(vec![]); rendered.tags_json = "[]".into(); } } @@ -274,7 +274,7 @@ pub fn collect_card_form(store: &Store, mut form: MapFromForm) -> IndexMap { let mut tags: Vec = input - .split(' ') + .split(',') .map(ToOwned::to_owned) .filter_map(|tag| { if options.contains(&tag) { @@ -291,7 +291,7 @@ pub fn collect_card_form(store: &Store, mut form: MapFromForm) -> IndexMap { let mut tags: Vec = input - .split(' ') + .split(',') .map(str::trim) .filter(|s| !s.is_empty()) .map(ToOwned::to_owned) diff --git a/templates/_form_macros.html.tera b/templates/_form_macros.html.tera index 572dc83..ad2c0c1 100644 --- a/templates/_form_macros.html.tera +++ b/templates/_form_macros.html.tera @@ -104,7 +104,7 @@ let hiden_field = document.querySelector('#field-{{field.key}}'); let onchange = () => { - let values = taggle.tag.values.join(" "); + let values = taggle.tag.values.join(","); hiden_field.setAttribute("value", values); }; diff --git a/templates/index.html.tera b/templates/index.html.tera index 283f3b3..7358593 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -28,17 +28,27 @@ Delete {%- for field in card.fields %} - {%- if field.kind == "bool" -%} + {% if field.checked %} ✔ {% else %} ✘ {% endif %} + + + {%- elif field.kind == "tags" or field.kind == "free_tags" -%} + + {% for tag in field.tags %} + {{ tag }} + {% endfor %} + + {%- else -%} + {{ field.value }} - {%- endif -%} + {%- endif -%} {%- endfor %} {% endfor %} diff --git a/templates/static/style.css b/templates/static/style.css index 2b04dac..d199ec4 100644 --- a/templates/static/style.css +++ b/templates/static/style.css @@ -143,6 +143,18 @@ textarea:focus, border-bottom: 2px solid silver; } +.cards-table td.tags { + padding: .25rem; +} + +.cards-table .tag { + background: #E2E1DF; + font-size: 90%; + padding: 0.25rem .45rem; + border-radius: 3px; + display: inline-block; +} + .paginate { margin: 1rem auto; width: 300px; @@ -182,3 +194,4 @@ textarea:focus, color: gray; background: transparent; } +