From 275c6f4c8a4931a39ab1e96e27c63e69a3602a4c Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Fri, 9 Nov 2012 16:25:11 +0800 Subject: [PATCH] get_album_json function can get readable json --- .../gallery/back_end/albums_controller.rb | 52 ++++++++++++++++--- .../built_in_modules/gallery/config/routes.rb | 3 ++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb index 0c203459..bf32b693 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb @@ -1,7 +1,7 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController include AdminHelper - before_filter :force_order_for_user, :except => [:index,:imgs] + before_filter :force_order_for_user, :except => [:index,:get_album_json] def index if is_manager? || is_admin? || is_sub_manager? @@ -113,6 +113,47 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController render :json =>{"success"=>true}.to_json end + def get_album_json + albums = GalleryAlbum.all + output = Array.new + + albums.each do |album| + tag_names = Array.new + all_image = Array.new + + images = album.gallery_images.all + images.each do |image| + tags = Array.new + + image.tag_ids.each do |tag| + tags << GalleryTag.find(tag)[I18n.locale] + end + + all_image << { + image_title: image.title, + image_description: image.description, + image_file: { url: "http://#{request.host_with_port+image.file.url}", + thumb: "http://#{request.host_with_port+image.file.thumb.to_s}"}, + image_tag_names: tags} + end + + album.tag_ids.each do |tag| + tag_names << GalleryTag.find(tag)[I18n.locale] + end + + output << { + album_cover_file: "http://#{request.host_with_port+album.cover_path}", + album_name: album.name, + album_tag_names: tag_names, + images: all_image + } + end + + #render :json=>{:images => @output, + # :tag_names => @tag_names}.to_json + render :json=>JSON.pretty_generate(output) + end + def imgs @album = GalleryAlbum.find(params[:album_id]) @tag_names = Array.new @@ -146,10 +187,12 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController 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'] @@ -186,11 +229,4 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController @tags = GalleryTag.all render :action => :show end - end - - - - - - diff --git a/vendor/built_in_modules/gallery/config/routes.rb b/vendor/built_in_modules/gallery/config/routes.rb index b8c64f3c..8795594b 100644 --- a/vendor/built_in_modules/gallery/config/routes.rb +++ b/vendor/built_in_modules/gallery/config/routes.rb @@ -11,6 +11,9 @@ Rails.application.routes.draw do match "imgs" => "albums#imgs" match "upload_panel" => "albums#upload_panel" match "images_tags" => "albums#images_tags" + collection do + get "get_album_json" + end end match "album_images/#!/:id" => "album_images#show"