{% extends 'ddm/admin/base.html' %}

{% block page_title %}Data Donation Overview{% endblock %}

{% block main_heading %}Data Donation Overview{% endblock %}

{% block main_body %}
<div class="ddm-admin-section">
  <div class="w-75">
    <p>Data donations from participants are collected through <i>Uploaders</i>. Each Uploader is associated with a set of <i>Donation Instructions</i> and one or multiple <i>File Blueprints</i>.</p>

    <h5>Uploader</h5>
    <p>
      An <b>Uploader</b> can either be configured to expect a single file (e.g., one JSON file) or a ZIP container as a donation. <br>
      Each Uploader can be assigned <b>one or multiple File Blueprints</b>.<br>
      Usually, a File Uploader relates to one data export (e.g., to a Google Data Takeout or a TikTok Data Takeout).
    </p>

    <h5>File Blueprint</h5>
    <p>
      A File Blueprint defines how the data contained in a single file (e.g., in a .json or a .csv file) will be validated and extracted. <br>
      If a File Blueprint is assigned to a ZIP Uploader, an additional path must be provided that defines where the file is located within the ZIP container.
      The validation and extraction logic will then be applied to the first file in a ZIP container that matches this file path.
    </p>
  </div>
</div>

<div class="ddm-admin-section">
  <div class="ddm-admin-section-header">Uploader Configuration</div>
  <div class="ddm-admin-section-body">
    <table class="table">
      <tr>
        <th>Index</th>
        <th>Uploader</th>
        <th>Upload Type</th>
        <th>Donation Instructions</th>
        <th>Associated Blueprints</th>
      </tr>
      {% for uploader in file_uploaders %}
      <tr>
        <td>{{ uploader.index }}</td>
        <td>{{ uploader.name }} (<a href="{% url 'file-uploader-edit' project.pk uploader.pk %}">Edit</a> | <a href="{% url 'file-uploader-delete' project.pk uploader.pk %}">Delete</a>)</td>
        <td>{{ uploader.upload_type }}</td>
        <td><a href="{% url 'instruction-overview' project.pk uploader.pk %}">Edit Instructions</a></td>
        <td>
          {% if uploader.donationblueprint_set.all %}
          <ul>
            {% for blueprint in uploader.donationblueprint_set.all %}
            <li>{{ blueprint.name }} (<a href="{{ blueprint.get_absolute_url }}">Edit</a> | <a href="{% url 'blueprint-delete' project.pk blueprint.pk %}">Delete</a>)</li>
            {% endfor %}
          </ul>
          {% else %}
          No associated Blueprints
          {% endif %}
        </td>
      </tr>
      {% empty %}
      <tr>
        <td colspan="4">You have yet to create an Uploader for this project.</td>
      </tr>
      {% endfor %}
    </table>
    <a class="ddm-btn" href="{% url 'file-uploader-create' project.pk %}"><b>+</b>&nbsp;&nbsp;Create new Uploader</a>
    <a class="ddm-btn" href="{% url 'blueprint-create' project.pk %}"><b>+</b>&nbsp;&nbsp;Create new File Blueprint</a>
  </div>
</div>

<div class="ddm-admin-section">
  <div><h5>Unassociated File Blueprints</h5></div>
  <div class="ddm-admin-section-body">
    <table class="table">
      <tr>
        <th>Name</th>
        <th></th>
      </tr>
      {% for blueprint in lonely_blueprints %}
      <tr>
        <td>{{ blueprint.name }}</td>
        <td><a href="{{ blueprint.get_absolute_url }}">Edit</a> | <a href="{% url 'blueprint-delete' project.pk blueprint.pk %}">Delete</a></td>
      </tr>
      {% empty %}
      <tr>
        <td colspan="2">No unassociated File Blueprints.</td>
      </tr>
      {% endfor %}
    </table>
    <a class="ddm-btn" href="{% url 'blueprint-create' project.pk %}"><b>+</b>&nbsp;&nbsp;Create new File Blueprint</a>
  </div>
</div>

<div>
  <a href="{% url 'project-detail' project.pk %}">&#129040; Back</a>
</div>

{% endblock %}

{% block breadcrumbs %}
<a href="{% url 'project-list' %}">Projects</a> /
<a href="{% url 'project-detail' project.pk %}">"{{ project.name|truncatechars:15 }}" Project</a> /
Data Donation Overview
{% endblock %}
