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)



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

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)
end

- (Object) autocomplete



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/alternate_values_controller.rb', line 80

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



119
120
121
# File 'app/controllers/alternate_values_controller.rb', line 119

def breakout_types(collection)
  collection
end

- (Object) create

POST /alternate_values POST /alternate_values.json



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/alternate_values_controller.rb', line 26

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 json: @alternate_value, status: :created, location: @alternate_value }
    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



58
59
60
61
62
63
64
# File 'app/controllers/alternate_values_controller.rb', line 58

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



96
97
98
# File 'app/controllers/alternate_values_controller.rb', line 96

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

- (Object) edit



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

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

def index
  @recent_objects = AlternateValue.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



66
67
68
# File 'app/controllers/alternate_values_controller.rb', line 66

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

- (Object) new



16
17
18
# File 'app/controllers/alternate_values_controller.rb', line 16

def new
  @alternate_value = AlternateValue.new(alternate_value_params)
end

- (Object) search

GET /alternate_values/search



71
72
73
74
75
76
77
78
# File 'app/controllers/alternate_values_controller.rb', line 71

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)



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

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



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/alternate_values_controller.rb', line 43

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: :created, location: @alternate_value }
    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