Class: DepictionsController

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

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Instance Method Details

- (Object) create

POST /depictions POST /depictions.json



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

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)



103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/depictions_controller.rb', line 103

def depiction_params
  params.require(:depiction).permit(
    :depiction_object_id, :depiction_object_type,
    :annotated_global_entity, :caption,
    :image_id,
    :figure_label,
    image_attributes: [:image_file],
    sqed_depiction_attributes: [:id, :_destroy, :boundary_color, :boundary_finder, :has_border, :layout, metadata_map: {}]
  )
end

- (Object) destroy

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



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

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



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

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(
        Queries::Annotator::polymorphic_params(params, Depiction)
      )
    }
  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



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

def new
  @depiction = Depiction.new
end

- (Object) set_depiction (private)



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

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

- (Object) show

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



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

def show
  @depiction.sqed_depiction.preprocess(false) if @depiction.sqed_depiction
end

- (Object) sort



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

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



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

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