diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb index 43303e8..63b1a7f 100644 --- a/app/controllers/admin/books_controller.rb +++ b/app/controllers/admin/books_controller.rb @@ -8,6 +8,44 @@ class Admin::BooksController < OrbitMemberController before_action :need_access_right before_action :allow_admin_only, :only => [:index, :setting] + def merge_process + params['book_id'].each do |book_id| + book_ids = book_id.split('/') + books = Book.find(book_ids) + member_ids = books.collect(&:member_profile_id).uniq + books.each_with_index do |book,index1| + if index1== 0 + book.member_profile_id = member_ids + book.save! + else + book.delete + end + end + end + redirect_to :action=> 'index' + end + def merge + @books=Book.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:book_title],v[:isbn]]} + @books.each do |key,value| + if value.length<=1 + @books.delete key + end + end + if params['mode']!='simple' + @books.each do |key,value| + @books[key] = value.group_by{|v| [get_publisher(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]} + @books[key].each do |key1,value1| + if value1.length<=1 + @books[key].delete key1 + end + end + if @books[key].length==0 + @books.delete key + end + end + + end + end def index @writing_books = Book.order_by(:year=>'desc').page(params[:page]).per(10) @@ -49,14 +87,15 @@ class Admin::BooksController < OrbitMemberController end def edit - @member = @book.member_profile + @member = get_member(@book) if params[:desktop] render :layout => false end end def update - @member = @book.member_profile + @member = get_member(@book) + book_params['member_profile_id'] = params[:author_members] @book.update_attributes(book_params) @book.save if params[:desktop] == "true" @@ -68,7 +107,7 @@ class Admin::BooksController < OrbitMemberController def new @book = Book.new - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @member = Array(MemberProfile.find_by(:uid=>params['uid'])) rescue nil if params[:desktop] render :layout => false end @@ -90,9 +129,9 @@ class Admin::BooksController < OrbitMemberController elsif !params[:author_members].blank? - params[:author_members].each do |author_member| + #params[:author_members].each do |author_member| - book_params['member_profile_id'] = author_member + book_params['member_profile_id'] = params[:author_members] @book = Book.new(book_params) @book.save @@ -100,7 +139,7 @@ class Admin::BooksController < OrbitMemberController render json: {"data" => get_paper_list}.to_json end - end + #end redirect_to params['referer_url'] diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb index 11964ee..218d03a 100644 --- a/app/controllers/personal_books_controller.rb +++ b/app/controllers/personal_books_controller.rb @@ -1,4 +1,5 @@ class PersonalBooksController < ApplicationController + include Admin::PersonalBooksHelper def index params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count @@ -45,6 +46,10 @@ class PersonalBooksController < ApplicationController books_show = books_temp.select { |value| search_all_words((value.book_type.title rescue ''), params[:keywords]) } when 'language' books_show = books_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } + when 'authors' + books_show = books_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) } + when 'note' + books_show = books_temp.select { |value| search_all_words(Nokogiri::HTML(value.note).text, params[:keywords]) } else books_show = books_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } end @@ -73,6 +78,10 @@ class PersonalBooksController < ApplicationController t << { 'value' => (!book.language.nil? ? t(book.language.to_s) : '') } when 'book_paper_type' t << { 'value' => (book.book_type.title rescue '') } + when 'url' + t << { 'value' => book.url.to_s.blank? ? "" : "#{book.url}"} + when 'authors' + t << { 'value' => get_authors_show(book) } else t << { 'value' => (book.send(fs) rescue '') } end @@ -135,6 +144,7 @@ class PersonalBooksController < ApplicationController file publication_date language + note ] { 'plugin_datas' => plugin.get_plugin_data(fields_to_show) } @@ -158,6 +168,7 @@ class PersonalBooksController < ApplicationController url publication_date language + note ] @fields_to_show = @fields_to_show.map { |fs| [t("personal_book.#{fs}"), fs] } @default_fields_to_show = %w[ diff --git a/app/helpers/admin/personal_books_helper.rb b/app/helpers/admin/personal_books_helper.rb index c51cc41..87e6daa 100644 --- a/app/helpers/admin/personal_books_helper.rb +++ b/app/helpers/admin/personal_books_helper.rb @@ -1,5 +1,25 @@ module Admin::PersonalBooksHelper - + def get_authors_text(book) + (book.authors.to_s.blank? ? get_member(book).collect(&:name).join('/') : Nokogiri::HTML(book.authors.to_s).text rescue '') + end + def get_authors_show(book) + (book.authors.to_s.blank? ? get_member(book).collect{|member| "#{member.name}"}.join('/') : book.authors.to_s rescue '') + end + def get_member(book) + Array(MemberProfile.find(Array(book).collect(&:member_profile_id))) + end + def get_publisher(book) + book.publisher + end + def get_author_type(book) + book.book_author_types.collect(&:title).join(', ') rescue '' + end + def get_paper_type(book) + !book.book_type.blank? ? book.book_type.title : nil + end + def get_publication_date(book) + book.publication_date.strftime('%Y/%m/%d') rescue '' + end def get_paper_list user = current_user.nil? ? OrbitHelper.current_user : current_user user_profile = user.member_profile diff --git a/app/models/book.rb b/app/models/book.rb index b871f30..03b559c 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -2,7 +2,7 @@ class Book include Mongoid::Document include Mongoid::Timestamps include Mongoid::Attributes::Dynamic - + include Admin::PersonalBooksHelper include OrbitModel::Status include MemberHelper include Slug @@ -175,6 +175,10 @@ class Book files << (url.nil? ? "" : "
  • #{title}
  • ") end value = files.join("") + when "url" + value = self.url.to_s.blank? ? "" : "#{self.url}" + when "authors" + value = get_authors_show(self) else value = self.send(field) rescue "" end diff --git a/app/views/admin/books/_form.html.erb b/app/views/admin/books/_form.html.erb index 4ec80b8..9b10d38 100644 --- a/app/views/admin/books/_form.html.erb +++ b/app/views/admin/books/_form.html.erb @@ -87,7 +87,7 @@
    <%= f.fields_for :authors_translations do |f| %> - <%= f.text_area locale, class: "input-block-level", placeholder: t("personal_book.authors"), value: (@book.authors_translations[locale] rescue nil) %> + <%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t("personal_book.authors"), value: (@book.authors_translations[locale] rescue nil) %> <% end %>
    @@ -141,26 +141,17 @@
    - <% if !@member.nil? %> -
    - <%= @member.name rescue ''%> - <%= f.hidden_field :member_profile_id, :value => @member.id %> -
    -
    - - <% else %> - -
    - -
    - <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %> + <% if !@member.nil? %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:@member} %> + <% else %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %> + <% end %>
    - <% end %>
    @@ -263,7 +254,7 @@
    - <%= f.text_area :note, rows: 2, class: "input-block-level" %> + <%= f.text_area :note, rows: 2, class: "ckeditor input-block-level" %>
    diff --git a/app/views/admin/books/_writing_book.html.erb b/app/views/admin/books/_writing_book.html.erb index 53140f2..47dcd36 100644 --- a/app/views/admin/books/_writing_book.html.erb +++ b/app/views/admin/books/_writing_book.html.erb @@ -2,7 +2,7 @@ <%= writing_book.year %> - <%= link_to writing_book.create_link, OrbitHelper.url_to_plugin_show(writing_book.to_param,'personal_book'), target: "blank" %> + <%= link_to Nokogiri::HTML(writing_book.create_link).text, OrbitHelper.url_to_plugin_show(writing_book.to_param,'personal_book'), target: "blank" %>