Class: Alchemy::Admin::PicturesController

Inherits:
ResourcesController show all
Includes:
UploaderResponses
Defined in:
app/controllers/alchemy/admin/pictures_controller.rb

Instance Method Summary collapse

Methods included from UploaderResponses

#failed_uploader_response, #succesful_uploader_response

Methods inherited from ResourcesController

#edit, #new, #resource_handler

Methods included from ResourcesHelper

#contains_relations?, #current_location_params, #edit_resource_path, #new_resource_path, #render_attribute, #render_resources, #resource_attribute_field_options, #resource_filter_select, #resource_has_filters, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_name, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_header, #resources_instance_variable, #resources_path, #sortable_resource_header_column

Methods inherited from BaseController

#leave

Methods included from Modules

included, #module_definition_for, register_module

Methods included from Alchemy::AbilityHelper

#current_ability

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?, #prefix_locale?

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 30

def create
  @picture = Picture.new(picture_params)
  @picture.name = @picture.humanized_name
  if @picture.save
    render succesful_uploader_response(file: @picture)
  else
    render failed_uploader_response(file: @picture)
  end
end

#delete_multipleObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 69

def delete_multiple
  if request.delete? && params[:picture_ids].present?
    pictures = Picture.find(params[:picture_ids])
    names = []
    not_deletable = []
    pictures.each do |picture|
      if picture.deletable?
        names << picture.name
        picture.destroy
      else
        not_deletable << picture.name
      end
    end
    if not_deletable.any?
      flash[:warn] = Alchemy.t(
        "These pictures could not be deleted, because they were in use",
        names: not_deletable.to_sentence
      )
    else
      flash[:notice] = Alchemy.t("Pictures deleted successfully", names: names.to_sentence)
    end
  else
    flash[:warn] = Alchemy.t("Could not delete Pictures")
  end
rescue => e
  flash[:error] = e.message
ensure
  redirect_to_index
end

#destroyObject



99
100
101
102
103
104
105
106
107
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 99

def destroy
  name = @picture.name
  @picture.destroy
  flash[:notice] = Alchemy.t("Picture deleted successfully", name: name)
rescue => e
  flash[:error] = e.message
ensure
  redirect_to_index
end

#edit_multipleObject



40
41
42
43
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 40

def edit_multiple
  @pictures = Picture.where(id: params[:picture_ids])
  @tags = @pictures.collect(&:tag_list).flatten.uniq.join(', ')
end

#flushObject



109
110
111
112
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 109

def flush
  FileUtils.rm_rf Rails.root.join('public', Alchemy::MountPoint.get, 'pictures')
  @notice = Alchemy.t('Picture cache flushed')
end

#indexObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 13

def index
  @size = params[:size].present? ? params[:size] : 'medium'
  @query = Picture.ransack(params[:q])
  @pictures = Picture.search_by(params, @query, pictures_per_page_for_size(@size))

  if in_overlay?
    archive_overlay
  end
end

#showObject



23
24
25
26
27
28
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 23

def show
  @previous = @picture.previous(params)
  @next = @picture.next(params)
  @pages = @picture.essence_pictures.group_by(&:page)
  render action: 'show'
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 45

def update
  if @picture.update(picture_params)
    @message = {
      body: Alchemy.t(:picture_updated_successfully, name: @picture.name),
      type: 'notice'
    }
  else
    @message = {
      body: Alchemy.t(:picture_update_failed),
      type: 'error'
    }
  end
  render :update
end

#update_multipleObject



60
61
62
63
64
65
66
67
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 60

def update_multiple
  @pictures = Picture.find(params[:picture_ids])
  @pictures.each do |picture|
    picture.update_name_and_tag_list!(params)
  end
  flash[:notice] = Alchemy.t("Pictures updated successfully")
  redirect_to_index
end