Added method for importing page data

This commit is contained in:
saurabhbhatia 2013-09-13 14:09:58 +08:00
parent f16d1908be
commit 249644e72c
4 changed files with 70 additions and 1 deletions

View File

@ -4,6 +4,8 @@ require 'net/http'
require 'open-uri' require 'open-uri'
class Admin::ImportDataController < OrbitBackendController class Admin::ImportDataController < OrbitBackendController
helper Admin::PagePartsHelper
include Admin::FrontendWidgetInterface
def get_teacher_data def get_teacher_data
uri = URI("https://tp.rulingcom.com:33333/teachers.xml") uri = URI("https://tp.rulingcom.com:33333/teachers.xml")
@ -238,5 +240,69 @@ class Admin::ImportDataController < OrbitBackendController
@bulletin.save! @bulletin.save!
end end
end end
def get_page_data
f = File.open("/home/rwub/orbit-db/ntu_mb/pages/management_pages.xml")
page_xml = Nokogiri::XML(f)
#open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
@pages = page_xml.xpath("//management-page").map do |cp_node|
{
menu_title: (cp_node>"menu-title").text,
content: (cp_node>"content").text
}
end
if @pages.present?
@pages.each do |b|
get_variables_for_new
@page = Page.new
@page.parent = "4f45f3b9e9d02c5db900005d"
@page.design = "50ac424983e75219d2000021"
@page.theme_id = "50ac424a83e75219d2000025"
@page.menu_enabled_for= ["en", "zh_tw", ""]
@page.enabled_for= ["en", "zh_tw", ""]
@page.is_published = false
if b[:menu_title].blank?
@page.title = "No Title Present"
@page.name = "No Name Present"
else
@page.title = b[:menu_title]
@page.name = b[:menu_title]
end
if b[:content].blank?
@page.content = "No Content Present"
else
@page.content = b[:content]
end
@page.save
end
else
puts "No Page Data"
end
end
def get_variables_for_new
@designs = Design.all.entries
@themes = Design.first.themes
@module_apps = ModuleApp.for_frontend_select
@app_frontend_urls = nil
@categories = nil
@tags = nil
@page_frontend_data_counts = nil
@frontend_styles = nil
@selected={
:design => @designs.first,
:theme=> @themes.first,
:module_app=>nil,#@module_apps.first
:app_frontend_url=> nil, #@module_apps.first
:category=>nil,
:tag=>nil,
:page_frontend_data_count=>nil,
:frontend_style => nil
}
end
end end

View File

@ -95,7 +95,7 @@ class Admin::PagesController < Admin::ItemsController
if @item.module_app && @item.module_app.key == 'page_content' if @item.module_app && @item.module_app.key == 'page_content'
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id ) @item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end end
if @item.save if @item.save
flash.now[:notice] = t('create.success.page') flash.now[:notice] = t('create.success.page')
respond_to do |format| respond_to do |format|

View File

@ -0,0 +1 @@
<p>Successfully Imported Page Data!</p>

View File

@ -206,6 +206,8 @@ Orbit::Application.routes.draw do
get "import_data/get_conference_data" get "import_data/get_conference_data"
get "import_data/get_journal_paper_data" get "import_data/get_journal_paper_data"
get "import_data/get_announcement_data" get "import_data/get_announcement_data"
get "import_data/get_page_data"
resources :tags do resources :tags do
collection do collection do