Skip to content

Commit 3f14b85

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] server: update html repr to have dyn indentation
1 parent 8ca0f32 commit 3f14b85

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

server/src/core/config.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl ConfigFile {
117117
val.get("value").is_some() && val.get("sources").is_some() && val.get("sources").unwrap().is_array()
118118
}
119119

120-
fn render_field(key: &str, value: &serde_json::Value) -> String {
120+
fn render_field(key: &str, value: &serde_json::Value, ident: usize) -> String {
121121
let mut rows = String::new();
122122
if is_sourced_field(value) {
123123
let val = &value["value"];
@@ -131,7 +131,7 @@ impl ConfigFile {
131131
// Nested object
132132
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{} = {{</div><div class=\"toml-right\"></div></div>\n", key));
133133
for (k, v) in val.as_object().unwrap() {
134-
for line in render_field(k, v).lines() {
134+
for line in render_field(k, v, ident + 1).lines() {
135135
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\"> {}</div></div>\n", line));
136136
}
137137
}
@@ -148,15 +148,15 @@ impl ConfigFile {
148148
.map(render_source)
149149
.collect::<Vec<_>>()
150150
.join(", ");
151-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\"> {},</div><div class=\"toml-right\">{}</div></div>\n", item_val, item_rendered_src));
151+
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{}{},</div><div class=\"toml-right\">{}</div></div>\n", " ".repeat((ident + 1) * 2), item_val, item_rendered_src));
152152
} else {
153-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\"> {},</div><div class=\"toml-right\">{}</div></div>\n", item, rendered_src));
153+
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{}{},</div><div class=\"toml-right\">{}</div></div>\n", " ".repeat((ident + 1) * 2), item, rendered_src));
154154
}
155155
}
156156
rows.push_str("<div class=\"toml-row\"><div class=\"toml-left\">]</div><div class=\"toml-right\"></div></div>\n");
157157
} else {
158158
// Single value
159-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{} = {}</div><div class=\"toml-right\">{}</div></div>\n", key, val, rendered_src));
159+
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{}{} = {}</div><div class=\"toml-right\">{}</div></div>\n", " ".repeat(ident * 2), key, val, rendered_src));
160160
}
161161
} else if value.is_array() {
162162
// Array of Sourced or primitive values
@@ -170,24 +170,24 @@ impl ConfigFile {
170170
.map(render_source)
171171
.collect::<Vec<_>>()
172172
.join(", ");
173-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\"> {},</div><div class=\"toml-right\">{}</div></div>\n", item_val, item_rendered_src));
173+
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{}{},</div><div class=\"toml-right\">{}</div></div>\n", " ".repeat((ident + 1) * 2), item_val, item_rendered_src));
174174
} else {
175-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\"> {},</div><div class=\"toml-right\"></div></div>\n", item));
175+
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{}{},</div><div class=\"toml-right\"></div></div>\n", " ".repeat((ident + 1) * 2), item));
176176
}
177177
}
178178
rows.push_str("<div class=\"toml-row\"><div class=\"toml-left\">]</div><div class=\"toml-right\"></div></div>\n");
179179
} else if value.is_object() && !value.is_null() {
180180
// Nested object
181181
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{} = {{</div><div class=\"toml-right\"></div></div>\n", key));
182182
for (k, v) in value.as_object().unwrap() {
183-
for line in render_field(k, v).lines() {
184-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\"> {}</div></div>\n", line));
183+
for line in render_field(k, v, ident + 1).lines() {
184+
rows.push_str(line);
185185
}
186186
}
187187
rows.push_str("<div class=\"toml-row\"><div class=\"toml-left\">}</div><div class=\"toml-right\"></div></div>\n");
188188
} else {
189189
// Primitive value
190-
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{} = {}</div><div class=\"toml-right\"></div></div>\n", key, value));
190+
rows.push_str(&format!("<div class=\"toml-row\"><div class=\"toml-left\">{}{} = {}</div><div class=\"toml-right\"></div></div>\n", " ".repeat(ident * 2), key, value));
191191
}
192192
rows
193193
}
@@ -233,7 +233,7 @@ impl ConfigFile {
233233
];
234234
for key in order {
235235
if let Some(val) = map.get(key) {
236-
entry_html.push_str(&render_field(key, val));
236+
entry_html.push_str(&render_field(key, val, 0));
237237
}
238238
}
239239
}
@@ -671,17 +671,17 @@ fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<HashMap<String, Conf
671671

672672
let config = raw.config.into_iter().map(|mut entry| {
673673
// odoo_path
674-
entry.odoo_path.as_mut().map(|sourced| { sourced.sources.insert(path.sanitize());});
674+
entry.odoo_path.iter_mut().for_each(|sourced| { sourced.sources.insert(path.sanitize());});
675675

676676
// addons_paths
677-
entry.addons_paths.as_mut().map(|paths| {
677+
entry.addons_paths.iter_mut().for_each(|paths| {
678678
paths.iter_mut().for_each(|sourced| {
679679
sourced.sources.insert(path.sanitize());
680680
});
681681
});
682682

683683
// additional_stubs
684-
entry.additional_stubs.as_mut().map(|stubs| {
684+
entry.additional_stubs.iter_mut().for_each(|stubs| {
685685
stubs.iter_mut().for_each(|sourced| {
686686
sourced.sources.insert(path.sanitize());
687687
});
@@ -700,6 +700,9 @@ fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<HashMap<String, Conf
700700
entry.auto_refresh_delay.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
701701
entry.add_workspace_addon_path.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
702702
entry.version.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
703+
entry.diagnostic_settings.values_mut().for_each(|sourced| {
704+
sourced.sources.insert(path.sanitize());
705+
});
703706

704707
(entry.name.clone(), entry)
705708
}).collect();

0 commit comments

Comments
 (0)