diff --git a/app/controllers/admin/import_controller.rb b/app/controllers/admin/import_controller.rb index 91659a8..4a2bbbc 100644 --- a/app/controllers/admin/import_controller.rb +++ b/app/controllers/admin/import_controller.rb @@ -204,7 +204,7 @@ class Admin::ImportController < OrbitAdminController data = response.body data = JSON.parse(data) pages = data["pages"] - @@import_stats["total"] = data["total_pages"] + @@import_stats["total"] = data["total_pages"].to_i @@import_stats["current_stattus"] = 0 pages.each do |page| @@import_stats["current_page"] = page["page_id"] @@ -267,16 +267,77 @@ class Admin::ImportController < OrbitAdminController end def get_import_status - if @@thread.alive? - render :json => {"success" => true, "total_pages" => @@import_stats["total"], "current_status" => @@import_stats["current_stattus"], "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]} - else - if @@import_stats["current_stattus"] == @@import_stats["total"] - render :json => {"success" => true, "total_pages" => @@import_stats["total"], "current_status" => @@import_stats["current_stattus"], "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]} - + case params["module"] + when "pages" + if @@thread.alive? + render :json => {"success" => true, "total_pages" => @@import_stats["total"], "current_status" => @@import_stats["current_stattus"], "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]} else - render :json => {"success" => false, "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]} + if @@import_stats["current_stattus"] == @@import_stats["total"] + render :json => {"success" => true, "total_pages" => @@import_stats["total"], "current_status" => @@import_stats["current_stattus"], "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]} + + else + render :json => {"success" => false, "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]} + end + end + when "gallery" + if @@thread.alive? + render :json => {"success" => true, "total_images" => @@import_stats["total_images"], "current_status" => @@import_stats["current_status"], "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]} + else + if @@import_stats["current_status"] == @@import_stats["total_images"] + render :json => {"success" => true, "total_images" => @@import_stats["total_images"], "current_status" => @@import_stats["current_status"], "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]} + else + render :json => {"success" => false, "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]} + end + end end + end + + def rss2_galleries + uri = URI.parse(params['url']) + @@thread = Thread.new do + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + data = response.body + data = JSON.parse(data) + @@import_stats["total_images"] = data["total_images"].to_i + @@import_stats["current_status"] = 0 + albums = data["albums"] + current_locale = I18n.locale + I18n.locale = :en + category = Category.where(:title => "RSS2 Gallery").first + I18n.locale = current_locale + if category.nil? + module_app = ModuleApp.find_by_key("gallery") + category = Category.new + category.title_translations = {"en" => "RSS2 Gallery", "zh_tw" => "RSS2畫廊"} + category.save + module_app.categories << category + end + albums.each do |album| + @@import_stats["current_album_id"] = album["albumid"] + if Album.where(:rss2_id => album["albumid"]).count == 0 + @@import_stats["current_album_name"] = album["name"]["zh_tw"] + newalbum = Album.new(:name_translations => {"en" => album["name"]["en"], "zh_tw" => album["name"]["zh_tw"]}, :description_translations => {"en" => album["description"]["en"], "zh_tw" => album["description"]["zh_tw"]},"rss2_id" => album["albumid"]) + newalbum.category_id = category.id + newalbum.save + images = album["images"] + if !images.blank? + images.each do |image| + if AlbumImage.where(:rss2_id => image["photoid"]).count == 0 + img = newalbum.album_images.new + img.description_translations = {"en" => image["description"]["en"], "zh_tw" => image["description"]["zh_tw"]} + img.remote_file_url = image["image"] + img.save + end + @@import_stats["current_status"] = @@import_stats["current_status"] + 1 + end + end + end + end end + @@thread.abort_on_exception = true + render :json => {"success" => true}.to_json end private diff --git a/app/templates/orbit_bootstrap/home/pagination.html.erb b/app/templates/orbit_bootstrap/home/pagination.html.erb index 7a5e994..96c2b2f 100644 --- a/app/templates/orbit_bootstrap/home/pagination.html.erb +++ b/app/templates/orbit_bootstrap/home/pagination.html.erb @@ -1,7 +1,3 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/app/views/admin/import/index.html.erb b/app/views/admin/import/index.html.erb index e91cfc3..c96d3af 100644 --- a/app/views/admin/import/index.html.erb +++ b/app/views/admin/import/index.html.erb @@ -9,7 +9,7 @@ margin-bottom: 10px; } #import-container{ - width: 600px; + width: auto; margin: 0 auto; } #loading{ @@ -32,6 +32,8 @@ } #site-url-wrapper{ height: 100px; + width: 600px; + margin: 0 auto; } #import-modules{ margin-top: 30px; @@ -63,6 +65,8 @@ font-size: 12px; } .alert{ + width: 500px; + margin: 0 auto; } .module-icon{ font-size: 64px; @@ -133,6 +137,13 @@ <%= t("page_content.page") %> + +