aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/templates/entity_macros.html
blob: d5ecd9b60d7c1b39d89175c12b53633a0ba5cb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

{% macro fatcat_bits(entity, entity_type, expand="", editgroup=None) -%}

{% if entity.state == None and editgroup %}
  <div class="ui segment pink inverted attached">
  {% if editgroup.changelog_index %}
    <b>Accepted Edit Version</b>
    <p>This is the version of the entity as of a specific merged editgroup:
  {% elif editgroup.submitted %}
    <b>Submitted Edit Version</b>
    <p>This is a version of the entity that has been submitted for approval as part of an editgroup:
  {% else %}
    <b>Edit In Progress</b>
    <p>This is a version of the entity that has not yet been submitted for approval, part of an editgroup:
  {% endif %}
  <b><a href="/editgroup/{{ editgroup.editgroup_id }}" style="color: white; font-weight: bold;">{{ editgroup.editgroup_id }}</a></b>
  </div>
{% elif entity.state == None and entity.ident == None %}
<div class="ui segment pink inverted attached">
  <b>Revision</b>
  <p>This is a specific, static metadata record, not necessarily linked to any current entity in the catalog.
</div>
{% elif entity.state == "wip" %}
<div class="ui segment pink inverted attached">
  <b>Work In Progress</b>
  <p>This entity has not been "accepted" into the official database yet.
</div>
{% endif %}

