Blob Blame Raw
{% macro render_row(items) -%}
    {% for repo in items %}
      {% set url = url_for('ui_ns.view_repo',
        username=repo.user.username if repo.is_fork else None,
        repo=repo.name, namespace=repo.namespace) %}
  <div class="col-lg-4 col-md-6">
    <div class="project_wrapper m-b-1">
      {% if repo.avatar_email %}
        <img class="projecticon pull-xs-left" src="{{ repo.avatar_email | avatar_url }}" width=60 height=60 />
      {% else %}
        <div class="projecticon pull-xs-left"><span class="oi" data-glyph="document"></span></div>
      {% endif %}
      <a class="project_link logo_link" href="{{ url }}">
        <div class="repo_name">
          <strong>
            {{ repo.namespace + '/' if repo.namespace }}{{ repo.name }}
          </strong>
        </div>
      </a>
      <div class="repo_desc" title="{{ repo.description }}" data-toggle="tooltip">
        <small>
          {% if repo.description %}{{ repo.description }}{% else %}
          <span class="text-muted">no description<span>{% endif %}
        </small>
      </div>
      <div class="project_metadata">
        <span class="p-l-1">
          <small>created {{repo.date_created|humanize}}</small>
        </span>
        <div style="text-align:right;" class="p-r-1 text-muted pull-xs-right">
          <span title="Forks" data-toggle="tooltip">
            <span class="oi" data-glyph="fork"></span>
            {{repo.forks|count}}
          </span>
        </div>
      </div>
    </div>
  </div>
    {% else %}
<p>No projects found</p>
    {% endfor %}
{%- endmacro %}


{% macro pagination_link(pagetitle, page, total) -%}
{% set prev_page = request.url | combine_url(
    page=page-1, pagetitle=pagetitle, **kwargs) %}
{% set next_page = request.url | combine_url(
    page=page+1, pagetitle=pagetitle, **kwargs) %}
<aside>
    <nav class="text-center">
      <ul class="pagination">
        <li {% if page <= 1%} class="disabled" {% endif %}>
          <a href="{{ prev_page }}">
            <span aria-hidden="true">&laquo;</span>
            <span class="sr-only">Newer</span>
          </a>
        </li>
        <li class="active">page {{ page }} of {{ total }}</li>
        <li {% if page >= total %}class="disabled"{%endif%}>
          <a href="{{ next_page }}">
            <span aria-hidden="true">&raquo;</span>
            <span class="sr-only">Older</span>
          </a>
        </li>
      </ul>
    </nav>
</aside>
{%- endmacro %}


{% macro render_repos(
        list, total, pagetitle, page, title, count, id,
        username=None, hide=True, sorting=None) %}

    <section class="project_list container p-t-2" id="{{ id }}">
        <h2 class="m-b-1">{{
            title
            }} <span class="label label-default">{{ count }}</span>
            {%- if username -%}
            <a href="{{ url_for('ui_ns.new_project') }}">
            <button type="button" class="btn btn-success pull-xs-right">
              New Project
            </button>
            </a>
            {%- endif -%}
        </h2>
        <div class="row">
          <div class="col-sm-6">
            {% if total and total > 1 %}
            {{ pagination_link(pagetitle, page, total, sorting=sorting) }}
            {% endif %}
          </div>
          <div class="col-sm-6 text-xs-right">
            <span class="btn-group">
              <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Sort
              </button>
              <div class="dropdown-menu dropdown-menu-right">
                <a class="dropdown-item" href="{{
                    url_for('ui_ns.browse_projects') }}">
                  {% if not sorting or sorting == 'name'%}
                  <span class="oi" data-glyph="check"></span>
                  {%endif%}
                  Name
                </a>
                <a class="dropdown-item" href="{{
                    url_for('ui_ns.browse_projects', sorting='latest') }}">
                  {% if sorting == 'latest'%}
                  <span class="oi" data-glyph="check"></span>
                  {%endif%}
                  Recent First
                </a>
                <a class="dropdown-item" href="{{
                    url_for('ui_ns.browse_projects', sorting='oldest') }}">
                  {% if sorting == 'oldest'%}
                  <span class="oi" data-glyph="check"></span>
                  {%endif%}
                  Oldest First
                </a>
              </div>
            </span>
          </div>
        </div>
        <div class="row">
            {{ render_row(list) }}
        </div>
        {% if total and total > 1 %}
        {{ pagination_link(pagetitle, page, total, sorting=sorting) }}
        {% endif %}
    </section>
{% endmacro %}

