2014-07-31 09:12:57 +00:00
|
|
|
class Admin::GalleriesController < OrbitAdminController
|
2014-05-05 06:07:18 +00:00
|
|
|
before_filter :setup_vars
|
2014-10-20 11:46:03 +00:00
|
|
|
before_action :authenticate_user, :except => "imgs"
|
|
|
|
before_action :log_user_action
|
2014-05-01 07:06:48 +00:00
|
|
|
def index
|
2016-09-02 10:21:00 +00:00
|
|
|
@tags = @module_app.tags
|
|
|
|
categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(categories, @tags)
|
|
|
|
@filter_fields.delete(:status)
|
|
|
|
@albums = Album.where(:order => -1).desc(:created_at).with_categories(filters("category")).with_tags(filters("tag"))
|
2016-09-02 10:29:50 +00:00
|
|
|
@albums = search_data(@albums,[:name])
|
2016-09-02 10:21:00 +00:00
|
|
|
albums = Album.where(:order.gt => -1).asc(:order).with_categories(filters("category")).with_tags(filters("tag"))
|
2016-09-02 10:29:50 +00:00
|
|
|
albums = search_data(albums,[:name])
|
2016-06-28 08:40:23 +00:00
|
|
|
@albums = @albums.concat(albums)
|
2016-09-02 10:29:50 +00:00
|
|
|
|
2016-09-02 10:21:00 +00:00
|
|
|
if request.xhr?
|
|
|
|
render :partial => "album", :collection => @albums
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@album = Album.find(params[:id])
|
2016-06-28 08:40:23 +00:00
|
|
|
@images = @album.album_images.where(:order => -1).desc(:created_at)
|
|
|
|
images = @album.album_images.where(:order.gt => -1).asc(:order)
|
|
|
|
@images = @images.concat(images)
|
2014-07-21 08:28:09 +00:00
|
|
|
image_content = []
|
2014-05-05 06:07:18 +00:00
|
|
|
@images.each do |image|
|
2014-07-21 08:28:09 +00:00
|
|
|
image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}}
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
@tags = @module_app.tags
|
2014-07-21 08:28:09 +00:00
|
|
|
@photos_data = {"galleries" => image_content}.to_json
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@album = Album.new
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
album = Album.new(album_params)
|
|
|
|
album.save!
|
|
|
|
redirect_to admin_galleries_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
album = Album.find(params[:id])
|
|
|
|
album.destroy
|
|
|
|
redirect_to admin_galleries_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@album = Album.find(params[:id])
|
2014-07-31 09:47:11 +00:00
|
|
|
if can_edit_or_delete?(@album)
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories
|
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_cover
|
|
|
|
if params[:set_cover] == "true"
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
image = AlbumImage.find(params[:image_id])
|
|
|
|
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:image_id]})
|
|
|
|
else
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
album.update_attributes({:cover_path => nil, :cover=>"default"})
|
|
|
|
end
|
|
|
|
render :json =>{"success"=>true}.to_json
|
|
|
|
end
|
|
|
|
|
2014-07-21 08:28:09 +00:00
|
|
|
def get_photoData_json
|
|
|
|
@album = Album.find(params[:id])
|
2016-06-28 08:40:23 +00:00
|
|
|
@images = @album.album_images.where(:order => -1).desc(:created_at)
|
|
|
|
images = @album.album_images.where(:order.gt => -1).asc(:order)
|
|
|
|
@images = @images.concat(images)
|
2014-07-21 08:28:09 +00:00
|
|
|
image_content = []
|
|
|
|
@images.each do |image|
|
|
|
|
image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}}
|
|
|
|
end
|
|
|
|
render :json=>{"galleries" => image_content}.to_json
|
|
|
|
end
|
|
|
|
|
2014-05-05 06:07:18 +00:00
|
|
|
def get_album_json
|
|
|
|
albums = Album.all
|
|
|
|
output = Array.new
|
|
|
|
|
|
|
|
albums.each do |album|
|
|
|
|
tag_names = Array.new
|
|
|
|
|
|
|
|
album.tag_ids.each do |tag|
|
|
|
|
tag_names << get_tags.include?(tag)
|
|
|
|
end
|
|
|
|
if album.cover_path
|
|
|
|
cover_path = album.cover_path
|
|
|
|
else
|
|
|
|
cover_path = "/assets/gallery/default.jpg"
|
|
|
|
end
|
|
|
|
output << {
|
|
|
|
album_cover_file: "http://#{request.host_with_port}"+cover_path,
|
|
|
|
album_name: album.name,
|
|
|
|
album_tag_names: tag_names,
|
|
|
|
album_link:"http://#{request.host_with_port}#{panel_gallery_back_end_album_get_imgs_json_path(album)}",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json=>JSON.pretty_generate(output)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_imgs_json
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
images = album.album_images.all
|
|
|
|
output = Array.new
|
|
|
|
|
|
|
|
images.each do |image|
|
|
|
|
tags = Array.new
|
|
|
|
|
|
|
|
image.tag_ids.each do |tag|
|
|
|
|
tags << get_tags.include?(tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
if image.file.theater.present?
|
|
|
|
@image_file = image.file.theater.url
|
|
|
|
else
|
|
|
|
@image_file = image.file.url
|
|
|
|
end
|
|
|
|
|
|
|
|
output << {
|
|
|
|
image_title: image.title,
|
|
|
|
image_description: image.description,
|
|
|
|
image_file: { url: "http://#{request.host_with_port}#{@image_file}",
|
|
|
|
thumb: "http://#{request.host_with_port}#{image.file.thumb.to_s}"},
|
|
|
|
image_tag_names: tags}
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json=>JSON.pretty_generate(output)
|
|
|
|
end
|
|
|
|
|
|
|
|
def imgs
|
2014-10-20 12:29:45 +00:00
|
|
|
@album = Album.find(params[:gallery_id])
|
2014-05-05 06:07:18 +00:00
|
|
|
@tag_names = Array.new
|
2015-04-16 12:07:54 +00:00
|
|
|
@images = @album.album_images.asc(:order)
|
2014-05-05 06:07:18 +00:00
|
|
|
@output = Array.new
|
|
|
|
@images.each do |values|
|
|
|
|
@output << { _id: values.id.to_s,
|
|
|
|
theater_link: admin_image_path(values),
|
|
|
|
description: values.description,
|
|
|
|
title: values.title,
|
|
|
|
file: values.file.as_json[:file],
|
|
|
|
gallery_album_id: values.album_id,
|
2015-04-16 12:07:54 +00:00
|
|
|
order: values.order,
|
2014-05-05 06:07:18 +00:00
|
|
|
tags: values.tags}
|
|
|
|
end
|
|
|
|
render :json=>{"images" => @output, "tags" => @album.tags}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upload_image
|
|
|
|
@album = Album.find(params[:album_id])
|
|
|
|
@files = params['files']
|
|
|
|
a = Array.new
|
|
|
|
@files.each do |file|
|
|
|
|
@image = @album.album_images.new
|
|
|
|
@image.file = file
|
|
|
|
@image.tags = @album.tags rescue []
|
|
|
|
@image.save!
|
|
|
|
a << {"thumbnail_url"=>@image.file.thumb.url,"url"=>admin_image_path(@image)}
|
|
|
|
end
|
|
|
|
render :json=>{"files"=>a}.to_json
|
|
|
|
end
|
|
|
|
|
2016-06-28 08:40:23 +00:00
|
|
|
def last_image_id
|
|
|
|
album = Album.find(params[:albumid])
|
|
|
|
lastimage = album.album_images.last
|
|
|
|
render :json => {"last_image_id" => lastimage.id.to_s}.to_json
|
|
|
|
end
|
2014-05-05 06:07:18 +00:00
|
|
|
|
2016-06-28 08:40:23 +00:00
|
|
|
def new_images
|
|
|
|
@album = Album.find(params[:album_id])
|
|
|
|
if params[:last_image_id].present?
|
|
|
|
lastimage = AlbumImage.find(params[:last_image_id])
|
|
|
|
@newimages = @album.album_images.where(:created_at.gt => lastimage.created_at,:order => -1).desc(:created_at)
|
2014-05-05 06:07:18 +00:00
|
|
|
else
|
2016-06-28 08:40:23 +00:00
|
|
|
@newimages = @album.album_images.where(:order => -1).desc(:created_at)
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
render :layout=>false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def images_tags
|
|
|
|
album = Album.find(params[:album_id])
|
|
|
|
tags = Array.new
|
|
|
|
images = album.album_images.all
|
|
|
|
images.each do |image|
|
|
|
|
tags << {"id"=>image.id, "tags" => image.tags}
|
|
|
|
end
|
|
|
|
render :json=>tags.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-03-02 04:31:47 +00:00
|
|
|
album = Album.find(params[:id])
|
2014-05-05 06:07:18 +00:00
|
|
|
tagsToDestroy = []
|
|
|
|
tagsToAdd = []
|
|
|
|
new_tags = params[:album][:tags] || []
|
2016-03-02 04:31:47 +00:00
|
|
|
old_tags = album.tags.collect{|t| t.id.to_s}
|
2014-05-05 06:07:18 +00:00
|
|
|
old_tags.each do |tag|
|
|
|
|
if !new_tags.include?(tag)
|
|
|
|
tagsToDestroy << tag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if new_tags != nil
|
|
|
|
new_tags.each do |tag|
|
|
|
|
if !old_tags.include?(tag)
|
|
|
|
tagsToAdd << tag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-02 04:31:47 +00:00
|
|
|
update_children_image_tag(album,tagsToDestroy,tagsToAdd)
|
|
|
|
album.update_attributes(album_params)
|
|
|
|
redirect_to "/admin/galleries/"+album.id.to_s
|
2014-05-05 06:07:18 +00:00
|
|
|
end
|
|
|
|
|
2016-03-02 04:31:47 +00:00
|
|
|
def update_children_image_tag(album,tagsToDestroy,tagsToAdd)
|
2014-05-05 06:07:18 +00:00
|
|
|
# tagsToDestroy will contain all tag ids which have to be deleted from the galley_images
|
|
|
|
# tagsToAdd will contain all tag ids which ve to be added in tall album_images
|
2016-03-02 04:31:47 +00:00
|
|
|
images = album.album_images
|
|
|
|
images.each do |image|
|
2014-05-05 06:07:18 +00:00
|
|
|
image_tags = image.tags.collect{|t| t.id.to_s}
|
|
|
|
tagsToAdd.each do |tag|
|
|
|
|
image_tags << tag
|
|
|
|
end
|
|
|
|
tagsToDestroy.each do |tag|
|
|
|
|
if image_tags.include?tag
|
|
|
|
image_tags.delete(tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
image.tags = image_tags
|
|
|
|
image.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def setup_vars
|
|
|
|
@module_app = ModuleApp.where(:key=>"gallery").first
|
|
|
|
end
|
|
|
|
|
|
|
|
def album_params
|
|
|
|
p = params.require(:album).permit!
|
|
|
|
p["tags"] = p["tags"] || []
|
|
|
|
p
|
2014-05-01 07:06:48 +00:00
|
|
|
end
|
|
|
|
end
|