SpeciesFileGroup/taxonworks

View on GitHub
app/controllers/keywords_controller.rb

Summary

Maintainability
A
20 mins
Test Coverage
class KeywordsController < ApplicationController
  include DataControllerConfiguration::ProjectDataControllerConfiguration

  # TODO: deprecate for CVT + params
  def autocomplete
    predicates = Keyword.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).distinct

    data = predicates.collect do |t|
      str = t.name + ': ' + t.definition
      {id: t.id,
       label: str,
       response_values: {
         params[:method] => t.id},
       label_html: str
      }
    end

    render json: data
  end

  # TODO: deprecat for CVT + params
  def lookup_keyword
    @keywords = Keyword.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
    render(json: @keywords.collect { |t|
      {
          label: t.name,
          object_id: t.id,
          definition: t.definition
      }
    })
  end

  def select_options
    @keywords = Keyword.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:klass))
  end

end