From 310d7523bdd3a2ffe088a89d52639d56cb35775a Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 14 Nov 2012 12:01:42 +0800 Subject: [PATCH] modified gallery json format but it have some bugs... --- .../gallery/back_end/albums_controller.rb | 53 ++++++++++--------- .../built_in_modules/gallery/config/routes.rb | 5 ++ 2 files changed, 34 insertions(+), 24 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 ee19a269..e69bd50a 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,:get_album_json] + before_filter :force_order_for_user, :except => [:index,:get_album_json,:get_img_json] def index if is_manager? || is_admin? || is_sub_manager? @@ -119,37 +119,42 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController 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 + album_cover_file: "http://#{request.host_with_port}#{album.cover_path}", + album_name: album.name, + album_tag_names: tag_names, + album_link:"http://#{request.host_with_port}" } end - #render :json=>{:images => @output, - # :tag_names => @tag_names}.to_json + render :json=>JSON.pretty_generate(output) + end + + def get_img_json + album = GalleryAlbum.find(params[:album_id]) + images = album.gallery_images.all + output = Array.new + + 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 + render :json=>JSON.pretty_generate(output) end diff --git a/vendor/built_in_modules/gallery/config/routes.rb b/vendor/built_in_modules/gallery/config/routes.rb index ce4888e9..2ca337e3 100644 --- a/vendor/built_in_modules/gallery/config/routes.rb +++ b/vendor/built_in_modules/gallery/config/routes.rb @@ -12,6 +12,11 @@ Rails.application.routes.draw do match "imgs" => "albums#imgs" match "upload_panel" => "albums#upload_panel" match "images_tags" => "albums#images_tags" + match "get_img_json/:album_id" => "album_images#get_img_json" + + collection do + get "get_album_json" + end end match "album_images/#!/:id" => "album_images#show"