{% extends "base.html" %}
{% block fullbody %}

<div class="ui stackable mobile reversed grid centered">
<div class="one wide column"></div>
<div class="fifteen wide column">
  <h1 class="ui header">{{ release.title }}
  <div class="sub header"><code>release {{ release.ident }}</code></div></h1>
  <p style="font-size: larger;">
  {% if authors != [] %} by {% endif %}
  {% for contrib in authors %}
    {% if contrib.creator_id %}
      <b><a href="/creator/{{contrib.creator_id}}">{{ contrib.raw_name }}</a></b>{% if not loop.last %}, {% endif %}
    {% else %}
      {% if contrib.raw_name != None %}{{ contrib.raw_name }}{% else %}<i>Unknown</i>{% endif %}{% if not loop.last %}, {% endif %}
    {% endif %}
  {% endfor %}
</div>
</div>

<div class="ui stackable mobile reversed grid centered">
<div class="one wide column"></div>
<div class="ten wide column" style="font-size: 16px;">

{% if release.release_date != None %}
  <p><b>Date (published):</b> {{ release.release_date }}
{% elif release.release_year != None %}
  <p><b>Date (published):</b> {{ release.release_year }}
{% endif %}
{% if release.pmid != None %}
<br><b>PubMed:</b> <a href="https://www.ncbi.nlm.nih.gov/pubmed/{{ release.pmid }}">&nbsp;<code>{{ release.pmid }}</code></a>
{% endif %}
{% if release.pmcid != None %}
<br><b>PubMed Central:</b> <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/{{ release.pmcid }}">&nbsp;<code>{{ release.pmcid }}</code></a>
{% endif %}
{% if release.wikidata_qid != None %}
<br><b>Wikidata Entity:</b> <a href="https://www.wikidata.org/wiki/{{ release.wikidata_qid }}">&nbsp;<code>{{ release.wikidata_qid }}</code></a>
{% endif %}
{% if release.language != None %}
<br><b>Primary Language:</b> &nbsp;<code>{{ release.language }}</code> (<a href="https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1={{ release.language }}">lookup ISO-639 code</a>)
{% endif %}
<br>This <i>{{ release.release_type or "unknown-type" }}</i> is a release
(version) of the work <a href="/work/{{ release.work_id }}">&nbsp;<code>{{
release.work_id }}</code></a>. There may be other releases (eg, pre-prints,
formal publications, etc) linked to the same work.

{% if container != None %}
<div class="ui styled accordion">
<div class="title">
  <i class="dropdown icon"></i>
  {% if release.release_status == 'published' %}
    Published in <a href="/container/{{ container.ident }}">{{ container.name }}</a>
  {% else %}
    Released in <i>{{ release.release_type }}</i> in <a href="/container/{{ container.ident }}">{{ container.name }}</a>
  {% endif %}
  {% if release.publisher %}
    by {{ release.publisher }}
  {% endif %}
</div><div class="content">
  {% if container != None and container.issnl != None %}<b>ISSN-L:</b> {{ container.issnl }}<br>{% endif %}
  {% if release.volume != None %}<b>Volume:</b> {{ release.volume }}<br>{% endif %}
  {% if release.issue != None %}<b>Issue:</b> {{ release.issue }}<br>{% endif %}
  {% if release.pages != None %}<b>Page(s):</b> {{ release.pages }}<br>{% endif %}
  {% if release.publisher != None %}<b>Publisher:</b> {{ release.publisher }}<br>{% endif %}
  {% if release.release_status != None %}<b>Release Status:</b> {{ release.release_status }}<br>{% endif %}
  {% if release.release_type != None %}<b>Release Type:</b> {{ release.release_type}}<br>{% endif %}
</div>
</div>
{% endif %}

{% if release.extra != None %}
<h3>Extra Metadata (raw JSON)</h3>
{% for (key, value) in release.extra.items() %}
<code><b>{{ key }}:</b> {% if key == "crossref" %} &lt;truncated, see full JSON&gt;{% else %} {{ value }} {% endif %}</code><br>
{% endfor %}
{% endif %}

<!--
Raw Object:
{{ release|safe }}
-->

<br>
<h3>Abstracts</h3>
{% if release.abstracts != [] %}
  {% for abstract in release.abstracts %}
  <b>Abstract (<code>{{ abstract.sha1 }}</code>, {{ abstract.mimetype }}):</b> {{ abstract.content }}
  {% endfor %}
{% else %}
<p>No known abstracts.
{% endif %}

