Class: ImagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ImagesController
- Defined in:
- app/controllers/images_controller.rb
Instance Method Summary collapse
- #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.
- #filter_params ⇒ Object private
- #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.
-
#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 RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
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
#autocomplete ⇒ Object
95 96 97 |
# File 'app/controllers/images_controller.rb', line 95 def autocomplete @images = Queries::Image::Autocomplete.new(params[:term], project_id: sessions_current_project_id).autocomplete end |
#create ⇒ Object
POST /images POST /images.json
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/images_controller.rb', line 39 def create @image = Image.new(image_params) respond_to do |format| 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 |
#destroy ⇒ Object
DELETE /images/1 DELETE /images/1.json
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/images_controller.rb', line 68 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
100 101 102 103 104 |
# File 'app/controllers/images_controller.rb', line 100 def download send_data(Export::Download.generate_csv(Image.where(project_id: sessions_current_project_id)), type: 'text', filename: "images_#{DateTime.now}.csv") end |
#edit ⇒ Object
GET /images/1/edit
34 35 |
# File 'app/controllers/images_controller.rb', line 34 def edit end |
#extract ⇒ Object
GET /images/:id/extract/:x/:y/:height/:width
107 108 109 |
# File 'app/controllers/images_controller.rb', line 107 def extract send_data Image.cropped_blob(params), type: 'image/jpg', disposition: 'inline' end |
#filter_params ⇒ Object (private)
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/controllers/images_controller.rb', line 150 def filter_params params.permit( :taxon_name_id, :ancestor_id_target, :otu_id, :collection_object_id, :image_id, :biocuration_class_id, :sled_image_id, :depiction, :user_id, # user :user_target, :user_date_start, :user_date_end, :identifier, :identifier_end, :identifier_exact, :identifier_start, keyword_ids: [], taxon_name_id: [], sled_image_id: [], biocuration_class_id: [], image_id: [], collection_object_id: [], otu_id: [] ).to_h.symbolize_keys.merge(project_id: sessions_current_project_id) end |
#image_params ⇒ Object (private)
184 185 186 187 188 189 190 191 |
# File 'app/controllers/images_controller.rb', line 184 def image_params params.require(:image).permit( :image_file, :rotate, :pixels_to_centimeter, 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(filter_params).all .where(project_id: sessions_current_project_id) .all.page(params[:page]).per(params[:per] || 50) } end end |
#list ⇒ Object
82 83 84 |
# File 'app/controllers/images_controller.rb', line 82 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
29 30 31 |
# File 'app/controllers/images_controller.rb', line 29 def new @image = Image.new end |
#ocr ⇒ Object
GET /images/:id/ocr/:x/:y/:height/:width
122 123 124 125 126 127 128 |
# File 'app/controllers/images_controller.rb', line 122 def ocr tempfile = Tempfile.new(['ocr', '.jpg'], "#{Rails.root}/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 |
#rotate ⇒ Object
!! This is a kludge until we get active storage working PATCH /images/123/rotate
132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/images_controller.rb', line 132 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
112 113 114 |
# File 'app/controllers/images_controller.rb', line 112 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'
117 118 119 |
# File 'app/controllers/images_controller.rb', line 117 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
87 88 89 90 91 92 93 |
# File 'app/controllers/images_controller.rb', line 87 def search if params[:id].blank? redirect_to images_path, notice: '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
144 145 146 |
# File 'app/controllers/images_controller.rb', line 144 def @images = Image.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target)) end |
#set_image ⇒ Object (private)
179 180 181 182 |
# File 'app/controllers/images_controller.rb', line 179 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
25 26 |
# File 'app/controllers/images_controller.rb', line 25 def show end |
#update ⇒ Object
PATCH/PUT /images/1 PATCH/PUT /images/1.json
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/images_controller.rb', line 54 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 |