{% macro render_user_repos(
        list, total, pagetitle, page, title, count, id, username=None, hide=True) %}
      <div class="card" id="{{ id }}">
          <div class="card-header">
              {{ title }} <span class="label label-default">{{ count }}</span>
          </div>
          {% if total and total > 1 %}
          {{ pagination_link(pagetitle, page, total) }}
          {% endif %}
          <div class="card-block">

            {% for repo in list %}
                <a class="project_link logo_link" href="{{
                    url_for(
                    'ui_ns.view_repo',
                    repo=repo.name,
                    username=repo.user.username if repo.is_fork else None,
                    namespace=repo.namespace)
                }}">
                  <div>
                    <strong>
                      {{ repo.namespace + '/' if repo.namespace }}{{ repo.name }}
                    </strong>
                  </div>
               </a>
            {% else %}
            <p>No projects found</p>
            {% endfor %}

          </div>
          {% if total and total > 1 %}
          {{ pagination_link(pagetitle, page, total) }}
          {% endif %}
      </div>
{% endmacro %}


{% macro repos_switch(all=True, hide=True) %}
    <aside class="show_parts">
        <div class="container">
        <strong>
            {% if all %}My repos:{% else %}Repos:{% endif %}
        </strong>
        <label class="switch">
            <input type="checkbox" class="switch-input"
                name="{% if all %}my{% endif %}repos"
                {%- if (
                    (all and 'myrepos' in config.get('SHOW_PROJECTS_INDEX', []))
                    or
                    (not all and 'repos' not in config.get('SHOW_PROJECTS_INDEX', []))
                  )
                  or not hide %} checked {% endif %}/>
            <span class="switch-label" data-on="On" data-off="Off"></span>
            <span class="switch-handle"></span>
        </label>
        <strong>Forks:</strong>
        <label class="switch">
            <input type="checkbox" class="switch-input"
                name="{% if all %}my{% endif %}forks" {%
                if 'myforks' in config.get('SHOW_PROJECTS_INDEX', []) or not hide
                %} checked {% endif %}/>
            <span class="switch-label" data-on="On" data-off="Off"></span>
            <span class="switch-handle"></span>
        </label>
        {% if all %}
        <strong>All repos:</strong>
        <label class="switch">
            <input type="checkbox" class="switch-input"
                name="repos" id="allrepos" {%
                if 'repos' in config.get('SHOW_PROJECTS_INDEX', []) or not hide
                %} checked {% endif %}/>
            <span class="switch-label" data-on="On" data-off="Off"></span>
            <span class="switch-handle"></span>
        </label>
        {% endif %}
        </div>
    </aside>
{% endmacro %}

