From 4e151690e92adaabdcd0d505294deebfcf69c3d6 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 20 Feb 2013 10:18:28 +0800 Subject: [PATCH] fixed archive bug, make it have page and category --- .../front_end/archive_files_controller.rb | 128 +++++++++++------- .../built_in_modules/archive/config/routes.rb | 12 +- 2 files changed, 85 insertions(+), 55 deletions(-) diff --git a/vendor/built_in_modules/archive/app/controllers/panel/archive/front_end/archive_files_controller.rb b/vendor/built_in_modules/archive/app/controllers/panel/archive/front_end/archive_files_controller.rb index 72728f15..05aacbc6 100644 --- a/vendor/built_in_modules/archive/app/controllers/panel/archive/front_end/archive_files_controller.rb +++ b/vendor/built_in_modules/archive/app/controllers/panel/archive/front_end/archive_files_controller.rb @@ -1,47 +1,81 @@ -class Panel::Archive::FrontEnd::ArchiveFilesController < OrbitWidgetController - - def initialize - super - @app_title = 'archive_files' - end - - def index - - @item = Page.find(params[:page_id]) - - @title = @item.title - - if @item.frontend_data_count - @page_num = @item.frontend_data_count - else - @page_num = 0 - end - - date_now = Time.now - - @archive_file_categorys = ArchiveFileCategory.all - - # @archive_files = ArchiveFile.where( :is_hidden => false ).desc(:is_top).page(params[:page]).per(@page_num) - - if !params[:category_id].blank? - @archive_files = ArchiveFile.all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num) - @current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil - elsif !params[:tag_id].blank? - @tag = ArchiveTag.find(params[:tag_id]) rescue nil - @tag = ArchiveTag.where(key: params[:tag_id])[0] unless @tag - @archive_files = @tag.archive_files.can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num) - - get_categorys - else - @archive_files = ArchiveFile.all.can_display.merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num) - - get_categorys - end - - end - - def get_categorys - @archive_file_categorys = ArchiveFileCategory.excludes('disable' => true) - end - -end +class Panel::Archive::FrontEnd::ArchiveFilesController < OrbitWidgetController + + def initialize + super + @app_title = 'archive_files' + end + + def index + @item = Page.find(params[:page_id]) + @title = @item.title + if !@item.frontend_data_count.blank? + @page_num = @item.frontend_data_count + else + @page_num = 1 + end + + date_now = Time.now + @archive_file_categorys = ArchiveFileCategory.all + + # @archive_files = ArchiveFile.where( :is_hidden => false ).desc(:is_top).page(params[:page]).per(@page_num) + + if !params[:category_id].blank? && !params[:tag_id].blank? + @tag = ArchiveTag.find(params[:tag_id]) rescue nil + @tag = ArchiveTag.where(key: params[:tag_id])[0] unless @tag + @archive_files = @tag.archive_files.can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num) + @archive_files = @archive_files.can_display.where(:archive_file_category_id => params[:category_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num) + + @current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil + + elsif !params[:category_id].blank? + @archive_files = ArchiveFile.can_display.where(:archive_file_category_id => params[:category_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num) + @current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = ArchiveTag.find(params[:tag_id]) rescue nil + @tag = ArchiveTag.where(key: params[:tag_id])[0] unless @tag + @archive_files = @tag.archive_files.can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num) + else + @archive_files = ArchiveFile.can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num) + end + + get_categorys + end + + def show + @item = Page.find(params[:page_id]) + @title = @item.title + @archive_file = ArchiveFile.find(params[:id]) + get_categorys + end + + protected + + def reload_archive_files + @item = Page.find(params[:page_id]) + @title = @item.title + if @item.frontend_data_count + @page_num = @item.frontend_data_count + else + @page_num = 0 + end + date_now = Time.now + @archive_file_categorys = ArchiveFileCategory.all + # @archive_files = ArchiveFile.where( :is_hidden => false ).desc(:is_top).page(params[:page]).per(@page_num) + + if !params[:category_id].blank? + @archive_files = ArchiveFile.can_display.where(:archive_file_category_id => params[:category_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num) + @current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = ArchiveTag.find(params[:tag_id]) rescue nil + @tag = ArchiveTag.where(key: params[:tag_id])[0] unless @tag + @archive_files = @tag.archive_files.can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num) + else + @archive_files = ArchiveFile.can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num) + end + get_categorys + end + + def get_categorys + @archive_file_categorys = ArchiveFileCategory.excludes('disabled' => true) + end +end diff --git a/vendor/built_in_modules/archive/config/routes.rb b/vendor/built_in_modules/archive/config/routes.rb index e9d1facb..9bb56fff 100644 --- a/vendor/built_in_modules/archive/config/routes.rb +++ b/vendor/built_in_modules/archive/config/routes.rb @@ -1,17 +1,13 @@ Rails.application.routes.draw do - namespace :panel do namespace :archive do namespace :back_end do - resources :archive_files do - collection do - get 'delete' - end - end - resources :archive_file_categorys + resources :archive_files + resources :archive_file_categorys resources :tags end namespace :front_end do + match "archive_files" => "archive_files#index" resources :archive_files end namespace :widget do @@ -19,5 +15,5 @@ Rails.application.routes.draw do end end end - match "/appfront/*path" => redirect("/panel/*path") + match "/appfront/*path" => redirect("/panel/*path") end