135 lines
4.2 KiB
Ruby
135 lines
4.2 KiB
Ruby
class Admin::ArchiveFilesController < OrbitAdminController
|
|
def show
|
|
module_pages = Page.where(:module => 'archive').collect{|p| p.url}
|
|
if module_pages.length<1
|
|
render :text => t('archive.no_page').to_s
|
|
else
|
|
redirect_to '/' + I18n.locale.to_s + module_pages[0] + '?title=' + params['title'].to_s
|
|
end
|
|
end
|
|
def save_categories_order
|
|
puts ['1test2',params.inspect]
|
|
end
|
|
def index
|
|
|
|
if ArchiveSortOrder.count == 0
|
|
ArchiveSortOrder.new('sort_order' => false).save
|
|
end
|
|
if !(params['order_asc'].nil?)
|
|
if params['order_asc'] == 'true'
|
|
ArchiveSortOrder.first.update_attributes('sort_order' => true)
|
|
elsif params['order_asc'] == 'false'
|
|
ArchiveSortOrder.first.update_attributes('sort_order' => false)
|
|
end
|
|
end
|
|
@choose = ArchiveSortOrder.first['sort_order']
|
|
@table_fields = [:status, :category, :title, :updated_at,:last_modified,"archive.downloaded_times"]
|
|
@categories = @module_app.categories
|
|
@tags = @module_app.tags
|
|
@filter_fields = filter_fields(@categories, @tags)
|
|
@archives = ArchiveFile.order_by(sort)
|
|
.with_categories(filters("category"))
|
|
.with_tags(filters("tag"))
|
|
.with_status(filters("status"))
|
|
|
|
@archives = search_data(@archives,[:title]).page(params[:page]).per(10)
|
|
|
|
render :partial => "index" if request.xhr?
|
|
end
|
|
|
|
def new
|
|
@archive_file = ArchiveFile.new
|
|
@tags = @module_app.tags
|
|
@categories = @module_app.categories
|
|
end
|
|
|
|
def edit
|
|
@archive_file = ArchiveFile.find(params[:id])
|
|
if can_edit_or_delete?(@archive_file)
|
|
@tags = @module_app.tags
|
|
@categories = @module_app.categories
|
|
else
|
|
render_401
|
|
end
|
|
end
|
|
def categories_order
|
|
categories = @module_app.categories
|
|
categories.each do |category|
|
|
archive_cat = ArchiveCategory.all.select{ |value| value.category_id.to_s == category.id.to_s}
|
|
if archive_cat.length == 0
|
|
ArchiveCategory.create(category_id: category.id.to_s)
|
|
end
|
|
end
|
|
cats_with_nil = ArchiveCategory.all.in(sort_number: nil)
|
|
cats_no_nil = ArchiveCategory.all.not_in(sort_number: nil)
|
|
@cats = cats_no_nil.concat(cats_with_nil).collect do |cat|
|
|
[categories.where(:_id => cat.category_id).first,cat.sort_number.to_s]
|
|
end
|
|
render :partial => "categories_order" if request.xhr?
|
|
end
|
|
def create
|
|
@archive_file = ArchiveFile.new(archive_vars)
|
|
@archive_file.create_user_id = current_user.id
|
|
@archive_file.update_user_id = current_user.id
|
|
|
|
respond_to do |format|
|
|
if @archive_file.save
|
|
format.html { redirect_to(edit_admin_archive_file_path(@archive_file.id)) }
|
|
format.xml { render :xml => @archive_file, :status => :created, :location => @archive_file }
|
|
else
|
|
@tags = @module_app.tags
|
|
format.html { render :action => "new" }
|
|
format.xml { render :xml => @archive_file.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PUT /archive_files/1
|
|
# PUT /archive_files/1.xml
|
|
def update
|
|
@archive_file = ArchiveFile.find(params[:id])
|
|
|
|
@archive_file.update_user_id = current_user.id
|
|
|
|
respond_to do |format|
|
|
if @archive_file.update_attributes(archive_vars)
|
|
format.html { redirect_to(edit_admin_archive_file_path(@archive_file.id)) }
|
|
format.xml { head :ok }
|
|
else
|
|
format.html { render :action => "edit" }
|
|
format.xml { render :xml => @archive_file.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
archive_file = ArchiveFile.find(params[:id])
|
|
archive_file.destroy
|
|
redirect_to admin_archive_files_path
|
|
end
|
|
|
|
private
|
|
|
|
def archive_vars
|
|
params[:archive_file][:tags] ||=[]
|
|
params.require(:archive_file).permit!
|
|
end
|
|
|
|
def setup_vars
|
|
@module_app = ModuleApp.where(:key => "archive").first
|
|
end
|
|
# def sort
|
|
# unless params[:sort].blank?
|
|
# case params[:sort]
|
|
# when "downloaded_times"
|
|
|
|
# else
|
|
# @sort = sort
|
|
# end
|
|
# else
|
|
# @sort = sort
|
|
# end
|
|
# @sort
|
|
# end
|
|
end
|