{% if request.user.hasPermission('View', 'query') %}
  <p>
    <b>{% trans %}Your Queries{% endtrans %}</b> (<a href="query?@template=edit">{% trans %}edit{% endtrans %}</a>)
    {% for qs in request.user.queries %}
    <br />
    <a href="{{ qs.klass.plain() }}?{{ qs.url.plain() }}&amp;@dispname={{ qs.name.url_quote()|u }}">{{ qs.name.plain()|u }}</a>
    {% endfor %}
  </p>
{% endif %}

{% if request.user.hasPermission('View', 'issue') %}
  <ul class='nav flex-column'>
    <li class='nav-header'>
      <i class='icon-fire'></i>{% trans %}Issues{% endtrans %}
    </li>
    {% if request.user.hasPermission('Create', 'issue') %}
      <li>
        <a href="issue?@template=item">{% trans %}Create New{% endtrans %}</a>
      </li>
    {% endif %}

    <li class="nav-item">
      <a href="{{ request.indexargs_url('issue', {
        '@sort': '-activity',
        '@group': 'priority',
        '@filter': 'status,assignedto',
        '@columns': columns,
        '@search_text': '',
        'status': status_notresolved,
        'assignedto': '-1',
        '@dispname': i18n.gettext('Show Unassigned'),
       })|u }}">{% trans %}Show Unassigned{% endtrans %}</a>
    </li>
    <li class="nav-item">
      <a href="{{ request.base }}?@dispname={{ i18n.gettext('Show All')|u|urlencode }}">{% trans %}Show All{% endtrans %}</a>
    </li>
    <li>
      <a href="issue?@template=search">{% trans %}Search{% endtrans %}</a>
    </li>
    <li>
      <form method="POST" class='form-inline' action="{{ request.base }}">
        <div class="form-group">
          <input type="hidden" name="@type" value="issue">
          <input type="hidden" name="@action" value="show">
          <input class="form-control form-control-sm col-2" type="text" name="@number">
          <input class="btn btn-sm btn-outline-secondary" type="submit" value="{% trans %}Show issue{% endtrans %}">
        </div>
      </form>
    </li>
  </ul>
  <hr>
{% else %}
  <p class='text-error'>{% trans %}You don't have permission to view issues.{% endtrans %}</p>
{% endif %}

<ul class='nav flex-column'>
  {% if request.user.hasPermission('Create', 'keyword')
        or request.user.hasPermission('Edit', 'keyword') %}
    <li class='nav-header'>
      <i class='icon-star'></i>{% trans %}Keywords{% endtrans %}
    </li>
  {% endif %}
  {% if request.user.hasPermission('Create', 'keyword') %}
    <li class="nav-item">
      <a href="keyword?@template=item">{% trans %}Create New{% endtrans %}</a>
    </li>
  {% endif %}
  {% if request.user.hasPermission('Edit', 'keyword') %}
    <li class="nav-item">
      <a href="keyword?@template=item">{% trans %}Edit Existing{% endtrans %}</a>
    </li>
  {% endif %}
</ul>
{% if request.user.hasPermission('Create', 'keyword')
      or request.user.hasPermission('Edit', 'keyword') %}
<hr>
{% endif %}

{% if request.user.hasPermission('View', 'user') %}
  <ul class='nav flex-column'>
    <li class='nav-header'>
      <i class='icon-eye-open'></i>{% trans %}Administration{% endtrans %}
    </li>

    {% if request.user.hasPermission('Edit', None) %}
      <li>
        <a href="home?@template=classlist">{% trans %}Class List{% endtrans %}</a>
      </li>
    {% endif %}

    {% if request.user.hasPermission('View', 'user') or request.user.hasPermission('Edit', 'user') %}
      <li>
        <a href="user">{% trans %}User List{% endtrans %}</a>
      </li>
    {% endif %}

    {% if request.user.hasPermission('Create', 'user') %}
      <li>
        <a href="user?@template=item">{% trans %}Add User{% endtrans %}</a>
      </li>
    {% endif %}
  </ul>
  <hr>
{% endif %}

{% if request.user.username == 'anonymous' %}
  <form method="POST" action='{{ request.base }}'>
    <ul class='nav flex-column'>
      <li class='nav-header'>
        <i class='icon-user'></i>{% trans %}Login{% endtrans %}
      </li>
      <li class="nav-item">
        <input class="form-control form-control-sm" type='text' required name="__login_name" placeholder='username'>
      </li>
      <li class="nav-item">
        <input class="form-control form-control-sm" type="password" required name="__login_password" placeholder='password'>
      </li>
      <li class="nav-item">
        <label class="form-control form-control-sm" class='checkbox'>
          <input type="checkbox" name="remember"> {% trans %}Remember me?{% endtrans %}
        </label>
      </li>
      <li class="nav-item">
        <input class="btn btn-sm btn-secondary" type="submit" value="{% trans %}Login{% endtrans %}">
      </li>
      <li class='vspace-one'>
        {% if request.user.hasPermission('Register', 'user') %}
          <a href="user?@template=register">{% trans %}Register{% endtrans %}</a>
        {% endif %}
      </li>
      <li class="nav-item">
        <a href="user?@template=forgotten">{% trans %}Lost&nbsp;your&nbsp;login?{% endtrans %}</a>
      </li>
    </ul>
    <input type="hidden" name="@action" value="Login">
    <input type="hidden" name="__came_from" value="{{ request.base }}{{ request.env.PATH_INFO }}{% if request.env.QUERY_STRING %}?{{ request.env.QUERY_STRING }}{% endif %}">
  </form>
  <hr>
{% else %}
  <ul class='nav flex-column'>
    <li class='nav-header'>
      <i class='icon-user'></i>{% trans %}Hello,{% endtrans %}
      <span class='username'>{{ request.user.username.plain(escape=1) }}</span>
    </li>
    <li>
      <a href="{{ request.indexargs_url('issue', {
        '@sort': '-activity',
        '@group': 'priority',
        '@filter': 'status,assignedto',
        '@columns': 'id,activity,title,creator,status',
        '@search_text': '',
        'status': status_notresolved,
        'assignedto': request.user.id,
        '@dispname': i18n.gettext('Your Issues'),
      })|u }}">{% trans %}Your Issues{% endtrans %}</a>
    </li>
    <li>
      <a href="user{{ request.user.id }}">{% trans %}Your Details{% endtrans %}</a>
    </li>
    <li>
      <a href="{{ request.indexargs_url('', {'@action':'logout'}) }}">{% trans %}Logout{% endtrans %}</a>
    </li>
  </ul>
  <hr>
{% endif %}

<ul class='nav flex-column'>
  <li class='nav-header'>
    <i class='icon-bookmark'></i>{% trans %}Help{% endtrans %}
  </li>
  <li>
    <a href="https://www.roundup-tracker.org">Roundup docs</a>
  </li>
</ul>
