diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index 3073be8..fa41c6d 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -2,20 +2,70 @@ require 'rubyXL' class Admin::JournalPapersController < OrbitMemberController include Admin::JournalPapersHelper layout "member_plugin" - before_action :set_journal_paper, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] before_action :need_access_right before_action :allow_admin_only, :only => [:index, :setting] - + def merge_process + params['journal_id'].each do |journal_id| + journal_ids = journal_id.split('/') + journals = JournalPaper.find(journal_ids) + member_ids = journals.collect(&:member_profile_id).uniq + journals.each_with_index do |journal,index1| + if index1== 0 + journal.member_profile_id = member_ids + journal.save! + else + journal.delete + end + end + end + redirect_to :action=> 'index' + end + def merge + @journals=JournalPaper.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:paper_title],v[:journal_title]]} + @journals.each do |key,value| + if value.length<=1 + @journals.delete key + end + end + #journals = JournalPaper.order_by(:year=>'desc').map{|value| value} + #journals_name1 = journals.map{|value| value[:paper_title]} + #journals_name2 = journals.map{|value| value[:journal_title]} + #compare1 = journals_name1.map{|v1| journals_name1.select{|v2| v2==v1}.count>1} + #compare2 = journals_name2.map{|v1| journals_name2.select{|v2| v2==v1}.count>1} + #compare = compare1 and compare2 + #@journal = Hash.new + #compare.each_with_index do |b,i| + # if b && !(@journal.keys.include? [journals_name1[i],journals_name2[i]]) + # @journal[[journals_name1[i],journals_name2[i]]] = [journals[i]] + # elsif b + # @journal[[journals_name1[i],journals_name2[i]]] << journals[i] + # end + #end + if params['mode']!='simple' + @journals.each do |key,value| + @journals[key] = value.group_by{|v| [get_level_type(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]} + @journals[key].each do |key1,value1| + if value1.length<=1 + @journals[key].delete key1 + end + end + if @journals[key].length==0 + @journals.delete key + end + end + + end + end def index @writing_journals = JournalPaper.order_by(:year=>'desc').page(params[:page]).per(10) end def new - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @member = Array(MemberProfile.find_by(:uid=>params['uid'])) rescue nil @journal_paper = JournalPaper.new if params[:desktop] @@ -64,17 +114,17 @@ class Admin::JournalPapersController < OrbitMemberController elsif !params[:author_members].blank? - params[:author_members].each do |author_member| + #params[:author_members].each do |author_member| - journal_paper_params['member_profile_id'] = author_member + journal_paper_params['member_profile_id'] = params[:author_members] @journal_paper = JournalPaper.new(journal_paper_params) @journal_paper.save - + if params[:desktop] == "true" render json: {"data" => get_paper_list}.to_json end - end + #end redirect_to params['referer_url'] @@ -96,14 +146,15 @@ class Admin::JournalPapersController < OrbitMemberController end def edit - @member = @journal_paper.member_profile + @member = get_member(@journal_paper) if params[:desktop] render :layout => false end end def update - @member = @journal_paper.member_profile + @member = get_member(@journal_paper) + journal_paper_params['member_profile_id'] = params[:author_members] @journal_paper.update_attributes(journal_paper_params) @journal_paper.save if params[:desktop] == "true" @@ -192,7 +243,6 @@ class Admin::JournalPapersController < OrbitMemberController end private - def set_journal_paper path = request.path.split('/') if path.last.include? '-' diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 8b3c826..4d156af 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -1,4 +1,5 @@ class PersonalJournalsController < ApplicationController + include Admin::JournalPapersHelper def index params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count @@ -42,6 +43,8 @@ class PersonalJournalsController < ApplicationController journal_papers_show = journal_papers_temp.select { |value| search_all_words((value.journal_paper_type.title rescue ''), params[:keywords]) } when 'language' journal_papers_show = journal_papers_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } + when 'authors' + journal_papers_show = journal_papers_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) } else journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } end @@ -72,6 +75,10 @@ class PersonalJournalsController < ApplicationController t << { 'value' => (journal_paper.journal_paper_type.title rescue '') } when 'language' t << { 'value' => (!journal_paper.language.nil? ? t(journal_paper.language.to_s) : '') } + when 'url' + t << { 'value' => journal_paper.url.to_s.blank? ? "" : "#{journal_paper.url}"} + when 'authors' + t << { 'value' => get_authors_show(journal_paper) } else t << { 'value' => (journal_paper.send(fs) rescue '') } end diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index a5abbbb..f5fa870 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -1,4 +1,25 @@ module Admin::JournalPapersHelper + def get_authors_text(journal) + (journal.authors.to_s.blank? ? get_member(journal).collect(&:name).join('/') : Nokogiri::HTML(journal.authors.to_s).text rescue "") + end + def get_authors_show(journal) + (journal.authors.to_s.blank? ? get_member(journal).collect{|member| "#{member.name}"}.join('/') : (journal.authors.to_s) rescue "") + end + def get_member(journal) + Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) + end + def get_level_type(journal) + !journal.journal_levels.blank? ? "(#{journal.journal_levels.collect(&:title).join(', ')})" : nil + end + def get_author_type(journal) + journal.journal_paper_author_types.collect(&:title).join(', ') rescue '' + end + def get_paper_type(journal) + journal.journal_paper_type.title rescue '' + end + def get_publication_date(journal) + journal.publication_date.strftime('%Y/%m/%d') rescue '' + end def page_for_journal_paper(journal_paper_object) journal_paper_page = nil pages = Page.where(:module=>"journal_paper") diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index 8ff8da1..9f82cf3 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -2,7 +2,7 @@ class JournalPaper include Mongoid::Document include Mongoid::Timestamps include Mongoid::Attributes::Dynamic - + include Admin::JournalPapersHelper include OrbitModel::Status include MemberHelper include Slug @@ -215,6 +215,11 @@ class JournalPaper files << (url.nil? ? "" : "