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

POST /depictions POST /depictions.json



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

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)



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

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



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

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



37
38
# File 'app/controllers/depictions_controller.rb', line 37

def edit
end

- (Object) index

GET /depictions GET /depictions.json



8
9
10
11
12
13
14
15
16
17
18
19
20
# 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(
        polymorphic_filter_params('depiction_object', [:observation_id, :content_id, :descriptor_id]) 
      )
    }
  end
end

- (Object) list



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

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

- (Object) new

GET /depictions/new



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

def new
  @depiction = Depiction.new
end

- (Object) set_depiction (private)



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

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

- (Object) show

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



28
29
# File 'app/controllers/depictions_controller.rb', line 28

def show
end

- (Object) sort



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

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



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

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