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

Export all if all issues are in 'Draft' state #1293

Open
wants to merge 5 commits into
base: develop
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
10 changes: 10 additions & 0 deletions app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ class ExportController < AuthenticatedController
include ProjectScoped

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

private

def non_draft_records?
issues = current_project.issues
issues.published.or(issues.ready_for_review).any? || non_draft_records_pro
end

def non_draft_records_pro
false
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>
25 changes: 17 additions & 8 deletions spec/features/export_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@

it 'presents the name of the project you are exporting' do
visit project_export_manager_path(current_project)
expect(page).to have_content(@project.name)
expect(page).to have_content(current_project.name)
end

it 'presents existing Issues' do
skip "For the time being we won't show the Issues in the Export Manager"
# @issuelib = @project.nodes.create(:label => 'All issues', :type_id => Node::Types::ISSUELIB)
# issue = create(:issue, :node => @issuelib)
#
# visit project_export_manager_path(current_project)
# page.should have_content(issue.title)
context 'Submit button' do
context 'when there are only draft records in the project' do
it 'presents the option to export all records' do
create(:issue, node: current_project.issue_library, state: :draft)
visit project_export_manager_path(current_project)
expect(page).to have_content('Export All Records')
end
end

context 'when there are published records in the project' do
it 'presents the option to export published records' do
create(:issue, node: current_project.issue_library, state: :published)
visit project_export_manager_path(current_project)
expect(page).to have_content('Export Published Records')
end
end
end

context 'a template is passed to the export action' do
Expand Down
Loading