aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn2/wqflask/edit.py38
-rw-r--r--gn2/wqflask/templates/dataset.html49
-rw-r--r--gn2/wqflask/templates/dataset_history.html20
3 files changed, 84 insertions, 23 deletions
diff --git a/gn2/wqflask/edit.py b/gn2/wqflask/edit.py
index 0397296e..ebf8449d 100644
--- a/gn2/wqflask/edit.py
+++ b/gn2/wqflask/edit.py
@@ -154,3 +154,41 @@ def save():
return redirect(
f"/datasets/{request.form.get('label')}"
)
+
+
+def __fetch_dataset_git_history__(
+ git_dir:str , dataset_name: str
+) -> Either:
+ """Fetch the git history of a given dataset."""
+ # Age, Commit, Message, Author
+ dataset_path = Path(git_dir) / "general/datasets/" / dataset_name
+ format_ = "<tr><td><i>%cr</i></td>\
+<td>\
+<a style='color:green;' href='https://git.genenetwork.org/gn-docs/commit/general?id=%H' \
+target='_blank'>%h</a></td>\
+<td>%s</td><td>%an</td></tr>"
+ args = [
+ "git", "-C", str(dataset_path), "log",
+ f"--pretty=format:{format_}"
+ ]
+ results = __run_cmd__(
+ args
+ )
+ return results
+
+
+@metadata.route("<id_>/history")
+def view_history(id_):
+ """View a datasets history"""
+ from gn2.utility.tools import get_setting
+ data = __fetch_dataset_git_history__(
+ Path(get_setting("DATA_DIR"), "gn-docs"), id_
+ ).either(
+ lambda error: flash(f"{error=}", error),
+ lambda x: x
+ )
+ return render_template(
+ "dataset_history.html",
+ name=request.args.get("name",""),
+ data=data.decode()
+ )
diff --git a/gn2/wqflask/templates/dataset.html b/gn2/wqflask/templates/dataset.html
index e4ae34ae..1e2c5bc4 100644
--- a/gn2/wqflask/templates/dataset.html
+++ b/gn2/wqflask/templates/dataset.html
@@ -73,30 +73,27 @@
{% if dataset %}
-<header class="page-header text-justify">
- <h1>
- {% if dataset.title or dataset.label or dataset.altLabel %}
- {{ dataset.title or dataset.label or dataset.altLabel }}
- {% if dataset.title != dataset.altLabel and dataset.label != dataset.altLabel %}
- <br/>
- <small>({{ dataset.altLabel }})</small>
- {% endif %}
- {% else %}
- {{ name }}
- {% endif %}
- <small>
- <sup>
- [&nbsp;
- <a href="" target="_blank">
- View history
- </a>
- &nbsp;]
- </sup>
- </small>
- </h1>
-</header>
-
<div class="container dataset-content">
+ <header class="page-header text-justify">
+ <h1>
+ {% if dataset.title or dataset.label or dataset.altLabel %}
+ {{ dataset.title or dataset.label or dataset.altLabel }}
+ {% if dataset.title != dataset.altLabel and dataset.label != dataset.altLabel %}
+ <br/>
+ <small>({{ dataset.altLabel }})</small>
+ {% endif %}
+ {% else %}
+ {{ name }}
+ {% endif %}
+ <small>
+ <sup>
+ [&nbsp;
+ <a hx-get={{ url_for('metadata.view_history', id_=dataset.id.split('/')[-1], name=name, title=(dataset.title or dataset.label or dataset.altLabel)) }} hx-target=".dataset-content" hx-push-url="true" hx-select="#history">History</a>
+ &nbsp;]
+ </sup>
+ </small>
+ </h1>
+ </header>
<div class="panel-about panel panel-info panel-metadata text-muted">
<div class="panel-heading">
<strong>
@@ -358,3 +355,9 @@
{% endif %}
{% endblock %}
+
+{% block js %}
+
+<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='htmx.min.js') }}"></script>
+
+{% endblock %}
diff --git a/gn2/wqflask/templates/dataset_history.html b/gn2/wqflask/templates/dataset_history.html
new file mode 100644
index 00000000..15105410
--- /dev/null
+++ b/gn2/wqflask/templates/dataset_history.html
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+
+{% block content %}
+<section class="container" id="history">
+ {% if data.error %}
+ <p class="lead">There was an error fetching the history.</p>
+ {% else %}
+ <table class=" table-condensed">
+ <tr>
+ <th>Age</th>
+ <th>Commit</th>
+ <th>Summary</th>
+ <th>Author</th>
+ </tr>
+ {{ data|safe }}
+ </table>
+ {% endif %}
+</section>
+
+{% endblock %}