forked from saurabh/orbit4-5
web_resource import added...
This commit is contained in:
parent
40aa1adbfc
commit
e2dea41af7
|
@ -289,7 +289,17 @@ class Admin::ImportController < OrbitAdminController
|
|||
render :json => {"success" => false, "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]}
|
||||
end
|
||||
end
|
||||
end
|
||||
when "links"
|
||||
if @@thread.alive?
|
||||
render :json => {"success" => true, "current_import" => @@import_stats["current_import"], "total_links" => @@import_stats["total_links"], "current_status" => @@import_stats["current_status"], "current_link_id" => @@import_stats["current_link_id"], "current_link_name" => @@import_stats["current_album_name"]}
|
||||
else
|
||||
if @@import_stats["current_status"] == @@import_stats["total_links"]
|
||||
render :json => {"success" => true, "current_import" => @@import_stats["current_import"], "total_links" => @@import_stats["total_links"], "current_status" => @@import_stats["current_status"], "current_link_id" => @@import_stats["current_link_id"], "current_link_name" => @@import_stats["current_link_name"]}
|
||||
else
|
||||
render :json => {"success" => false, "current_link_id" => @@import_stats["current_link_id"], "current_link_name" => @@import_stats["current_link_name"]}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rss2_galleries
|
||||
|
@ -340,6 +350,50 @@ class Admin::ImportController < OrbitAdminController
|
|||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
def rss2_links
|
||||
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_links"] = data["total_links"].to_i
|
||||
@@import_stats["current_import"] = "categories"
|
||||
@@import_stats["current_status"] = 0
|
||||
categories = data["categories"]
|
||||
current_locale = I18n.locale
|
||||
I18n.locale = :zh_tw
|
||||
module_app = ModuleApp.find_by_key("web_resource")
|
||||
categories.each do |category|
|
||||
cat = Category.where(:title => category[1]["zh_tw"], :module_app_id => module_app.id).first
|
||||
if cat.nil?
|
||||
cat = Category.new
|
||||
cat.title_translations = {"en" => category[1]["en"], "zh_tw" => category[1]["zh_tw"]}
|
||||
cat.save
|
||||
module_app.categories << cat
|
||||
end
|
||||
end
|
||||
@@import_stats["current_import"] = "links"
|
||||
links = data["links"]
|
||||
links.each do |link|
|
||||
l = WebLink.where(:rss2_id => link["link_id"]).first
|
||||
if l.nil?
|
||||
@@import_stats["current_link_id"] = link["link_id"]
|
||||
@@import_stats["current_link_name"] = link["title"]["zh_tw"]
|
||||
weblink = WebLink.new(:title_translations => {"en" => link["title"]["en"], "zh_tw" => link["title"]["zh_tw"]}, :context_translations => {:en => link["description"]["en"], :zh_tw => link["description"]["zh_tw"]}, :url_translations => {"en" => link["url"], "zh_tw" => link["url"]}, :rss2_id => link["link_id"])
|
||||
category = Category.where(:title => link["category_name"], :module_app_id => module_app).first
|
||||
weblink.category_id = category.id
|
||||
weblink.save
|
||||
end
|
||||
@@import_stats["current_status"] = @@import_stats["current_status"] + 1
|
||||
end
|
||||
I18n.locale = current_locale
|
||||
end
|
||||
@@thread.abort_on_exception = true
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def page_present?(page)
|
||||
|
|
|
@ -144,6 +144,13 @@
|
|||
<%= t("gallery.gallery") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="links-module" class="module" onclick="importModule('links')">
|
||||
<div class="lead muted">
|
||||
<i class="icons-link"></i><br/>
|
||||
<%= t("web_link.web_link") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="import-progress" class="hide">
|
||||
|
@ -187,6 +194,9 @@
|
|||
case "gallery":
|
||||
importGallery();
|
||||
break;
|
||||
case "links":
|
||||
importLinks();
|
||||
break;
|
||||
default:
|
||||
getModuleCategories();
|
||||
}
|
||||
|
@ -211,6 +221,19 @@
|
|||
})
|
||||
}
|
||||
|
||||
var importLinks = function(){
|
||||
$("#import-progress .bar").css('width','0%');
|
||||
$("#import-progress-text").html("Importing Links...<br/>");
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url: '<%= admin_import_rss2_links_path %>',
|
||||
data : {"url" : url+'?module='+module}
|
||||
}).done(function(){
|
||||
startCheckinglinksImportStatus();
|
||||
})
|
||||
}
|
||||
|
||||
var importGallery = function(){
|
||||
$("#import-progress .bar").css('width','0%');
|
||||
$("#import-progress-text").html("Importing Galleries...<br/>");
|
||||
|
@ -224,6 +247,40 @@
|
|||
})
|
||||
}
|
||||
|
||||
var startCheckinglinksImportStatus = function(){
|
||||
$.ajax({
|
||||
type : "get",
|
||||
dataType : "json",
|
||||
data : {"module" : module},
|
||||
url : "<%= admin_import_get_import_status_path %>"
|
||||
}).done(function(status){
|
||||
if(status.success == true){
|
||||
if(status.current_import == "categories"){
|
||||
$("#import-progress-text").html("Importing categories <br/>");
|
||||
setTimeout("startCheckinglinksImportStatus()",700);
|
||||
}else{
|
||||
if(status.total_links != null){
|
||||
var percent = (status.current_status * 100) / status.total_links;
|
||||
$("#import-progress .bar").css('width',percent + "%");
|
||||
$("#import-progress-text").html("Importing links " + status.current_link_name + " .. " + status.current_status + "/" + status.total_links + "<br/>");
|
||||
}
|
||||
if(status.total_links != status.current_status){
|
||||
setTimeout("startCheckinglinksImportStatus()",700);
|
||||
}else{
|
||||
if(status.total_links == null){
|
||||
setTimeout("startCheckinglinksImportStatus()",700);
|
||||
}
|
||||
$("#import-progress-text").html("Finished importing links.<br/>");
|
||||
}
|
||||
}
|
||||
}else if(status.success == false){
|
||||
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
||||
$("#alert-msg").text("Error importing link " + status.current_link_name + " ID : " + status.current_link_id)
|
||||
$(".alert-danger").removeClass("hide").show();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var startCheckingImportStatus = function(){
|
||||
$.ajax({
|
||||
type : "get",
|
||||
|
|
|
@ -208,6 +208,7 @@ Orbit::Application.routes.draw do
|
|||
post "import/rss2_pages" => "import#rss2_pages"
|
||||
get "import/get_import_status" => "import#get_import_status"
|
||||
post "import/rss2_galleries" => "import#rss2_galleries"
|
||||
post "import/rss2_links" => "import#rss2_links"
|
||||
end
|
||||
|
||||
get 'mobile', to: 'pages#home'
|
||||
|
|
Loading…
Reference in New Issue