Class: Wco::GalleriesController
Instance Method Summary
collapse
#home, #tinymce
#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date
Instance Method Details
#create ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/wco/galleries_controller.rb', line 8
def create
params[:gallery][:tag_ids]&.delete ''
@gallery = Wco::Gallery.new params[:gallery].permit!
authorize! :create, @gallery
if @gallery.save
flash[:notice] = 'Success'
redirect_to edit_gallery_path(@gallery)
else
puts! @gallery.errors.messages
flash[:alert] = "Cannot create the gallery: #{@gallery.errors.full_messages.join(', ')}"
render :action => 'new'
end
end
|
#destroy ⇒ Object
30
31
32
33
34
35
|
# File 'app/controllers/wco/galleries_controller.rb', line 30
def destroy
authorize! :destroy, @gallery
@gallery.delete
flash[:notice] = 'Marked the gallery deleted.'
redirect_to( request.referrer || galleries_path )
end
|
#edit ⇒ Object
37
38
39
|
# File 'app/controllers/wco/galleries_controller.rb', line 37
def edit
authorize! :edit, @gallery
end
|
#index ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/wco/galleries_controller.rb', line 41
def index
authorize! :index, Wco::Gallery
@page_title = 'Galleries'
@galleries = Wco::Gallery.all.order_by( :created_at => :desc )
@tags = Wco::Tag.all.order_by( slug: :asc )
if params[:q]
q = URI.decode(params[:q])
@galleries = @galleries.where({ :name => /#{q}/i })
end
@galleries = @galleries.page( params[:galleries_page] ).per( current_profile.per_page )
render '_index'
end
|
#j_show ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/wco/galleries_controller.rb', line 57
def j_show
authorize! :show, @gallery
respond_to do |format|
format.json do
jjj = {}
jjj[:photos] = @gallery.photos.map do |ph|
{ :thumbnail_url => ph.photo.url( :thumb ),
:delete_type => 'DELETE',
:delete_url => photo_path(ph) }
end
render :json => jjj
end
end
end
|
#new ⇒ Object
72
73
74
75
76
|
# File 'app/controllers/wco/galleries_controller.rb', line 72
def new
@gallery = Wco::Gallery.new
@page_title = 'New Gallery'
authorize! :new, @gallery
end
|
#shared_with_me ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'app/controllers/wco/galleries_controller.rb', line 78
def shared_with_me
authorize! :index, Wco::Gallery
@page_title = 'Galleries Shared With Me'
@galleries = @current_profile.shared_galleries(
).order_by( :created_at => :desc
).page( params[:shared_galleries_page] ).per( 10 )
render params[:render_type]
end
|
#show ⇒ Object
87
88
89
90
91
|
# File 'app/controllers/wco/galleries_controller.rb', line 87
def show
authorize! :show, @gallery
@photos = @gallery.photos.order_by( ordering: :asc )
@deleted_photos = @gallery.photos.deleted.order_by( ordering: :asc )
end
|
#update ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'app/controllers/wco/galleries_controller.rb', line 103
def update
params[:gallery][:tag_ids]&.delete ''
authorize! :update, @gallery
old_shared_profile_ids = @gallery.shared_profiles.map(&:id)
if params[:gallery][:shared_profiles].present?
params[:gallery][:shared_profiles].delete('')
end
params[:gallery][:shared_profile_ids] = params[:gallery][:shared_profiles]
params[:gallery].delete :shared_profiles
flag = @gallery.update_attributes( params[:gallery].permit! )
if flag
if params[:gallery][:shared_profile_ids].present?
new_shared_profiles = Wco::Profile.find( params[:gallery][:shared_profile_ids]
).select { |p| !old_shared_profile_ids.include?( p.id ) }
Wco::GalleriesMailer.shared_galleries( new_shared_profiles, @gallery ).deliver
end
flash[:notice] = 'Success.'
redirect_to edit_gallery_path(@gallery)
else
puts! @gallery.errors.messages, 'cannot save gallery'
flash[:alert] = 'No Luck. ' + @gallery.errors.messages.to_s
render :action => :edit
end
end
|
#update_many ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'app/controllers/wco/galleries_controller.rb', line 130
def update_many
authorize! :update, Wco::Gallery
galleries = Wco::Gallery.where( :id.in => params[:gallery_ids] )
tags = Wco::Tag.where( :id.in => params[:tag_ids] )
if params[:remove]
galleries.each do |gallery|
tags.each do |tag|
gallery.tags.delete tag
end
gallery.save
end
else
galleries.each do |gallery|
gallery.tags.push tags
gallery.save
end
end
flash_notice 'Unknown outcome, no exception raised.'
redirect_to request.referrer
end
|
#update_ordering ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/wco/galleries_controller.rb', line 93
def update_ordering
authorize! :update, @gallery
flags = []
params[:ids].each_with_index do |id, idx|
flags.push Wco::Photo.find( id ).update( weight: idx )
end
flash_notice "Ordering photos: #{flags}"
redirect_to request.referrer
end
|