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