Added support for themeless searchable models.

This commit is contained in:
Martin Edenhofer 2015-08-16 11:14:24 +02:00
parent b2aa52c22a
commit dac3a506ec
8 changed files with 74 additions and 10 deletions

View file

@ -21,7 +21,7 @@ class SearchController < ApplicationController
# convert objects string into array of class names
# e.g. user-ticket-another_object = %w( User Ticket AnotherObject )
if !params[:objects]
objects = %w( Ticket User Organization )
objects = Setting.get('models_searchable')
else
objects = params[:objects].split('-').map(&:camelize)
end

View file

@ -79,7 +79,7 @@ returns
=end
def search (params)
def search(params)
# get params
query = params[:query]

View file

@ -0,0 +1,8 @@
# update settings for searchable models
if ActiveRecord::Base.connection.tables.include?('settings')
models_current = Models.searchable.map(&:to_s)
models_config = Setting.get('models_searchable')
if models_current != models_config
Setting.set('models_searchable', models_current)
end
end

View file

@ -0,0 +1,15 @@
class UpdateModelSearchable < ActiveRecord::Migration
def up
Setting.create_if_not_exists(
title: 'Define searchable models.',
name: 'models_searchable',
area: 'Models::Base',
description: 'Define the models which can be searched for.',
options: {},
state: [],
frontend: false,
)
end
end

View file

@ -1187,6 +1187,16 @@ Setting.create_if_not_exists(
frontend: true
)
Setting.create_if_not_exists(
title: 'Define searchable models.',
name: 'models_searchable',
area: 'Models::Base',
description: 'Define the models which can be searched for.',
options: {},
state: [],
frontend: false,
)
Setting.create_if_not_exists(
title: 'Default Screen',
name: 'default_controller',

View file

@ -10,11 +10,11 @@ get list of models
returns
{
'Some::Classname1' => {
Some::Classname1 => {
attributes: ['id', 'name', '...']
reflections: ...model.reflections...
},
'Some::Classname2' => {
Some::Classname2 => {
attributes: ['id', 'name', '...']
reflections: ...model.reflections...
},
@ -49,6 +49,28 @@ returns
=begin
get list of searchable models
result = Models.searchable
returns
[Model1, Model2, Model3]
=end
def self.searchable
models = []
all.each {|model_class, options|
next if !model_class
next if !model_class.respond_to? :search_preferences
models.push model_class
}
models
end
=begin
get reference list of a models
result = Models.references('User', 2)

View file

@ -235,4 +235,13 @@ class ModelTest < ActiveSupport::TestCase
end
test 'searchable test' do
searchable = Models.searchable
assert(searchable.include?(Ticket))
assert(searchable.include?(User))
assert(searchable.include?(Organization))
assert_equal(3, searchable.count)
end
end