This is an automated email from the git hooks/post-receive script.
praiskup pushed a commit to branch master
in repository copr/copr.
commit 30994cea15b8253df21b7a61c50ffe8a052b59e3
Author: Jakub Kadlcik <frostyx(a)email.cz>
AuthorDate: Fri Jan 17 01:24:21 2020 +0100
frontend: don't show builds table when there are none of them
This is a regression. Now `builds` variable doesn't contain list of
builds, but rather a SQL query to get them. Therefore condition
{% if builds %} is always true.
We are operating with large data here, so we want to avoid additional
query evaluating to find out if there are any results. The most
performance friendly solution should be for-else. Altough it works
fine, this change is a bit hacky from my point of view.
1. We need to loop the whole table because in the `else` block, we
don't want to have any table rendered
2. Of course it doesn't make any sense to render `table` and `thead`,
etc for every build. Just conditionally for `loop.first` and table
closing when `loop.last`
3. We need to call `build_states()` from within the `builds_table()`.
Because we want to show states only if there were any builds printed
and we don't have this information outside of the `build_table()`
macro.
4. We need to move the `no_builds_window()` code to `_builds_table.html`
so it can be rendered from the `for-else` else block.
Merges: #1215
---
.../templates/coprs/detail/_builds_table.html | 159 +++++++++++++--------
.../coprs/templates/coprs/detail/builds.html | 33 +----
.../coprs/templates/coprs/detail/module.html | 2 +-
3 files changed, 100 insertions(+), 94 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
b/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
index 513163b..2fcb586 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_table.html
@@ -1,70 +1,103 @@
{% 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,
initialize_datatables %}
+{% from "coprs/detail/_build_states.html" import build_states %}
+{% from "_helpers.html" import build_href_from_sql, build_state,
initialize_datatables, copr_url %}
-{% macro builds_table(builds) %}
-{% if builds %}
-<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>Build ID</th>
- <th>Package Name</th>
- <th>Package Version</th>
- <th>Submitted</th>
- <th>Build Time</th>
- <th>Status</th>
- {% if g.user and g.user.can_edit(copr) %}
- <th data-orderable="false"><a href="#"
onclick="$('tr.build-row :checkbox').prop('checked',
$('tr.build-row :checkbox').length != $('tr.build-row
:checkbox:checked').length); return false;">Mark all</a></th>
- {% endif %}
- </tr>
- </thead>
- <tbody>
- {# builds here is not a build object #}
- {% for build in builds %}
- <tr class="build-row" >
- <td data-order="{{ build.id }}">
- <b><a href="{{ build_href_from_sql(build) }}">
- {{ build.id }}
- </a></b>
- </td>
- <td>
- {# When builds are queried with custom SQL select #}
- {% if build.pkg_name %}
- {{ build.pkg_name }}
- {# When builds are really a ``models.Build`` instances #}
- {% elif build.package_name %}
- {{ build.package_name }}
- {% else %}
- -
- {% endif %}
- </td>
- <td>
- {% if build.pkg_version %}
- {{ build.pkg_version}}
- {% else %}
- -
- {% endif %}
- </td>
- <td data-order="{{build.submitted_on}}"> {{
build.submitted_on|time_ago() }} ago </td>
- <td
data-order="{{build.started_on|timestamp_diff(build.ended_on)}}"> {{
build.started_on|time_ago(build.ended_on) }} </td>
- <td>
- {{ build_state(build) }}
- </td>
+{% macro builds_table(builds, print_possible_states=True) %}
+ {% for build in builds %}
+ {% if loop.first %}
+ <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>Build ID</th>
+ <th>Package Name</th>
+ <th>Package Version</th>
+ <th>Submitted</th>
+ <th>Build Time</th>
+ <th>Status</th>
- {% if g.user and g.user.can_edit(copr) %}
- <td>
- <input type="checkbox" name="build_ids" value="{{
build.id }}"></input>
- </td>
- {% endif %}
- </tr>
- {% endfor %}
- </tbody>
- </table>
-{% else %}
- <h3>No builds so far</h3>
-{% endif %}
+ {% if g.user and g.user.can_edit(copr) %}
+ <th data-orderable="false"><a href="#"
onclick="$('tr.build-row :checkbox').prop('checked',
$('tr.build-row :checkbox').length != $('tr.build-row
:checkbox:checked').length); return false;">Mark all</a></th>
+ {% endif %}
+ </tr>
+ </thead>
+ <tbody>
+ {% endif %}
-{{ initialize_datatables() }}
+ <tr class="build-row" >
+ <td data-order="{{ build.id }}">
+ <b><a href="{{ build_href_from_sql(build) }}">
+ {{ build.id }}
+ </a></b>
+ </td>
+ <td>
+ {% if build.package_name %}
+ {{ build.package_name }}
+ {% else %}
+ -
+ {% endif %}
+ </td>
+ <td>
+ {% if build.pkg_version %}
+ {{ build.pkg_version}}
+ {% else %}
+ -
+ {% endif %}
+ </td>
+ <td data-order="{{build.submitted_on}}"> {{
build.submitted_on|time_ago() }} ago </td>
+ <td
data-order="{{build.started_on|timestamp_diff(build.ended_on)}}"> {{
build.started_on|time_ago(build.ended_on) }} </td>
+ <td>
+ {{ build_state(build) }}
+ </td>
+
+ {% if g.user and g.user.can_edit(copr) %}
+ <td>
+ <input type="checkbox" name="build_ids" value="{{
build.id }}"></input>
+ </td>
+ {% endif %}
+ </tr>
+
+ {% if loop.last %}
+ </tbody>
+ </table>
+ {{ initialize_datatables() }}
+ {% if print_possible_states %}
+ {{ build_states() }}
+ {% endif %}
+ {% endif %}
+
+ {% else %}
+ {{ no_builds_window() }}
+ {% endfor %}
+{% endmacro %}
+
+
+{% macro no_builds_window() %}
+ <div class="blank-slate-pf">
+ {% if not current_dirname %}
+ <div class="blank-slate-pf-icon">
+ <span class="pficon pficon pficon-add-circle-o"></span>
+ </div>
+ <h1>
+ No Builds in This Project
+ </h1>
+ <p>
+ Click on the New Build button to submit your first build.
+ </p>
+ <p>
+ You can also set up <strong>automatic builds</strong> directly from
your git. This can be done on the <a href="{{
copr_url('coprs_ns.copr_packages', copr) }}">Packages view</a>.
+ </p>
+ {% if g.user and g.user.can_build_in(copr) %}
+ <div class="blank-slate-pf-main-action">
+ <a class="btn btn-primary btn-lg" href="{{
copr_url('coprs_ns.copr_add_build', copr) }}"> Submit a New Build
</a>
+ </div>
+ {% endif %}
+ {% else %}
+ <h1>
+ No builds in this project directory.
+ </h1>
+ {% endif %}
+ </div>
{% endmacro %}
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/builds.html
b/frontend/coprs_frontend/coprs/templates/coprs/detail/builds.html
index 406b0c7..f72deee 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/builds.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/builds.html
@@ -46,34 +46,7 @@
</div>
</div>
{% endif %}
- {% if builds %}
- {{ builds_table(builds) }}
- {{ build_states() }}
- {% else %}
- <div class="blank-slate-pf">
- {% if not current_dirname %}
- <div class="blank-slate-pf-icon">
- <span class="pficon pficon pficon-add-circle-o"></span>
- </div>
- <h1>
- No Builds in This Project
- </h1>
- <p>
- Click on the New Build button to submit your first build.
- </p>
- <p>
- You can also set up <strong>automatic builds</strong> directly from
your git. This can be done on the <a href="{{
copr_url('coprs_ns.copr_packages', copr) }}">Packages view</a>.
- </p>
- {% if g.user and g.user.can_build_in(copr) %}
- <div class="blank-slate-pf-main-action">
- <a class="btn btn-primary btn-lg" href="{{
copr_url('coprs_ns.copr_add_build', copr) }}"> Submit a New Build
</a>
- </div>
- {% endif %}
- {% else %}
- <h1>
- No builds in this project directory.
- </h1>
- {% endif %}
- </div>
- {% endif %}
+
+ {{ builds_table(builds) }}
+
{% endblock %}
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/module.html
b/frontend/coprs_frontend/coprs/templates/coprs/detail/module.html
index 60595a2..acb8d03 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/module.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/module.html
@@ -163,7 +163,7 @@
</div>
</div>
- {{builds_table(module.builds)}}
+ {{builds_table(module.builds, print_possible_states=False)}}
</div>
</div>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.