Class: ImagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ImagesController
- Defined in:
- app/controllers/images_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#api_image_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/images - routed here to take advantage of Pagination.
-
#api_index ⇒ Object
GET /api/v1/images.
-
#api_scale_to_box ⇒ Object
GET ‘images/:id/scale_to_box/:x/:y/:width/:height/:box_width/:box_height’.
-
#api_show ⇒ Object
GET /api/v1/images/:id.
- #autocomplete ⇒ Object
-
#create ⇒ Object
POST /images POST /images.json.
-
#destroy ⇒ Object
DELETE /images/1 DELETE /images/1.json.
-
#download ⇒ Object
GET /images/download.
-
#edit ⇒ Object
GET /images/1/edit.
-
#extract ⇒ Object
GET /images/:id/extract/:x/:y/:height/:width.
- #image_params ⇒ Object private
-
#index ⇒ Object
GET /images GET /images.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /images/new.
-
#ocr ⇒ Object
GET /images/:id/ocr/:x/:y/:height/:width.
-
#regenerate_derivative ⇒ Object
!! This is a kludge until we get active storage working PATCH /images/123/regenerate_derivative.
-
#rotate ⇒ Object
!! This is a kludge until we get active storage working PATCH /images/123/rotate.
-
#scale ⇒ Object
GET /images/:id/extract/:x/:y/:height/:width/:new_height/:new_width.
-
#scale_to_box ⇒ Object
GET ‘images/:id/scale_to_box/:x/:y/:width/:height/:box_width/:box_height’.
-
#search ⇒ Object
TODO: remove for /images.json.
-
#select_options ⇒ Object
GET /images/select_options?target=TaxonDetermination.
- #set_image ⇒ Object private
-
#show ⇒ Object
GET /images/1 GET /images/1.json.
-
#update ⇒ Object
PATCH/PUT /images/1 PATCH/PUT /images/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_image_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/images
- routed here to take advantage of Pagination
25 26 27 28 29 30 31 |
# File 'app/controllers/images_controller.rb', line 25 def api_image_inventory @images = ::Queries::Image::Filter.new( params.permit( :otu_id, otu_scope: []) ).all.page(params[:page]).per(params[:per]) render '/images/api/v1/index' end |
#api_index ⇒ Object
GET /api/v1/images
39 40 41 42 43 44 |
# File 'app/controllers/images_controller.rb', line 39 def api_index @images = Queries::Image::Filter.new(params.merge!(api: true)).all .where(project_id: sessions_current_project_id) .page(params[:page]).per(params[:per]) render '/images/api/v1/index' end |
#api_scale_to_box ⇒ Object
GET ‘images/:id/scale_to_box/:x/:y/:width/:height/:box_width/:box_height’
156 157 158 |
# File 'app/controllers/images_controller.rb', line 156 def api_scale_to_box send_data Image.scaled_to_box_blob(params), type: 'image/jpg', disposition: 'inline' end |
#api_show ⇒ Object
GET /api/v1/images/:id
47 48 49 50 51 52 53 54 |
# File 'app/controllers/images_controller.rb', line 47 def api_show @image = Image.where(project_id: sessions_current_project_id).find_by(id: params[:id]) @image ||= Image.where(project_id: sessions_current_project_id).find_by(image_file_fingerprint: params[:id]) render plain: 'Not found. You may need to add a &project_token= param to the URL currently in your address bar to access these data. See https://api.taxonworks.org/ for more.', status: :not_found and return if @image.nil? render '/images/api/v1/show' end |
#autocomplete ⇒ Object
128 129 130 |
# File 'app/controllers/images_controller.rb', line 128 def autocomplete @images = Queries::Image::Autocomplete.new(params[:term], project_id: sessions_current_project_id).autocomplete end |
#create ⇒ Object
POST /images POST /images.json
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/images_controller.rb', line 67 def create @image = Image.deduplicate_create(image_params) respond_to do |format| if @image.persisted? format.html { redirect_to @image, notice: 'Identical image exists.' } format.json { render :show, status: :ok, location: @image } else if @image.save format.html { redirect_to @image, notice: 'Image was successfully created.' } format.json { render :show, status: :created, location: @image } else format.html { render :new } format.json { render json: @image.errors, status: :unprocessable_entity } end end end end |
#destroy ⇒ Object
DELETE /images/1 DELETE /images/1.json
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/images_controller.rb', line 101 def destroy if @image.destroy respond_to do |format| format.html { redirect_to images_url, notice: 'Image was successfully destroyed.' } format.json { head :no_content } end else respond_to do |format| format.html { redirect_to images_url, notice: @image.errors..join('. ') } format.json { head :no_content, status: :im_used } end end end |
#download ⇒ Object
GET /images/download
133 134 135 136 137 138 |
# File 'app/controllers/images_controller.rb', line 133 def download send_data( Export::CSV.generate_csv(Image.where(project_id: sessions_current_project_id)), type: 'text', filename: "images_#{DateTime.now}.tsv") end |
#edit ⇒ Object
GET /images/1/edit
62 63 |
# File 'app/controllers/images_controller.rb', line 62 def edit end |
#extract ⇒ Object
GET /images/:id/extract/:x/:y/:height/:width
141 142 143 |
# File 'app/controllers/images_controller.rb', line 141 def extract send_data Image.cropped_blob(params), type: 'image/jpg', disposition: 'inline' end |
#image_params ⇒ Object (private)
204 205 206 207 208 209 210 211 212 |
# File 'app/controllers/images_controller.rb', line 204 def image_params params.require(:image).permit( :image_file, :rotate, :pixels_to_centimeter, :filename_depicts_object, citations_attributes: [:id, :is_original, :_destroy, :source_id, :pages, :citation_object_id, :citation_object_type], sled_image_attributes: [:id, :_destroy, :metadata, :object_layout] ) end |
#index ⇒ Object
GET /images GET /images.json
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/images_controller.rb', line 9 def index respond_to do |format| format.html do @recent_objects = Image.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @images = Queries::Image::Filter.new(params).all .where(project_id: sessions_current_project_id) .page(params[:page]).per(params[:per]) } end end |
#list ⇒ Object
115 116 117 |
# File 'app/controllers/images_controller.rb', line 115 def list @images = Image.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) #.per(3) end |
#new ⇒ Object
GET /images/new
57 58 59 |
# File 'app/controllers/images_controller.rb', line 57 def new @image = Image.new end |
#ocr ⇒ Object
GET /images/:id/ocr/:x/:y/:height/:width
161 162 163 164 165 166 167 |
# File 'app/controllers/images_controller.rb', line 161 def ocr tempfile = Tempfile.new(['ocr', '.jpg'], "#{Rails.root.join("public/images/tmp")}", encoding: 'utf-8') tempfile.write(Image.cropped_blob(params).force_encoding('utf-8')) tempfile.rewind render json: {text: RTesseract.new(tempfile.path).to_s&.strip} end |
#regenerate_derivative ⇒ Object
!! This is a kludge until we get active storage working PATCH /images/123/regenerate_derivative
184 185 186 187 188 189 190 |
# File 'app/controllers/images_controller.rb', line 184 def regenerate_derivative begin @image.image_file.reprocess! flash[:notice] = 'Image derivatives regenerated.' end render :show end |
#rotate ⇒ Object
!! This is a kludge until we get active storage working PATCH /images/123/rotate
171 172 173 174 175 176 177 178 179 180 |
# File 'app/controllers/images_controller.rb', line 171 def rotate begin @image.rotate = params.require(:image).require(:rotate) @image.image_file.reprocess! flash[:notice] = 'Image rotated.' rescue ActionController::ParameterMissing flash[:notice] ='Select a rotation option.' end render :show end |
#scale ⇒ Object
GET /images/:id/extract/:x/:y/:height/:width/:new_height/:new_width
146 147 148 |
# File 'app/controllers/images_controller.rb', line 146 def scale send_data Image.resized_blob(params), type: 'image/jpg', disposition: 'inline' end |
#scale_to_box ⇒ Object
GET ‘images/:id/scale_to_box/:x/:y/:width/:height/:box_width/:box_height’
151 152 153 |
# File 'app/controllers/images_controller.rb', line 151 def scale_to_box send_data Image.scaled_to_box_blob(params), type: 'image/jpg', disposition: 'inline' end |
#search ⇒ Object
TODO: remove for /images.json
120 121 122 123 124 125 126 |
# File 'app/controllers/images_controller.rb', line 120 def search if params[:id].blank? redirect_to images_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to image_path(params[:id]) end end |
#select_options ⇒ Object
GET /images/select_options?target=TaxonDetermination
193 194 195 |
# File 'app/controllers/images_controller.rb', line 193 def @images = Image.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target)) end |
#set_image ⇒ Object (private)
199 200 201 202 |
# File 'app/controllers/images_controller.rb', line 199 def set_image @image = Image.with_project_id(sessions_current_project_id).find(params[:id]) @recent_object = @image end |
#show ⇒ Object
GET /images/1 GET /images/1.json
35 36 |
# File 'app/controllers/images_controller.rb', line 35 def show end |
#update ⇒ Object
PATCH/PUT /images/1 PATCH/PUT /images/1.json
87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/images_controller.rb', line 87 def update respond_to do |format| if @image.update(image_params) format.html { redirect_to @image, notice: 'Image was successfully updated.' } format.json { render :show, status: :ok, location: @image } else format.html { render :edit } format.json { render json: @image.errors, status: :unprocessable_entity } end end end |