forked from saurabh/orbit4-5
Import Archive from RSS2 and basic Import UI
This commit is contained in:
parent
0f58f39eb5
commit
b1fe5264ce
|
@ -4,28 +4,15 @@ require "uri"
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
class Admin::ImportController < OrbitAdminController
|
class Admin::ImportController < OrbitAdminController
|
||||||
|
before_action :get_data ,:except=>'index'
|
||||||
|
|
||||||
def rss2_news
|
def rss2_news
|
||||||
@url = params['url']
|
|
||||||
uri = URI.parse(@url)
|
|
||||||
@host = uri.host
|
|
||||||
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)
|
|
||||||
@categories = data['categories']
|
|
||||||
@data = data['data']
|
|
||||||
@xxx = []
|
|
||||||
@new_category_ids = {}
|
@new_category_ids = {}
|
||||||
l = I18n.locale
|
|
||||||
I18n.locale = :zh_tw
|
|
||||||
module_id = ModuleApp.where(:key=>"announcement").first.id
|
module_id = ModuleApp.where(:key=>"announcement").first.id
|
||||||
|
|
||||||
@categories.each do |category|
|
@categories.each do |category|
|
||||||
x = Category.where(:title => category["zh_tw"]).first
|
x = Category.where(:title => category["zh_tw"]).first
|
||||||
if x.nil?
|
if x.nil?
|
||||||
@xxx << category
|
|
||||||
cat = Category.new
|
cat = Category.new
|
||||||
titles = {}
|
titles = {}
|
||||||
@site_valid_locales.each do |locale|
|
@site_valid_locales.each do |locale|
|
||||||
|
@ -40,8 +27,6 @@ class Admin::ImportController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@user = User.where(:user_name => "rulingcom").first
|
|
||||||
|
|
||||||
@data.each do |row|
|
@data.each do |row|
|
||||||
bulletin = Bulletin.new
|
bulletin = Bulletin.new
|
||||||
bulletin.update_user = @user
|
bulletin.update_user = @user
|
||||||
|
@ -118,8 +103,87 @@ class Admin::ImportController < OrbitAdminController
|
||||||
bulletin.save!
|
bulletin.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
I18n.locale = l
|
I18n.locale = @org_locale
|
||||||
|
|
||||||
redirect_to('/admin/announcements')
|
redirect_to('/admin/announcements')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rss2_archive
|
||||||
|
unless @site_url.nil?
|
||||||
|
module_app = ModuleApp.where(:key=>"archive").first
|
||||||
|
|
||||||
|
@new_categories = {}
|
||||||
|
@categories.each do |id, category|
|
||||||
|
old_cate = Category.where(:title => category['title']["zh-tw"]).first
|
||||||
|
if old_cate.nil?
|
||||||
|
cate = Category.new
|
||||||
|
titles = {}
|
||||||
|
@site_valid_locales.each do |locale|
|
||||||
|
titles[locale] = category['title'][locale.to_s.gsub('_', '-')]
|
||||||
|
end
|
||||||
|
cate.title_translations = titles
|
||||||
|
cate.save!
|
||||||
|
module_app.categories << cate
|
||||||
|
@new_categories[id] = cate.id
|
||||||
|
else
|
||||||
|
@new_categories[id] = old_cate.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
I18n.locale = :en
|
||||||
|
|
||||||
|
@data.each do |id, file|
|
||||||
|
titles = {}
|
||||||
|
@site_valid_locales.each do |locale|
|
||||||
|
titles[locale] = file['title'][locale.to_s.gsub('_', '-')]
|
||||||
|
end
|
||||||
|
|
||||||
|
the_file = ArchiveFileMultiple.new({
|
||||||
|
:file_title_translations=>titles,
|
||||||
|
:choose_lang => @site_valid_locales,
|
||||||
|
:remote_file_url => @site_url+file['url'],
|
||||||
|
:sort_number=>file['sort_number']
|
||||||
|
})
|
||||||
|
the_file.save
|
||||||
|
|
||||||
|
archive_file = ArchiveFile.new({
|
||||||
|
:title_translations=>titles,
|
||||||
|
:sort_number=>file['sort_number']
|
||||||
|
})
|
||||||
|
archive_file.category = Category.find(@new_categories[file["category"]])
|
||||||
|
|
||||||
|
archive_file.create_user_id = current_user.id
|
||||||
|
archive_file.update_user_id = current_user.id
|
||||||
|
|
||||||
|
archive_file.save
|
||||||
|
archive_file.archive_file_multiples << the_file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
I18n.locale = @org_locale
|
||||||
|
|
||||||
|
redirect_to admin_archive_files_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_data
|
||||||
|
@org_locale = I18n.locale
|
||||||
|
I18n.locale = :zh_tw
|
||||||
|
|
||||||
|
@site_url = params['site_url']
|
||||||
|
@url = params['url']
|
||||||
|
uri = URI.parse(@url)
|
||||||
|
|
||||||
|
@host = uri.host
|
||||||
|
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)
|
||||||
|
|
||||||
|
@categories = data['categories']
|
||||||
|
@data = data['data']
|
||||||
|
|
||||||
|
@user = User.where(:user_name => "rulingcom").first
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,31 @@
|
||||||
|
<style type="text/css">
|
||||||
|
.import_wrapper{
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
.import_wrapper .import-url{
|
||||||
|
width: 500px;
|
||||||
|
}
|
||||||
|
.import_wrapper .btn{
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.lead{
|
||||||
|
border-bottom: 1px solid #DDD;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="import_wrapper">
|
||||||
|
<div class="lead muted"><i class="icons-megaphone"></i><%= t("announcement.announcement") %></div>
|
||||||
|
<form method="post" action="/admin/import/rss2_news">
|
||||||
|
<input type="text" class="import-url" name="url" placeholder="RSS2 Export URL ex: http://rss2.rulingcom.com/DEMO24_ALL/export_news/"><br/>
|
||||||
|
<input type="submit" class="btn btn-primary" value="<%= t(:submit) %>">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="import_wrapper">
|
||||||
|
<div class="lead muted"><i class="icons-archive"></i><%= t("archive.archive") %></div>
|
||||||
|
<form method="post" action="/admin/import/rss2_archive">
|
||||||
|
<input type="text" class="import-url" name="site_url" placeholder="RSS2 Site URL ex: http://rss2.rulingcom.com/DEMO24_ALL"><br/>
|
||||||
|
<input type="text" class="import-url" name="url" placeholder="RSS2 Export URL ex: http://rss2.rulingcom.com/DEMO24_ALL/export_archive/"><br/>
|
||||||
|
<input type="submit" class="btn btn-primary" value="<%= t(:submit) %>">
|
||||||
|
</form>
|
||||||
|
</div>
|
|
@ -1,6 +1,6 @@
|
||||||
gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'
|
gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'
|
||||||
gem 'ad_banner', git: 'git@gitlab.tp.rulingcom.com:saurabh/adbanner-test.git'
|
gem 'ad_banner', git: 'git@gitlab.tp.rulingcom.com:saurabh/adbanner-test.git'
|
||||||
gem "archive", git: 'git@gitlab.tp.rulingcom.com:saurabh/archive.git'
|
gem "archive", path: '/home/manson/dev/workspace/modules/archive'
|
||||||
gem 'gallery', git: 'git@gitlab.tp.rulingcom.com:saurabh/gallery.git'
|
gem 'gallery', git: 'git@gitlab.tp.rulingcom.com:saurabh/gallery.git'
|
||||||
gem 'links', git: 'git@gitlab.tp.rulingcom.com:saurabh/links.git'
|
gem 'links', git: 'git@gitlab.tp.rulingcom.com:saurabh/links.git'
|
||||||
gem 'page_content', git: 'git@gitlab.tp.rulingcom.com:saurabh/pagecontent.git'
|
gem 'page_content', git: 'git@gitlab.tp.rulingcom.com:saurabh/pagecontent.git'
|
||||||
|
|
|
@ -196,7 +196,9 @@ Orbit::Application.routes.draw do
|
||||||
get 'design_list' => 'designs#design_list'
|
get 'design_list' => 'designs#design_list'
|
||||||
get 'module_store' => 'module_store#index'
|
get 'module_store' => 'module_store#index'
|
||||||
|
|
||||||
get "import/rss2_news" => "import#rss2_news"
|
get "import" => "import#index"
|
||||||
|
post "import/rss2_news" => "import#rss2_news"
|
||||||
|
post "import/rss2_archive" => "import#rss2_archive"
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'mobile', to: 'pages#home'
|
get 'mobile', to: 'pages#home'
|
||||||
|
|
Loading…
Reference in New Issue