{% extends 'base_templates/page_base_half.html' %}

{% block content %}
{% from "base_templates/form_macros.html" import render_field, render_file_field, render_select_field, render_submit_field, render_checkbox_field with context %}

{%- if allowed_to_upgrade %}
<h2>{{ word('Upgrade docassemble') }}</h2>
<p class="h6">{{ version }}</p>

<div>
  <p>The Upgrade button will not upload the server to the latest
  version.  In order to upgrade <strong>docassemble</strong> to
  version 1.2.x, you will need to perform a system upgrade. See
  <a href="https://docassemble.org/docs/docker.html#upgrading" target="_blank">Upgrading
  <strong>docassemble</strong> when using Docker</a> for instructions on how to perform
  a system upgrade.  If you are not using some form of persistent data storage
  (a Docker volume, S3, or Azure Blob Storage), you will need to manually save your data
  or else it will be deleted by the system upgrade process.</p>

  <p><a class="btn {{ config['BUTTON_STYLE'] }}secondary {{ config['BUTTON_CLASS'] }}" href="{{ url_for('update_package', package='docassemble.webapp', limitation=limitation, action='update') }}">{{ word('Upgrade') }}</a></p>
</div>
{%- endif %}

<h2>{{ word('Install or update a package') }}</h2>

<form action="{{ url_for('update_package') }}" method="POST" class="form" role="form" enctype="multipart/form-data">
  {{ form.hidden_tag() }}
  <div class="form-group">
    <h4>{{ word('You can provide a:') }}</h4>
    {{ render_field(form.giturl, placeholder='https://github.com/username/packagename') }}
    {{ render_select_field(form.gitbranch) }}
    <h4>{{ word('Or you can upload a:') }}</h4>
    {{ render_file_field(form.zipfile) }}
    <h4>{{ word('Or you can specify a:') }}</h4>
    {{ render_field(form.pippackage) }}
  </div>
  <div class="form-actions">
    {{ render_submit_field(form.submit) }}
  </div>
</form>

<h2>{{ word('Update or uninstall an existing package') }}</h2>

<table class="table table-striped">
  <thead>
    <tr>
      <th>Package name</th>
      <th style="text-align:right;">Actions</th>
    </tr>
  </thead>
  <tbody>
  {% for package in package_list %}
    <tr>
      <td>{{ package.package.name }}{% if package.package.packageversion %} <span class="text-muted">{{ package.package.packageversion }}</span>{% endif %}{% if package.package.gitbranch %} ({{ package.package.gitbranch }}){% endif %}</td>
      <td style="text-align:right;">{% if package.can_update %}<a class="btn {{ config['BUTTON_STYLE'] }}secondary btn-sm" href="{{ url_for('update_package', package=package.package.name, action='update') }}">{{ word('Update') }}</a>{% endif %} {% if package.can_uninstall %}<a class="btn {{ config['BUTTON_STYLE'] }}warning btn-sm" href="{{ url_for('update_package', package=package.package.name, action='uninstall') }}">{{ word('Uninstall') }}</a>{% endif %}</td>
    </tr>
{% endfor %}
  </tbody>
</table>

{% endblock %}
