{% extends "master.html" %}

{% block title %}Home{% endblock %}
{% set tag = "projects" %}
{% from "_browseheader.html" import browse_header %}


{% block header %}
  <link rel="stylesheet" type="text/css" media="screen"
      href="{{ url_for('static', filename='toggle.css') }}"/>
{% endblock %}


{% from "_render_repo.html" import render_repos_as_card, render_contributions_graph %}

{% block content %}
<div class="p-t-2">
  <div class="container">
    <div class="row">
      <div class="col-md-8">
        <div class="card">
          <div class="card-header">
            My Projects <span class="label label-default">{{repos | count}}</span>
            {% if config.get('ENABLE_NEW_PROJECTS', True) and repos %}
            <span class="pull-xs-right">
              <a class="btn btn-secondary btn-sm" href="{{ url_for('new_project') }}">
                <span class="oi" data-glyph="plus" data-toggle="tooltip"
                    title="Create New Project" aria-hidden="true">
                </span>
              </a>
            </span>
          {% endif %}
          </div>
          {% if repos %}
            <div class="list-group list-group-flush">
            {% for repo in repos %}
              <div class="list-group-item">
                {% if repo.is_fork %}
                  {% set url = url_for('view_repo', username=repo.user.username, repo=repo.name) %}
                {% else %}
                  {% set url = url_for('view_repo', repo=repo.name) %}
                {% endif %}
                <a href="{{ url }}">
                  {% if repo.avatar_email %}
                    <img class="projecticon pull-xs-left" src="{{ repo.avatar_email | avatar_url }}" width=20 height=20 />&nbsp;
                  {% else %}
                    <span class="oi text-muted" data-glyph="document"></span>
                  {% endif %}
                  <strong>{{ repo.name }}</strong>
                </a>
                  <div class="pull-xs-right">
                    {% if config.get('ENABLE_TICKETS', True) and repo.settings.get('issue_tracker', True) %}
                      {% if repo.open_tickets_public == 0 %}
                        <span class="text-muted" data-toggle="tooltip"
                          title="{{ repo.open_tickets_public }} open issues against {{repo.name}}">
                          <span class="oi" data-glyph="warning"></span>
                          {{- repo.open_tickets_public }}
                        </span>
                      {% else %}
                        <a class="notblue" data-toggle="tooltip"
                          href="{{ url_for('.view_issues', repo=repo.name) }}"
                          title="{{ repo.open_tickets_public }} open issues against {{repo.name}}">
                          <span class="oi" data-glyph="warning"></span>
                          {{- repo.open_tickets_public }}
                        </a>
                      {% endif %}
                    {% endif %}

                    {% if repo.open_requests == 0 %}
                      <span class="text-muted" data-toggle="tooltip"
                        title="{{repo.open_requests}} open pull requests in {{repo.name}}">
                        <span class="oi" data-glyph="arrow-thick-bottom"></span>
                        {{- repo.open_requests}}
                      </span>
                    {% else %}
                      <a class="notblue" data-toggle="tooltip"
                        href="{{ url_for('.request_pulls', repo=repo.name) }}"
                        title="{{repo.open_requests}} open pull requests in {{repo.name}}">
                        <span class="oi" data-glyph="arrow-thick-bottom"></span>
                        {{- repo.open_requests}}
                      </a>
                    {% endif %}

                  </div>
              </div>
            {% endfor %}
            </div>
        {% else %}
          <div class="card-block">
            <div class="text-xs-center">You have no projects</div>
            <div class="text-xs-center m-t-1">
              {% if config.get('ENABLE_NEW_PROJECTS', True) %}
              <a class="btn btn-success" href="{{ url_for('new_project') }}">
                <span class="oi" data-glyph="plus" data-toggle="tooltip"
                    title="Create New Project" aria-hidden="true">
                </span> Create a Project
              </a>
              {% endif %}
            </div>
          </div>
        {% endif %}
        </div>

        <div class="card">
          <div class="card-header">
            My Forks <span class="label label-default">{{forks | count}}</span>
          </div>
          {% if forks %}
            <div class="list-group list-group-flush">
            {% for fork in forks %}
              <div class="list-group-item">
                {% if fork.is_fork %}
                  {% set url = url_for('view_repo', username=fork.user.username, repo=fork.name) %}
                {% else %}
                  {% set url = url_for('view_repo', repo=fork.name) %}
                {% endif %}
                <a href="{{ url }}">
                  <span class="oi text-muted" data-glyph="fork"></span>
                  <strong>{{username}}/{{ fork.name }}</strong>
                </a>
                  <div class="pull-xs-right">
                  <span class="text-muted">forked from</span>
                  <a href="{{ url_for('view_repo', repo=fork.parent.name) }}">
                    {{fork.parent.name}}
                  </a>
                  {% if fork.settings.get('issue_tracker', True) %}
                    {% if fork.open_tickets_public == 0 %}
                      <span class="text-muted" data-toggle="tooltip"
                        title="{{ fork.open_tickets_public }} open issues against {{fork.name}}">
                        <span class="oi" data-glyph="warning"></span>
                        {{- fork.open_tickets_public }}
                      </span>
                    {% else %}
                      <a class="notblue" data-toggle="tooltip"
                        href="{{ url_for('.view_issues', repo=fork.name) }}"
                        title="{{ fork.open_tickets_public }} open issues against {{fork.name}}">
                        <span class="oi" data-glyph="warning"></span>
                        {{- fork.open_tickets_public }}
                      </a>
                    {% endif %}
                  {% endif %}
                  {% if fork.settings.get('pull_requests', True) %}
                    {% if fork.open_requests == 0 %}
                      <span class="text-muted" data-toggle="tooltip"
                        title="{{fork.open_requests}} open pull requests in {{fork.name}}">
                        <span class="oi" data-glyph="arrow-thick-bottom"></span>
                        {{- fork.open_requests}}
                      </span>
                    {% else %}
                      <a class="notblue" data-toggle="tooltip"
                        href="{{ url_for('.request_pulls', repo=fork.name) }}"
                        title="{{fork.open_requests}} open pull requests in {{fork.name}}">
                        <span class="oi" data-glyph="arrow-thick-bottom"></span>
                        {{- fork.open_requests}}
                      </a>
                    {% endif %}
                  {% endif %}
                  </div>
              </div>
            {% endfor %}
            </div>
        {% else %}
          <div class="card-block">
            <p>You have no forks</p>
          </div>
        {% endif %}
        </div>

        {{render_contributions_graph(username)}}

      </div>
      <div class="col-md-4">
        <div class="card" id="group_list">
            <div class="card-header">
                My Groups <span class="label label-default">{{ user.groups | length }}</span>
            </div>
            {% for group in user.groups %}
              <div class="list-group">
                <a class="list-group-item" href="{{ url_for(
                    'view_group', group=group)}}">
                  <div class=""><strong><span class="oi" data-glyph="people">
                    </span> &nbsp;{{ group }}</strong>
                  </div>
                </a>
              </div>
            {% else %}
            <div class="card-block">
                <p>No group found</p>
            </div>
            {% endfor %}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}

{% block jscripts %}
    {{ super() }}
    <script type="text/javascript">
      $(function(){
        $('.show_parts input[type="checkbox"]').change(function(){
          $('#' + $(this).attr('name')).toggle();
        });
      });
    </script>
{% endblock %}
