Class: ControlledVocabularyTermsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 101

def autocomplete
  @controlled_vocabulary_terms = ControlledVocabularyTerm.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))

  data = @controlled_vocabulary_terms.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.controlled_vocabulary_term_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.controlled_vocabulary_term_tag(t)
    }
  end

  render :json => data
end

- (Object) controlled_vocabulary_term_params (private)

Never trust parameters from the scary internet, only allow the white list through.



135
136
137
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 135

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

- (Object) create

POST /controlled_vocabulary_terms POST /controlled_vocabulary_terms.json



30
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
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 30

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_to :back
        else
          render action: 'new'
        end
      }
      format.json { render json: @controlled_vocabulary_term.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

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



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

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

- (Object) download

GET /controlled_vocabulary_terms/download



118
119
120
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 118

def download
  send_data ControlledVocabularyTerm.generate_download(ControlledVocabularyTerm.where(project_id: $project_id)), type: 'text', filename: "controlled_vocabulary_terms_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /controlled_vocabulary_terms/1/edit



25
26
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 25

def edit
end

- (Object) index

GET /controlled_vocabulary_terms GET /controlled_vocabulary_terms.json



8
9
10
11
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 8

def index
  @recent_objects = ControlledVocabularyTerm.recent_from_project_id($project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



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

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

- (Object) new

GET /controlled_vocabulary_terms/new



19
20
21
22
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 19

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

- (Object) search



89
90
91
92
93
94
95
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 89

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

- (Object) set_controlled_vocabulary_term (private)

Use callbacks to share common setup or constraints between actions.



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

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

- (Object) show

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



15
16
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 15

def show
end

- (Object) tagged_objects

GET /controlled_vocabulary_terms/1/tagged_objects



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

def tagged_objects
  set_controlled_vocabulary_term
end

- (Object) update

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



66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/controlled_vocabulary_terms_controller.rb', line 66

def update
  respond_to do |format|
    if @controlled_vocabulary_term.update(controlled_vocabulary_term_params)
      format.html { redirect_to @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