dev_aliyun
daiao 5 years ago
commit 84f77edead

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

@ -6,6 +6,8 @@
<%= hidden_field_tag :tag_ids, tag_ids.join(',') %>
<div class="edu-back-white">
<div class="padding30">
<div class="clearfix">
<span class="upload_Title">标题</span>
<li class="fl">
@ -14,8 +16,28 @@
</li>
<span class="color-grey-c font-12 fl mt6">简明扼要介绍文档/视频所包含的主要的内容</span>
</div>
</div>
<div class="padding30 bor-top-greyE">
<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[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[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>
<div class="clearfix mt20 mb20">
<span class="upload_Title">标签</span>
<ul class="fl libraries_tab">
<% LibraryTag.where(nil).each do |tag| %>
<li class="<%= tag_ids.include?(tag.id) ? 'active' : '' %>" data-id="<%= tag.id %>"><%= tag.name %></li>
<% end %>
</ul>
</div>
<div class="clearfix">
<span class="upload_Title">描述</span>
<div class="fl" style="width: 1078px">
@ -25,18 +47,53 @@
<p style="height:22px;line-height:22px;"><span class="color-red none" id="des_notice">请输入描述内容</span></p>
</div>
</div>
<div class="clearfix mb20">
<span class="upload_Title">标签</span>
<ul class="fl libraries_tab">
<% LibraryTag.where(nil).each do |tag| %>
<li class="<%= tag_ids.include?(tag.id) ? 'active' : '' %>" data-id="<%= tag.id %>"><%= tag.name %></li>
<% end %>
</ul>
</div>
<!-- <div class="clearfix mb20">-->
<!-- <span class="upload_Title">标签</span>-->
<!-- <ul class="fl libraries_tab">-->
<%# LibraryTag.where(nil).each do |tag| %>
<!-- <li class="<%#= tag_ids.include?(tag.id) ? 'active' : '' %>" data-id="<%#= tag.id %>"><%#= tag.name %></li>-->
<%# end %>
<!-- </ul>-->
<!-- </div>-->
<div style="padding-left: 62px">
<%= render partial: 'attachments/from_libraries', locals: { container: @library } %>
<p style="height:22px;line-height:22px;"><span class="color-red none" id="file_notice">请上传附件</span></p>
</div>
<div class="clearfix lineheight35">
<% cover_exists = @library.cover_id.present? %>
<div><span class="upload_Titles">封面图</span> <span class="color-grey-c">上传尺寸120*90 px</span></div>
<div class="surfacePlot ml25">
<img src="/images/educoder/unite.png" class="marginuploading"/>
</div>
<% 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="ml5 shixun_image_show ml50 none" width="150px" height="150px" id="shixun_image_show_<%= @library.id %>"/>
<% 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)
} %>
<div>
<a href="javascript:void(0);" id="object_upload_img_<%= @library.id %>" class="<%= cover_exists ? "mr10 ml60" : "mr10 ml60 decoration4CACFF" %>" onclick="$('#upload_img_<%= @library.id %>').click();">
<%= cover_exists ? "重新上传" : "上传图片" %>
</a>
</div>
</div>
</div>
<div class="padding30 bor-top-greyE">
<li class="lineh-25 color-grey-6 font-18 mb20">审核说明</li>

@ -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">
<ul class="fl library_nav mt20">
<li class="<%= params[:type] == 'mine' ? '' : 'active' %>">
<%= link_to '全部', libraries_path(search: params[:search]), remote: true %>
</li>
<li class="<%= params[:type] == 'mine' ? 'active' : '' %>">
<%= link_to '我的', libraries_path(search: params[:search], type: 'mine'), remote: true %>
</li>
</ul>
<% 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

@ -17,37 +17,45 @@ class SiderBar extends Component {
render() {
return (
<div className="-task-sidebar">
<div className="gotop" style={{"display":"none"}} tooltips="返回顶部">
<a href="javascript:void(0)" className="inline">
<i class="iconfont icon-shangjiantou color-white fl mt7"></i>
</a>
</div>
<div className="feedback" tooltips="意见反馈">
<a target="_blank" className="color_white inline" href="/help?index=6">
<i className="iconfont icon-yijianfankui color-white font-22 fl mt7"></i>
</a>
</div>
<div className="scan pr">
<span className="inline"><i className="iconfont icon-erweima color-white font-22 fl mt7"></i></span>
<div className="scan_ewm">
<div className="pr padding10">
<img src={getImageUrl('/images/edu_user/EWM.jpg')} style={{"widht":"158px","height":"158px"}} />
<p className="mb0 mt8">微信扫一扫</p>
<p className="mb0">关注公众号</p>
<span className="trangle_right"></span>
</div>
</div>
</div>
<div className="consult" tooltips="在线咨询">
<a target="_blank" className="color_white inline" href="//shang.qq.com/wpa/qunwpa?idkey=2f2043d88c1bd61d182b98bf1e061c6185e23055bec832c07d8148fe11c5a6cd">
<i className="iconfont icon-qqzaixianzixun color-white font-22 fl mt7"></i>
</a>
</div>
</div>
<div>
<div className="-task-sidebar">
<div className="gotop" style={{"display": "none"}} tooltips="返回顶部">
<a href="javascript:void(0)" className="inline">
<i className="iconfont icon-shangjiantou color-white fl mt7"></i>
</a>
</div>
<div className="feedback" tooltips="意见反馈">
<a target="_blank" className="color_white inline" href="/help?index=6">
<i className="iconfont icon-yijianfankui color-white font-22 fl mt7"></i>
</a>
</div>
<div className="scan pr">
<span className="inline"><i className="iconfont icon-erweima color-white font-22 fl mt7"></i></span>
<div className="scan_ewm">
<div className="pr padding10">
<img src={getImageUrl('/images/edu_user/EWM.jpg')} style={{"widht": "158px", "height": "158px"}}/>
<p className="mb0 mt8">微信扫一扫</p>
<p className="mb0">关注公众号</p>
<span className="trangle_right"></span>
</div>
</div>
</div>
<div className="consult" tooltips="在线咨询">
<a target="_blank" className="color_white inline"
href="//shang.qq.com/wpa/qunwpa?idkey=2f2043d88c1bd61d182b98bf1e061c6185e23055bec832c07d8148fe11c5a6cd">
<i className="iconfont icon-qqzaixianzixun color-white font-22 fl mt7"></i>
</a>
</div>
</div>
<div className="-task-sidebars" style={{right: "240px"}}>
<img src={getImageUrl("/images/educoder/competition/lvmeng.png")} width="150px" height="150px" />
</div>
</div>
);
}
}

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

@ -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;
}
Loading…
Cancel
Save