Class: AlternateValuesController

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

Overview

This is a top-level class documentation comment for the Alternate Value Controller RuboCop likes this

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 included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

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) alternate_value_params (private)



117
118
119
120
121
122
123
# File 'app/controllers/alternate_values_controller.rb', line 117

def alternate_value_params
  params.require(:alternate_value).permit(
    :value, :type, :language_id, 
    :alternate_value_object_type, :alternate_value_object_id, 
    :alternate_value_object_attribute, :is_community_annotation, :annotated_global_entity
  )
end

- (Object) autocomplete



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/alternate_values_controller.rb', line 85

def autocomplete
  @alternate_values = AlternateValue.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))

  data = @alternate_values.collect do |t|
    str = render_to_string(partial: 'tag', locals: {alternate_value: t})
    {id:              t.id,
     label:           str,
     response_values: {params[:method] => t.id},
     label_html:      str
    }
  end

  render json: data
end

- (Object) breakout_types(collection) (private)

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

a_v_params = ActionController::Parameters.new({

                                              })
a_v_params.require(:alternate_value).permit(:value, :type, :language_id, :alternate_value_object_type, :alternate_value_object_id, :alternate_value_object_attribute, :project_members_only)

end



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

def breakout_types(collection)
  collection
end

- (Object) create

POST /alternate_values POST /alternate_values.json



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/alternate_values_controller.rb', line 31

def create
  @alternate_value = AlternateValue.new(alternate_value_params)
  respond_to do |format|
    @alternate_value.project_id = sessions_current_project_id if params[:project_members_only] == 'checked'

    if @alternate_value.save
      format.html { redirect_to @alternate_value.alternate_value_object.metamorphosize, notice: 'Alternate value was successfully created.' }
      format.json { render action: :show, status: :created, location: @alternate_value.metamorphosize }
    else
      format.html { render 'new', notice: 'Alternate value was NOT successfully created.' }
      format.json { render json: @alternate_value.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /alternate_values/1 DELETE /alternate_values/1.json



63
64
65
66
67
68
69
# File 'app/controllers/alternate_values_controller.rb', line 63

def destroy
  @alternate_value.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Alternate value was successfully destroyed.')}
    format.json { head :no_content }
  end
end

- (Object) download

GET /alternate_values/download



101
102
103
# File 'app/controllers/alternate_values_controller.rb', line 101

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

- (Object) edit



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

def edit
  @alternate_value = AlternateValue.find_by_id(params[:id]).metamorphosize
end

- (Object) index

GET /alternate_values GET /alternate_values.json



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

def index
  respond_to do |format|
    format.html {
      @recent_objects = AlternateValue.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @alternate_values = AlternateValue.where(project_id: sessions_current_project_id).where(
        polymorphic_filter_params('alternate_value_object', AlternateValue.related_foreign_keys )
      )
    }
  end
end

- (Object) list



71
72
73
# File 'app/controllers/alternate_values_controller.rb', line 71

def list
  @alternate_values = AlternateValue.where(project_id: sessions_current_project_id).order(:alternate_value_object_type).page(params[:page])
end

- (Object) metadata

GET /alternate_values/:global_id/metadata



106
107
108
# File 'app/controllers/alternate_values_controller.rb', line 106

def 
  @object = GlobalID::Locator.locate(params.require(:global_id))
end

- (Object) search

GET /alternate_values/search



76
77
78
79
80
81
82
83
# File 'app/controllers/alternate_values_controller.rb', line 76

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

- (Object) set_alternate_value (private)



112
113
114
115
# File 'app/controllers/alternate_values_controller.rb', line 112

def set_alternate_value
  @alternate_value = AlternateValue.find(params[:id])
  render status: 404 if !@alternate_value.project_id.blank? && (sessions_current_project_id != @alternate_value.project_id)
end

- (Object) update

PATCH/PUT /alternate_values/1 PATCH/PUT /alternate_values/1.json



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/alternate_values_controller.rb', line 48

def update
  respond_to do |format|
    @alternate_value.project_id = sessions_current_project_id if params[:project_members_only] == 'checked'
    if @alternate_value.update(alternate_value_params)
      format.html { redirect_to @alternate_value.alternate_value_object.metamorphosize, notice: 'Alternate value was successfully updated.' }
      format.json { render json: @alternate_value, status: :ok, location: @alternate_value.metamorphosize }
    else
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Alternate value was NOT successfully updated.')}
      format.json { render json: @alternate_value.errors, status: :unprocessable_entity }
    end
  end
end