diff --git a/app/assets/javascripts/admin/book_author_types.js b/app/assets/javascripts/admin/book_author_types.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/book_author_types.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/admin/book_intros.js b/app/assets/javascripts/admin/book_intros.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/book_intros.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/admin/book_types.js b/app/assets/javascripts/admin/book_types.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/book_types.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/admin/books.js b/app/assets/javascripts/admin/books.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/books.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/books.js b/app/assets/javascripts/books.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/books.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admin/book_author_types.css b/app/assets/stylesheets/admin/book_author_types.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/book_author_types.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/admin/book_intros.css b/app/assets/stylesheets/admin/book_intros.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/book_intros.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/admin/book_types.css b/app/assets/stylesheets/admin/book_types.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/book_types.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/admin/books.css b/app/assets/stylesheets/admin/books.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/books.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/books.css b/app/assets/stylesheets/books.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/books.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/admin/book_author_types_controller.rb b/app/controllers/admin/book_author_types_controller.rb new file mode 100644 index 0000000..1135803 --- /dev/null +++ b/app/controllers/admin/book_author_types_controller.rb @@ -0,0 +1,50 @@ +class Admin::BookAuthorTypesController < ApplicationController + before_action :set_book_author_type, only: [:edit, :update, :destroy] + + def initialize + super + @app_type = 'book_author_type' + end + + def new + @book_author_type = BookAuthorType.new + end + + def edit + end + + def create + @book_author_type = BookAuthorType.new(book_author_type_attributes) + + respond_to do |format| + if @book_author_type.save + format.js { render 'create_book_setting' } + end + end + end + + def update + respond_to do |format| + if @book_author_type.update_attributes(book_author_type_attributes) + format.js { render 'update_book_setting' } + end + end + end + + def destroy + @book_author_type.destroy + respond_to do |format| + format.js { render 'delete_book_setting' } + end + end + + private + + def set_book_author_type + @book_author_type = BookAuthorType.find(params[:id]) + end + + def book_author_type_attributes + params.require(:book_author_type).permit! rescue nil + end +end diff --git a/app/controllers/admin/book_intros_controller.rb b/app/controllers/admin/book_intros_controller.rb new file mode 100644 index 0000000..c852824 --- /dev/null +++ b/app/controllers/admin/book_intros_controller.rb @@ -0,0 +1,8 @@ +class Admin::BookIntrosController < Admin::PersonalPluginIntrosController + def initialize + super + @app_type = 'book_intro' + @app_type_name = 'book_paper' + @reback_name = 'Book' + end +end diff --git a/app/controllers/admin/book_types_controller.rb b/app/controllers/admin/book_types_controller.rb new file mode 100644 index 0000000..488dc13 --- /dev/null +++ b/app/controllers/admin/book_types_controller.rb @@ -0,0 +1,50 @@ +class Admin::BookTypesController < ApplicationController + before_action :set_book_type, only: [:edit, :update, :destroy] + + def initialize + super + @app_type = 'book_type' + end + + def new + @book_type = BookType.new + end + + def edit + end + + def create + @book_type = BookType.new(book_type_attributes) + respond_to do |format| + if @book_type.save + format.js { render 'create_book_setting' } + end + end + end + + def update + respond_to do |format| + if @book_type.update_attributes(book_type_attributes) + format.js { render 'update_book_setting' } + end + end + end + + def destroy + @book_type.destroy + respond_to do |format| + format.js { render 'delete_book_setting' } + end + end + + private + + def set_book_type + @book_type = BookType.find(params[:id]) + end + + def book_type_attributes + params.require(:book_type).permit! rescue nil + end + +end diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb new file mode 100644 index 0000000..2e144b8 --- /dev/null +++ b/app/controllers/admin/books_controller.rb @@ -0,0 +1,165 @@ +class Admin::BooksController < OrbitMemberController + include Admin::JournalPapersHelper + + before_action :set_book, only: [:show, :edit , :update, :destroy] + before_action :get_plugins, only: [:index, :book_setting, :new, :create, :edit, :update] + before_action :set_types, only: [:index,:book_setting, :new, :edit, :create, :update] + + def index + @writing_books = Book.all + respond_to do |format| + format.html # index.html.erb + format.js { } + format.xml { render :xml => @books } + end + end + + def show + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @book } + end + end + + def edit + @members_data = Book.member_data rescue nil + end + + def update + @book_authors = @book.book_authors + + respond_to do |format| + if @book.update_attributes(book_attributes) + format.html { redirect_to admin_books_path } + format.xml { head :ok } + else + format.html { render action: "edit" } + format.xml { render :xml => @book.errors, :status => :unprocessable_entity } + end + end + end + + def new + @book = Book.new + @members_data = Book.member_data rescue nil + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @book } + end + end + + def create + @book = Book.new(book_attributes) + respond_to do |format| + if @book.save + format.html { redirect_to admin_books_path } + format.xml { render :xml => @book, :status => :created, :location => @book } + else + format.html { render action: "new" } + format.xml { render :xml => @book.errors, :status => :unprocessable_entity } + end + end + end + + def book_setting + @set_author_type = BookAuthorType.new(display: 'List') + @author_type_url = admin_books_path + + @set_book_type = BookType.new(display: 'List') + @book_type_url = admin_books_path + end + + def destroy + @book.destroy + + respond_to do |format| + format.html { redirect_to(admin_books_url) } + format.js + end + end + + def add_author_type + @set_author_type = BookAuthorType.new(display: 'List') + @author_type_url = admin_book_author_types_path + @set_author_type.id = params[:id] + + respond_to do |format| + format.js + end + end + + def edit_author_type + @set_author_type = BookAuthorType.find(params[:book_id]) + @author_type_url = admin_book_author_type_path(@set_author_type) + + respond_to do |format| + format.js + end + end + + def add_book_type + @set_book_type = BookType.new(display: 'List') + @book_type_url = admin_book_types_path + @set_book_type.id = params[:id] + + respond_to do |format| + format.js + end + end + + def edit_book_type + @set_book_type = BookType.find(params[:book_id]) + @book_type_url = admin_book_type_path(@set_book_type) + + respond_to do |format| + format.js + end + end + + def data_share + if params[:ids] + @books = Book.any_in(_id: params[:ids]) + + @books.each do |book| + book.is_hidden = params[:disable] + book.save + end + end + + respond_to do |format| + format.html { redirect_to(admin_member_path(id: params[:member_profile_id],show_plugin_profile: "Book")) } + format.json { render json: {"success"=>true}.to_json} + end + end + + def delete + end + + private + + def set_book + path = request.path.split('/') + if path.last.include? '-' + uid = path[-1].split("-").last + uid = uid.split("?").first + else + uid = path[-2].split("-").last + uid = uid.split("?").first + end + @book = Book.find_by(uid: uid) + end + + def book_attributes + params.require(:book).permit! rescue nil + end + + def get_plugins + @plugins = OrbitApp::Plugin::Registration.all rescue nil + end + + def set_types + @author_types = BookAuthorType.all + @book_types = BookType.all + end +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..ea843f8 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,43 @@ +class BooksController < ApplicationController + def index + books = Book.asc(:created_at) + book_list = books.collect do |book| + { + "book_title" => book.book_title, + "authors" => book.authors, + "link_to_show" => OrbitHelper.url_to_show(book.to_param) + } + end + { + "books" => book_list, + "extras" => {"widget-title" => "Books"} + } + end + + def show + params = OrbitHelper.params + book = Book.find_by(uid: params[:uid]) + publication_date = book.publication_date.to_date.strftime("%Y/%m/%d") rescue nil + publish_date = book.publish_date.to_date.strftime("%Y/%m/%d") rescue nil + files = book.book_files.map{|file| { "file_url" => file.member_book_file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue [] + { + "book_files" => files, + "data" => { + "title" => book.book_title, + "year" => book.year, + "authors" => book.authors, + "isbn" => book.isbn, + "language" => t(book.language), + "pages" => book.pages, + "keywords" => book.keywords, + "publication_date" => publication_date , + "url" => book.url, + "note" => book.note, + "extracted_chapters" => book.extracted_chapters, + "publish_date" => publish_date, + "publisher" => book.publisher, + "editor" => book.editor + } + } + end +end diff --git a/app/helpers/admin/book_author_types_helper.rb b/app/helpers/admin/book_author_types_helper.rb new file mode 100644 index 0000000..72adcd2 --- /dev/null +++ b/app/helpers/admin/book_author_types_helper.rb @@ -0,0 +1,2 @@ +module Admin::BookAuthorTypesHelper +end diff --git a/app/helpers/admin/book_intros_helper.rb b/app/helpers/admin/book_intros_helper.rb new file mode 100644 index 0000000..31fce53 --- /dev/null +++ b/app/helpers/admin/book_intros_helper.rb @@ -0,0 +1,2 @@ +module Admin::BookIntrosHelper +end diff --git a/app/helpers/admin/book_types_helper.rb b/app/helpers/admin/book_types_helper.rb new file mode 100644 index 0000000..7745eab --- /dev/null +++ b/app/helpers/admin/book_types_helper.rb @@ -0,0 +1,2 @@ +module Admin::BookTypesHelper +end diff --git a/app/helpers/admin/books_helper.rb b/app/helpers/admin/books_helper.rb new file mode 100644 index 0000000..3849308 --- /dev/null +++ b/app/helpers/admin/books_helper.rb @@ -0,0 +1,9 @@ +module Admin::BooksHelper + def page_for_book(book_object) + book_page = nil + page = Page.find_by(:module=>"book") rescue nil + + book_page = page if book_page.nil? + request.protocol+(request.host_with_port+book_page.url+'/'+book_object.to_param).gsub('//','/') rescue "/" + end +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000..4b9311e --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000..6dd04c5 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,94 @@ +class Book + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + + include OrbitModel::Status + include MemberHelper + include Slug + + field :book_title, as: :slug_title, type: String, localize: true + field :extracted_chapters, type: String, localize: true + field :publisher, type: String, localize: true + field :editor, type: String, localize: true + field :year, type: String + field :language, type: String + field :publish_date, type: DateTime + field :pages, type: String + field :isbn, type: String + field :keywords, type: String + field :publication_date, type: DateTime + field :url, type: String + field :note, type: String + + paginates_per 10 + + belongs_to :member_profile + + has_many :book_files, autosave: true, dependent: :destroy + accepts_nested_attributes_for :book_files + + has_and_belongs_to_many :book_authors + accepts_nested_attributes_for :book_authors + + belongs_to :book_type + before_validation :add_http + + after_save :save_book_files, :save_book_authors + + + def create_link + title = [] + title << "#{self.book_authors.collect{|j| j.name}.join(', ')}" if self.book_authors.present? + title << self.book_title if self.book_title.present? + title << self.publisher if self.publisher.present? + title << self.isbn if self.isbn.present? + + if !self.publish_date.nil? + pd = self.publish_date.strftime("%Y-%m-%d").split('-') + title << pd[0]+"/"+pd[1] + end + + title.join(', ') + end + + def self.member_data + members = MemberProfile.all + member_data = [] + members.each do |m| + member_data << {"memberId" => m.id.to_s, "memberName" => m.name} + end + member_data.to_json + end + + def save_book_files + self.book_files.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def save_book_authors + self.book_authors.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def authors + authors = [] + authors << self.member_profile.name if self.member_profile_id.present? + authors << (!self.book_authors.blank? ? "#{self.book_authors.collect{|j| j.name}.join(', ')}" : nil) + authors.join(', ') + end + + protected + + def add_http + unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//] + self.url = 'http://' + self.url + end + end +end diff --git a/app/models/book_author.rb b/app/models/book_author.rb new file mode 100644 index 0000000..21b310c --- /dev/null +++ b/app/models/book_author.rb @@ -0,0 +1,14 @@ +class BookAuthor + include Mongoid::Document + include Mongoid::Timestamps + + field :name, type: String, localize: true + field :email, type: String + field :should_destroy, type: Boolean + + has_and_belongs_to_many :books + has_and_belongs_to_many :book_author_types + + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/ + validates :email, format: { with: VALID_EMAIL_REGEX }, allow_blank: true +end diff --git a/app/models/book_author_type.rb b/app/models/book_author_type.rb new file mode 100644 index 0000000..8374faf --- /dev/null +++ b/app/models/book_author_type.rb @@ -0,0 +1,11 @@ +class BookAuthorType + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + include OrbitCoreLib::ObjectDisable + + field :key, type: String + field :title, type: String, localize: true + + has_and_belongs_to_many :book_authors +end diff --git a/app/models/book_file.rb b/app/models/book_file.rb new file mode 100644 index 0000000..4081924 --- /dev/null +++ b/app/models/book_file.rb @@ -0,0 +1,12 @@ +class BookFile + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + + field :description, type: String, localize: true + field :title, type: String, localize: true + field :should_destroy, type: Boolean + + mount_uploader :member_book_file, AssetUploader + belongs_to :book +end diff --git a/app/models/book_intro.rb b/app/models/book_intro.rb new file mode 100644 index 0000000..4621f26 --- /dev/null +++ b/app/models/book_intro.rb @@ -0,0 +1,3 @@ +class BookIntro < PersonalPluginIntro + +end diff --git a/app/models/book_type.rb b/app/models/book_type.rb new file mode 100644 index 0000000..08f7541 --- /dev/null +++ b/app/models/book_type.rb @@ -0,0 +1,11 @@ +class BookType + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + include OrbitCoreLib::ObjectDisable + + field :key, type: String + field :title, type: String, localize: true + + has_many :books +end diff --git a/app/views/admin/book_author_types/create_book_setting.js.erb b/app/views/admin/book_author_types/create_book_setting.js.erb new file mode 100644 index 0000000..9913b08 --- /dev/null +++ b/app/views/admin/book_author_types/create_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal2").modal('hide'); +$('<%= j render :partial => 'admin/books/list_author_type', :collection => [@book_author_type] %>').appendTo('#author_types').hide().fadeIn(); \ No newline at end of file diff --git a/app/views/admin/book_author_types/delete_book_setting.js.erb b/app/views/admin/book_author_types/delete_book_setting.js.erb new file mode 100644 index 0000000..1958000 --- /dev/null +++ b/app/views/admin/book_author_types/delete_book_setting.js.erb @@ -0,0 +1,3 @@ +$('.delete_author').bind('ajax:success', function() { + $(this).closest('tr').fadeOut(); +}); \ No newline at end of file diff --git a/app/views/admin/book_author_types/update_book_setting.js.erb b/app/views/admin/book_author_types/update_book_setting.js.erb new file mode 100644 index 0000000..4a57749 --- /dev/null +++ b/app/views/admin/book_author_types/update_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal2").modal('hide'); +$("#<%= dom_id @book_author_type %>").replaceWith("<%= j render :partial => 'admin/books/list_author_type', :collection => [@book_author_type] %>"); \ No newline at end of file diff --git a/app/views/admin/book_types/create_book_setting.js.erb b/app/views/admin/book_types/create_book_setting.js.erb new file mode 100644 index 0000000..db9dce7 --- /dev/null +++ b/app/views/admin/book_types/create_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal1").modal('hide'); +$('<%= j render :partial => 'admin/books/list_book_type', :collection => [@book_type] %>').appendTo('#level_types').hide().fadeIn(); \ No newline at end of file diff --git a/app/views/admin/book_types/delete_book_setting.js.erb b/app/views/admin/book_types/delete_book_setting.js.erb new file mode 100644 index 0000000..eb842a2 --- /dev/null +++ b/app/views/admin/book_types/delete_book_setting.js.erb @@ -0,0 +1,3 @@ +$('.delete_level').bind('ajax:success', function() { + $(this).closest('tr').fadeOut(); +}); \ No newline at end of file diff --git a/app/views/admin/book_types/update_book_setting.js.erb b/app/views/admin/book_types/update_book_setting.js.erb new file mode 100644 index 0000000..90c0a3c --- /dev/null +++ b/app/views/admin/book_types/update_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal1").modal('hide'); +$("#<%= dom_id @book_type %>").replaceWith("<%= j render :partial => 'admin/books/list_book_type', :collection => [@book_type] %>"); \ No newline at end of file diff --git a/app/views/admin/books/_author_autocomplete.html.erb b/app/views/admin/books/_author_autocomplete.html.erb new file mode 100644 index 0000000..1c0226c --- /dev/null +++ b/app/views/admin/books/_author_autocomplete.html.erb @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/app/views/admin/books/_author_type_qe.html.erb b/app/views/admin/books/_author_type_qe.html.erb new file mode 100644 index 0000000..d4f3eec --- /dev/null +++ b/app/views/admin/books/_author_type_qe.html.erb @@ -0,0 +1,33 @@ +<% # encoding: utf-8 %> +<%= form_for(@set_author_type, :remote => true, :url => @author_type_url ) do |f| %> + +
+ <%= t(:add) %> +
++ <%= hidden_field_tag 'plugin_file_field_count', @book.book_files.count %> + <%= t(:add) %> +
+ ++ <%= t('add')%> + <%= t("personal_book.book_paper_type") %> +
++ <%= t('add')%> + <%= t("personal_book.author_type") %> +
+<%= t("personal_book.year") %> | +<%= t("personal_book.book_title") %> | +<%= t("personal_plugins.author") %> | +
---|
+ <% end -%> + | <%= t('personal_journal.year') %> | +<%= t('module_name.book') %> | + <% if not @user%> +<%= t('personal_journal.authors') %> | + <% end %> +
---|---|---|---|
+ <%= check_box_tag 'to_change[]', book.id.to_s, false, :class => "list-check" %> + | + <% end -%> +<%= book.year %> | +
+ <%= link_to book.create_link, page_for_book(book), target: "blank"%>
+
+
+
+
+ |
+ <%= book.authors %> | +