library modify

dev_aliyun
p31729568 6 years ago
parent a300b32735
commit 7f8dba8549

@ -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

@ -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

@ -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

@ -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

@ -23,6 +23,23 @@ class Libraries::SaveService
library.assign_attributes(params)
library.save!
deal_library_tag!
Attachment.where(id: attachment_ids, author_id: user.id)
.update_all(container_id: library.id, container_type: 'Library')
end
library
end
private
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)
@ -35,16 +52,5 @@ class Libraries::SaveService
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')
end
library
end
private
def validate_params!
raise Error, '附件不能为空' if params[:attachment_ids].try(:compact).blank?
end
end

@ -20,11 +20,11 @@
<div class="clearfix mt20">
<span class="upload_Title">作者</span>
<li class="fl">
<input class="greyInput winput-300-35 mr20 fl winput150" id="library_title" name="library[title]" placeholder="请输入姓名" size="30" type="text" width="163">
<input class="greyInput winput-300-35 mr20 fl winput150" id="library_title" name="library[author_name]" placeholder="请输入姓名" size="30" type="text" width="163">
<p style="height:20px;line-height:20px;"><span class="color-red none" id="title_notice">请输入姓名</span></p>
</li>
<li class="fl">
<input class="greyInput winput-300-35 mr20 fl" id="library_title" name="library[title]" placeholder="请输入作者单位名称" size="30" type="text">
<input class="greyInput winput-300-35 mr20 fl" id="library_title" name="library[author_school_name]" placeholder="请输入作者单位名称" size="30" type="text">
<p style="height:20px;line-height:20px;"><span class="color-red none" id="title_notice">请输入作者单位名称</span></p>
</li>
</div>
@ -63,14 +63,15 @@
<div class="clearfix lineheight35">
<% cover_exists = @library.cover_id.present? %>
<span class="upload_Titles">封面图</span> <span class="color-grey-c">上传尺寸120*90 px</span>
<% if File.exist?(disk_filename("Career", career.id)) %>
<%= image_tag(url_to_avatar(career), :class => "w120 h90 ml5 shixun_image_show", :id => "shixun_image_show_#{career.id}") %>
<% if cover_exists %>
<%= image_tag(named_attachment_path(@library.cover.id, @library.cover.filename), :class => "w120 h90 ml5 shixun_image_show") %>
<% else %>
<img src="" class="w80 h80 ml5 shixun_image_show none" id="shixun_image_show_<%= career.id %>"/>
<img src="" class="w80 h80 ml5 shixun_image_show none" id="shixun_image_show_<%= @library.id %>"/>
<% end %>
<%= file_field_tag 'avatar[image]',
:id => "upload_img_#{career.id}",
<%= file_field_tag 'library[cover_id]',
:id => "upload_img_#{@library.id}",
:style => 'display:none;',
:size => "1",
:multiple => false,
@ -81,14 +82,11 @@
: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 => upload_avatar_path(:format => 'js'),
:upload_path => uploads_path(:format => 'js',:project =>nil),
:description_placeholder => nil ,# l(:label_optional_description)
:source_type => "Career",
:source_id => career.id,
:is_direct => 1
} %>
<a href="javascript:void(0);" id="object_upload_img_<%= career.id %>" class="mr10" onclick="$('#upload_img_<%= career.id %>').click();">
<%= File.exist?(disk_filename("Career", career.id)) ? "重新上传" : "上传图片" %>
<a href="javascript:void(0);" id="object_upload_img_<%= @library.id %>" class="mr10" onclick="$('#upload_img_<%= @library.id %>').click();">
<%= cover_exists ? "重新上传" : "上传图片" %>
</a>
</div>

@ -2,24 +2,31 @@
<% if @libraries.present? %>
<% @libraries.each do |library| %>
<li class="library_list_item">
<%= 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') %>
<div class="flex1">
<p class="clearfix mb15 lineh-40 mt10">
<%= 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' %>
<span class="color-grey-c mr20">上传时间:<%= library.created_at.strftime('%Y-%m-%d %H:%M') %></span>
<span class="color-grey-c mr20 fr">上传时间:<%= library.created_at.strftime('%Y-%m-%d %H:%M') %></span>
<% else %>
<span class="color-grey-c mr20">发布时间:<%= library.published_at.try(:strftime, '%Y-%m-%d %H:%M') %></span>
<span class="color-grey-c mr20 fr">发布时间:<%= library.published_at.try(:strftime, '%Y-%m-%d %H:%M') %></span>
<% end %>
</p>
<p class="clearfix lineh-20">
<span class="color-grey-c">作者:</span>
<span class="color-grey-3 mr10"><%= link_to library.user.show_real_name, user_path(library.user) %></span>
<span class="color-grey-3 mr20">学校</span>
<span class="color-grey-3 mr10"><%= library.author_name %></span>
<span class="color-grey-3 mr20"><%= library.author_school_name %></span>
<span class="color-grey-c mr20"><span class=" item-group-icon mr5"><i class="fa fa-eye"></i></span><%= library.visited_count || 0 %> 浏览</span>
<span class="color-grey-c mr20"><span class=" item-group-icon mr5"><i class="fa fa-download"></i></span><%= library.visited_count || 0 %> 下载</span>
<span class="color-grey-c mr20"><span class=" item-group-icon mr5"><i class="fa fa-thumbs-o-up"></i></span><%= library.visited_count || 0 %> 赞</span>
<% download_count = @download_count_map.try(:fetch, library.id, 0) || library.attachments.count %>
<% if download_count.nonzero? %>
<span class="color-grey-c mr20"><span class=" item-group-icon mr5"><i class="fa fa-download"></i></span><%= download_count %> 下载</span>
<% end %>
<% if library.praise_tread_cache.try(:praise_num).to_i.nonzero? %>
<span class="color-grey-c mr20"><span class=" item-group-icon mr5"><i class="fa fa-thumbs-o-up"></i></span><%= library.praise_tread_cache.try(:praise_num) %> 赞</span>
<% end %>
</p>
</div>
</li>

