now new albums and images are sorted by created date and are on the top. also modified loading new images

This commit is contained in:
Harry Bomrah 2016-06-28 16:40:23 +08:00
parent 1769924137
commit afb11a2fa2
5 changed files with 45 additions and 24 deletions

View File

@ -243,6 +243,8 @@ $(function() {
})
//
var last_image_id = null;
$('.add-imgs').on({
click: function() {
$('#fileupload').slideToggle(300, function() {
@ -250,6 +252,14 @@ $(function() {
$('.add-imgs').html('<i class="icons-cross-2"></i> Close panel');
$('.rgbody').stop(true, false).animate({'padding-bottom': 280}, 300);
$("#edit-order-btn").hide();
$.ajax({
url : "/admin/galleries/last_image_id",
data : {"albumid" : $("#fileupload_aid").val()},
dataType : "json",
type : "get"
}).done(function(d){
last_image_id = d.last_image_id;
})
} else {
$('.add-imgs').html('<i class="icons-plus"></i> Add Image');
$('.files').empty()
@ -263,20 +273,19 @@ $(function() {
}
});
var fetchNewImages = function(){
var lastid = ( $("li.rgalbum:last").length ? $("li.rgalbum:last").data("image-id") : null),
albumid = $("#fileupload_aid").val();
var albumid = $("#fileupload_aid").val();
$.getJSON('/admin/galleries/get_photoData_json?id='+albumid, function(json, textStatus) {
photosData = json;
});
$.ajax({
url : "/admin/new_images",
data : {"last_image_id" : lastid, "album_id" : albumid},
url : "/admin/galleries/new_images",
data : {"last_image_id" : last_image_id, "album_id" : albumid},
success : function(data){
var $e = $(data);
$imgs = $e.find("img");
$("#imgholder").append($e);
$("#imgholder").prepend($e);
$os = $e.find("a.open");
$os.pageslide({
loadComplete: function(instance,elem) {

View File

@ -4,13 +4,17 @@ class Admin::GalleriesController < OrbitAdminController
before_action :log_user_action
layout "back_end"
def index
@albums = Album.all.asc(:order)
@albums = Album.where(:order => -1).desc(:created_at)
albums = Album.where(:order.gt => -1).asc(:order)
@albums = @albums.concat(albums)
@tags = @module_app.tags
end
def show
@album = Album.find(params[:id])
@images = @album.album_images.asc(:order)
@images = @album.album_images.where(:order => -1).desc(:created_at)
images = @album.album_images.where(:order.gt => -1).asc(:order)
@images = @images.concat(images)
image_content = []
@images.each do |image|
image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}}
@ -61,7 +65,9 @@ class Admin::GalleriesController < OrbitAdminController
def get_photoData_json
@album = Album.find(params[:id])
@images = @album.album_images
@images = @album.album_images.where(:order => -1).desc(:created_at)
images = @album.album_images.where(:order.gt => -1).asc(:order)
@images = @images.concat(images)
image_content = []
@images.each do |image|
image_content << {"id" => image.id.to_s, "description" => image.description_translations,"tags" => image.tags.collect{|t| t.id.to_s}}
@ -158,17 +164,20 @@ class Admin::GalleriesController < OrbitAdminController
render :json=>{"files"=>a}.to_json
end
def last_image_id
album = Album.find(params[:albumid])
lastimage = album.album_images.last
render :json => {"last_image_id" => lastimage.id.to_s}.to_json
end
def new_images
if params[:last_image_id] != ""
@lastimage = AlbumImage.find(params[:last_image_id])
@album = Album.find(params[:album_id])
@newimages = @album.album_images.where(:created_at.gt => @lastimage.created_at)
@album = Album.find(params[:album_id])
if params[:last_image_id].present?
lastimage = AlbumImage.find(params[:last_image_id])
@newimages = @album.album_images.where(:created_at.gt => lastimage.created_at,:order => -1).desc(:created_at)
else
@album = Album.find(params[:album_id])
@newimages = @album.album_images
@newimages = @album.album_images.where(:order => -1).desc(:created_at)
end
render :layout=>false
end

View File

@ -13,7 +13,7 @@ class Album
field :tag_names
field :uid, type: String
field :rss2_id, type: String
field :order, type: Integer, default: 0
field :order, type: Integer, default: -1
# has_and_belongs_to_many :tags, :class_name => "GalleryTag"
has_many :album_images, :autosave => true, :dependent => :destroy

View File

@ -9,7 +9,7 @@ class AlbumImage
field :title
field :description, localize: true
field :rss2_id, type: String
field :order, type: Integer, default: 0
field :order, type: Integer, default: -1
# has_and_belongs_to_many :tags, :class_name => "GalleryTag"

View File

@ -7,18 +7,21 @@ Rails.application.routes.draw do
namespace :admin do
get "galleries/get_photoData_json" => "galleries#get_photoData_json"
get "galleries/new_images" => "galleries#new_images"
get "galleries/last_image_id" => "galleries#last_image_id"
post "galleries/set_cover" => "galleries#set_cover"
post "galleries/delete_photos" => "images#delete_photos"
post "galleries/update_image" => "images#update_image"
post "galleries/image_tagging" => "images#image_tagging"
post "galleries/order" => "images#changeorder"
resources :galleries do
get "imgs" => "galleries#imgs"
end
resources :images
post "galleries/upload_image" => "galleries#upload_image"
get "new_images" => "galleries#new_images"
post "galleries/set_cover" => "galleries#set_cover"
post "galleries/delete_photos" => "images#delete_photos"
post "galleries/update_image" => "images#update_image"
post "galleries/image_tagging" => "images#image_tagging"
post "galleries/order" => "images#changeorder"
# match "image_tagging" => "album_images#image_tagging"
end
end