Class: DepictionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DepictionsController
- Defined in:
- app/controllers/depictions_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_gallery ⇒ Object
-
#api_index ⇒ Object
GET /api/v1/otus.
- #api_show ⇒ Object
-
#create ⇒ Object
POST /depictions POST /depictions.json.
- #depiction_params ⇒ Object private
-
#destroy ⇒ Object
DELETE /depictions/1 DELETE /depictions/1.json.
-
#download ⇒ Object
GET /depictions/download.
-
#edit ⇒ Object
GET /depictions/1/edit.
-
#index ⇒ Object
GET /depictions GET /depictions.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /depictions/new.
- #set_depiction ⇒ Object private
-
#show ⇒ Object
GET /depictions/1 GET /depictions/1.json.
-
#sort ⇒ Object
PATCH /sort?depiction_ids[]=1&depiction_ids=2.json.
-
#update ⇒ Object
PATCH/PUT /depictions/1 PATCH/PUT /depictions/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
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
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_gallery ⇒ Object
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_index ⇒ Object
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_show ⇒ Object
36 37 38 |
# File 'app/controllers/depictions_controller.rb', line 36 def api_show render '/depictions/api/v1/show' end |
#create ⇒ Object
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_params ⇒ Object (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 |
#destroy ⇒ Object
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 |
#download ⇒ Object
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 |
#edit ⇒ Object
GET /depictions/1/edit
65 66 |
# File 'app/controllers/depictions_controller.rb', line 65 def edit end |
#index ⇒ Object
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 |
#list ⇒ Object
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 |
#new ⇒ Object
GET /depictions/new
60 61 62 |
# File 'app/controllers/depictions_controller.rb', line 60 def new @depiction = Depiction.new end |
#set_depiction ⇒ Object (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 |
#show ⇒ Object
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 |
#sort ⇒ Object
PATCH /sort?depiction_ids[]=1&depiction_ids=2.json
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 |
#update ⇒ Object
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 |