#456 Show project forks #409
Merged 5 years ago by frostyx. Opened 5 years ago by frostyx.
copr/ frostyx/copr show-forks  into  master

@@ -232,6 +232,14 @@ 

  {%- endmacro %}

  

  

+ {%- macro owner_url(copr) %}

+   {% if copr.is_a_group_project %}

+     {{- url_for('groups_ns.list_projects_by_group', group_name=copr.group.name) }}

+   {% else %}

+     {{- url_for('coprs_ns.coprs_by_user', username=copr.user.name) }}

+   {% endif %}

+ {%- endmacro %}

+ 

  

  {% macro user_projects_panel(user) %}

    <div class="panel panel-default">
@@ -574,6 +582,7 @@ 

        </div>

  {% endmacro %}

  

+ 

  {% macro warn_server_admin(copr) %}

    {% if g.user and g.user.admin and g.user != copr.user %}

      {% if not g.user.permissions_for_copr(copr) or g.user.permissions_for_copr(copr).copr_admin < 2 %}
@@ -583,3 +592,15 @@ 

      {% endif %}

    {% endif %}

  {% endmacro %}

+ 

+ 

+ {% macro initialize_datatables(order="desc") %}

+   <script>

+   // Initialize Datatables

+   $(document).ready(function() {

+     $('.datatable').dataTable({

+       "order": [[ 0, "{{ order }}" ]]

+     });

+   });

+   </script>

+ {% endmacro %}

@@ -1,5 +1,5 @@ 

  {% from "coprs/detail/_builds_forms.html" import copr_build_cancel_form, copr_build_repeat_form, copr_build_delete_form %}

- {% from "_helpers.html" import build_href_from_sql, build_state %}

+ {% from "_helpers.html" import build_href_from_sql, build_state, initialize_datatables %}

  

  {% macro builds_table(builds) %}

  {% if builds %}
@@ -51,13 +51,6 @@ 

    <h3>No builds so far</h3>

  {% endif %}

  

- <script>

-   // Initialize Datatables

-   $(document).ready(function() {

-     $('.datatable').dataTable({

-       "order": [[ 0, "desc" ]]

-     });

-   });

- </script>

+ {{ initialize_datatables() }}

  

  {% endmacro %}

@@ -1,5 +1,5 @@ 

  {% from "_helpers.html" import copr_url %}

- {% from "_helpers.html" import module_state %}

+ {% from "_helpers.html" import module_state, initialize_datatables %}

  

  {% macro modules_table(modules) %}

  {% if modules %}
@@ -34,13 +34,6 @@ 

  <h3>No modules so far</h3>

  {% endif %}

  

- <script>

-   // Initialize Datatables

-   $(document).ready(function() {

-     $('.datatable').dataTable({

-       "order": [[ 0, "desc" ]]

-     });

-   });

- </script>

+ {{ initialize_datatables() }}

  

  {% endmacro %}

@@ -1,5 +1,5 @@ 

  {% from "coprs/detail/_builds_forms.html" import copr_build_cancel_form, copr_build_repeat_form, copr_build_delete_form %}

- {% from "_helpers.html" import build_href_from_sql, build_state %}

+ {% from "_helpers.html" import build_href_from_sql, build_state, initialize_datatables %}

  

  {% macro package_table(builds) %}

  <noscript><p>WARNING!! This page is using JavaScript to filter and sort the table.</p></noscript>
@@ -43,13 +43,6 @@ 

    <h3>No builds so far</h3>

  {% endif %}

  

- <script>

-   // Initialize Datatables

-   $(document).ready(function() {

-     $('.datatable').dataTable({

-       "order": [[ 0, "desc" ]]

-     });

-   });

- </script>

+ {{ initialize_datatables() }}

  

  {% endmacro %}

@@ -1,4 +1,4 @@ 

- {% from "_helpers.html" import copr_url, build_state %}

+ {% from "_helpers.html" import copr_url, build_state, initialize_datatables %}

  

  {% macro packages_table(packages) %}

  {% if packages %}
@@ -66,13 +66,6 @@ 

    <h3>No packages so far</h3>

  {% endif %}

  

- <script>

-   // Initialize Datatables

