From 2490668d06993f8e9e6c52411753f454fecd5d21 Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Tue, 8 Oct 2013 18:41:37 +0800 Subject: [PATCH] albums api with get albums and images within the album --- .../panel/gallery/back_end/albums_controller.rb | 17 ++++++++++------- .../built_in_modules/gallery/config/routes.rb | 3 ++- 2 files changed, 12 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 b0c3349c7..ca426af65 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 @@ -4,8 +4,9 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController # before_filter :force_order_for_user, :except => [:index,:get_album_json,:get_imgs_json] before_filter :force_order_for_visitor,:only=>[:index,:show,:get_imgs_json,:get_albums,:imgs] - before_filter :force_order_for_user,:except => [:index,:show,:get_album_json,:get_imgs_json,:get_albums,:imgs] - before_filter :for_app_sub_manager,:except => [:index,:show,:get_album_json,:get_imgs_json,:get_albums,:imgs] + before_filter :force_order_for_user,:except => [:index,:show,:get_album_json,:get_albums,:imgs,:get_image_json] + before_filter :for_app_sub_manager,:except => [:index,:show,:get_album_json,:get_albums,:imgs,:get_image_json] + # before_filter lambda def index @@ -126,17 +127,18 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController 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}#{panel_gallery_back_end_album_get_imgs_json_path(album)}" + album_link:"http://#{request.host_with_port}/panel/gallery/back_end/albums/get_image_json?album_id=#{album.id}" } end render :json=>JSON.pretty_generate(output) end - def get_imgs_json - album = GalleryAlbum.find(params[:album_id]) - images = album.gallery_images.all - output = Array.new + def get_image_json + album = GalleryAlbum.where(:_id => params[:album_id]) + if album.first.present? + images = album.first.gallery_images.all + output = Array.new images.each do |image| tags = Tag.find(image.tagged_ids).map{|t| t.name} @@ -150,6 +152,7 @@ class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController end render :json=>JSON.pretty_generate(output) + end end def imgs diff --git a/vendor/built_in_modules/gallery/config/routes.rb b/vendor/built_in_modules/gallery/config/routes.rb index d9acd934f..b41454072 100644 --- a/vendor/built_in_modules/gallery/config/routes.rb +++ b/vendor/built_in_modules/gallery/config/routes.rb @@ -7,13 +7,14 @@ Rails.application.routes.draw do match "upload_image" => "albums#upload_image" match "save_tags" => "tags#save_tags" match "albums/save_tags" => "tags#save_tags" + + match "albums/get_image_json" => "albums#get_image_json" 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" - match "get_imgs_json" => "albums#get_imgs_json" collection do get "get_album_json"