diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb index 16efc0c5..db5d20b0 100644 --- a/app/controllers/libraries_controller.rb +++ b/app/controllers/libraries_controller.rb @@ -8,17 +8,22 @@ class LibrariesController < ApplicationController libraries = Library.where(nil) libraries = - if params[:type] == 'mine' + if current_user.logged? && params[:type] == 'mine' libraries.where(user_id: current_user.id).order('created_at desc') else libraries.where(status: :published).order('visited_count desc') end search = params[:search].to_s.strip - libraries = libraries.where('title LIKE :search OR uuid LIKE :search', search: "%#{search}%") if search.present? + if search.present? + libraries = libraries.where('title LIKE :search OR author_name LIKE :search OR author_school_name LIKE :search', + search: "%#{search}%") + end per_page = params[:per_page].to_i <= 0 ? 20 : params[:per_page].to_i - @libraries = paginateHelper libraries.includes(user: :user_extensions), per_page + @libraries = paginateHelper libraries.includes(:library_tags, :praise_tread_cache, user: :user_extensions), per_page + + @download_count_map = Attachment.where(container_type: 'Library', container_id: @libraries.map(&:id)).group(:container_id).count end def show diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index d56ffa31..7368e0fb 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -47,6 +47,7 @@ class PraiseTreadController < ApplicationController end respond_to do |format| format.js + format.json { render_api_ok } end end end @@ -85,6 +86,7 @@ class PraiseTreadController < ApplicationController #@obj = User.find_by_id(@obj) respond_to do |format| format.js + format.json { render_api_ok } end end @@ -177,6 +179,8 @@ class PraiseTreadController < ApplicationController @obj = Challenge.find_by_id(id) when 'Discuss' @obj = Discuss.find_by_id(id) + when 'Library' + @obj = Library.find_by_id(id) else @obj = nil end diff --git a/app/helpers/libraries_helper.rb b/app/helpers/libraries_helper.rb index 60beab53..14c6ce37 100644 --- a/app/helpers/libraries_helper.rb +++ b/app/helpers/libraries_helper.rb @@ -1,8 +1,9 @@ module LibrariesHelper - def show_library_tags(library) + def show_library_tags(library, opts = {}) html = '' library.library_tags.each do |tag| - html += content_tag(:span, tag.name, class: "edu-filter-btn fl cdefault mt10 ml10 #{library_tag_class(tag)}") + klass = "edu-filter-btn fl cdefault #{library_tag_class(tag)} #{opts[:class]}" + html += content_tag(:span, tag.name, class: klass) end raw html @@ -10,7 +11,7 @@ module LibrariesHelper def library_tag_class(tag) case tag.name - when '获奖案例' then 'edu-activity-red' + when '优秀案例' then 'edu-activity-red' when '入库案例' then 'edu-activity-blue' end end diff --git a/app/models/library.rb b/app/models/library.rb index 2ff3c4c4..c0fe35ee 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -2,17 +2,22 @@ class Library < ActiveRecord::Base include AASM belongs_to :user + belongs_to :cover, class_name: 'Attachment', foreign_key: :cover_id has_many :library_applies, dependent: :delete_all has_many :attachments, as: :container has_many :library_library_tags, dependent: :delete_all has_many :library_tags, through: :library_library_tags - attr_accessible :title, :content + has_one :praise_tread_cache, as: :object - validates :title, presence: true + attr_accessible :title, :content, :author_name, :author_school_name, :cover_id + + validates :title, presence: true, length: { maximum: 255 } validates :content, presence: true validates :uuid, presence: true, uniqueness: true + validates :author_name, presence: true, length: { maximum: 10 } + validates :author_school_name, length: { maximum: 50 }, allow_blank: true acts_as_attachable @@ -44,7 +49,13 @@ class Library < ActiveRecord::Base self.uuid = uuid end - def increment_visited_count! - Library.connection.execute("update libraries set visited_count = COALESCE(visited_count, 0) + 1 where id = #{id}") + def increment_visited_count!(num = 1) + increment_column!(:visited_count, num) + end + + private + + def increment_column!(column, num = 1) + self.class.connection.execute("update #{self.class.table_name} set #{column} = COALESCE(#{column}, 0) + #{num} where id = #{id}") end end \ No newline at end of file diff --git a/app/services/libraries/save_service.rb b/app/services/libraries/save_service.rb index 393d3911..88a85fc8 100644 --- a/app/services/libraries/save_service.rb +++ b/app/services/libraries/save_service.rb @@ -23,20 +23,10 @@ class Libraries::SaveService library.assign_attributes(params) library.save! - new_tag_ids = LibraryTag.where(id: params[:tag_ids].presence || []).pluck(:id) - old_tag_ids = library.library_library_tags.pluck(:library_tag_id) + deal_library_tag! - # 删除标签 - destroy_ids = old_tag_ids - new_tag_ids - library.library_library_tags.where(library_tag_id: destroy_ids).delete_all - - # 创建标签 - created_ids = new_tag_ids - old_tag_ids - created_ids.each do |id| - library.library_library_tags.create!(library_tag_id: id) - end - - Attachment.where(id: attachment_ids).update_all(container_id: library.id, container_type: 'Library') + Attachment.where(id: attachment_ids, author_id: user.id) + .update_all(container_id: library.id, container_type: 'Library') end library @@ -46,5 +36,21 @@ class Libraries::SaveService def validate_params! raise Error, '附件不能为空' if params[:attachment_ids].try(:compact).blank? + raise Error , '封面不能为空' if params[:cover_id].blank? + end + + def deal_library_tag! + new_tag_ids = LibraryTag.where(id: params[:tag_ids].presence || []).pluck(:id) + old_tag_ids = library.library_library_tags.pluck(:library_tag_id) + + # 删除标签 + destroy_ids = old_tag_ids - new_tag_ids + library.library_library_tags.where(library_tag_id: destroy_ids).delete_all + + # 创建标签 + created_ids = new_tag_ids - old_tag_ids + created_ids.each do |id| + library.library_library_tags.create!(library_tag_id: id) + end end end diff --git a/app/views/libraries/_form.html.erb b/app/views/libraries/_form.html.erb index e1e6aa0b..36d09bed 100644 --- a/app/views/libraries/_form.html.erb +++ b/app/views/libraries/_form.html.erb @@ -6,6 +6,8 @@ <%= hidden_field_tag :tag_ids, tag_ids.join(',') %>
+ +
标题
  • @@ -14,8 +16,28 @@
  • 简明扼要介绍文档/视频所包含的主要的内容
    -
    -
    + +
    + 作者 +
  • + +

    请输入姓名

    +
  • +
  • + +

    请输入作者单位名称

    +
  • +
    + +
    + 标签 +
      + <% LibraryTag.where(nil).each do |tag| %> +
    • <%= tag.name %>
    • + <% end %> +
    +
    +
    描述
    @@ -25,18 +47,53 @@

    请输入描述内容

    -
    - 标签 -
      - <% LibraryTag.where(nil).each do |tag| %> -
    • <%= tag.name %>
    • - <% end %> -
    -
    + + + + + <%# LibraryTag.where(nil).each do |tag| %> + + <%# end %> + +
    <%= render partial: 'attachments/from_libraries', locals: { container: @library } %>

    请上传附件

    + + +
    + <% cover_exists = @library.cover_id.present? %> +
    封面图 (上传尺寸:120*90 px)
    +
    + +
    + <% if cover_exists %> + <%= image_tag(named_attachment_path(@library.cover.id, @library.cover.filename), :class => "w120 h90 ml5 shixun_image_show") %> + <% else %> + + <% end %> + <%= file_field_tag 'library[cover_id]', + :id => "upload_img_#{@library.id}", + :style => 'display:none;', + :size => "1", + :multiple => false, + :onchange => 'addInputAvatar(this);', + :data => { + :max_file_size => Setting.authentication_img_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_user_auth_too_big, :max_size => number_to_human_size(Setting.authentication_img_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :file_type => Redmine::Configuration['pic_types'].to_s, + :type_support_message => l(:error_pic_type), + :upload_path => uploads_path(:format => 'js',:project =>nil), + :description_placeholder => nil ,# l(:label_optional_description) + } %> +
    + " onclick="$('#upload_img_<%= @library.id %>').click();"> + <%= cover_exists ? "重新上传" : "上传图片" %> + +
    +
  • 审核说明
  • diff --git a/app/views/libraries/_library_list.html.erb b/app/views/libraries/_library_list.html.erb index 21e96536..2b142b44 100644 --- a/app/views/libraries/_library_list.html.erb +++ b/app/views/libraries/_library_list.html.erb @@ -2,24 +2,31 @@ <% if @libraries.present? %> <% @libraries.each do |library| %>
  • - <%= link_to image_tag(url_to_avatar(library.user), width: 120, height: 90, class: ' mr15 mt3'), user_path(library.user) %> + <% image_url = library.cover.present? ? named_attachment_path(library.cover.id, library.cover.filename) : 'educoder/library-default-cover.png' %> + <%= image_tag(image_url, width: 120, height: 90, class: 'mr15 mt3 radius4') %>

    <%= link_to library.title, library_path(library),:class => "task-hide font-22 library_l_name" %> - <%= show_library_tags(library) %> + <%= show_library_tags(library, class: 'mt10 ml10') %> + <% if params[:type] == 'mine' %> - 上传时间:<%= library.created_at.strftime('%Y-%m-%d %H:%M') %> + 上传时间:<%= library.created_at.strftime('%Y-%m-%d %H:%M') %> <% else %> - 发布时间:<%= library.published_at.try(:strftime, '%Y-%m-%d %H:%M') %> + 发布时间:<%= library.published_at.try(:strftime, '%Y-%m-%d %H:%M') %> <% end %>

    作者: - <%= link_to library.user.show_real_name, user_path(library.user) %> - 学校 + <%= library.author_name %> + <%= library.author_school_name %> <%= library.visited_count || 0 %> 浏览 - <%= library.visited_count || 0 %> 下载 - <%= library.visited_count || 0 %> 赞 + <% download_count = @download_count_map.try(:fetch, library.id, 0) || library.attachments.count %> + <% if download_count.nonzero? %> + <%= download_count %> 下载 + <% end %> + <% if library.praise_tread_cache.try(:praise_num).to_i.nonzero? %> + <%= library.praise_tread_cache.try(:praise_num) %> 赞 + <% end %>

  • diff --git a/app/views/libraries/index.html.erb b/app/views/libraries/index.html.erb index 1c15217c..08495304 100644 --- a/app/views/libraries/index.html.erb +++ b/app/views/libraries/index.html.erb @@ -6,14 +6,18 @@ <%= link_to '发布案例', new_library_path, class: 'white-btn edu-filter-btn-blue fr mr10 mt8', style: 'color: #4CACFF' %>

    -
      -
    • - <%= link_to '全部', libraries_path(search: params[:search]), remote: true %> -
    • -
    • - <%= link_to '我的', libraries_path(search: params[:search], type: 'mine'), remote: true %> -
    • -
    + <% if User.current.logged? %> +
      +
    • + <%= link_to '全部', libraries_path(search: params[:search]), remote: true %> +
    • + <% if User.current.logged? %> +
    • + <%= link_to '我的', libraries_path(search: params[:search], type: 'mine'), remote: true %> +
    • + <% end %> +
    + <% end %>
    <%= hidden_field_tag(:type, params[:type]) %> diff --git a/app/views/libraries/show.html.erb b/app/views/libraries/show.html.erb index 9fe19994..09515dd6 100644 --- a/app/views/libraries/show.html.erb +++ b/app/views/libraries/show.html.erb @@ -10,7 +10,7 @@ <%= @library.title %> - <%= show_library_tags(@library) %> + <%= show_library_tags(@library, class: 'mt3 ml10') %> <% if admin_or_self %> <% if @library.pending? %> 草稿 @@ -53,7 +53,7 @@
    作者: - 张丹/南京大学 + <%= @library.author_name %>/<%= @library.author_school_name %>
    @@ -64,10 +64,9 @@ <%= render partial: 'attachments/links', locals: { attachments: @library.attachments, options: {} } %>
    - -


    0

    - -

    已赞
    0

    +
    + <%= render partial: 'praise_tread/new_praise', locals: { object: @library } %> +
    diff --git a/app/views/praise_tread/_new_praise.html.erb b/app/views/praise_tread/_new_praise.html.erb new file mode 100644 index 00000000..facdabad --- /dev/null +++ b/app/views/praise_tread/_new_praise.html.erb @@ -0,0 +1,42 @@ +<% + praised = PraiseTread.praised(object) + praise_num = get_praise_num(object) || 0 +%> +


    <%= praise_num %>

    +

    已赞
    <%= praise_num %>

    + + \ No newline at end of file diff --git a/config/locales/libraries/zh.yml b/config/locales/libraries/zh.yml index 3dae730c..fd514c72 100644 --- a/config/locales/libraries/zh.yml +++ b/config/locales/libraries/zh.yml @@ -6,3 +6,5 @@ library: title: '标题' content: '描述' + author_name: '作者姓名' + author_school_name: '作者单位名称' diff --git a/db/migrate/20190708024123_add_columns_to_libraries.rb b/db/migrate/20190708024123_add_columns_to_libraries.rb new file mode 100644 index 00000000..50566344 --- /dev/null +++ b/db/migrate/20190708024123_add_columns_to_libraries.rb @@ -0,0 +1,7 @@ +class AddColumnsToLibraries < ActiveRecord::Migration + def change + add_column :libraries, :author_name, :string + add_column :libraries, :author_school_name, :string + add_column :libraries, :cover_id, :integer + end +end diff --git a/public/images/educoder/library-default-cover.png b/public/images/educoder/library-default-cover.png new file mode 100644 index 00000000..d54b8df0 Binary files /dev/null and b/public/images/educoder/library-default-cover.png differ diff --git a/public/images/educoder/unite.png b/public/images/educoder/unite.png new file mode 100755 index 00000000..8ebb4984 Binary files /dev/null and b/public/images/educoder/unite.png differ diff --git a/public/react/src/modules/tpm/SiderBar.js b/public/react/src/modules/tpm/SiderBar.js index 1710752d..71e33695 100644 --- a/public/react/src/modules/tpm/SiderBar.js +++ b/public/react/src/modules/tpm/SiderBar.js @@ -17,37 +17,45 @@ class SiderBar extends Component { render() { return ( -
    -
    - - - -
    - -
    - - - -
    - -
    - -
    -
    - -

    微信扫一扫

    -

    关注公众号

    - -
    -
    -
    -
    - - - -
    - -
    +
    + +
    +
    + + + +
    + +
    + + + +
    + +
    + +
    +
    + +

    微信扫一扫

    +

    关注公众号

    + +
    +
    +
    +
    + + + +
    +
    + +
    + +
    + +
    ); } } diff --git a/public/stylesheets/educoder/edu-all.css b/public/stylesheets/educoder/edu-all.css index 9ea717ba..f1cfa765 100644 --- a/public/stylesheets/educoder/edu-all.css +++ b/public/stylesheets/educoder/edu-all.css @@ -3466,9 +3466,10 @@ line-height: 16px;display: inline-block;color: rgba(65, 140, 205, 1) !important; margin-bottom: 30px; } .library_list_item{ - background: #fff;padding:30px;margin-bottom: 30px;display: flex; + background: #fff;padding:20px 30px;margin-bottom: 30px;display: flex; } -.library_list_item .library_l_name{max-width: 900px;float: left;} +.library_list_item:hover { box-shadow:0px 4px 8px rgba(158,158,158,0.16); } +.library_list_item .library_l_name{max-width: 600px;float: left;} .upload_Title{ position: relative;margin-right: 30px;float: left;line-height: 35px;font-size: 16px;width: 32px; } diff --git a/public/stylesheets/educoder/edu-main.css b/public/stylesheets/educoder/edu-main.css index 7059dea9..05cea010 100644 --- a/public/stylesheets/educoder/edu-main.css +++ b/public/stylesheets/educoder/edu-main.css @@ -1179,4 +1179,44 @@ html>body #ajax-indicator { position: fixed; } right: 0; bottom: 30px; z-index: 10; +} + +.winput150{ + width:150px; +} + + +.upload_Titles{ + position: relative; + float: left; + line-height: 35px; + font-size: 16px; + width: 50px; +} + +.lineheight35{ + line-height: 35px; +} + +.w120{ + width:120px; +} +.h90{ + width:90px; +} + +.decoration4CACFF{ + color: #4CACFF !important; + border-bottom: 1px solid #4CACFF; +} + +.surfacePlot{ + width:120px; + height:90px; + background:rgba(250,250,250,1); + border:1px solid rgba(221,221,221,1); +} + +.marginuploading{ + margin: 27px 42px; } \ No newline at end of file