Skip to content

Commit dff23c5

Browse files
committed
Add search capability to CSET UI
Additionally included is a conversion of the index to JSON Lines (In theory it should be more efficient, but in practice we still load the whole string first. At least it looks nicer in the index file.) Non-useful entries are removed from the index before it is written, so it only contains information the client will need.
1 parent f1f2745 commit dff23c5

File tree

5 files changed

+834
-184
lines changed

5 files changed

+834
-184
lines changed

src/CSET/cset_workflow/app/finish_website/bin/finish_website.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from importlib.metadata import version
3030
from pathlib import Path
3131

32-
from CSET._common import combine_dicts, sort_dict
32+
from CSET._common import sort_dict
3333

3434
logging.basicConfig(
3535
level=os.getenv("LOGLEVEL", "INFO"), format="%(asctime)s %(levelname)s %(message)s"
@@ -64,35 +64,25 @@ def install_website_skeleton(www_root_link: Path, www_content: Path):
6464
def construct_index(www_content: Path):
6565
"""Construct the plot index."""
6666
plots_dir = www_content / "plots"
67-
index = {}
68-
# Loop over all diagnostics and append to index.
69-
for metadata_file in plots_dir.glob("**/*/meta.json"):
70-
try:
71-
with open(metadata_file, "rt", encoding="UTF-8") as fp:
72-
plot_metadata = json.load(fp)
73-
74-
category = plot_metadata["category"]
75-
case_date = plot_metadata.get("case_date", "")
76-
relative_url = str(metadata_file.parent.relative_to(plots_dir))
77-
78-
record = {
79-
category: {
80-
case_date if case_date else "Aggregation": {
81-
relative_url: plot_metadata["title"].strip()
82-
}
83-
}
84-
}
85-
except (json.JSONDecodeError, KeyError, TypeError) as err:
86-
logging.error("%s is invalid, skipping.\n%s", metadata_file, err)
87-
continue
88-
index = combine_dicts(index, record)
89-
90-
# Sort index of diagnostics.
91-
index = sort_dict(index)
92-
93-
# Write out website index.
94-
with open(plots_dir / "index.json", "wt", encoding="UTF-8") as fp:
95-
json.dump(index, fp, indent=2)
67+
with open(plots_dir / "index.jsonl", "wt", encoding="UTF-8") as index_fp:
68+
# Loop over all diagnostics and append to index. The glob is sorted to
69+
# ensure a consistent ordering.
70+
for metadata_file in sorted(plots_dir.glob("**/*/meta.json")):
71+
try:
72+
with open(metadata_file, "rt", encoding="UTF-8") as plot_fp:
73+
plot_metadata = json.load(plot_fp)
74+
plot_metadata["path"] = str(metadata_file.parent.relative_to(plots_dir))
75+
# Remove keys that are not useful for the index.
76+
plot_metadata.pop("description", None)
77+
plot_metadata.pop("plots", None)
78+
# Sort plot metadata.
79+
plot_metadata = sort_dict(plot_metadata)
80+
# Write metadata into website index.
81+
json.dump(plot_metadata, index_fp, separators=(",", ":"))
82+
index_fp.write("\n")
83+
except (json.JSONDecodeError, KeyError, TypeError) as err:
84+
logging.error("%s is invalid, skipping.\n%s", metadata_file, err)
85+
continue
9686

9787

9888
def bust_cache(www_content: Path):

src/CSET/cset_workflow/app/finish_website/file/html/index.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414
<header>
1515
<h1>CSET</h1>
1616
<button id="clear-plots">⎚ Clear view</button>
17+
<button id="clear-query">⌫ Clear search</button>
1718
<button id="description-toggle">⇲ Hide description</button>
19+
<search>
20+
<input type="search" name="query" id="filter-query" placeholder="Filter...">
21+
<!-- TODO: Add help for query syntax. -->
22+
<fieldset id="filter-facets">
23+
<legend>Search facets</legend>
24+
</fieldset>
25+
</search>
1826
</header>
19-
<hr>
20-
<!-- Links to diagnostics get inserted here. -->
27+
<ul id="diagnostics">
28+
<!-- Links to diagnostics get inserted here. -->
29+
<loading-throbber></loading-throbber>
30+
</ul>
2131
</nav>
2232
<main>
2333
<article id="single-frame">

0 commit comments

Comments
 (0)