all of user can get json of gallery from outside
This commit is contained in:
parent
43d969a72b
commit
b4f5a0b04b
|
@ -1,185 +1,191 @@
|
||||||
class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController
|
class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController
|
||||||
include AdminHelper
|
include AdminHelper
|
||||||
|
|
||||||
# before_filter :force_order_for_visitor,:only=>[:index]
|
before_filter :force_order_for_user, :except => [:index,:imgs]
|
||||||
before_filter :force_order_for_user#,:except => [:index]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if is_manager? || is_admin? || is_sub_manager?
|
if is_manager? || is_admin? || is_sub_manager?
|
||||||
@authenticated = true #turn this value to false for view only
|
@authenticated = true #turn this value to false for view only
|
||||||
else
|
else
|
||||||
@authenticated = false
|
@authenticated = false
|
||||||
end
|
end
|
||||||
@categorylist = GalleryCategory.all
|
@categorylist = GalleryCategory.all
|
||||||
@cid = params['cat']
|
@cid = params['cat']
|
||||||
@tags = GalleryTag.all
|
@tags = GalleryTag.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if is_manager? || is_admin? || is_sub_manager?
|
if is_manager? || is_admin? || is_sub_manager?
|
||||||
@authenticated = true #turn this value to false for view only
|
@authenticated = true #turn this value to false for view only
|
||||||
else
|
else
|
||||||
@authenticated = false
|
@authenticated = false
|
||||||
end
|
end
|
||||||
@album = GalleryAlbum.find(params[:id])
|
@album = GalleryAlbum.find(params[:id])
|
||||||
@tags = GalleryTag.all
|
@tags = GalleryTag.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
if is_manager? || is_admin?
|
if is_manager? || is_admin?
|
||||||
@categorylist = GalleryCategory.all
|
@categorylist = GalleryCategory.all
|
||||||
elsif is_sub_manager?
|
elsif is_sub_manager?
|
||||||
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
|
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
|
||||||
end
|
end
|
||||||
@album = GalleryAlbum.new
|
@album = GalleryAlbum.new
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
album = GalleryAlbum.new(params[:gallery_album])
|
album = GalleryAlbum.new(params[:gallery_album])
|
||||||
album.save!
|
album.save!
|
||||||
respond_to do |h|
|
respond_to do |h|
|
||||||
h.js
|
h.js
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_albums
|
def get_albums
|
||||||
@categoryids = params["cid"]
|
@categoryids = params["cid"]
|
||||||
@tags = params["tid"]
|
@tags = params["tid"]
|
||||||
@albums = Array.new
|
@albums = Array.new
|
||||||
if @categoryids == "all"
|
if @categoryids == "all"
|
||||||
if @tags
|
if @tags
|
||||||
if @tags.kind_of?(Array)
|
if @tags.kind_of?(Array)
|
||||||
@tags.each do |tag|
|
@tags.each do |tag|
|
||||||
@albums << GalleryAlbum.where(tag_ids: tag)
|
@albums << GalleryAlbum.where(tag_ids: tag)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@albums << GalleryAlbum.where(tag_ids: @tags)
|
@albums << GalleryAlbum.where(tag_ids: @tags)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@albums << GalleryAlbum.all
|
@albums << GalleryAlbum.all
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@categoryids.each do |id|
|
@categoryids.each do |id|
|
||||||
category = GalleryCategory.find(id)
|
category = GalleryCategory.find(id)
|
||||||
if @tags
|
if @tags
|
||||||
if @tags.kind_of?(Array)
|
if @tags.kind_of?(Array)
|
||||||
@tags.each do |tag|
|
@tags.each do |tag|
|
||||||
@albums << category.gallery_albums.where(tag_ids: tag)
|
@albums << category.gallery_albums.where(tag_ids: tag)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@albums << category.gallery_albums.where(tag_ids: @tags)
|
@albums << category.gallery_albums.where(tag_ids: @tags)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@albums << category.gallery_albums.all
|
@albums << category.gallery_albums.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@output = Array.new
|
@output = Array.new
|
||||||
@albums.each do |album|
|
@albums.each do |album|
|
||||||
@albs = Array.new
|
@albs = Array.new
|
||||||
album.each do |values|
|
album.each do |values|
|
||||||
tags = Array.new
|
tags = Array.new
|
||||||
values.tag_ids.each do |tag|
|
values.tag_ids.each do |tag|
|
||||||
tags << GalleryTag.find(tag)[I18n.locale]
|
tags << GalleryTag.find(tag)[I18n.locale]
|
||||||
end
|
end
|
||||||
category = GalleryCategory.find(values.gallery_category_id).name
|
category = GalleryCategory.find(values.gallery_category_id).name
|
||||||
@albs << {"_id"=>values.id,"show_path"=>panel_gallery_back_end_album_path(values),"cover"=>values.cover,"cover_path"=>values.cover_path,"description"=>values.description,"category_name"=>category,"gallery_category_id" => values.gallery_category_id,"name"=>values.name,"tag_ids"=>values.tag_ids,"tag_names"=>tags}
|
@albs << {"_id"=>values.id,"show_path"=>panel_gallery_back_end_album_path(values),"cover"=>values.cover,"cover_path"=>values.cover_path,"description"=>values.description,"category_name"=>category,"gallery_category_id" => values.gallery_category_id,"name"=>values.name,"tag_ids"=>values.tag_ids,"tag_names"=>tags}
|
||||||
end
|
end
|
||||||
@output << @albs
|
@output << @albs
|
||||||
end
|
end
|
||||||
render :json=>@output.to_json
|
render :json=>@output.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
album = GalleryAlbum.find(params[:id])
|
album = GalleryAlbum.find(params[:id])
|
||||||
album.delete
|
album.delete
|
||||||
render :json =>{"success"=>true}.to_json
|
render :json =>{"success"=>true}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
if is_manager? || is_admin? || is_sub_manager?
|
if is_manager? || is_admin? || is_sub_manager?
|
||||||
@album = GalleryAlbum.find(params[:id])
|
@album = GalleryAlbum.find(params[:id])
|
||||||
@images = @album.gallery_images.all
|
@images = @album.gallery_images.all
|
||||||
@album_name = @album.name_translations
|
@album_name = @album.name_translations
|
||||||
@cover = @album.cover
|
@cover = @album.cover
|
||||||
@tags = GalleryTag.all
|
@tags = GalleryTag.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_cover
|
def set_cover
|
||||||
album = GalleryAlbum.find(params[:album_id])
|
album = GalleryAlbum.find(params[:album_id])
|
||||||
image = GalleryImage.find(params[:imageid])
|
image = GalleryImage.find(params[:imageid])
|
||||||
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]})
|
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]})
|
||||||
render :json =>{"success"=>true}.to_json
|
render :json =>{"success"=>true}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def imgs
|
def imgs
|
||||||
@album = GalleryAlbum.find(params[:album_id])
|
@album = GalleryAlbum.find(params[:album_id])
|
||||||
@tag_names = Array.new
|
@tag_names = Array.new
|
||||||
@images = @album.gallery_images.all
|
@images = @album.gallery_images.all
|
||||||
@output = Array.new
|
@output = Array.new
|
||||||
@images.each do |values|
|
@images.each do |values|
|
||||||
tags = Array.new
|
tags = Array.new
|
||||||
values.tag_ids.each do |tag|
|
values.tag_ids.each do |tag|
|
||||||
tags << GalleryTag.find(tag)[I18n.locale]
|
tags << GalleryTag.find(tag)[I18n.locale]
|
||||||
end
|
end
|
||||||
@output << {"_id"=>values.id,"theater_link"=>panel_gallery_back_end_album_image_path(values),"description"=>values.description,"title"=>values.title,"file"=>values.file,"gallery_album_id"=>values.gallery_album_id,"tag_ids"=>values.tag_ids,"tag_names"=>tags}
|
@output << { _id: values.id,
|
||||||
end
|
theater_link: panel_gallery_back_end_album_image_path(values),
|
||||||
if is_manager? || is_admin? || is_sub_manager?
|
description: values.description,
|
||||||
@authenticated = true #turn this value to false for view only
|
title: values.title,
|
||||||
else
|
file: values.file,
|
||||||
@authenticated = false
|
gallery_album_id: values.gallery_album_id,
|
||||||
end
|
tag_ids: values.tag_ids,
|
||||||
if @authenticated
|
tag_names: tags}
|
||||||
render :json=>{"images" => @output, "tags" => @album.tag_ids}.to_json
|
end
|
||||||
else
|
if is_manager? || is_admin? || is_sub_manager?
|
||||||
@album.tag_ids.each do |tag|
|
@authenticated = true #turn this value to false for view only
|
||||||
@tag_names << GalleryTag.find(tag)[I18n.locale]
|
else
|
||||||
end
|
@authenticated = false
|
||||||
render :json=>{"images" => @output, "tags" => @album.tag_ids, "tag_names" => @tag_names}.to_json
|
end
|
||||||
end
|
if @authenticated
|
||||||
end
|
render :json=>{"images" => @output, "tags" => @album.tag_ids}.to_json
|
||||||
def upload_panel
|
else
|
||||||
@album = GalleryAlbum.find(params[:album_id])
|
@album.tag_ids.each do |tag|
|
||||||
render :layout => false
|
@tag_names << GalleryTag.find(tag)[I18n.locale]
|
||||||
end
|
end
|
||||||
def upload_image
|
render :json=>{"images" => @output, "tags" => @album.tag_ids, "tag_names" => @tag_names}.to_json
|
||||||
@album = GalleryAlbum.find(params[:album_id])
|
end
|
||||||
@files = params['files']
|
end
|
||||||
a = Array.new
|
def upload_panel
|
||||||
@files.each do |file|
|
@album = GalleryAlbum.find(params[:album_id])
|
||||||
@image = @album.gallery_images.new
|
render :layout => false
|
||||||
@image.file = file
|
end
|
||||||
@image.save!
|
def upload_image
|
||||||
a << {"thumbnail_url"=>@image.file.thumb.url}
|
@album = GalleryAlbum.find(params[:album_id])
|
||||||
end
|
@files = params['files']
|
||||||
render :json=>a.to_json
|
a = Array.new
|
||||||
end
|
@files.each do |file|
|
||||||
def images_tags
|
@image = @album.gallery_images.new
|
||||||
album = GalleryAlbum.find(params[:album_id])
|
@image.file = file
|
||||||
tags = Array.new
|
@image.save!
|
||||||
images = album.gallery_images.all
|
a << {"thumbnail_url"=>@image.file.thumb.url}
|
||||||
images.each do |image|
|
end
|
||||||
tags << {"id"=>image.id, "tags" => image.tag_ids}
|
render :json=>a.to_json
|
||||||
end
|
end
|
||||||
render :json=>tags.to_json
|
def images_tags
|
||||||
end
|
album = GalleryAlbum.find(params[:album_id])
|
||||||
|
tags = Array.new
|
||||||
|
images = album.gallery_images.all
|
||||||
|
images.each do |image|
|
||||||
|
tags << {"id"=>image.id, "tags" => image.tag_ids}
|
||||||
|
end
|
||||||
|
render :json=>tags.to_json
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@album = GalleryAlbum.find(params[:id])
|
@album = GalleryAlbum.find(params[:id])
|
||||||
@album.update_attributes(params[:gallery_album])
|
@album.update_attributes(params[:gallery_album])
|
||||||
if is_manager? || is_admin? || is_sub_manager?
|
if is_manager? || is_admin? || is_sub_manager?
|
||||||
@authenticated = true #turn this value to false for view only
|
@authenticated = true #turn this value to false for view only
|
||||||
else
|
else
|
||||||
@authenticated = false
|
@authenticated = false
|
||||||
end
|
end
|
||||||
if params['delete_cover'] == "true"
|
if params['delete_cover'] == "true"
|
||||||
@album.update_attributes(:cover=>"default")
|
@album.update_attributes(:cover=>"default")
|
||||||
end
|
end
|
||||||
@tags = GalleryTag.all
|
@tags = GalleryTag.all
|
||||||
render :action => :show
|
render :action => :show
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,54 +1,52 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
namespace :panel do
|
namespace :panel do
|
||||||
namespace :gallery do
|
namespace :gallery do
|
||||||
namespace :back_end do
|
namespace :back_end do
|
||||||
match "get_albums" => "albums#get_albums"
|
match "get_albums" => "albums#get_albums"
|
||||||
match "upload_image" => "albums#upload_image"
|
match "upload_image" => "albums#upload_image"
|
||||||
match "save_tags" => "tags#save_tags"
|
match "save_tags" => "tags#save_tags"
|
||||||
match "albums/save_tags" => "tags#save_tags"
|
match "albums/save_tags" => "tags#save_tags"
|
||||||
resources :albums do
|
resources :albums do
|
||||||
match "set_cover" => "albums#set_cover"
|
match "set_cover" => "albums#set_cover"
|
||||||
match "imgs" => "albums#imgs"
|
match "imgs" => "albums#imgs"
|
||||||
match "upload_panel" => "albums#upload_panel"
|
match "upload_panel" => "albums#upload_panel"
|
||||||
match "images_tags" => "albums#images_tags"
|
match "images_tags" => "albums#images_tags"
|
||||||
end
|
end
|
||||||
|
|
||||||
match "album_images/#!/:id" => "album_images#show"
|
match "album_images/#!/:id" => "album_images#show"
|
||||||
|
|
||||||
resources :album_images
|
resources :album_images
|
||||||
|
resources :gallery_categories
|
||||||
|
resources :tags
|
||||||
|
|
||||||
|
end
|
||||||
resources :gallery_categories
|
namespace :front_end do
|
||||||
resources :tags
|
match "get_albums" => "albums#get_albums"
|
||||||
|
# match "orbit_galleries" => "orbit_galleries#index"
|
||||||
end
|
# match "gallery_category_save" => "orbit_galleries#new_category"
|
||||||
namespace :front_end do
|
# match "categorylist" => "orbit_galleries#categorylist"
|
||||||
match "get_albums" => "albums#get_albums"
|
# match "gallery_category_delete" => "orbit_galleries#gallery_category_delete"
|
||||||
# match "orbit_galleries" => "orbit_galleries#index"
|
# match "add_album" => "orbit_galleries#add_album"
|
||||||
# match "gallery_category_save" => "orbit_galleries#new_category"
|
# match "create_album" => "orbit_galleries#create_album"
|
||||||
# match "categorylist" => "orbit_galleries#categorylist"
|
# match "get_albums" => "orbit_galleries#get_albums"
|
||||||
# match "gallery_category_delete" => "orbit_galleries#gallery_category_delete"
|
# match "upload_image" => "orbit_galleries#upload_image"
|
||||||
# match "add_album" => "orbit_galleries#add_album"
|
# match "upload_panel" => "orbit_galleries#upload_panel"
|
||||||
# match "create_album" => "orbit_galleries#create_album"
|
# match "get_images" => "orbit_galleries#get_images"
|
||||||
# match "get_albums" => "orbit_galleries#get_albums"
|
# match "theater" => "orbit_galleries#theater"
|
||||||
# match "upload_image" => "orbit_galleries#upload_image"
|
# match "delete_album" => "orbit_galleries#delete_album"
|
||||||
# match "upload_panel" => "orbit_galleries#upload_panel"
|
# match "edit_album" => "orbit_galleries#edit_album"
|
||||||
# match "get_images" => "orbit_galleries#get_images"
|
# match "set_cover" => "orbit_galleries#set_cover"
|
||||||
# match "theater" => "orbit_galleries#theater"
|
# match "delete_images" => "orbit_galleries#delete_images"
|
||||||
# match "delete_album" => "orbit_galleries#delete_album"
|
# match "update_album" => "orbit_galleries#update_album"
|
||||||
# match "edit_album" => "orbit_galleries#edit_album"
|
# match "save_tags" => "orbit_galleries#save_tags"
|
||||||
# match "set_cover" => "orbit_galleries#set_cover"
|
resources :albums do
|
||||||
# match "delete_images" => "orbit_galleries#delete_images"
|
member do
|
||||||
# match "update_album" => "orbit_galleries#update_album"
|
get "imgs"
|
||||||
# match "save_tags" => "orbit_galleries#save_tags"
|
get "theater"
|
||||||
resources :albums do
|
end
|
||||||
member do
|
end
|
||||||
get "imgs"
|
resources :album_images
|
||||||
get "theater"
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :album_images
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue