From 1159375de791d7a28de6b81e448d3beb91559d9c Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Thu, 26 Sep 2013 18:49:27 +0800 Subject: [PATCH] Updated Import to Sync Data for all personal plugins --- .../admin/import_data_controller.rb | 180 ++++++++++++++++++ .../admin/import_data/sync_book_data.html.erb | 1 + .../import_data/sync_conference_data.html.erb | 1 + .../sync_journal_paper_data.html.erb | 1 + config/routes.rb | 3 + .../personal_book/plugin/_profile.html.erb | 2 + .../plugin/_profile.html.erb | 2 + .../personal_journal/plugin/_profile.html.erb | 2 + 8 files changed, 192 insertions(+) create mode 100644 app/views/admin/import_data/sync_book_data.html.erb create mode 100644 app/views/admin/import_data/sync_conference_data.html.erb create mode 100644 app/views/admin/import_data/sync_journal_paper_data.html.erb diff --git a/app/controllers/admin/import_data_controller.rb b/app/controllers/admin/import_data_controller.rb index 1f86544df..a66ab342a 100644 --- a/app/controllers/admin/import_data_controller.rb +++ b/app/controllers/admin/import_data_controller.rb @@ -258,6 +258,186 @@ class Admin::ImportDataController < OrbitBackendController end end + def sync_conference_data + @conference_data = WritingConference.where(create_user_id: "#{params[:user_id]}") + @conference_data.delete_all + @user = User.find("#{params[:user_id]}") + + # teachers.each do |hash| + if @user.sid.present? + ntu_seq = @user.sid + conference_xml = Nokogiri::XML( \ + open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=C")) + #open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml")) + @conference_papers = conference_xml.xpath("//Paper").map do |cp_node| + { + author: (cp_node>"Authors").text, + year: (cp_node>"PublishYear").text, + title: (cp_node>"PaperTitle").text, + conference: (cp_node>"PublishOn").text, + date: Date::MONTHNAMES[(cp_node>"PublishMonth").text.to_i], + location: "#{(cp_node>"Country").text} #{(cp_node>"location").text}", + conference_title: (cp_node>"PublishOn").text, + remarks: (cp_node>"Remarks").text + } + end + if @conference_papers.present? + @conference_papers.each do |b| + @conference_paper = WritingConference.new + I18n.locale = :zh_tw + @conference_paper.authors = b[:author] + if b[:title].blank? + @conference_paper.paper_title = "No Title Present" + else + @conference_paper.paper_title = b[:title] + end + if b[:conference_title].blank? + @conference_paper.conference_title = "No Title Present" + else + @conference_paper.conference_title = b[:conference_title] + end + + @conference_paper.note = b[:remarks] + I18n.locale = :en + @conference_paper.authors = b[:author] + if b[:title].blank? + @conference_paper.paper_title = "No Title Present" + else + @conference_paper.paper_title = b[:title] + end + if b[:conference_title].blank? + @conference_paper.conference_title = "No Title Present" + else + @conference_paper.conference_title = b[:conference_title] + end + @conference_paper.note = b[:remarks] + + @conference_paper.location = b[:location] + @conference_paper.year = b[:year] + @conference_paper.create_user_id = @user.id + + @conference_paper.save! + end + else + puts "No conference by Teacher" + end + end + end + + + def sync_journal_paper_data + @journal_data = WritingJournal.where(create_user_id: "#{params[:user_id]}") + @journal_data.delete_all + @user = User.find("#{params[:user_id]}") + + # teachers.each do |hash| + if @user.sid.present? + ntu_seq = @user.sid + paper_xml = Nokogiri::XML( \ + #open("http://versatile.management.ntu.edu.tw/publication1/journal/#{ntuseq}.xml")) + open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=J")) + @journal_papers = paper_xml.xpath("//Paper").map do |paper_node| + { + author: (paper_node>"Authors").text, + year: (paper_node>"PublishYear").text, + title: (paper_node>"PaperTitle").text, + journal: (paper_node>"PublishOn").text, + volume:(paper_node>"Volume").text, + volumeno:(paper_node>"VolumeNo").text, + beginpage:(paper_node>"BeginPage").text, + endpage:(paper_node>"EndPage").text, + subgroup:(paper_node>"subgroup").text, + remarks: (paper_node>"Remarks").text, + cate: ((paper_node>"subgroup")>"Group").text + } + end + if @journal_papers.present? + @journal_papers.each do |b| + @journal_paper = WritingJournal.new + I18n.locale = :zh_tw + @journal_paper.authors = b[:author] + if b[:title].blank? + @journal_paper.paper_title = "No Title Present" + else + @journal_paper.paper_title = b[:title] + end + @journal_paper.journal_title = b[:journal] + @journal_paper.note = b[:remarks] + I18n.locale = :en + @journal_paper.authors = b[:author] + if b[:title].blank? + @journal_paper.paper_title = "No Title Present" + else + @journal_paper.paper_title = b[:title] + end + @journal_paper.journal_title = b[:journal] + @journal_paper.note = b[:remarks] + @journal_paper.year = b[:year] + @journal_paper.vol_no = b[:volumeno] + @journal_paper.form_to_start = b[:beginpage] + @journal_paper.form_to_end = b[:endpage] + if !b[:cate].blank? + @level_type = JournalLevelType.where(:key => b[:cate]) + if @level_type.present? + @journal_paper.journal_level_type_ids = ["#{@level_type.first.id}"] + end + end + + @journal_paper.create_user_id = @user.id + @journal_paper.save! + end + else + puts "No journal paper by Teacher" + end + end + end + +def sync_book_data + @books_data = WritingBook.where(create_user_id: "#{params[:user_id]}") + @books_data.delete_all + @user = User.find("#{params[:user_id]}") + + # teachers.each do |hash| + if @user.sid.present? + ntu_seq = @user.sid + books_xml = Nokogiri::XML( \ + open("http://ann.cc.ntu.edu.tw/Achv/xmlBook.asp?Seq=#{ntu_seq}")) + @books = books_xml.xpath("//Book").map do |book_node| + { + author: (book_node>"Authors").text, + year: (book_node>"PublishYear").text, + title: (book_node>"DocTitle").text, + remarks: (book_node>"Remarks").text, + publisher: (book_node>"Publisher").text, + book_title: (book_node>"BookTitle").text + } + end + if @books.present? + @books.each do |b| + @book = WritingBook.new + I18n.locale = :zh_tw + @book.authors = b[:author] + @book.paper_title = b[:title] + @book.book_title = b[:book_title] + @book.note = b[:remarks] + @book.publisher = b[:publisher] + I18n.locale = :en + @book.authors = b[:author] + @book.paper_title = b[:title] + @book.book_title = b[:book_title] + @book.note = b[:remarks] + @book.publisher = b[:publisher] + @book.year = b[:year] + @book.create_user_id = @user.id + @book.save + end + else + puts "No books by Teacher" + end + end + end + + def get_announcement_data uri = URI("https://localhost:8000/announcements.xml") diff --git a/app/views/admin/import_data/sync_book_data.html.erb b/app/views/admin/import_data/sync_book_data.html.erb new file mode 100644 index 000000000..1f99d5169 --- /dev/null +++ b/app/views/admin/import_data/sync_book_data.html.erb @@ -0,0 +1 @@ +