@ -6,14 +6,18 @@
<%= link_to '发布案例', new_library_path, class: 'white-btn edu-filter-btn-blue fr mr10 mt8', style: 'color: #4CACFF' %>
</p>
<div class="clearfix pl30 pr30">
<% if User.current.logged? %>
<ul class="fl library_nav mt20">
<li class="<%= params[:type] == 'mine' ? '' : 'active' %>">
<%= link_to '全部', libraries_path(search: params[:search]), remote: true %>
</li>
<% if User.current.logged? %>
<li class="<%= params[:type] == 'mine' ? 'active' : '' %>">
<%= link_to '我的', libraries_path(search: params[:search], type: 'mine'), remote: true %>
</li>
<% end %>
</ul>
<% end %>
<div class="edu-position fr mt12">
<%= hidden_field_tag(:type, params[:type]) %>
<input class="winput-300-35 panel-box-sizing" placeholder="输入教学案例标题、编号进行检索" type="text" id="search_name">

@ -10,7 +10,7 @@
<span class="font-22 fl mr10 task-hide" style="max-width: 800px">
<%= @library.title %>
</span>
<%= show_library_tags(@library) %>
<%= show_library_tags(@library, class: 'mt3 ml10') %>
<% if admin_or_self %>
<% if @library.pending? %>
<span class="fl edu-filter-btn edu-activity-green mt3 ml10">草稿</span>
@ -53,7 +53,7 @@
<!--增加姓名大学-->
<div>
<span class="fl color-grey-9">作者:</span>
张丹/南京大学
<%= @library.author_name %>/<%= @library.author_school_name %>
</div>
<div>
@ -64,10 +64,9 @@
<%= render partial: 'attachments/links', locals: { attachments: @library.attachments, options: {} } %>
</div>
</div>
<!--未点赞-->
<p class="noteDetailPoints" ><i class="iconfont icon-dianzan"></i><br><span>0</span></p>
<!--已点赞-->
<p class="noteDetailPointsBCD1E3" ><span>已赞</span><br><span>0</span></p>
<div class="mt40">
<%= render partial: 'praise_tread/new_praise', locals: { object: @library } %>
</div>
</div>
</div>
</div>

@ -0,0 +1,42 @@
<%
praised = PraiseTread.praised(object)
praise_num = get_praise_num(object) || 0
%>
<p class="noteDetailPoints plus-praise-btn" data-tip-down="点赞" style="<%= praised ? 'display:block' : 'display:none' %>"><i class="iconfont icon-dianzan"></i><br><span class="praise-num"><%= praise_num %></span></p>
<p class="noteDetailPointsBCD1E3 minus-praise-btn" data-tip-down="取消点赞" style="<%= praised ? 'display:none' : 'display:block' %>"><span>已赞</span><br><span class="praise-num"><%= praise_num %></span></p>
<script>
$(function(){
var $plusPraiseBtn = $('.plus-praise-btn');
var $minusPraiseBtn = $('.minus-praise-btn');
var praiseNum = parseInt(<%= praise_num %>);
$plusPraiseBtn.on('click', function(){
$.ajax({
method: "get",
url: "<%= praise_tread_praise_plus_path(obj_id: object.id, obj_type: object.class) %>",
dataType: 'json',
success: function(){
$plusPraiseBtn.hide();
praiseNum += 1;
$minusPraiseBtn.find('.praise-num').html(praiseNum);
$minusPraiseBtn.show();
}
})
});
$minusPraiseBtn.on('click', function(){
$.ajax({
method: "get",
url: "<%= praise_tread_praise_minus_path(obj_id: object.id, obj_type: object.class) %>",
dataType: 'json',
success: function(){
$minusPraiseBtn.hide();
praiseNum -= 1;
$plusPraiseBtn.find('.praise-num').html(praiseNum);
$plusPraiseBtn.show();
}
})
});
})
</script>

@ -6,3 +6,5 @@
library:
title: '标题'
content: '描述'
author_name: '作者姓名'
author_school_name: '作者单位名称'

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@ -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;
}

Loading…
Cancel
Save