diff --git a/.gitignore b/.gitignore index 97ef970..9bc0d3e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ app/views/frontend /public/uploads/* public/assets/* +public/import_status.yml diff --git a/app/controllers/admin/import_controller.rb b/app/controllers/admin/import_controller.rb index 047aa43..6618157 100644 --- a/app/controllers/admin/import_controller.rb +++ b/app/controllers/admin/import_controller.rb @@ -154,9 +154,12 @@ class Admin::ImportController < OrbitAdminController a = Asset.new a.remote_data_url = url a.title_translations = {"en" => a.data.filename, "zh_tw" => a.data.filename} - a.save! - @user.assets << a - temp.gsub!(CGI::escapeHTML(url), a.data.to_s) + if(a.save! rescue false) + temp.gsub!(CGI::escapeHTML(url), "#") + else + @user.assets << a + temp.gsub!(CGI::escapeHTML(url), a.data.to_s) + end end news['Content'][locale] = temp end @@ -172,8 +175,9 @@ class Admin::ImportController < OrbitAdminController bl = BulletinLink.new bl.url = news["URL"] bl.title_translations = {"en" => "Link", "zh_tw" => "Link"} - bl.save! - bulletin.bulletin_links << bl + if (bl.save! rescue false) + bulletin.bulletin_links << bl + end end news['files'].each do |f| bf = BulletinFile.new @@ -192,9 +196,10 @@ class Admin::ImportController < OrbitAdminController file = File.new("tmp/uploads/#{bf.title}#{file_ext}","w+b") file.write(bf.file.read) bf.file.cache!(file) - bf.save! - bulletin.bulletin_files << bf + if (bf.save! rescue false) + bulletin.bulletin_files << bf + end File.delete(file) end diff --git a/app/views/admin/import/index.html.erb b/app/views/admin/import/index.html.erb index 2d7809c..f280664 100644 --- a/app/views/admin/import/index.html.erb +++ b/app/views/admin/import/index.html.erb @@ -66,7 +66,7 @@ } .alert{ width: 500px; - margin: 0 auto; + margin: 20px auto 0; } .module-icon{ font-size: 64px; @@ -104,7 +104,7 @@
- + Download Rss2 Export API
@@ -204,6 +204,7 @@ $("#import-back-btn").click(function(){ $("#import-progress").fadeOut(300,function(){ $("#import-head").fadeIn(0); + $('#import-start-btn').show(); $("#import-modules").fadeIn(300); }); }); @@ -364,6 +365,7 @@ var importModule = function(m){ module = m; + progress = 0; dataList=Array(); categories=null; @@ -409,6 +411,7 @@ var importModuleDatas = function(){ progress = 0; + $('#import-start-btn').hide(); $("#import-progress-text").html("Start import...

"); if(dataList!=null && categories!=null){ @@ -422,6 +425,11 @@ if(progress>=dataList.length) return; var data = dataList[progress]; + if(data['category']==0){ + progress++; + importModuleData(); + return; + } var category_id = categories[data['category']]['id']; var Sn = data['Sn']; @@ -439,6 +447,10 @@ category: category_id } }).done(function(data){ + }).fail(function(data){ + $("#alert-msg").html('Faild to import Sn:'+progress+'
Message:'+data['status']+'-'+data['statusText']); + $(".alert").fadeIn(300).delay(5000).fadeOut(300); + }).always(function(){ progress++; percentage = parseInt((progress/dataList.length)*100)+'%'; $("#import-progress .bar").css('width',percentage); diff --git a/public/import_status.yml b/public/import_status.yml deleted file mode 100644 index 82b2d7a..0000000 --- a/public/import_status.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -total_images: 6 -current_status: 0 -success: true -current_album_id: '1' -current_album_name: "系統測試"