#532 [frontend] build batch deletion by xhr
Merged 9 months ago by msuchy. Opened 9 months ago by clime.

@@ -200,3 +200,29 @@ 

      </button>

    </form>

  {% endmacro %}

+ 

+ {% macro copr_delete_builds(copr, class="") %}

+   <form class="{{ class }} delete-builds" action="#" method="post">

+     <button class="btn btn-danger" type="submit">

+       <span class="pficon pficon-delete"></span> Delete all marked

+     </button>

+   </form>

+ 

+   <script>

+     $('form.delete-builds').submit(function(event) {

+       var build_ids = [];

+       $('tr.build-row :checkbox[name=build_ids]:checked').each(function() {

+         build_ids.push(this.value);

+       });

+ 

+       if (!confirm('Are you sure, you want to delete ' + build_ids.length + ' builds from your copr?')) {

+         return false;

+       }

+ 

+       $.post("{{ url_for('coprs_ns.copr_delete_builds', username=copr.user.name, coprname=copr.name) }}", {"build_ids": build_ids}, function() {

+         $(location).attr('href', '{{ copr_url('coprs_ns.copr_builds', copr) }}');

+       });

+       return false;

+   });

+   </script>

+ {% endmacro %}

@@ -13,6 +13,7 @@ 

          <th>Submitted</th>

          <th>Build Time</th>

          <th>Status</th>

+         <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>

        </tr>

      </thead>

      <tbody>

@@ -43,6 +44,9 @@ 

          <td>

            {{ build_state(build) }}

          </td>

+         <td>

+           <input type="checkbox" name="build_ids" value="{{ build.id }}"></input>

+         </td>

        </tr>

      {% endfor %}

      </tbody>

@@ -4,6 +4,7 @@ 

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

  {% from "coprs/detail/_builds_table.html" import builds_table with context %}

  {% from "coprs/detail/_build_states.html" import build_states %}

+ {% from "coprs/detail/_builds_forms.html" import copr_delete_builds %}

  

  {% set selected_tab = "builds" %}

  

@@ -15,7 +16,12 @@ 

  

  {% block detail_body %}

  {% if g.user and g.user.can_build_in(copr) %}

-   <a class="btn btn-primary button-new pull-right" href="{{ copr_url('coprs_ns.copr_add_build', copr) }}"><span class="pficon pficon-add-circle-o"></span> New Build</a>

+   <a class="btn btn-primary button-new pull-right" style="margin-left:5px" href="{{ copr_url('coprs_ns.copr_add_build', copr) }}">

+     <span class="pficon pficon-add-circle-o"></span> New Build

+   </a>

+   {% if builds %}

+     {{ copr_delete_builds(copr, class="pull-right button-build-action") }}

+   {% endif %}

  {% endif %}

  

  <h2 class="page-title">Project Builds</h2>

@@ -471,3 +471,24 @@ 

          flask.flash("Build has been deleted successfully.")

  

      return flask.redirect(helpers.url_for_copr_builds(build.copr))

+ 

+ ################################ xhr batch delete ################################

+ 

+ @coprs_ns.route("/<username>/<coprname>/delete_builds/", methods=["POST"])

+ @coprs_ns.route("/g/<group_name>/<coprname>/delete_builds/", methods=["POST"])

+ @login_required

+ @req_with_copr

+ def copr_delete_builds(copr):

+     build_ids = flask.request.form.getlist("build_ids[]")

+ 

+     for build_id in build_ids:

+         build = ComplexLogic.get_build_safe(build_id)

+         try:

+             builds_logic.BuildsLogic.delete_build(flask.g.user, build)

+         except (InsufficientRightsException, ActionInProgressException) as e:

+             flask.flash(str(e), "error")

+ 

+     db.session.commit()

+     build_ids_str = ", ".join(build_ids).strip(", ")

+     flask.flash("Builds {} have been deleted successfully.".format(build_ids_str), "success")

+     return flask.jsonify({"msg": "success"})