{% macro render_repos_as_card(list, total, name, pagetitle, page, total_page) %}
        {% if total_page and total_page > 1 %}
        {{ pagination_link(pagetitle, page, total_page) }}
        {% endif %}
        <div class="card">
          <div class="card-header">
            {{name}} <span class="label label-default">{{total}}</span>
          </div>
          {% if list %}
            <div class="list-group">
            {% for repo in list %}
              <div class="list-group-item">
                {% set url = url_for('ui_ns.view_repo',
                  repo=repo.name,
                  username=repo.user.username if repo.is_fork else None,
                  namespace=repo.namespace) %}

                {% if repo.avatar_email %}
                  <img class="projecticon pull-xs-left"
                    src="{{ repo.avatar_email | avatar_url }}"
                    width=60 height=60 />
                {% else %}
                    <div class="projecticon pull-xs-left">
                      <span class="oi" data-glyph="document"></span>
                    </div>
                {% endif %}

                <a class="project_link logo_link" href="{{ url }}">
                    <div class="repo_name">
                      <strong>
                        {{ repo.fullname }}
                      </strong>
                    </div>
                </a>

                <div class="repo_desc" title="{{ repo.description }}"
                    data-toggle="tooltip">
                  <small>{% if
                    repo.description %}{{ repo.description }}{%
                    else %}<span class="text-muted">no description<span>{%
                    endif %}</small>
                </div>
              </div>
            {% endfor %}
            </div>
        {% else %}
          <div class="card-block">
            <p>No projects found</p>
          </div>
        {% endif %}
        </div>
        {% if total_page and total_page > 1 %}
        {{ pagination_link(pagetitle, page, total_page) }}
        {% endif %}
{% endmacro %}

{% macro render_activity_graph(username) %}
<script type="text/javascript"src="{{
  url_for('static', filename='vendor/jquery/jquery.min.js') }}"></script>
<script type="text/javascript" src="{{
  url_for('static', filename='vendor/d3/d3.v3.min.js') }}"></script>
<script type="text/javascript" src="{{
  url_for('static', filename='vendor/cal-heatmap/cal-heatmap.min.js') }}"></script>
<link rel="stylesheet" href="{{
  url_for('static', filename='vendor/cal-heatmap/cal-heatmap.css') }}" />


<div class="card" id="user_graph">
  <div class="card-header">Activity</div>
  <div class="card-block p-a-0">
    <div id="cal-heatmap">
    </div>
    <div id="user-activity" class="hidden">
      <div class="card-header">
        <span id="user-activity-title">
        Recent Activity
        </span>
        <span class="pull-xs-right">
          <button class="btn btn-secondary btn-sm" id="hide_activity">
            <span class="oi" data-glyph="x" data-toggle="tooltip"
              title="Hide activity info" aria-hidden="true">
            </span>
          </button>
        </span>
      </div>
      <div class="list-group" id="user-activity-body"></div>
    </div>
    <script type="text/javascript">
      function padStr(i) {
          return (i < 10) ? "0" + i : "" + i;
      }
      $('#hide_activity').click(function(){
        $('#user-activity').hide();
      });
      var cal = new CalHeatMap();
      cal.init({
        cellSize: 9,
        domain: "month",
        subDomain: "day",
        domainLabelFormat: "%b",
        start: new Date(new Date().setMonth(new Date().getMonth() - 11)),
        data: "{{ url_for(
          'api_ns.api_view_user_activity_stats',
          username=username, format='timestamp') }}",
        dataType: "json",
        highlight: "now",
        onClick: function(date, nb) {
          date = date.getFullYear() + '-' + padStr(date.getMonth() + 1)
            + '-' + padStr(date.getDate());
          $.ajax({
            type: 'GET',
            url: "{{ url_for(
              'api_ns.api_view_user_activity_date',
              username=username, date='') }}" + date + '?grouped=1',
            contentType: "application/json",
            dataType: 'json',
            success: function(data) {
              $('#user-activity-body').html('');
              $('#user-activity-title').text('Activity on ' + date);
              $('#user-activity').show();
              if (data.activities.length > 0){
                for (var i=0; i<data.activities.length; i++){
                  var d = data.activities[i];
                  $('#user-activity-body').append(
                    '<div class="list-group-item">'
                    + d.description_mk
                    + '</div>'
                  );
                }
              }
               else {
                  $('#user-activity-body').append(
                  '<div class="list-group-item">No activity recorded on that day</div>'
                );
              }
            }
          });
        }
      });
    </script>
  </div>
</div>
{% endmacro%}