Class: ControlledVocabularyTermsController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Instance Method Details

#autocompleteObject



106
107
108
109
110
111
112
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 106

def autocomplete
  @controlled_vocabulary_terms = Queries::ControlledVocabularyTerm::Autocomplete.new(
    params.require(:term),
    type: filter_params[:type],
    project_id: sessions_current_project_id
  ).all
end

#citationsObject



98
99
100
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 98

def citations
  render json: @controlled_vocabulary_terms.citations
end

#confidencesObject



102
103
104
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 102

def confidences
  render json: @controlled_vocabulary_terms.confidences
end

#controlled_vocabulary_term_paramsObject (private)



133
134
135
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 133

def controlled_vocabulary_term_params
  params.require(:controlled_vocabulary_term).permit(:type, :name, :definition, :uri, :uri_relation, :css_color)
end

#createObject

POST /controlled_vocabulary_terms POST /controlled_vocabulary_terms.json



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 37

def create
  @controlled_vocabulary_term = ControlledVocabularyTerm.new(controlled_vocabulary_term_params)
  respond_to do |format|
    if @controlled_vocabulary_term.save
      format.html { redirect_to url_for(@controlled_vocabulary_term.metamorphosize), notice: "#{@controlled_vocabulary_term.type} '#{@controlled_vocabulary_term.name}' was successfully created." }
      format.json {
        render action: 'show', status: :created, location: @controlled_vocabulary_term.metamorphosize
      }
    else
      format.html {
        flash[:notice] = 'Controlled vocabulary term NOT successfully created.'
        render action: 'new'
      }
      format.json {
        render json: @controlled_vocabulary_term.errors, status: :unprocessable_entity
      }
    end
  end
end

#depictionsObject



94
95
96
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 94

def depictions
  render json: @controlled_vocabulary_terms.depictions
end

#destroyObject

DELETE /controlled_vocabulary_terms/1 DELETE /controlled_vocabulary_terms/1.json



73
74
75
76
77
78
79
80
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 73

def destroy
  redirect_url = (request.env['HTTP_REFERER'].include?(controlled_vocabulary_term_path(@controlled_vocabulary_term.metamorphosize)) ? controlled_vocabulary_terms_url : :back)
  @controlled_vocabulary_term.destroy
  respond_to do |format|
    format.html { redirect_to redirect_url }
    format.json { head :no_content }
  end
end

#downloadObject

GET /controlled_vocabulary_terms/download



115
116
117
118
119
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 115

def download
  send_data(Export::Download.generate_csv(ControlledVocabularyTerm.where(project_id: sessions_current_project_id)),
            type: 'text',
            filename: "controlled_vocabulary_terms_#{DateTime.now}.csv")
end

#editObject

GET /controlled_vocabulary_terms/1/edit



32
33
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 32

def edit
end

#filter_paramsObject (private)



137
138
139
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 137

def filter_params
  params.permit(type: [], id: []).to_h.symbolize_keys.merge!(project_id: sessions_current_project_id)
end

#indexObject

GET /controlled_vocabulary_terms GET /controlled_vocabulary_terms.json



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 8

def index
  respond_to do |format|
    format.html do
      @recent_objects = ControlledVocabularyTerm.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @controlled_vocabulary_terms = ControlledVocabularyTerm.where(filter_params).order(:name)
    }
  end
end

#listObject



90
91
92
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 90

def list
  @controlled_vocabulary_terms = ControlledVocabularyTerm.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) #.per(3)
end

#newObject

GET /controlled_vocabulary_terms/new



26
27
28
29
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 26

def new
  @controlled_vocabulary_term = ControlledVocabularyTerm.new
  @return_path = params.permit(:return_path)[:return_path]
end

#searchObject



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

def search
  if params[:id].blank?
    redirect_to controlled_vocabulary_term_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to controlled_vocabulary_term_path(params[:id])
  end
end

#set_controlled_vocabulary_termObject (private)



128
129
130
131
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 128

def set_controlled_vocabulary_term
  @controlled_vocabulary_term = ControlledVocabularyTerm.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @controlled_vocabulary_term
end

#showObject

GET /controlled_vocabulary_terms/1 GET /controlled_vocabulary_terms/1.json



22
23
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 22

def show
end

#tagged_objectsObject

GET /controlled_vocabulary_terms/1/tagged_objects



122
123
124
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 122

def tagged_objects
  set_controlled_vocabulary_term
end

#updateObject

PATCH/PUT /controlled_vocabulary_terms/1 PATCH/PUT /controlled_vocabulary_terms/1.json



59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 59

def update
  respond_to do |format|
    if @controlled_vocabulary_term.update(controlled_vocabulary_term_params)
      format.html { redirect_to url_for(@controlled_vocabulary_term.metamorphosize), notice: 'Controlled vocabulary term was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @controlled_vocabulary_term.errors, status: :unprocessable_entity }
    end
  end
end