Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a modal when there are many types of works to select from
Fixes #2434
- Loading branch information
Showing
10 changed files
with
218 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Sufia | ||
class SelectTypeListPresenter | ||
# @param classification [CurationConcerns::QuickClassificationQuery] | ||
def initialize(classification) | ||
@classification = classification | ||
end | ||
|
||
class_attribute :row_presenter | ||
self.row_presenter = SelectTypePresenter | ||
|
||
def each | ||
@classification.each { |i| yield row_presenter.new(i) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Sufia | ||
class SelectTypePresenter | ||
def initialize(concern) | ||
@concern = concern | ||
end | ||
|
||
attr_reader :concern | ||
|
||
def icon_class | ||
translate('icon_class') | ||
end | ||
|
||
def description | ||
translate('description') | ||
end | ||
|
||
def name | ||
translate('name') | ||
end | ||
|
||
private | ||
|
||
def object_name | ||
@object_name ||= concern.model_name.i18n_key | ||
end | ||
|
||
def translate(key) | ||
defaults = [] | ||
defaults << :"sufia.select_type.#{object_name}.#{key}" | ||
defaults << :"sufia.select_type.#{key}" | ||
defaults << '' | ||
I18n.t(defaults.shift, default: defaults) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% classification = CurationConcerns::QuickClassificationQuery.new(current_user) %> | ||
<% if classification.authorized_models.size > 1 %> | ||
<%= render 'select_work_type', presenter: Sufia::SelectTypeListPresenter.new(classification) %> | ||
<% else %> | ||
<div class="col-xs-6 col-sm-2 heading-tile"> | ||
<% classification.each do |concern| %> | ||
<%= link_to(new_polymorphic_path([main_app, concern]), | ||
class: "item-option contextual-quick-classify #{dom_class(concern, 'new').gsub('_', '-')}", | ||
role: 'menuitem' | ||
) do %> | ||
<span class="glyphicon glyphicon-upload"></span> | ||
<%= I18n.t("sufia.dashboard.create_work", work_type: concern.human_readable_type) %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% end %> |
15 changes: 2 additions & 13 deletions
15
app/views/dashboard/_index_partials/_heading_actions.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div class="modal fade" id="worktypes-to-create" tabindex="-1" role="dialog" aria-labelledby="select-worktype-label"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | ||
<h4 class="modal-title" id="select-worktype-label"><%= t('sufia.dashboard.heading_actions.select_type_of_work') %></h4> | ||
</div> | ||
<div class="modal-body"> | ||
<table class="table"> | ||
<% presenter.each do |row_presenter| %> | ||
<tr> | ||
<td class="select-work-icon"> | ||
<%= link_to(new_polymorphic_path([main_app, row_presenter.concern]), | ||
class: "item-option contextual-quick-classify #{dom_class(row_presenter.concern, 'new').gsub('_', '-')}", | ||
role: 'menuitem' | ||
) do %> | ||
<span class="<%= row_presenter.icon_class %>"></span> | ||
<% end %> | ||
</td> | ||
<td class="select-work-description"> | ||
<%= link_to(new_polymorphic_path([main_app, row_presenter.concern]), | ||
class: "item-option contextual-quick-classify #{dom_class(row_presenter.concern, 'new').gsub('_', '-')}", | ||
role: 'menuitem' | ||
) do %> | ||
<h3><%= row_presenter.name %></h3> | ||
<p><%= row_presenter.description %></p> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('sufia.dashboard.heading_actions.close') %></button> | ||
<button type="button" class="btn btn-primary"><%= t('sufia.dashboard.heading_actions.create_work') %></button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="col-xs-6 col-sm-2 heading-tile"> | ||
<%= link_to('#', data: { toggle: "modal", target:"#worktypes-to-create" }) do %> | ||
<span class="glyphicon glyphicon-upload"></span> | ||
<%= t("sufia.dashboard.create_work") %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Sufia::SelectTypePresenter do | ||
let(:instance) { described_class.new(model) } | ||
let(:model) { GenericWork } | ||
|
||
describe "#icon_class" do | ||
subject { instance.icon_class } | ||
it { is_expected.to eq 'fa fa-file-text-o' } | ||
end | ||
|
||
describe "#description" do | ||
subject { instance.description } | ||
it { is_expected.to eq 'Generic work works' } | ||
end | ||
|
||
describe "#name" do | ||
subject { instance.name } | ||
it { is_expected.to eq 'Generic Work' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'dashboard/create_work_action.html.erb', type: :view do | ||
let(:classification) { double } | ||
before do | ||
allow(CurationConcerns::QuickClassificationQuery).to receive(:new).and_return(classification) | ||
allow(view).to receive(:current_user).and_return(double) | ||
allow(classification).to receive(:authorized_models).and_return(results) | ||
end | ||
|
||
context "when we have more than one model" do | ||
let(:results) { [GenericWork, double] } | ||
before do | ||
stub_template 'dashboard/_select_work_type.html.erb' => 'SelectType' | ||
render 'dashboard/create_work_action', classification: classification | ||
end | ||
it "renders the select template" do | ||
expect(rendered).to have_content 'SelectType' | ||
end | ||
end | ||
|
||
context "when we have one model" do | ||
let(:results) { [GenericWork] } | ||
before do | ||
allow(classification).to receive(:each).and_yield(GenericWork) | ||
render 'dashboard/create_work_action', classification: classification | ||
end | ||
it "doesn't draw the modal" do | ||
expect(rendered).not_to include "modal" | ||
expect(rendered).to have_link "Create Work", href: '/concern/generic_works/new' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'dashboard/select_work_type.html.erb', type: :view do | ||
let(:presenter) { instance_double Sufia::SelectTypeListPresenter } | ||
let(:row1) do | ||
instance_double(Sufia::SelectTypePresenter, | ||
icon_class: 'icon', | ||
name: 'Generic Work', | ||
description: 'Workhorse', | ||
concern: GenericWork) | ||
end | ||
let(:row2) do | ||
instance_double(Sufia::SelectTypePresenter, | ||
icon_class: 'icon', | ||
name: 'Book', | ||
description: 'Book of things', | ||
concern: other_model) | ||
end | ||
let(:other_model) do | ||
double(persisted?: false, | ||
model_name: double(singular_route_key: 'foo', param_key: 'foo')) | ||
end | ||
before do | ||
allow(presenter).to receive(:each).and_yield(row1).and_yield(row2) | ||
allow(view).to receive(:new_polymorphic_path).and_return('/foos/new') | ||
render 'dashboard/select_work_type', presenter: presenter | ||
end | ||
let(:results) { [GenericWork, other_model] } | ||
|
||
it "draws the modal" do | ||
expect(rendered).to have_selector "#worktypes-to-create.modal" | ||
expect(rendered).to have_selector 'a[data-toggle="modal"][data-target="#worktypes-to-create"]' | ||
expect(rendered).to have_link "Book", href: '/foos/new' | ||
expect(rendered).to have_link "Generic Work" | ||
end | ||
end |