Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-457: Add ability to select all stories in a project #331

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 51 additions & 18 deletions app/assets/javascripts/project.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
document.addEventListener("turbolinks:load", function () {
$("input[name='stories[]']").click(() => {
const selected = $("input[name='stories[]']:checked");
const is_unlocked = $("#stories").data("unlocked");
if (!is_unlocked) {
return;
}

if (selected.length > 0) {
const ending = selected.length == 1 ? "y" : "ies";
$("#bulk_delete")
.text(`Bulk Delete (${selected.length} Stor${ending})`)
.attr("aria-disabled", "false")
.prop("disabled", false);
} else {
$("#bulk_delete")
.text("Bulk Delete")
.attr("aria-disabled", "true")
.prop("disabled", true);
}
updateBulkDeleteStatus();
updateSelectAllStatus();
});


$(".import-export-header").click(function () {
$(this).children(".rotate").toggleClass("left");
});


$("#select_all").click((event) => {
let checked = event.target.checked;

$("input[name='stories[]']").each((_, checkbox) => {
checkbox.checked = checked;
})

updateBulkDeleteStatus();
})

$("#bulk_delete").click((event) => {
let stories_ids = [];
$("input[name='stories[]']:checked").each((_, checkbox) => {
Expand Down Expand Up @@ -118,3 +114,40 @@ function toggleCloneSubProjects(value) {
.querySelectorAll("#sub-projects-to-clone input[type='checkbox']")
.forEach((el) => (el.checked = value));
}

function updateBulkDeleteStatus() {
const selected = $("input[name='stories[]']:checked");
const is_unlocked = $("#stories").data("unlocked");
if (!is_unlocked) {
return;
}

if (selected.length > 0) {
const ending = selected.length == 1 ? "y" : "ies";
$("#bulk_delete")
.text(`Bulk Delete (${selected.length} Stor${ending})`)
.attr("aria-disabled", "false")
.prop("disabled", false);
} else {
$("#bulk_delete")
.text("Bulk Delete")
.attr("aria-disabled", "true")
.prop("disabled", true);
}
}

function updateSelectAllStatus() {
Copy link
Member

@JuanVqz JuanVqz Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@torresga regarding updateBulkDeleteStatus, you verified the unlocked status; I’m curious if this check is also necessary during this process.

const selected = $("input[name='stories[]']:checked");
const checkboxes = $("input[name='stories[]']");

if (selected.length == 0) {
$("#select_all")[0].checked = false;
$("#select_all")[0].indeterminate = false;
} else if (selected.length == checkboxes.length) {
$("#select_all")[0].checked = true;
$("#select_all")[0].indeterminate = false;
} else {
$("#select_all")[0].checked = false;
$("#select_all")[0].indeterminate = true;
}
}
4 changes: 4 additions & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<th class="project-table__cell">Best<br />Estimate</th>
<th class="project-table__cell">Worst<br />Estimate</th>
<th class="project-table__cell story_actions">
<div>
<input type="checkbox" name="select_all" id="select_all">
<label for="select_all">Select All</label>
</div>
<%= link_unless_archived(@project, "Add a Story", new_project_story_path(@project), classes: "green") if is_unlocked?(@project) %>
<button id="bulk_delete" class="button magenta" aria-disabled="true" disabled>Bulk Delete</button>
</th>
Expand Down
15 changes: 15 additions & 0 deletions spec/features/stories_manage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@
expect(page).to have_content "Story updated!"
end

it "allows me to select all stories" do
visit project_path(id: project.id)
check("Select All")

expect(page).to have_checked_field(name: "stories[]")
end

it "allows me to unselect all stories" do
visit project_path(id: project.id)
check("Select All")
uncheck("Select All")

expect(page).to have_unchecked_field(name: "stories[]")
end

it "allows me to delete a story" do
visit project_path(id: project.id)

Expand Down
Loading