<br>
<h3>All Contributors</h3>
{% if release.contribs.size != 0 %}
<table class="ui compact table">
  <thead>
    <tr><th>Attribution Order
        <th>Name
        <th>Role
  </thead>
  <tbody>
  {% for contrib in release.contribs %}
  <tr><td>{% if contrib.index or contrib.index == 0 %} {{ contrib.index + 1 }}{% endif %}
      {% if contrib.creator_id %}
        <td><a href="/creator/{{contrib.creator_id}}">{{ contrib.raw_name }}</a> 
      {% else %}
        <td>{{ contrib.raw_name }}
      {% endif %}
      <td>{{ contrib.role or '' }}
  {% endfor %}
  </tbody>
</table>
{% else %}
<p>Contributors (authors, translators, etc) not known.
{% endif %}

<br>
<h3>Known Files and URLs</h3>
{% if files != [] %}
<table class="ui compact table">
  <thead>
    <tr><th>SHA-1
        <th>Size (bytes)
        <th>File Type
        <th>Links
  </thead>
  <tbody>
  {% for file in files %}
  <tr><td><small><code><a href="/file/{{ file.ident }}">{% if file.sha1 != None %}{{ file.sha1[:16] + "..." }}{% else %}N/A{% endif %}</a></code></small>
      <td>{% if file.size != None %}{{ file.size }}{% endif %}
      <td>{% if file.mimetype != None %}{{ file.mimetype }}{% endif %}
      <td>{% for url in file.urls %}
        <a href="{{ url.url }}">{{ url.url.split('/')[2] }}</a> ({{ url.rel }})<br>
      {% endfor %}
  {% endfor %}
  </tbody>
</table>
</ul>
{% else %}
<p>There are no known files associated with this release (you could try
<a href="/work/{{ release.work_id }}">other releases for this work?</a>).
{% endif %}

