Class: ImagesController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/images_controller.rb', line 79

def autocomplete
  @images = Image.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) # in model

  data = @images.collect do |t|
    {id:              t.id,
     label:           ImagesHelper.image_tag(t), # in helper
     response_values: {
       params[:method] => t.id
     },
     label_html:      ImagesHelper.image_tag(t) #  render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
    }
  end
  render :json => data
end

- (Object) create

POST /images POST /images.json



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/images_controller.rb', line 29

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

- (Object) destroy

DELETE /images/1 DELETE /images/1.json



59
60
61
62
63
64
65
# File 'app/controllers/images_controller.rb', line 59

def destroy
  @image.destroy
  respond_to do |format|
    format.html { redirect_to images_url, notice: 'Image was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /images/download



95
96
97
# File 'app/controllers/images_controller.rb', line 95

def download
  send_data Image.generate_download( Image.where(project_id: $project_id) ), type: 'text', filename: "images_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /images/1/edit



24
25
# File 'app/controllers/images_controller.rb', line 24

def edit
end

- (Object) extract

GET /images/:id/extract/:x/:y/:height/:width



100
101
102
# File 'app/controllers/images_controller.rb', line 100

def extract
  send_data Image.cropped_blob(params), type: 'image/jpg', disposition: 'inline'
end

- (Object) image_params (private)

Never trust parameters from the scary internet, only allow the white list through.



131
132
133
# File 'app/controllers/images_controller.rb', line 131

def image_params
  params.require(:image).permit(:image_file)
end

- (Object) index

GET /images GET /images.json



8
9
10
11
# File 'app/controllers/images_controller.rb', line 8

def index
  @recent_objects = Image.recent_from_project_id($project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



67
68
69
# File 'app/controllers/images_controller.rb', line 67

def list
  @images = Image.with_project_id($project_id).order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /images/new



19
20
21
# File 'app/controllers/images_controller.rb', line 19

def new
  @image = Image.new
end

- (Object) ocr

GET /images/:id/ocr/:x/:y/:height/:width



115
116
117
118
119
120
121
# File 'app/controllers/images_controller.rb', line 115

def ocr 
  tempfile = Tempfile.new(['ocr', '.jpg'], "#{Rails.root.to_s}/public/images/tmp", encoding: 'ASCII-8BIT' ) 
  tempfile.write( Image.cropped_blob(params) )
  tempfile.rewind

  render json: {text:  RTesseract.new(Magick::Image.read(tempfile.path).first).to_s.strip }
end

- (Object) scale

GET /images/:id/extract/:x/:y/:height/:width/:new_height/:new_width



105
106
107
# File 'app/controllers/images_controller.rb', line 105

def scale 
  send_data Image.resized_blob(params), type: 'image/jpg', disposition: 'inline'
end

- (Object) scale_to_box

GET 'images/:id/scale_to_box/:x/:y/:width/:height/:box_width/:box_height'



110
111
112
# File 'app/controllers/images_controller.rb', line 110

def scale_to_box
  send_data Image.scaled_to_box_blob(params), type: 'image/jpg', disposition: 'inline'
end

- (Object) search



71
72
73
74
75
76
77
# File 'app/controllers/images_controller.rb', line 71

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

- (Object) set_image (private)

Use callbacks to share common setup or constraints between actions.



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

def set_image
  @image = Image.with_project_id($project_id).find(params[:id])
  @recent_object = @image 
end

- (Object) show

GET /images/1 GET /images/1.json



15
16
# File 'app/controllers/images_controller.rb', line 15

def show
end

- (Object) update

PATCH/PUT /images/1 PATCH/PUT /images/1.json



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/images_controller.rb', line 45

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