From c18846b6b0bcbae407ea4a69356166e4f35280a7 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 29 Sep 2014 21:21:41 +0800 Subject: [PATCH] added clean button for the modules import --- app/controllers/admin/import_controller.rb | 21 +++++++++++++++++++++ app/views/admin/import/index.html.erb | 20 +++++++++++++++++--- config/routes.rb | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/import_controller.rb b/app/controllers/admin/import_controller.rb index ae97f3f..ccbf3e8 100644 --- a/app/controllers/admin/import_controller.rb +++ b/app/controllers/admin/import_controller.rb @@ -29,6 +29,27 @@ class Admin::ImportController < OrbitAdminController render :json=>{"status"=>msg} end + def clean_old_data + case params[:module] + when "members" + User.where(:user_name.ne => "rulingcom").destroy_all + member_profle_id = User.where(:user_name => "rulingcom").first.member_profile.id.to_s + MemberProfile.where(:id.ne => member_profle_id).destroy_all + Role.destroy_all + when "announcement" + Bulletin.where(:rss2_sn.ne => nil).destroy_all + when "archive" + ArchiveFile.where(:rss2_sn.ne => nil).destroy_all + when "pages" + Page.where(:rss2_id.ne => nil).destroy_all + when "gallery" + Album.where(:rss2_id.ne => nil).destroy_all + when "links" + WebLink.where(:rss2_id.ne => nil).destroy_all + end + render :json => {"success" => true}.to_json + end + def module_categories module_app = ModuleApp.find_by(:key=>params['module']) uri = URI.parse(params['url']) diff --git a/app/views/admin/import/index.html.erb b/app/views/admin/import/index.html.erb index 7ff279d..f432eb4 100644 --- a/app/views/admin/import/index.html.erb +++ b/app/views/admin/import/index.html.erb @@ -157,12 +157,13 @@
-
+
-
- +
+ +
@@ -208,6 +209,19 @@ getModuleCategories(); } }); + + $("#import-clean-btn").click(function(){ + $("#import-progress-text").html("Cleaning up " + module + ". Please wait."); + $.ajax({ + url : "<%= admin_import_clean_old_data_path %>", + type : "post", + dataType : "json", + data : {"module" : module} + }).done(function(){ + $("#import-progress-text").html("Cleaning up successful. Ready to import."); + }) + }) + $("#import-back-btn").click(function(){ $("#import-progress").fadeOut(300,function(){ $("#import-head").fadeIn(0); diff --git a/config/routes.rb b/config/routes.rb index 7ca2ee8..f64c939 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -231,6 +231,7 @@ Orbit::Application.routes.draw do post "import/rss2_members" => "import#rss2_members" post "import/rss2_members_info" => "import#rss2_members_info" get "import/import_plugin" => "import#import_plugin" + post "import/clean_old_data" => "import#clean_old_data" end get 'mobile', to: 'pages#home'