This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1247 from pulibrary/controlled_vocabulary_qa
Add language dropdown from Vocabularies.
- Loading branch information
Showing
15 changed files
with
163 additions
and
8 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
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
class Vocabulary < ApplicationRecord | ||
belongs_to :parent, class_name: "Vocabulary" | ||
validates :label, presence: true | ||
after_create :register_authority | ||
|
||
def register_authority | ||
Qa::Authorities::Local.register_subauthority(label, 'VocabularySubauthority') | ||
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
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,14 @@ | ||
class AuthorityFinder | ||
def self.for(property:, model:) | ||
return unless model.model_name.singular == "ephemera_folder" | ||
begin | ||
case property | ||
when :language | ||
Qa::Authorities::Local.subauthority_for('languages') | ||
end | ||
rescue Qa::InvalidSubAuthority | ||
Rails.logger.debug("Non-existent sub-authority requested for property #{property}") | ||
nil | ||
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,10 @@ | ||
<% authority = AuthorityFinder.for(property: key, model: f.object) %> | ||
<% if authority %> | ||
<% languages = Hyrax::QaSelectService.new(authority.subauthority_name) %> | ||
<%= f.input :language, | ||
collection: languages.select_active_options, | ||
include_blank: true, | ||
input_html: { class: 'form-control', multiple: f.object.multiple?(key) } %> | ||
<% else %> | ||
<%= render "records/edit_fields/default", f: f, key: key%> | ||
<% 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
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
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,49 @@ | ||
require 'rails_helper' | ||
include SimpleForm::ActionViewExtensions::FormHelper | ||
|
||
RSpec.describe 'records/edit_fields/_language.html.erb' do | ||
let(:vocabulary) { nil } | ||
before do | ||
Qa::Authorities::Local.registry.instance_variable_get(:@hash).delete("languages") | ||
allow(view).to receive(:f).and_return(simple_form_for(form)) | ||
allow(view).to receive(:key).and_return(:language) | ||
vocabulary | ||
render | ||
end | ||
after do | ||
Qa::Authorities::Local.registry.instance_variable_get(:@hash).delete("languages") | ||
end | ||
|
||
context 'with an ephemera folder' do | ||
let(:form) { Hyrax::EphemeraBoxForm.new(EphemeraFolder.new, nil, nil) } | ||
context "when there is no language vocabulary" do | ||
it "doesn't create a select box" do | ||
expect(rendered).not_to have_selector "select" | ||
end | ||
end | ||
context "when there is a language vocabulary" do | ||
let(:vocabulary) do | ||
Vocabulary.create!(label: "languages").tap do |vocab| | ||
VocabularyTerm.create!(vocabulary: vocab, label: "English") | ||
VocabularyTerm.create!(vocabulary: vocab, label: "Japanese") | ||
end | ||
end | ||
it "creates a select box" do | ||
expect(rendered).to have_select("Language", options: ['', 'English', 'Japanese']) | ||
end | ||
end | ||
end | ||
|
||
context 'with a scanned resource' do | ||
let(:form) { Hyrax::ScannedResourceForm.new(ScannedResource.new, nil, nil) } | ||
let(:vocabulary) do | ||
Vocabulary.create!(label: "languages").tap do |vocab| | ||
VocabularyTerm.create!(vocabulary: vocab, label: "English") | ||
VocabularyTerm.create!(vocabulary: vocab, label: "Japanese") | ||
end | ||
end | ||
it "doesn't create a select box" do | ||
expect(rendered).not_to have_selector "select" | ||
end | ||
end | ||
end |