-   $(document).ready(function() {

-     $('.datatable').dataTable({

-       "order": [[ 0, "asc" ]]

-     });

-   });

- </script>

+ {{ initialize_datatables(order="asc") }}

  

  {% endmacro %}

@@ -0,0 +1,45 @@ 

+ {% extends "coprs/detail.html" %}

+ {% from "_helpers.html" import copr_name, owner_url, initialize_datatables %}

+ 

+ {% block title %}Forks of {{ copr_name(copr) }}{% endblock %}

+ {% set selected_tab = "forks" %}

+ 

+ {%block project_breadcrumb %}

+ <li class="active">Forks</li>

+ {%endblock%}

+ 

+ {% block detail_body %}

+ {% if g.user %}

+ <a class="btn btn-primary button-new pull-right" href="{{ copr_url('coprs_ns.copr_fork', copr) }}"><i class="fa fa-code-fork"></i> Fork this project</a>

+ {% endif %}

+ <h2 class="page-title">Forks of the project</h2>

+ 

+ {% if copr.forks %}

+ <noscript><p>WARNING!! This page is using JavaScript to filter and sort the table.</p></noscript>

+ <table class="datatable table table-striped table-bordered">

+   <thead>

+   <tr>

+     <th>Owner</th>

+     <th>Name</th>

+   </tr>

+   </thead>

+   <tbody>

+   {% for fork in copr.forks %}

+     <tr class="fork-row" >

+       <td class="col-md-3" data-order="{{ fork.owner_name }}">

+         <b><a href="{{ owner_url(fork) }}">{{ fork.owner_name }}</a></b>

+       </td>

+       <td>

+         <b><a href="{{ copr_url('coprs_ns.copr_detail', fork) }}">{{ fork.name }}</a></b>

+       </td>

+     </tr>

+   {% endfor %}

+   </tbody>

+ </table>

+ {% else %}

+ <h3>Nobody forked this project</h3>

+ {% endif %}

+ 

+ {{ initialize_datatables() }}

+ 

+ {% endblock %}

@@ -166,7 +166,11 @@ 

            <a href="{{ copr_url('coprs_ns.copr_fork', copr) }}" class="btn btn-default">

              <i class="fa fa-code-fork"></i> Fork this project

            </a>

+           <a href="{{ copr_url('coprs_ns.copr_forks', copr) }}" class="btn btn-default">

+             {{ copr.forks | count }}

+           </a>

          </div>

+         <br>

          {% endif %}

  

          <a href="{{ copr_url('coprs_ns.copr_report_abuse', copr) }}">

@@ -1,5 +1,5 @@ 

  {% extends "layout.html" %}

- {% from "_helpers.html" import fas_group_href %}

+ {% from "_helpers.html" import fas_group_href, initialize_datatables %}

  {% block title %}Add a Group{% endblock %}

  {% block header %}Add a Group{% endblock %}

  
@@ -61,16 +61,6 @@ 

    <h3>You are not listed in any FAS group.</h3>

  {% endif %}

  

- <script>

-   // Initialize Datatables

-   $(document).ready(function() {

-     $('.datatable').dataTable({

-       "order": [[ 0, "desc" ]]

-     });

-   });

- </script>

- 

- 

- 

+ {{ initialize_datatables() }}

  

  {% endblock %}

@@ -833,6 +833,13 @@ 

      return render_copr_fork(copr, form)

  

  

+ @coprs_ns.route("/<username>/<coprname>/forks/")

+ @coprs_ns.route("/g/<group_name>/<coprname>/forks/")

+ @req_with_copr

+ def copr_forks(copr):

+     return flask.render_template("coprs/detail/forks.html", copr=copr)

+ 

+ 

  @coprs_ns.route("/update_search_index/", methods=["POST"])

  def copr_update_search_index():

      subprocess.call(['/usr/share/copr/coprs_frontend/manage.py', 'update_indexes_quick', '1'])

This implements RFE #409
Also, there is a small refactoring that adds initialize_datatables macro to get rid of duplicating the JS code in each file.

Here are some screenshots of this feature.

There are conflicts, please rebase this PR

rebased onto 545d247

5 years ago

Rebased and fixed the conflicts. Merging.

Pull-Request has been merged by frostyx

5 years ago