|
|
|
@ -43,17 +43,9 @@ impl<'a> RenderedField<'a> { |
|
|
|
|
match &field.kind { |
|
|
|
|
FieldKind::String => { |
|
|
|
|
rendered.kind = "string"; |
|
|
|
|
|
|
|
|
|
if let Some(Value::String(s)) = value { |
|
|
|
|
rendered.value = Cow::Borrowed(&s.as_str()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FieldKind::Text => { |
|
|
|
|
rendered.kind = "text"; |
|
|
|
|
|
|
|
|
|
if let Some(Value::String(s)) = value { |
|
|
|
|
rendered.value = Cow::Borrowed(&s.as_str()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FieldKind::Bool { default } => { |
|
|
|
|
rendered.kind = "bool"; |
|
|
|
@ -117,26 +109,11 @@ impl<'a> RenderedField<'a> { |
|
|
|
|
let group = enum_group.as_ref().unwrap_or(key); |
|
|
|
|
let options = index.free_enums.get(group).unwrap_or(&EMPTY_VEC); |
|
|
|
|
rendered.options = Some(options); |
|
|
|
|
|
|
|
|
|
if let Some(Value::String(s)) = value { |
|
|
|
|
rendered.value = Cow::Borrowed(&s.as_str()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FieldKind::Tags { options } => { |
|
|
|
|
rendered.kind = "tags"; |
|
|
|
|
rendered.options = Some(options); |
|
|
|
|
|
|
|
|
|
if value.is_some() { |
|
|
|
|
rendered.value = serde_json::from_value::<Vec<String>>(value.unwrap().clone()) |
|
|
|
|
.unwrap().join(" ").into(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(Value::Array(items)) = value { |
|
|
|
|
rendered.tags_json = serde_json::to_string(items).unwrap(); |
|
|
|
|
} else { |
|
|
|
|
rendered.tags_json = "[]".into(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
rendered.all_tags_json = serde_json::to_string(options).unwrap(); |
|
|
|
|
} |
|
|
|
|
FieldKind::FreeTags { tag_group } => { |
|
|
|
@ -144,20 +121,33 @@ impl<'a> RenderedField<'a> { |
|
|
|
|
let group = tag_group.as_ref().unwrap_or(key); |
|
|
|
|
let options = index.free_tags.get(group).unwrap_or(&EMPTY_VEC); |
|
|
|
|
|
|
|
|
|
if value.is_some() { |
|
|
|
|
rendered.value = serde_json::from_value::<Vec<String>>(value.unwrap().clone()) |
|
|
|
|
.unwrap().join(" ").into(); |
|
|
|
|
rendered.options = Some(options); |
|
|
|
|
rendered.all_tags_json = "[]".into(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let Some(Value::Array(items)) = value { |
|
|
|
|
rendered.tags_json = serde_json::to_string(items).unwrap(); |
|
|
|
|
// Shared code by multiple variants
|
|
|
|
|
match field.kind { |
|
|
|
|
FieldKind::Text | FieldKind::String => { |
|
|
|
|
if let Some(Value::String(s)) = value { |
|
|
|
|
rendered.value = Cow::Borrowed(&s.as_str()); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
FieldKind::Enum { .. } | FieldKind::FreeEnum { .. } => { |
|
|
|
|
if let Some(Value::String(s)) = value { |
|
|
|
|
rendered.value = Cow::Borrowed(&s.as_str()); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
FieldKind::Tags { .. } | FieldKind::FreeTags { .. } => { |
|
|
|
|
if let Some(v) = value { |
|
|
|
|
rendered.value = serde_json::from_value::<Vec<String>>(v.clone()) |
|
|
|
|
.unwrap().join(" ").into(); |
|
|
|
|
rendered.tags_json = serde_json::to_string(v).unwrap(); |
|
|
|
|
} else { |
|
|
|
|
rendered.tags_json = "[]".into(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
rendered.options = Some(options); |
|
|
|
|
rendered.tags_json = serde_json::to_string(options).unwrap(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
_ => {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rendered |
|
|
|
|