{% ckan_extends %}

{% block resource_actions_inner %}
  {% if h.check_access('package_update', {'id':pkg.id }) and not is_activity_archive %}
    <li>{% link_for _('Manage'), named_route=pkg.type ~ '_resource.edit', id=pkg.name, resource_id=res.id, class_='btn btn-default', icon='wrench' %}</li>
  {% endif %}
  {% if res.url and h.is_url(res.url) %}
    <li>
      <div class="btn-group">
        <a class="btn btn-primary resource-url-analytics resource-type-{{ res.resource_type }}" href="javascript:window.location.href += '/download';">
          {% if res.resource_type in ('listing', 'service') %}
            <i class="fa fa-eye"></i> {{ _('View') }}
          {% elif  res.resource_type == 'api' %}
            <i class="fa fa-key"></i> {{ _('API Endpoint') }}
          {% elif not res.has_views and not res.url_type == 'upload' %}
            <i class="fa fa-external-link"></i> {{ _('Go to resource') }}
          {% else %}
            <i class="fa fa-arrow-circle-o-down"></i> {{ _('Download') }}
          {% endif %}
        </a>
        {% block download_resource_button %}
          {% if res.datastore_active %}
            <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
              <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
              <li>
                <a href="{{ h.url_for('datastore.dump', resource_id=res.id, bom=True) }}"
                  target="_blank"><span>CSV</span></a>
                <a href="{{ h.url_for('datastore.dump', resource_id=res.id, format='tsv', bom=True) }}"
                  target="_blank"><span>TSV</span></a>
                <a href="{{ h.url_for('datastore.dump', resource_id=res.id, format='json') }}"
                  target="_blank"><span>JSON</span></a>
                <a href="{{ h.url_for('datastore.dump', resource_id=res.id, format='xml') }}"
                  target="_blank"><span>XML</span></a>
              </li>
            </ul>
          {% endif %}
        {% endblock %}
      </div>
    </li>
  {% endif %}
  {% if h.is_enabled_utilizations() %}
    <li>
      <div class="btn-group">
        <a class="btn btn-primary resource-url-analytics resource-type-{{ res.resource_type }}" href="{{ h.url_for('utilization.new', package_name=pkg.name, resource_id=res.id, return_to_resource=true) }}">
          <i class="fa fa-pencil-square-o"></i> {{ _('Create utilization application') }}
        </a>
      </div>
    </li>
  {% endif %}
  {% if h.is_enabled_resources() %}
    <li>
      <div class="btn-group">
        <a class="btn btn-primary resource-url-analytics resource-type-{{ res.resource_type }}" href="{{ h.url_for('resource_comment.comment', resource_id=res.id) }}">
          <i class="fa fa-commenting-o"></i> {{ _('Comment') }}
        </a>
      </div>
    </li>
  {% endif %}
{% endblock %}

{% block resource_read_url %}
  {% if res.url and h.is_url(res.url) %}
    <p class="text-muted ellipsis">{{ _('URL:') }} <a class="resource-url-analytics" href="javascript:window.location.href += '/download';" title="{{ res.url }}">{{ res.url }}</a></p>
  {% elif res.url %}
    <p class="text-muted break-word">{{ _('URL:') }} {{ res.url }}</p>
  {% endif %}
{% endblock %}

{% block resource_additional_information_inner %}
  <div class="module-content">
    <h2>{{ _('Additional Information') }}</h2>
    <table class="table table-striped table-bordered table-condensed" data-module="table-toggle-more">
      <thead>
        <tr>
          <th scope="col">{{ _('Field') }}</th>
          <th scope="col">{{ _('Value') }}</th>
        </tr>
      </thead>
      <tbody>
        {% if h.is_enabled_downloads() %}
          <tr>
            <th scope="row">{{ _('Downloads') }}</th>
            <td>{{ h.get_resource_downloads(res.id) }}</td>
          </tr>
        {% endif %}
        {% if h.is_enabled_utilizations() %}
          <tr>
            <th scope="row">{{ _('Utilizations') }}</th>
            <td><a href="{{ h.url_for('utilization.search', id=resource.id, disable_keyword=true) }}">{{ h.get_resource_utilizations(resource.id) }}</a></td>
          </tr>
        {% endif %}
        {% if h.is_enabled_resources() %}
        <tr>
          <th scope="row">{{ _('Comments') }}</th>
          <td><a href="{{ h.url_for('resource_comment.comment', resource_id=res.id) }}">{{ h.get_resource_comments(resource.id) }}</a></td>
        </tr>
        <tr>
          <th scope="row">{{ _('Rating') }}</th>
          <td>{{ h.get_resource_rating(resource.id)|round(1) }}</td>
        </tr>
        {% endif %}
        {% if h.is_enabled_utilizations() %}
          <tr>
            <th scope="row">{{ _('Issue Resolutions') }}</th>
            <td>{{ h.get_resource_issue_resolutions(res.id) }}</td>
          </tr>
        {% endif %}
        <tr>
          <th scope="row">{{ _('Data last updated') }}</th>
          <td>{{ h.render_datetime(res.last_modified) or h.render_datetime(res.created) or _('unknown') }}</td>
        </tr>
        <tr>
          <th scope="row">{{ _('Metadata last updated') }}</th>
          <td>{{ h.render_datetime(res.metadata_modified) or h.render_datetime(res.created) or _('unknown') }}</td>
        </tr>
        <tr>
          <th scope="row">{{ _('Created') }}</th>
          <td>{{ h.render_datetime(res.created) or _('unknown') }}</td>
        </tr>
        <tr>
          <th scope="row">{{ _('Format') }}</th>
          <td>{{ res.format or res.mimetype_inner or res.mimetype or _('unknown') }}</td>
        </tr>
        <tr>
          <th scope="row">{{ _('License') }}</th>
          <td>{% snippet "snippets/license.html", pkg_dict=pkg, text_only=True %}</td>
        </tr>
        {% for key, value in h.format_resource_items(res.items()) %}
          {% if key not in ('created', 'metadata modified', 'last modified', 'format') %}
            <tr class="toggle-more"><th scope="row">{{ key | capitalize }}</th><td>{{ value }}</td></tr>
          {% endif %}
        {% endfor %}
      </tbody>
    </table>
  </div>

{% endblock %}