<div class="ui segment attached">
  <b>Fatcat Bits</b>
  <p>
  {% if entity.state %}
    State is "{{ entity.state }}".
  {% endif %}
  {% if entity.revision %}
    Revision:
    <br><small><code><a href="/{{ entity_type }}/rev/{{ entity.revision }}">{{ entity.revision }}</a></code></small>
  {% endif %}
  <br><a href="
  {%- if config.FATCAT_DOMAIN == 'dev.fatcat.wiki' -%}
    http://localhost:9411
  {%- else -%}
    https://api.{{ config.FATCAT_DOMAIN }}
  {%- endif -%}
  /v0
  {%- if editgroup and entity.ident -%}
    /editgroup/{{ editgroup.editgroup_id }}{# /{{ entity_type }}/{{ entity.ident }} #}
  {%- elif entity.ident -%}
    /{{ entity_type }}/{{ entity.ident }}
  {%- elif entity.revision -%}
    /{{ entity_type }}/rev/{{ entity.revision }}
  {% endif %}
  {% if expand %}?expand={{ expand}}{% endif %}">
  As JSON object via API
  </a>
</div>

{% if entity.ident %}
<div class="two ui buttons bottom attached">
  <a href="{% if editgroup %}/editgroup/{{ editgroup.editgroup_id }}{% endif %}/{{ entity_type }}/{{ entity.ident }}/edit" class="ui blue button">Edit Metadata</a>
  <a href="/{{ entity_type }}/{{ entity.ident }}/history" class="ui button">View History</a>
</div>
{% endif %}
{%- endmacro %}


{% macro extra_metadata(extra) -%}
<table class="ui definition single line fixed compact small unstackable table">
<tbody>
{% for (key, value) in extra.items()|sort %}
  {% if key in ("ia", "crossref", "datacite", "kbart", "arxiv", "jstor", "pubmed") and value is mapping and value %}
    {% for (inner_key, inner_value) in value.items()|sort %}
      <tr><td class="three wide right aligned"><code>{{ key }}.{{ inner_key }}</code></td>
          <td class="seven wide"><code>{{ inner_value }}</code>
    {% endfor %}
  {% elif key in ("urls", "webarchive_urls") and value and value is iterable and value is not string and value[0] is string %}
    <tr><td class="three wide right aligned"><code>{{ key }}</code></td>
        <td class="seven wide">
          <code>
          {% for u in value %}
            <a href="{{ u }}">{{ u }}</a><br>
          {% endfor %}
          </code>
  {% else %}
    <tr><td class="three wide right aligned"><code>{{ key }}</code></td>
        <td class="seven wide"><code>{% if value != None %}{{ value }}{% endif %}</code>
  {% endif %}
{% endfor %}
</tbody>
</table>
{%- endmacro %}


{% macro release_list(releases) -%}
<table class="ui very basic celled table">
<tbody>
{% for release in releases %}
  <tr><td class="collapsing center aligned">
        {% if release.release_date %}{{ release.release_date }}{% elif release.release_year %}{{ release.release_year }}{% else %}<i>unknown</i>{% endif %}
      <td class="">
        <b><a href="/release/{{ release.ident }}">{{ release.title }}</a></b>
        <br><small>{{ release.release_stage or "unknown status" }}
            | {{ release.release_type or "unknown type" }}
            {% if release.version %} | {{ release.version }}{% endif %}
            {% if release.license_slug %} | {{ release.license_slug }}{% endif %}
        </small>
        {% if release.ext_ids.doi %}
          <br><a href="https://doi.org/{{ release.ext_ids.doi }}" style="color:green;">doi:{{ release.ext_ids.doi }}</a>
        {% endif %}
{% endfor %}
</tbody>
</table>
{%- endmacro %}


{% macro url_list(urls) -%}
<table class="ui very basic compact single line fixed table">
<tbody>
  {% for url in urls %}
    <tr><td class="two wide right aligned">{{ url.rel }}
        <td class="eight wide"><small><code><a href="{{ url.url }}">
        {% if url.url.count('/') >= 3 and url.rel != "dweb" %}
          {{ '/'.join(url.url.split('/')[0:2]) }}/<b>{{ ''.join(url.url.split('/')[2]) }}</b>/{{ '/'.join(url.url.split('/')[3:]) }}
        {% else %}
          {{ url.url }}
        {% endif %}
        </a></code></small>
  {% endfor %}
</tbody>
</table>
{%- endmacro %}

{% macro lookup_form(entity_type, key, example, lookup_key, lookup_value, lookup_error) -%}
<form class="ui form" role="search" action="/{{ entity_type }}/lookup" method="get">
  <div class="ui form">
    <div class="field {% if key == lookup_key %}{% if lookup_error == 400 %}error{% elif lookup_error == 404 %}warning{% endif %}{% endif %}">
      {% if key == lookup_key and lookup_error == 400 %}
        <div class="ui pointing below red label">
          Not correct syntax. Expected, eg, {{ example }}
        </div>
      {% endif %}
      <div class="ui action input big fluid">
        <input type="text" placeholder="{% if example %}eg, {{ example }}{% endif %}" name="{{ key }}" value="{% if key == lookup_key %}{{ lookup_value }}{% endif %}" aria-label="{{ key }} lookup">
        <button class="ui button">Go!</button>
      </div>
    </div>
  </div>
</form>
{%- endmacro %}

{% macro release_search_result_row(paper) -%}
<div>
  <h4 style="margin-top: 1em; margin-bottom: 0px; font-size: 1.1em;">
    <a href="/release/{{ paper.ident }}" style="color: #2224c7;">
      {% if paper.title %}
        {{ paper.title[:512] }}
        {% if paper.title|length > 512 %}...{% endif %}
      {% else %}
        [blank]
      {% endif %}
    </a>

    {# release type suffix #}
    {% if paper.release_type in ("article-journal", "paper-conference") %}
      {# pass #}
    {% elif not paper.release_type %}
      <b style="text-transform: uppercase; color: black;">[unknown]</b>
    {% else %}
      <b style="text-transform: uppercase; color: black;">[{{ paper.release_type }}]</b>
    {% endif %}

    {# show original_title #}
    {% if paper.original_title and paper.title != paper.original_title %}
      <br>
      <i style="font-weight: normal;">
        {{ paper.original_title[:512] }} {% if paper.original_title|length > 512 %}...{% endif %}
      </i>
    {% endif %}

  </h4>

  {% if paper.best_pdf_url %}
  <div style="float: right; padding: 4px;">
  &nbsp;&nbsp;<a href="{{ paper.best_pdf_url }}" class="ui violet tag label"><i class="file icon"></i>fulltext</a>
  </div>
  {% endif %}

  {# ### AUTHOR ROW #}
  {% if paper.contrib_names %}
    <div style="margin-top: 0px; margin-bottom: 0px; font-size: 1em;">
    <b>
    {{ ", ".join(paper.contrib_names[:12]) }}
    {% if paper.contrib_names|length > 12 %}<i>(+{{ paper.contrib_names|length - 12 }} others)</i>{% endif %}
    </b>
    </div>
  {% endif %}


  {# ### JOURNAL ROW #}
  {% if paper.release_year %}
    {{ paper.release_year }}
  {% endif %}
  {% if paper.release_year and paper.container_name %}
    |
  {% endif %}
  {% if paper.container_name %}
    {% if paper.container_id %}
      <a href="/container/{{ paper.container_id }}" style="color: black;">{{ paper.container_name }}</a>
    {% else %}
      {{ paper.container_name }}
    {% endif %}
    {% if paper.container_is_oa %}<i class="icon unlock orange small"></i>{% endif %}
  {% endif %}

  {% if paper.release_stage == "submitted" %}
    <b style="color: brown; text-transform: uppercase;">pre-print</b>
  {% elif paper.release_stage and paper.release_stage != "published" %}
    <b style="color: brown; text-transform: uppercase;">{{ paper.release_stage }} version</b>
  {% elif not paper.release_stage %}
    <b style="color: brown; text-transform: uppercase;">unpublished</b>
  {% endif %}

  {% if paper.withdrawn_status %}
    <b style="color: red; text-transform: uppercase;">{{ paper.withdrawn_status }}</b>
  {% endif %}

  {# ### IDENTIFIERS #}
  {% if paper.doi or paper.pmid or paper.arxiv_id or paper.jstor_id or paper.pmcid %}
    <br>
  {% endif %}
  {% if paper.doi %}
    <a href="https://doi.org/{{paper.doi }}" style="color: green;">doi:{{ paper.doi }}</a> &nbsp;
  {% endif %}
  {% if paper.pmid %}
    <a href="https://www.ncbi.nlm.nih.gov/pubmed/{{paper.pmid }}" style="color: green;">pmid:{{ paper.pmid }}</a> &nbsp;
  {% endif %}
  {% if paper.pmcid %}
    <a href="https://pubmed.ncbi.nlm.nih.gov/{{paper.pmcid }}/" style="color: green;">pmcid:{{ paper.pmcid }}</a> &nbsp;
  {% endif %}
  {% if paper.arxiv_id %}
    <a href="https://arxiv.org/abs/{{paper.arxiv_id }}" style="color: green;">arXiv:{{ paper.arxiv_id }}</a> &nbsp;
  {% endif %}

{# WIP: elastic release work grouping searches
  <br>
  <a href="/work/{{ paper.work_id }}"><i class="sitemap icon"></i> and 5 other versions of the same work!</a>
#}

</div>
{% endmacro %}

{% macro progress_color(frac) -%}
{% if frac >= 1 %}
green
{% elif frac > 0.95 %}
olive
{% elif frac < 0.5 %}
red
{% else %}
yellow
{% endif %}
{%- endmacro %}


{% macro preservation_bar(stats, extra_class="") -%}

  {% set frac_bright = stats.bright/stats.total %}
  {% set frac_dark = stats.dark/stats.total %}
  {% set frac_none = stats.none/stats.total %}

  <div class="ui {{ extra_class }} multiple progress" data-percent="0,0,0,0" style="margin-bottom: 0.1em;">
    <div class="green bar" style="border-radius: 0; min-width: 0; width: {{ (frac_bright*100)|round(method='ceil') }}%;" title="bright">
      <div class="progress">{# {{ (frac_bright*100)|int }}% #}</div>
    </div>
    <div class="green bar" style="border-radius: 0; min-width: 0; width: {{ (frac_dark*100)|round(method='ceil') }}%; background-color: darkgreen;" title="dark">
      <div class="progress">{# {{ (frac_dark*100)|int }}% #}</div>
    </div>
    {% if stats.shadows_only %}
  {% set frac_shadows_only = stats.shadows_only/stats.total %}
    <div class="red bar" style="border-radius: 0; min-width: 0; width: {{ (frac_shadows_only*100)|round(method='ceil') }}%; background-color: darkred;" title="shadows only">
      <div class="progress">{# {{ (frac_shadows_only*100)|int }}% #}</div>
    </div>
    {% endif %}
    <div class="red bar" style="border-radius: 0; min-width: 0; width: {{ (frac_none*100)|round(method='ceil') }}%;" title="no preservation">
      <div class="progress">{# {{ (frac_none*100)|int }}% #}</div>
    </div>
  </div>


{%- endmacro %}

{% macro preservation_table(stats) -%}

  {% set frac_bright = stats.bright/stats.total %}
  {% set frac_dark = stats.dark/stats.total %}
  {% set frac_none = stats.none/stats.total %}

  <table class="ui very basic very compact collapsing table" style="font-weight: bold; margin-left: 1em;">
    <tbody>
      <tr>
        <td style="background-color: #21ba45;">
        <td class="right aligned" >{{ "{:,}".format(stats.bright) }}
        <td class="right aligned" >{{ (frac_bright*100)|round(2,method='ceil') }}%
        <td>preserved and publicly accessible (bright)
      <tr>
        <td style="background-color: darkgreen;">
        <td class="right aligned" >{{ "{:,}".format(stats.dark) }}
        <td class="right aligned" >{{ (frac_dark*100)|round(2,method='ceil') }}%
        <td>preserved but not publicly accessible (dark)
      {% if stats.shadows_only %}
      {% set frac_shadows_only = stats.shadows_only/stats.total %}
      <tr>
        <td style="background-color: darkred;">
        <td class="right aligned" >{{ "{:,}".format(stats.shadows_only) }}
        <td class="right aligned" >{{ (frac_shadows_only*100)|round(2,method='ceil') }}%
        <td>only independently preserved in "shadow" libraries
      {% endif %}
      <tr>
        <td style="background-color: #db2828;">
        <td class="right aligned" >{{ "{:,}".format(stats.none) }}
        <td class="right aligned" >{{ (frac_none*100)|round(2,method='ceil') }}%
        <td>no known independent preservation
    </tbody>
  </table>

{%- endmacro %}

{% macro preservation_small_table(stats) -%}

  {% set frac_bright = stats.bright/stats.total %}
  {% set frac_dark = stats.dark/stats.total %}
  {% set frac_none = stats.none/stats.total %}

  <table class="ui very basic very compact collapsing table">
    <tbody>
      <tr>
        <td style="background-color: #21ba45;">
        <td class="right aligned" >{{ "{:,}".format(stats.bright) }}
        <td>preserved and accessble (bright)
      <tr>
        <td style="background-color: darkgreen;">
        <td class="right aligned" >{{ "{:,}".format(stats.dark) }}
        <td>preserved, inaccessible (dark)
      {% if stats.shadows_only %}
      {% set frac_shadows_only = stats.shadows_only/stats.total %}
      <tr>
        <td style="background-color: darkred;">
        <td class="right aligned" >{{ "{:,}".format(stats.shadows_only) }}
        <td>shadow library only
      {% endif %}
      <tr>
        <td style="background-color: #db2828;">
        <td class="right aligned" >{{ "{:,}".format(stats.none) }}
        <td>no known preservation
    </tbody>
  </table>

{%- endmacro %}