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



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

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

#api_indexObject

GET /api/v1/otus



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

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

#api_showObject



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

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

#createObject

POST /depictions POST /depictions.json



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

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)



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

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



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

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



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

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



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

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



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

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

#newObject

GET /depictions/new



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

def new
  @depiction = Depiction.new
end

#set_depictionObject (private)



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

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

#showObject

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



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

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

#sortObject



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

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



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

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