Class: TopicsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/topics_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#createObject

TODO: deprecate fully POST /controlled_vocabulary_terms POST /controlled_vocabulary_terms.json



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/topics_controller.rb', line 31

def create
  @controlled_vocabulary_term = ControlledVocabularyTerm.new(controlled_vocabulary_term_params)
  respond_to do |format|
    if @controlled_vocabulary_term.save
      msg = "#{@controlled_vocabulary_term.type} '#{@controlled_vocabulary_term.name}' was successfully created."

      if !params.permit(:return_path)[:return_path].blank?
        # case - coming from otu -> new tag -> new cvt -> back to tag/new
        redirect_url = params.permit(:return_path)[:return_path] + "&tag[keyword_id]=#{@controlled_vocabulary_term.to_param}"
      elsif request.env['HTTP_REFERER'].include?('controlled_vocabulary_terms/new')
        # case - coming from cvt index -> cvt/new
        redirect_url = controlled_vocabulary_term_path(@controlled_vocabulary_term)
      else
        # case - coming from task -> return to task
        redirect_url = :back
      end

      format.html { redirect_to redirect_url, notice: msg } # !! new behaviour to test
      format.json { render action: 'show', status: :created, location: @controlled_vocabulary_term.metamorphosize }

    else
      format.html {
        flash[:notice] = 'Controlled vocabulary term NOT successfully created.'
        if redirect_url == :back
          redirect_back(fallback_location: (request.referer || root_path), notice: 'Controlled vocabulary term NOT successfully created.')
        else
          render action: 'new'
        end
      }
      format.json { render json: @controlled_vocabulary_term.errors, status: :unprocessable_entity }
    end
  end
end

#get_definitionObject



76
77
78
79
# File 'app/controllers/topics_controller.rb', line 76

def get_definition
  @topic = Topic.find(params[:id])
  render(json: {definition: @topic.definition})
end

#indexObject

get /topics.json



5
6
7
8
# File 'app/controllers/topics_controller.rb', line 5

def index
  @controlled_vocabulary_terms = Topic.order(:name).where(project_id: sessions_current_project_id).all
  render '/controlled_vocabulary_terms/index'
end

#listObject

TODO: deprecate for index? List should be paginated.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/topics_controller.rb', line 11

def list
  topics = Topic.order(:name).where(project_id: sessions_current_project_id).all

  data = topics.collect do |t|
    str = t.name + ': ' + t.definition
    { id: t.id,
      name: t.name,
      definition: t.definition, 
      color: t.css_color,
      css_color: t.css_color,
      label:  t.name # TODO: referenced in js picker, refactor to use name rather than label
    }
  end

  render json: data
end

#lookup_topicObject



65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/topics_controller.rb', line 65

def lookup_topic
  @topics = Topic.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
  render(json: @topics.collect { |t|
    {
      label:     t.name,
      object_id: t.id,
      definition: t.definition
    }
  })
end

#select_optionsObject

GET /topics/select_options?target=Citation&klass=TaxonName GET /topics/select_options?target=Content



83
84
85
86
87
88
89
# File 'app/controllers/topics_controller.rb', line 83

def select_options
  if params.require(:target) == 'Citation'
    @topics = Topic.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:klass), 'Citation')
  elsif  params.require(:target) == 'Content'
    @topics = Topic.select_optimized(sessions_current_user_id, sessions_current_project_id, nil, 'Content')
  end
end