{% extends "repo_master.html" %}

{% block title %}File history - {{ repo.fullname }}{% endblock %}
{% set tag = "home" %}

{% block header %}
<link  nonce="{{ g.nonce }}" rel="stylesheet" href="{{
  url_for('static', filename='vendor/highlight.js/styles/github.css') }}?version={{ g.version}}"/>

<style nonce="{{ g.nonce }}">
  .hljs {
    background: #fff;
  }
</style>
{% endblock %}

{% block repo %}
  <div class="row m-b-1">
    <div class="col-sm-6">
    <h3>
      History {{ filename }}
    </h3>
    </div>

    <div class="col-sm-6">
      <div class="float-right">
      {% if branchname %}
        <div class="btn-group">
          <button type="button" class="btn btn-outline-light border-secondary text-dark btn-sm dropdown-toggle"
                  data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="fa fa-random fa-fw"></span> Branch: <span class="font-weight-bold">{{ branchname }}</span>
          </button>
          <div class="dropdown-menu dropdown-menu-right">
            {% for branch in g.branches %}
              {% if origin == 'view_tree' %}
                <a class="dropdown-item" href="{{ url_for(
                    'ui_ns.view_tree',
                    repo=repo.name,
                    username=username,
                    namespace=repo.namespace,
                    identifier=branch) }}">
                  {{ branch }}
                </a>
              {% elif origin == 'view_file' %}
                <a class="dropdown-item" href="{{ url_for(
                    'ui_ns.view_file',
                    repo=repo.name,
                    username=username,
                    namespace=repo.namespace,
                    identifier=branch,
                    filename=filename | unicode ) }}">
                  {{ branch }}
                </a>
              {% endif %}
            {% endfor %}
          </div>
        </div>
      {% endif %}
    </div>
  </div>

  </div>
    <div class="card">
      <div class="card-header">
        <ol class="breadcrumb p-0 bg-transparent mb-0">
          <li>
            <a href="{{ url_for('ui_ns.view_tree',
                repo=repo.name,
                username=username,
                namespace=repo.namespace,
                identifier=branchname)
          }}">
              <span class="fa fa-random">
              </span>&nbsp; {{ branchname }}
            </a>
          </li>
        {% set path = '' %}
        {% for file in filename.split('/') %}
          {% if loop.first %}
          {% set path = file %}
          {% else %}
          {% set path = path + '/' + file %}
          {% endif %}
          {% if loop.index != loop.length %}<li><a
          href="{{ url_for('ui_ns.view_file',
                repo=repo.name,
                username=username,
                namespace=repo.namespace,
                identifier=branchname,
                filename=path | unicode)}}">
            <span class="fa fa-folder"></span>&nbsp; {{ file }}</a>
          </li>
          {% elif file %}
          <li class="active">
            <span class="fa {% if output_type == 'tree' %}fa-folder{% else %}fa-file{% endif %}">
            </span>&nbsp; {{ file }}
          </li>
          {% endif %}
        {% endfor %}
        </ol>
      </div>

{% if log %}
  <div class="card-block p-a-0">
    <div class="bg-light border pr-2">

          <div class="list-group my-2">
              {% for line in log %}
              {% set commit = g.repo_obj[line[0]] %}
              <div class="list-group-item " id="c_{{ commit.hex }}">
                <div class="row align-items-center">
                  <div class="col">
                    <a href="{{ url_for('ui_ns.view_commit',
                      repo=repo.name,
                      username=username,
                      namespace=repo.namespace,
                      commitid=commit.hex, branch=branchname) }}"
                      class="notblue">
                      <strong>{{ commit.message.split('\n')[0] }}</strong>
                    </a>
                    <div>
                    {{commit.author|author2user_commits(
                      link=url_for('ui_ns.view_commits',
                          repo=repo.name,
                          branchname=branchname,
                          username=username,
                          namespace=repo.namespace,
                          author=commit.author.email),
                      cssclass="notblue")|safe}}
                      <span class="commitdate"
                      title="{{ commit.commit_time|format_ts }}"> &bull;
                    {{ commit.commit_time|humanize }}</span>&nbsp;&nbsp;
                      <span id="commit-actions"></span>
                    </div>
                  </div>
                  <div class="col-xs-auto pr-3 text-right">
                    <div class="btn-group">
                      <a href="{{ url_for('ui_ns.view_commit',
                        repo=repo.name,
                        username=username,
                        namespace=repo.namespace,
                        commitid=commit.hex, branch=branchname) }}"
                        class="btn btn-outline-primary font-weight-bold commithash" id="c_{{ commit.hex }}">
                        <code>{{ commit.hex|short }}</code>
                      </a>
                      <a class="btn btn-outline-primary font-weight-bold" href="{{ url_for(
                        'ui_ns.view_tree', username=username, namespace=repo.namespace,
                        repo=repo.name, identifier=commit.hex) }}"><span class="fa fa-file-code-o fa-fw"></span></a>
                    </div>
                  </div>
                </div>
              </div>
            {% endfor %}
          </div>

    </div>
  </div>
{% else %}
No history found for this file in this repository
{% endif %}
 </div> <!-- end .card-->

{% endblock %}

{% block jscripts %}
{{ super() }}

<script type="text/javascript" nonce="{{ g.nonce }}">
$(document).ready(function () {
  $('.fork_project_btn').click($("[name=fork_project]").submit);
});
</script>
{% endblock %}
