all of user can get json of gallery from outside

This commit is contained in:
Rueshyna 2012-11-08 01:24:01 +08:00
parent 43d969a72b
commit b4f5a0b04b
2 changed files with 224 additions and 220 deletions

View File

@ -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]
def index before_filter :force_order_for_user, :except => [:index,:imgs]
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 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
@album = GalleryAlbum.find(params[:id]) @categorylist = GalleryCategory.all
@tags = GalleryTag.all @cid = params['cat']
end @tags = GalleryTag.all
end
def new def show
if is_manager? || is_admin? if is_manager? || is_admin? || is_sub_manager?
@categorylist = GalleryCategory.all @authenticated = true #turn this value to false for view only
elsif is_sub_manager? else
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album") @authenticated = false
end end
@album = GalleryAlbum.new @album = GalleryAlbum.find(params[:id])
render :layout => false @tags = GalleryTag.all
end end
def create def new
album = GalleryAlbum.new(params[:gallery_album]) if is_manager? || is_admin?
album.save! @categorylist = GalleryCategory.all
respond_to do |h| elsif is_sub_manager?
h.js @categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
end end
end @album = GalleryAlbum.new
render :layout => false
end
def get_albums def create
@categoryids = params["cid"] album = GalleryAlbum.new(params[:gallery_album])
@tags = params["tid"] album.save!
@albums = Array.new respond_to do |h|
if @categoryids == "all" h.js
if @tags end
if @tags.kind_of?(Array) end
@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 def get_albums
album = GalleryAlbum.find(params[:id]) @categoryids = params["cid"]
album.delete @tags = params["tid"]
render :json =>{"success"=>true}.to_json @albums = Array.new
end 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 edit def destroy
if is_manager? || is_admin? || is_sub_manager? album = GalleryAlbum.find(params[:id])
@album = GalleryAlbum.find(params[:id]) album.delete
@images = @album.gallery_images.all render :json =>{"success"=>true}.to_json
@album_name = @album.name_translations end
@cover = @album.cover
@tags = GalleryTag.all
end
end
def set_cover def edit
album = GalleryAlbum.find(params[:album_id]) if is_manager? || is_admin? || is_sub_manager?
image = GalleryImage.find(params[:imageid]) @album = GalleryAlbum.find(params[:id])
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]}) @images = @album.gallery_images.all
render :json =>{"success"=>true}.to_json @album_name = @album.name_translations
end @cover = @album.cover
@tags = GalleryTag.all
end
end
def imgs def set_cover
@album = GalleryAlbum.find(params[:album_id]) album = GalleryAlbum.find(params[:album_id])
@tag_names = Array.new image = GalleryImage.find(params[:imageid])
@images = @album.gallery_images.all album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]})
@output = Array.new render :json =>{"success"=>true}.to_json
@images.each do |values| end
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 def imgs
@album = GalleryAlbum.find(params[:id]) @album = GalleryAlbum.find(params[:album_id])
@album.update_attributes(params[:gallery_album]) @tag_names = Array.new
if is_manager? || is_admin? || is_sub_manager? @images = @album.gallery_images.all
@authenticated = true #turn this value to false for view only @output = Array.new
else @images.each do |values|
@authenticated = false tags = Array.new
end values.tag_ids.each do |tag|
if params['delete_cover'] == "true" tags << GalleryTag.find(tag)[I18n.locale]
@album.update_attributes(:cover=>"default") end
end @output << { _id: values.id,
@tags = GalleryTag.all theater_link: panel_gallery_back_end_album_image_path(values),
render :action => :show description: values.description,
end 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
end end

View File

@ -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
resources :gallery_categories end
resources :tags namespace :front_end do
match "get_albums" => "albums#get_albums"
end # match "orbit_galleries" => "orbit_galleries#index"
namespace :front_end do # match "gallery_category_save" => "orbit_galleries#new_category"
match "get_albums" => "albums#get_albums" # match "categorylist" => "orbit_galleries#categorylist"
# match "orbit_galleries" => "orbit_galleries#index" # match "gallery_category_delete" => "orbit_galleries#gallery_category_delete"
# match "gallery_category_save" => "orbit_galleries#new_category" # match "add_album" => "orbit_galleries#add_album"
# match "categorylist" => "orbit_galleries#categorylist" # match "create_album" => "orbit_galleries#create_album"
# match "gallery_category_delete" => "orbit_galleries#gallery_category_delete" # match "get_albums" => "orbit_galleries#get_albums"
# match "add_album" => "orbit_galleries#add_album" # match "upload_image" => "orbit_galleries#upload_image"
# match "create_album" => "orbit_galleries#create_album" # match "upload_panel" => "orbit_galleries#upload_panel"
# match "get_albums" => "orbit_galleries#get_albums" # match "get_images" => "orbit_galleries#get_images"
# match "upload_image" => "orbit_galleries#upload_image" # match "theater" => "orbit_galleries#theater"
# match "upload_panel" => "orbit_galleries#upload_panel" # match "delete_album" => "orbit_galleries#delete_album"
# match "get_images" => "orbit_galleries#get_images" # match "edit_album" => "orbit_galleries#edit_album"
# match "theater" => "orbit_galleries#theater" # match "set_cover" => "orbit_galleries#set_cover"
# match "delete_album" => "orbit_galleries#delete_album" # match "delete_images" => "orbit_galleries#delete_images"
# match "edit_album" => "orbit_galleries#edit_album" # match "update_album" => "orbit_galleries#update_album"
# match "set_cover" => "orbit_galleries#set_cover" # match "save_tags" => "orbit_galleries#save_tags"
# match "delete_images" => "orbit_galleries#delete_images" resources :albums do
# match "update_album" => "orbit_galleries#update_album" member do
# match "save_tags" => "orbit_galleries#save_tags" get "imgs"
resources :albums do get "theater"
member do end
get "imgs" end
get "theater" resources :album_images
end end
end end
resources :album_images end
end
end
end
end end