Class: DepictionsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/depictions_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) create

POST /depictions POST /depictions.json



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/depictions_controller.rb', line 40

def create
  @depiction = Depiction.new(depiction_params)
  respond_to do |format|
    if @depiction.save
      format.html { redirect_to @depiction, notice: 'Depiction was successfully created.' }
      format.json { render :show, status: :created, location: @depiction }
    else
      format.html { render :new }
      format.json { render json: @depiction.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) depiction_params (private)



120
121
122
# File 'app/controllers/depictions_controller.rb', line 120

def depiction_params
  params.require(:depiction).permit(:depiction_object_id, :depiction_object_type, :caption, :figure_label, image_attributes: [:image_file])
end

- (Object) destroy

DELETE /depictions/1 DELETE /depictions/1.json



69
70
71
72
73
74
75
# File 'app/controllers/depictions_controller.rb', line 69

def destroy
  @depiction.destroy
  respond_to do |format|
    format.html { redirect_to depictions_url, notice: 'Depiction was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /depictions/1/edit



35
36
# File 'app/controllers/depictions_controller.rb', line 35

def edit
end

- (Object) filter_params (private)

handle the polymorphic resource



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/depictions_controller.rb', line 97

def filter_params
  h = params.permit(
    :content_id
  ).to_h
  if h.size > 1 
    respond_to do |format|
      format.html { render plain: '404 Not Found', status: :unprocessable_entity and return }
      format.json { render json: {success: false}, status: :unprocessable_entity and return }
    end
  end

  model = h.keys.first.split('_').first.classify
  return {depiction_object_type: model, depiction_object_id: h.values.first}
end

- (Object) index

GET /depictions GET /depictions.json



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

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

- (Object) list



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

def list
  @depictions = Depiction.where(project_id: sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /depictions/new



30
31
32
# File 'app/controllers/depictions_controller.rb', line 30

def new
  @depiction = Depiction.new
end

- (Object) set_depiction (private)

def depiction_object

filter_params[:depiction_object_type].find(filter_params[:depiction_object_id])

end



116
117
118
# File 'app/controllers/depictions_controller.rb', line 116

def set_depiction
  @depiction = Depiction.find(params[:id])
end

- (Object) show

GET /depictions/1 GET /depictions/1.json



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

def show
end

- (Object) sort



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

def sort
  respond_to do |format|
    begin 
      params.require(:depiction_ids).each_with_index do |d, i|
        Depiction.find(d).update_column(:position, i + 1)
      end
    rescue ActionController::ParameterMissing  
      format.json { render json: {success: false}, status: :unprocessable_entity and return }
    rescue ActiveRecord::RecordInvalid
      format.json { render json: {success: false}, status: :unprocessable_entity and return }
    end

    format.json { render json: {success: true}, status: :ok and return }
  end
end

- (Object) update

PATCH/PUT /depictions/1 PATCH/PUT /depictions/1.json



55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/depictions_controller.rb', line 55

def update
  respond_to do |format|
    if @depiction.update(depiction_params)
      format.html { redirect_to @depiction, notice: 'Depiction was successfully updated.' }
      format.json { render :show, status: :ok, location: @depiction }
    else
      format.html { render :edit }
      format.json { render json: @depiction.errors, status: :unprocessable_entity }
    end
  end
end