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