-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/admin facet per set #280
base: master
Are you sure you want to change the base?
Changes from all commits
e2d3b3f
cfab399
f2c0034
00738b1
7530727
3cf6a27
3dc1a8d
a7884ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,20 @@ def all_solr_fields | |
|
||
def solr_field_iterator | ||
@solr_field_iterator ||= iterator_factory.new(all_solr_fields).map do |k, v| | ||
setup_facet_item_set(v) if k == :set | ||
[k, HasFacetField.new(v, grouped_facets[k].try(:first) || FacetField.new(:key => k))] | ||
end | ||
end | ||
|
||
def setup_facet_item_set(value) | ||
top_terms = value.topTerms.each_slice(2).to_a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm making a guess here, so I could be way off, but it looks like you could never configure items that aren't in the top terms list. Is that what we really want? (I'm not actually finding what it is that |
||
top_terms.each { |item| facet_item item } | ||
end | ||
|
||
def facet_item(item) | ||
FacetItem.where(:value => item.first).first_or_create | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this first or create do here exactly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It finds an instance of FacetItem in the table, and creates one if it doesn't exist yet. |
||
end | ||
|
||
def iterator_factory | ||
FacetableSolrFieldIterator | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class FacetItem < ActiveRecord::Base | ||
validates :value, :presence => true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ | |
devise_for :users | ||
mount Hydra::RoleManagement::Engine => '/' | ||
|
||
|
||
get '/admin', :to => 'admin#index', :as => "admin_index" | ||
get '/admin/facets/:id/remove_item', :to => 'admin/facets#remove_item', :as => 'remove_item_admin_facet' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we do routing specs for these new routes that were added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
get '/admin/facets/:id/add_item', :to => 'admin/facets#add_item', :as => 'add_item_admin_facet' | ||
|
||
namespace :admin do | ||
resources :facets | ||
resources :form_templates | ||
|
@@ -37,5 +39,4 @@ | |
end | ||
end | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateFacetItems < ActiveRecord::Migration | ||
def change | ||
create_table :facet_items do |t| | ||
t.string :value | ||
t.boolean :visible, :default => true | ||
|
||
t.timestamps null: false | ||
end | ||
add_index :facet_items, :value, unique: true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FactoryGirl.define do | ||
sequence(:value) { |n| "MyString#{n}" } | ||
factory :facet_item do | ||
value | ||
visible true | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe FacetItem, type: :model do | ||
describe "validations" do | ||
it { should validate_presence_of :value } | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need less ambiguity - either the action (and private method) should have the word "toggle", or
set_visibility
should take a parameter and set visibility to that value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add - if we go with "toggle_item", we'd use it to replace both "add_item" and "remove_item"