Book Data Synced Successfully!

\ No newline at end of file diff --git a/app/views/admin/import_data/sync_conference_data.html.erb b/app/views/admin/import_data/sync_conference_data.html.erb new file mode 100644 index 000000000..f99d6138b --- /dev/null +++ b/app/views/admin/import_data/sync_conference_data.html.erb @@ -0,0 +1 @@ +

Conference Paper Data Synced Successfully!

\ No newline at end of file diff --git a/app/views/admin/import_data/sync_journal_paper_data.html.erb b/app/views/admin/import_data/sync_journal_paper_data.html.erb new file mode 100644 index 000000000..3671a456a --- /dev/null +++ b/app/views/admin/import_data/sync_journal_paper_data.html.erb @@ -0,0 +1 @@ +

Journal Paper Data Synced Successfully!

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b43d8a2af..c244fb26e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -207,6 +207,9 @@ Orbit::Application.routes.draw do get "import_data/get_journal_paper_data" get "import_data/get_announcement_data" get "import_data/get_page_data" + get "import_data/sync_book_data" + get "import_data/sync_journal_paper_data" + get "import_data/sync_conference_data" resources :tags do diff --git a/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb b/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb index d9df9f31e..a2d9fc6c0 100644 --- a/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_book/app/views/panel/personal_book/plugin/_profile.html.erb @@ -75,6 +75,8 @@ <% if is_admin? %>
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('personal_plugins.sync_data'), admin_import_data_sync_book_data_path(:user_id => @user.id), :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('personal_plugins.edit_brief_intro'), panel_personal_book_back_end_personal_book_intros_path(:user_id => @user.id), :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('announcement.add_new'), new_panel_personal_book_back_end_writing_book_path(:user_id => @user.id), :class => 'btn btn-primary' %>
diff --git a/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb b/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb index 081a3c581..5b486d236 100644 --- a/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/plugin/_profile.html.erb @@ -75,6 +75,8 @@ <% if is_admin? %>
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('personal_plugins.sync_data'), admin_import_data_sync_conference_data_path(:user_id => @user.id), :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('personal_plugins.edit_brief_intro'), panel_personal_conference_back_end_personal_conference_intros_path(:user_id => @user.id), :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('announcement.add_new'), new_panel_personal_conference_back_end_writing_conference_path(:user_id => @user.id), :class => 'btn btn-primary' %>
diff --git a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb index 124439f28..f4a6c9d68 100644 --- a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb +++ b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/plugin/_profile.html.erb @@ -80,6 +80,8 @@ <% if is_admin? %>
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('personal_plugins.sync_data'), admin_import_data_sync_journal_paper_data_path(:user_id => @user.id), :class => 'btn btn-primary' %> + <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('personal_plugins.edit_brief_intro'), panel_personal_journal_back_end_personal_journal_intros_path(:user_id => @user.id), :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus') + t('announcement.add_new'), new_panel_personal_journal_back_end_writing_journal_path(:user_id => @user.id), :class => 'btn btn-primary' %>