Skip to content

Commit

Permalink
check whether all issues are in draft state and pre-select export but…
Browse files Browse the repository at this point in the history
…ton scope accordingly
  • Loading branch information
caitmich committed Sep 11, 2024
1 parent a83fb02 commit 22f1f93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ class ExportController < AuthenticatedController
include ProjectScoped

def index
@default_button_state = non_draft_records? ? 'published' : 'all'
end

private

def non_draft_records?
issue_states = current_project.issues.pluck(:state).uniq
(issue_states & ['published', 'ready_for_review']).any?
end

# In case something goes wrong with the export, fail graciously instead of
# presenting the obscure Error 500 default page of Rails.
def rescue_action(exception)
Expand Down
20 changes: 10 additions & 10 deletions app/views/export/_submit_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<div class="btn-group btn-states" data-behavior="btn-states">
<button id="export-button" class="btn btn-lg btn-primary">Export <span data-behavior="state-button">Published</span> Records</button>
<button id="export-button" class="btn btn-lg btn-primary">Export <span data-behavior="state-button"><%= @default_button_state.humanize %></span> Records</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<%= collection_radio_buttons(nil, :scope, [['published', 'published'], ['all', 'all']], :first, :first) do |b| %>
<span>
<%= b.label class: 'state', for: "#{plugin_name}_scope_#{b.value}" do %>
<%= b.radio_button id: "#{plugin_name}_scope_#{b.value}", class: 'd-none', data: { behavior: 'state-radio'}, checked: b.value == 'published' %>
<%= b.radio_button id: "#{plugin_name}_scope_#{b.value}", class: 'd-none', data: { behavior: 'state-radio'}, checked: b.value == @default_button_state %>
<i class="fa-solid fa-check fa-fw"></i>
<div class="state-label">
<p data-behavior="state-label"><%= b.text.humanize %></p>
<% case b.value %>
<% when 'published' %>
<span>Only records that have been reviewed and published.</span>
<span>Only records that have been reviewed and published.</span>
<% when 'all' %>
<span>All records, regardless if they are draft, ready for review, or published.</span>
<% end %>
</div>
<% end %>
</span>
<% end %>
</div>
<span>All records, regardless if they are draft, ready for review, or published.</span>
<% end %>
</div>
<% end %>
</span>
<% end %>
</div>
</div>

0 comments on commit 22f1f93

Please sign in to comment.