From 1125eddcac0c9b2673dbfb1f62bb0fa9b1ab4054 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 23 Jul 2021 17:48:35 -0700 Subject: web: refactor refs table into separate refs_macros file --- python/fatcat_web/templates/entity_macros.html | 41 ++++++++++- python/fatcat_web/templates/refs_macros.html | 86 ++++++++++++++++++++++ .../templates/release_view_fuzzy_refs.html | 74 +------------------ 3 files changed, 127 insertions(+), 74 deletions(-) create mode 100644 python/fatcat_web/templates/refs_macros.html (limited to 'python') diff --git a/python/fatcat_web/templates/entity_macros.html b/python/fatcat_web/templates/entity_macros.html index 24d1b6d0..ac2b5a15 100644 --- a/python/fatcat_web/templates/entity_macros.html +++ b/python/fatcat_web/templates/entity_macros.html @@ -390,7 +390,7 @@ yellow {# this is useful for things like showing lists of releases in tables #} {% macro release_summary(release) %} -{{ release.title }} + {{ release.title }} {% if release.release_type not in ["article-journal", "conference-paper"] %} [{{ release.release_type or "unknown-type" }}] {% endif %} @@ -411,8 +411,13 @@ yellow {% elif release.extra and release.extra.container_name %} {{ release.extra.container_name }} {% endif %} - {% if release.release_stage != "published" %} -  {{ release.release_stage or "unpublished" }} + + {% if release.release_stage == "submitted" %} +  pre-print + {% elif release.release_stage and release.release_stage != "published" %} +  {{ release.release_stage }} version + {% elif not release.release_stage %} +  unpublished {% endif %}
{% if release.version %} @@ -438,3 +443,33 @@ yellow dblp:{{ release.ext_ids.dblp }}  {% endif %} {% endmacro %} + +{# similar to the release_summary above, but for CSL-JSON #} +{% macro csl_summary(csl) %} + {{ csl.title }} + {% if csl.title and csl.author %}
{% endif %} + {% if csl.author %} + {% for author in csl.author[:5] %} + {# TODO: other name variants? #} + {{ author.name }} + {%- if not loop.last %}, {% endif %} + {% endfor %} + {% if csl.author | length > 5 %} (+ more) {%endif %} + {% endif %} + + {% if csl.issued or csl["container-title"] %}
{% endif %} + {% if csl.issued and csl.issued.raw %}{{ csl.issued.raw }}  {% endif %} + {% if csl["container-title"] %} + {{ csl["container-title"] }} + {% endif %} +
+ {% if csl.volume %} + volume:{{ csl.volume}}  + {% endif %} + {% if csl.DOI %} + doi:{{ csl.DOI }}  + {% endif %} + {% if csl.URL %} + url:{{ csl.URL }}  + {% endif %} +{% endmacro %} diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html new file mode 100644 index 00000000..405aca73 --- /dev/null +++ b/python/fatcat_web/templates/refs_macros.html @@ -0,0 +1,86 @@ +{% import "entity_macros.html" as entity_macros %} + +{% macro pagination_row(hits, direction) %} + + {% if hits.offset %} + « prev   + {% endif %} + Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }} of {{ hits.count_total}} references (in {{ hits.query_wall_time_ms }}ms) + {% if hits.count_total != hits.count_returned and hits.offset + hits.limit < hits.count_total %} +  next » + {% endif %} +{% endmacro %} + +{% macro refs_table(hits, direction) %} + + + + + +{% for row in hits.result_refs %} + {% set release = row.release %} + +{% if hits.count_total != hits.count_returned %} + + +{% endif %} +
+ {{ pagination_row(hits) }} +
+ {# TODO: ref_locator? #} + {% if direction == "out" %} + {% if row.ref.ref_key %} + [{{ row.ref.ref_key }}]
+ {% endif %} + {% endif %} + {{ row.ref.match_status }}
+ {% if row.ref.match_provenance %} + via {{ row.ref.match_provenance }} + {% endif %} +
+ {% if release %} + {{ entity_macros.release_summary(release) }} + {% elif row.ref.target_unstructured %} + {{ row.ref.target_unstructured }} + {% if row.ref.target_openlibrary_work %} +
openlibrary:{{ row.ref.target_openlibrary_work }}  + {% endif %} + {% elif row.ref.target_csl %} + {{ entity_macros.csl_summary(row.ref.target_csl) }} + {% else %} + blank + {% endif %} +
+ {% if row.access %} + {% for access in row.access %} + + {%- if access.access_type.name == "wayback" %} + web.archive.org + {%- elif access.access_type.name == "ia_file" -%} + archive.org + {%- else -%} + {{ access.access_type.name }} + {%- endif -%} + {%- if access.mimetype == "application/pdf" %} + [PDF] + {%- elif access.mimetype == "text/html" %} + [HTML] + {%- endif -%} + +
+ {% endfor %} + {% elif direction == "out" and row.ref.target_unstructured %} +
+ + + +
+ {% endif %} +{% endfor %} +
+ {{ pagination_row(hits) }} +
+{% endmacro %} + diff --git a/python/fatcat_web/templates/release_view_fuzzy_refs.html b/python/fatcat_web/templates/release_view_fuzzy_refs.html index 43860a31..ffca0bc9 100644 --- a/python/fatcat_web/templates/release_view_fuzzy_refs.html +++ b/python/fatcat_web/templates/release_view_fuzzy_refs.html @@ -1,19 +1,9 @@ {% set release = entity %} {% set entity_view = "refs-" + direction %} {% set entity_type = "release" %} -{% import "entity_macros.html" as entity_macros %} +{% import "refs_macros.html" as refs_macros %} {% extends "entity_base.html" %} -{% macro pagination_row(hits) %} - - {% if hits.offset %} - « prev   - {% endif %} - Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }} of {{ hits.count_total}} references (in {{ hits.query_wall_time_ms }}ms) - {% if hits.count_total != hits.count_returned and hits.offset + hits.limit < hits.count_total %} -  next » - {% endif %} -{% endmacro %} {% block entity_main %} @@ -25,66 +15,8 @@ NOTE: currently batch computed and may include additional references sources, or be missing recent changes, compared to entity reference list. {% endif %} -{% if enriched_refs %} - - - - -{% for row in enriched_refs %} - {% set release = row.release %} - -{% if hits.count_total != hits.count_returned %} - - -{% endif %} -
- {{ pagination_row(hits) }} -
- {# TODO: ref_locator? #} - {% if direction == "out" %} - {% if row.ref.ref_key %} - [{{ row.ref.ref_key }}]
- {% endif %} - {% endif %} - {{ row.ref.match_status }}
- {% if row.ref.match_provenance %} - via {{ row.ref.match_provenance }} - {% endif %} -
- {% if release %} - {{ entity_macros.release_summary(release) }} - {% elif row.ref.target_unstructured %} - {{ row.ref.target_unstructured }} - {% else %} - blank - {% endif %} - - {% if row.access %} - {% for access in row.access %} - {{ access.access_type.name }}
- {% endfor %} - {% elif row.ref.target_unstructured %} -
- - - -
- {% endif %} - - {# TODO: include these as access options instead #} - {% if row.ref.target_openlibrary_work %} - openlibrary.org - {% endif %} - {% if row.ref.target_url %} - web -
wayback (?) - {% endif %} -{% endfor %} -
- {{ pagination_row(hits) }} -
+{% if hits.result_refs %} + {{ refs_macros.refs_table(hits, direction) }} {% else %}

None found {% endif %} -- cgit v1.2.3