Class: DepictionsController

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

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

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

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details



51
52
53
54
55
56
57
58
# File 'app/controllers/depictions_controller.rb', line 51

def api_gallery
  @depictions = Queries::Depiction::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('depictions.id')
    .page(params[:page])
    .per(params[:per])
  render '/depictions/api/v1/gallery'
end

#api_indexObject

GET /api/v1/otus



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

def api_index
  @depictions = Queries::Depiction::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('depictions.id')
    .page(params[:page])
    .per(params[:per])
  render '/depictions/api/v1/index'
end

#api_showObject



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

def api_show
  render '/depictions/api/v1/show'
end

#createObject

POST /depictions POST /depictions.json



71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/depictions_controller.rb', line 71

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

#depiction_paramsObject (private)



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/controllers/depictions_controller.rb', line 137

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

#destroyObject

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



100
101
102
103
104
105
106
# File 'app/controllers/depictions_controller.rb', line 100

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

#downloadObject

GET /depictions/download



126
127
128
129
# File 'app/controllers/depictions_controller.rb', line 126

def download
  send_data Export::CSV.generate_csv(
    Depiction.where(project_id: sessions_current_project_id)), type: 'text', filename: "depictions_#{DateTime.now}.tsv"
end

#editObject

GET /depictions/1/edit



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

def edit
end

#indexObject

GET /depictions GET /depictions.json



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

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 = Queries::Depiction::Filter.new(params)
      .all
      .where(project_id: sessions_current_project_id)
      .where(Queries::Annotator::polymorphic_params(params, Depiction))
      .page(params[:page])
      .per(params[:per])
    }
  end
end

#listObject



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

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

#newObject

GET /depictions/new



61
62
63
# File 'app/controllers/depictions_controller.rb', line 61

def new
  @depiction = Depiction.new
end

#set_depictionObject (private)



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

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

#showObject

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



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

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

#sortObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/depictions_controller.rb', line 109

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

#updateObject

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



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

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