<br>
{% if release.refs.size != 0 %}
<h3>References</h3>
This release citing other releases.
<ol>
  {% for ref in release.refs %}
    <li>
    {% if ref.title %}
      {{ ref.title }}
      {% if ref.container_name %}{{ ref.container_name }}.{% endif %}
      {% if ref.year %}{{ ref.year }}{% endif %}
      {% if ref.locator %}{{ ref.locator }}{% endif %}
    {% elif ref.extra and ref.extra.crossref %}
      {% if ref.extra.crossref.get('author') %}{{ ref.extra.crossref['author'] }}.{% endif %}
      {% if ref.extra.crossref.get('article-title') %}{{ ref.extra.crossref['article-title'] }}.{% endif %}
      {% if ref.container_name %}{{ ref.container_name }}.{% endif %}
      {% if ref.year %}{{ ref.year }}.{% endif %}
    {% elif ref.extra and ref.extra.unstructured %}
      {{ ref.extra.unstructured }}
    {% else %}
      <i>unknown</i>
    {% endif %}
    {% if ref.target_release_id != None %}
      (<a href="/release/{{ ref.target_release_id }}">fatcat release</a>)
{#    {% elif ref.extra != None and ref.extra.doi != None %}
      (DOI: <a href="/release/lookup?doi={{ ref.exta.get('doi') }}">{{ ref.extra.get('doi') }}</a>) #}
    {% endif %}
  {% endfor %}
</ol>
{% else %}
<p>No reference list available.
{% endif %}

</div>
<div class="five wide column">

{% if files != [] and files[0].urls != [] %}
<a href="https://web.archive.org/web/1/{{ files[0].urls[0].url }}" class="ui top attached fluid huge green button"><i class="file pdf outline icon"></i>Download Full Text</a>
{% else %}
<span class="ui top attached fluid huge grey button"><i class="file cross icon"></i>No Full Text Available</span>
{% endif %}

{% if release.release_type != None %}
<div class="ui segment attached">
<b>Release Type</b> <code>{{ release.release_type }}</code>
</div>
{% endif %}

{% if release.doi %}
<div class="ui segment attached">
<b>DOI </b> <a href="https://doi.org/{{ release.doi }}">{{ release.doi }}</a>
</div>
{% endif %}
{% if release.isbn13 != None %}
<div class="ui segment attached">
<p><b>ISBN-13 </b> &nbsp;<code>{{ release.isbn13 }}</code>
</div>
{% endif %}

{% if release.extra.is_oa == True %}
<div class="ui segment attached">
<b><i class="ui icon unlock alternate green"></i> Open Access</b>
</div><div class="ui segment attached">
{% elif release.extra.is_oa == False %}
<b><i class="ui icon lock red"></i> Not Open Access</b>
</div>
{% endif %}

{% if container != None %}
<div class="ui segment attached">
<b>Container Metadata</b><br>
{% if container.extra.is_oa == True %}
<i class="icon unlock orange"></i>Open Access Publication<br>
{% elif container.extra.is_oa == False  %}
<i class="icon lock black"></i>Not Open Access<br>
{% else %}
<i class="icon question grey"></i>Unknown OA Status<br>
{% endif %}
{% if (container.extra != None) %}
  {% if container.extra.in_doaj == True %}
    <i class="icon check green"></i> In <a href="https://doaj.org/toc/{{ container.issnl }}">DOAJ</a><br>
  {% elif container.extra.in_doaj == False %}
    <i class="icon times grey"></i> Not in <a href="https://doaj.org">DOAJ</a><br>
  {% endif %}
  {% if container.extra.in_road == True %}
    <i class="icon check green"></i> In <a href="http://road.issn.org/issn/{{ container.issnl }}">ISSN ROAD</a><br>
  {% elif container.extra.in_road == False %}
    <i class="icon times grey"></i> Not in <a href="https://road.issn.org">ISSN ROAD</a><br>
  {% endif %}
  {% if container.extra.is_kept == True %}
    <i class="icon check green"></i> In <a href="https://thekeepers.org/purl/issn/{{ container.issnl }}">Keepers Registery</a><br>
  {% elif container.extra.is_kept == False %}
    <i class="icon times grey"></i> Not in <a href="https://thekeepers.org/journals?query={{ container.issnl }}">Keepers Registry</a><br>
  {% endif %}
{% endif %}
{% if container.issnl != None %}
  <i class="icon hashtag"></i>ISSN-L: &nbsp;<code>{{ container.issnl }}</code><br>
{% endif %}
  <i class="icon linkify"></i>Fatcat: &nbsp;<small><code><a href="/container/{{ container.ident }}">{{ container.ident }}</a></code></small><br>
</div>
{% endif %}

<div class="ui segment attached accordion">
  <div class="title" style="padding: 0px;"><i class="dropdown icon"></i><b>Lookup Links</b></div>
  <div class="content">
{% if container != None and container.issnl != None %}
  <a href="http://www.sherpa.ac.uk/romeo/issn/{{ container.issnl }}/">SHERPA/RoMEO</a> (journal policies)<br/>
{% endif %}
{% if container != None and container.doi != None %}
  <a href="https://oadoi.org/{{ release.doi }}">oaDOI/unpaywall</a><br/>
{% endif %}
{% if release.isbn13 != None %}
  <a href="https://openlibrary.org/search?isbn={{ release.isbn13 }}">Open Library</a><br>
  <a href="http://www.worldcat.org/search?q=bn%3A{{ release.isbn13 }}">Worldcat</a><br>
{% else %}
  <a href="http://www.worldcat.org/search?qt=worldcat_org_art&q={{ release.title }}">Worldcat</a><br>
{% endif %}
{% if release.doi %}
<a href="https://api.crossref.org/v1/works/http://dx.doi.org/{{ release.doi }}">Crossref Metadata</a> (via API)<br>
{% endif %}
<a href="https://www.wikidata.org/w/index.php?search={{ release.title }}">wikidata.org</a><br>
<a href="https://core.ac.uk/search?q={{ release.title }}">CORE.ac.uk</a><br>
<a href="https://www.semanticscholar.org/search?q={{ release.title }}">Semantic Scholar</a> (CS, neuro)<br>
<a href="https://scholar.google.com/scholar?q={{ release.title }}">Google Scholar</a><br>
</div>
</div>

<div class="ui segment attached">
<b>Fatcat Bits</b>
<p>State is "{{ release.state }}". Revision:
<br><small><code>{{ release.revision }}</code></small>
<br><a href="https://api.{{ config.FATCAT_DOMAIN }}/v0/release/{{ release.ident }}?expand=container,files">As JSON object via API</a>

</div>
<div class="two ui buttons bottom attached">
  <a href="/release/{{ release.ident }}/edit" class="ui blue button">Edit Metadata</a>
  <a href="/release/{{ release.ident }}/history" class="ui button">View History</a>
</div>

</div>
</div>
{% endblock %}

{% block postscript %}
<script>
$('.ui.accordion')
  .accordion()
;
</script>
{% endblock %}