Add bulk table actions for team page

bulk-table-profile-actions
Kevin Chung 2020-05-02 14:09:47 -04:00
parent 735faf0e23
commit 5a9d79f2bb
5 changed files with 222 additions and 179 deletions

View File

@ -80,6 +80,74 @@ function updateTeam(event) {
});
}
function deleteSelectedSubmissions(event, target) {
let submissions;
let type;
let title;
switch(target){
case "solves":
submissions = $("input[data-submission-type=correct]:checked");
type = "solve";
title = "Solves"
break;
case "fails":
submissions = $("input[data-submission-type=incorrect]:checked");
type = "fail";
title = "Fails"
break;
default:
break;
}
let submissionIDs = submissions.map(function() {
return $(this).data("submission-id");
});
let target_string = submissionIDs.length === 1 ? type : (type + "s");
ezQuery({
title: `Delete ${title}`,
body: `Are you sure you want to delete ${submissionIDs.length} ${target_string}?`,
success: function() {
const reqs = [];
for (var subId of submissionIDs) {
reqs.push(CTFd.api.delete_submission({ submissionId: subId }));
}
Promise.all(reqs).then(responses => {
window.location.reload();
});
}
});
}
function deleteSelectedAwards(event) {
let awardIDs = $("input[data-award-id]:checked").map(function() {
return $(this).data("award-id");
});
let target = awardIDs.length === 1 ? "award" : "awards";
ezQuery({
title: `Delete Awards`,
body: `Are you sure you want to delete ${awardIDs.length} ${target}?`,
success: function() {
const reqs = [];
for (var awardID of awardIDs) {
let req = CTFd.fetch("/api/v1/awards/" + awardID, {
method: "DELETE",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
});
reqs.push(req);
}
Promise.all(reqs).then(responses => {
window.location.reload();
});
}
});
}
const api_funcs = {
team: [
x => CTFd.api.get_team_solves({ teamId: x }),
@ -335,82 +403,16 @@ $(() => {
});
});
$(".delete-submission").click(function(e) {
e.preventDefault();
const submission_id = $(this).attr("submission-id");
const submission_type = $(this).attr("submission-type");
const submission_challenge = $(this).attr("submission-challenge");
const body = "<span>Are you sure you want to delete <strong>{0}</strong> submission from <strong>{1}</strong> for <strong>{2}</strong>?</span>".format(
htmlEntities(submission_type),
htmlEntities(TEAM_NAME),
htmlEntities(submission_challenge)
);
const row = $(this)
.parent()
.parent();
ezQuery({
title: "Delete Submission",
body: body,
success: function() {
CTFd.fetch("/api/v1/submissions/" + submission_id, {
method: "DELETE",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
})
.then(function(response) {
return response.json();
})
.then(function(response) {
if (response.success) {
row.remove();
}
});
}
});
$("#solves-delete-button").click(function(e){
deleteSelectedSubmissions(e, "solves")
});
$(".delete-award").click(function(e) {
e.preventDefault();
const award_id = $(this).attr("award-id");
const award_name = $(this).attr("award-name");
$("#fails-delete-button").click(function(e){
deleteSelectedSubmissions(e, "fails")
});
const body = "<span>Are you sure you want to delete the <strong>{0}</strong> award from <strong>{1}</strong>?".format(
htmlEntities(award_name),
htmlEntities(TEAM_NAME)
);
const row = $(this)
.parent()
.parent();
ezQuery({
title: "Delete Award",
body: body,
success: function() {
CTFd.fetch("/api/v1/awards/" + award_id, {
method: "DELETE",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
})
.then(function(response) {
return response.json();
})
.then(function(response) {
if (response.success) {
row.remove();
}
});
}
});
$("#awards-delete-button").click(function(e){
deleteSelectedAwards(e);
});
$("#team-info-create-form").submit(createTeam);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -237,125 +237,173 @@
aria-controls="nav-awards" aria-selected="false">Awards</a>
</nav>
<div class="tab-content min-vh-25" id="nav-tabContent">
<div class="tab-content min-vh-50" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-solves" role="tabpanel" aria-labelledby="nav-solves-tab">
<h3 class="text-center pt-5 d-block">Solves</h3>
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<h3 class="text-center py-3 d-block">Solves</h3>
<thead>
<tr>
<td class="text-center"><b>Challenge</b></td>
<td class="text-center"><b>User</b></td>
<td class="text-center"><b>Submitted</b></td>
<td class="text-center"><b>Category</b></td>
<td class="text-center"><b>Value</b></td>
<td class="text-center"><b>Time</b></td>
<td class="text-center"><b>Delete</b></td>
</tr>
</thead>
<tbody>
{% for solve in solves %}
<tr class="chal-solve" data-href="{{ url_for("admin.challenges_detail", challenge_id=solve.challenge_id) }}">
<td class="text-center chal" id="{{ solve.challenge_id }}">
<a href="{{ url_for("admin.challenges_detail", challenge_id=solve.challenge_id) }}">
{{ solve.challenge.name }}
</a>
</td>
<td class="text-center">
<a href="{{ url_for("admin.users_detail", user_id=solve.user_id) }}">
{{ solve.user.name }}
</a>
</td>
<td class="flag" id="{{ solve.id }}"><pre>{{ solve.provided }}</pre></td>
<td class="text-center">{{ solve.challenge.category }}</td>
<td class="text-center">{{ solve.challenge.value }}</td>
<td class="text-center solve-time">
<span data-time="{{ solve.date | isoformat }}"></span>
</td>
<td class="text-center">
<span class="delete-submission" submission-id="{{ solve.id }}"
submission-type="{{ solve.type }}"
submission-challenge="{{ solve.challenge.name }}" data-toggle="tooltip"
data-placement="top" title="Delete solve #{{ solve.id }}">
<i class="fas fa-times"></i>
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="float-right pb-3">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-danger" id="solves-delete-button">
<i class="btn-fa fas fa-trash-alt"></i>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-striped border">
<thead>
<tr>
<th class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" data-checkbox-all>&nbsp;
</div>
</th>
<th class="sort-col text-center"><b>Challenge</b></th>
<th class="sort-col text-center"><b>User</b></th>
<th class="sort-col text-center"><b>Submitted</b></th>
<th class="sort-col text-center"><b>Category</b></th>
<th class="sort-col text-center"><b>Value</b></th>
<th class="sort-col text-center"><b>Time</b></th>
</tr>
</thead>
<tbody>
{% for solve in solves %}
<tr class="chal-solve" data-href="{{ url_for("admin.challenges_detail", challenge_id=solve.challenge_id) }}">
<td class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" value="{{ solve.id }}" data-submission-id="{{ solve.id }}"
data-submission-type="{{ solve.type }}"
data-submission-challenge="{{ solve.challenge.name }}">&nbsp;
</div>
</td>
<td class="text-center chal" id="{{ solve.challenge_id }}">
<a href="{{ url_for("admin.challenges_detail", challenge_id=solve.challenge_id) }}">
{{ solve.challenge.name }}
</a>
</td>
<td class="text-center">
<a href="{{ url_for("admin.users_detail", user_id=solve.user_id) }}">
{{ solve.user.name }}
</a>
</td>
<td class="flag" id="{{ solve.id }}"><pre>{{ solve.provided }}</pre></td>
<td class="text-center">{{ solve.challenge.category }}</td>
<td class="text-center">{{ solve.challenge.value }}</td>
<td class="text-center solve-time">
<span data-time="{{ solve.date | isoformat }}"></span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-wrong" role="tabpanel" aria-labelledby="nav-wrong-tab">
<h3 class="text-center pt-5 d-block">Fails</h3>
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<h3 class="text-center py-3 d-block">Fails</h3>
<thead>
<tr>
<td class="text-center"><b>Challenge</b></td>
<td class="text-center"><b>User</b></td>
<td class="text-center"><b>Submitted</b></td>
<td class="text-center"><b>Time</b></td>
<td class="text-center"><b>Delete</b></td>
</tr>
</thead>
<tbody>
{% for fail in fails %}
<tr class="chal-wrong" data-href="{{ url_for("admin.challenges_detail", challenge_id=fail.challenge_id) }}">
<td class="text-center chal" id="{{ fail.challenge_id }}">
<a href="{{ url_for("admin.challenges_detail", challenge_id=fail.challenge_id) }}">
{{ fail.challenge.name }}
</a>
</td>
<td class="text-center">
<a href="{{ url_for("admin.users_detail", user_id=fail.user_id) }}">
{{ fail.user.name }}
</a>
</td>
<td class="flag" id="{{ fail.id }}"><pre>{{ fail.provided }}</pre></td>
<td class="text-center solve-time">
<span data-time="{{ fail.date | isoformat }}"></span>
</td>
<td class="text-center">
<span class="delete-submission" submission-id="{{ fail.id }}"
submission-type="{{ fail.type }}"
submission-challenge="{{ fail.challenge.name }}" data-toggle="tooltip"
data-placement="top" title="Delete fail #{{ fail.id }}">
<i class="fas fa-times"></i>
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="float-right pb-3">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-danger" id="fails-delete-button">
<i class="btn-fa fas fa-trash-alt"></i>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-striped border">
<thead>
<tr>
<th class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" data-checkbox-all>&nbsp;
</div>
</th>
<th class="sort-col text-center"><b>Challenge</b></th>
<th class="sort-col text-center"><b>User</b></th>
<th class="sort-col text-center"><b>Submitted</b></th>
<th class="sort-col text-center"><b>Time</b></th>
</tr>
</thead>
<tbody>
{% for fail in fails %}
<tr class="chal-wrong" data-href="{{ url_for("admin.challenges_detail", challenge_id=fail.challenge_id) }}">
<td class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" value="{{ fail.id }}" data-submission-id="{{ fail.id }}"
data-submission-type="{{ fail.type }}"
data-submission-challenge="{{ fail.challenge.name }}">&nbsp;
</div>
</td>
<td class="text-center chal" id="{{ fail.challenge_id }}">
<a href="{{ url_for("admin.challenges_detail", challenge_id=fail.challenge_id) }}">
{{ fail.challenge.name }}
</a>
</td>
<td class="text-center">
<a href="{{ url_for("admin.users_detail", user_id=fail.user_id) }}">
{{ fail.user.name }}
</a>
</td>
<td class="flag" id="{{ fail.id }}"><pre>{{ fail.provided }}</pre></td>
<td class="text-center solve-time">
<span data-time="{{ fail.date | isoformat }}"></span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-awards" role="tabpanel" aria-labelledby="nav-awards-tab">
<h3 class="text-center pt-5 d-block">Awards</h3>
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<h3 class="text-center py-3 d-block">Awards</h3>
<div class="float-right pb-3">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-danger" id="awards-delete-button">
<i class="btn-fa fas fa-trash-alt"></i>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-striped border">
<thead>
<tr>
<td class="text-center"><b>Name</b></td>
<td class="text-center"><b>User</b></td>
<td class="text-center"><b>Description</b></td>
<td class="text-center"><b>Date</b></td>
<td class="text-center"><b>Value</b></td>
<td class="text-center"><b>Category</b></td>
<td class="text-center"><b>Icon</b></td>
<td class="text-center"><b>Delete</b></td>
<th class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" data-checkbox-all>&nbsp;
</div>
</th>
<th class="sort-col text-center"><b>Name</b></th>
<th class="sort-col text-center"><b>User</b></th>
<th class="sort-col text-center"><b>Description</b></th>
<th class="sort-col text-center"><b>Date</b></th>
<th class="sort-col text-center"><b>Value</b></th>
<th class="sort-col text-center"><b>Category</b></th>
<th class="sort-col text-center"><b>Icon</b></th>
</tr>
</thead>
<tbody id="awards-body">
{% for award in awards %}
<tr class="award-row">
<td class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" value="{{ award.id }}" data-award-id="{{ award.id }}" data-award-name="{{ award.name }}">&nbsp;
</div>
</td>
<td class="text-center chal" id="{{ award.id }}">{{ award.name }}</td>
<td class="text-center">
<a href="{{ url_for("admin.users_detail", user_id=award.user_id) }}">
@ -368,14 +416,7 @@
</td>
<td class="text-center">{{ award.value }}</td>
<td class="text-center">{{ award.category }}</td>
<td class="text-center">{{ award.icon }}</td>
<td class="text-center">
<span class="delete-award" award-id="{{ award.id }}" award-name="{{ award.name }}"
data-toggle="tooltip" data-placement="top" title="Delete award #{{ award.id }}">
<i class="fas fa-times"></i>
</span>
</td>
<td class="text-center"><i class="award-icon award-{{ award.icon }}"></i> {{ award.icon }}</td>
</tr>
{% endfor %}
</tbody>

File diff suppressed because one or more lines are too long