dev_aliyun
daiao 5 years ago
commit 3eb4e12e01

@ -359,6 +359,7 @@ class AttachmentsController < ApplicationController
saved = @attachment.save
respond_to do |format|
format.js
format.json { render json: { attachment_id: @attachment.id, url: download_attachment_path(@attachment.id) } }
format.api {
if saved
render :action => 'upload', :status => :created

@ -8,7 +8,7 @@ class LibrariesController < ApplicationController
libraries = Library.where(nil)
libraries =
if current_user.logged? && params[:type] == 'mine'
if User.current.logged? && params[:type] == 'mine'
libraries.where(user_id: current_user.id).order('created_at desc')
else
libraries.where(status: :published).order('visited_count desc')
@ -49,7 +49,7 @@ class LibrariesController < ApplicationController
rescue ActiveRecord::RecordInvalid => e
flash[:message] = e.record.errors.full_messages.join(',')
render 'new'
rescue Libraries::SubmitService::Error => ex
rescue Libraries::SubmitService::Error, Libraries::SaveService::Error => ex
flash[:message] = ex.message
render 'new'
end
@ -73,7 +73,7 @@ class LibrariesController < ApplicationController
rescue ActiveRecord::RecordInvalid => e
flash[:message] = e.record.errors.full_messages.join(',')
render 'edit'
rescue Libraries::SubmitService::Error => ex
rescue Libraries::SubmitService::Error, Libraries::SaveService::Error => ex
flash[:message] = ex.message
render 'edit'
end
@ -117,6 +117,7 @@ class LibrariesController < ApplicationController
hash = params[:library].presence || {}
hash[:tag_ids] = params[:tag_ids].to_s.split(',')
hash[:attachment_ids] = (params[:attachments].presence || []).values.map{|h| h[:attachment_id]}
hash[:cover_id] = save_cover.try(:id) || hash[:cover_id]
hash
end
end
@ -132,4 +133,14 @@ class LibrariesController < ApplicationController
def increment_visit_count
@library.increment_visited_count! if @library && @library.id
end
def save_cover
return if params[:cover_file].blank?
attachment = Attachment.new(file: params[:cover_file])
attachment.author = User.current
attachment.filename = Redmine::Utils.random_hex(16)
attachment.save
attachment
end
end

@ -17,7 +17,7 @@ class Library < ActiveRecord::Base
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
validates :author_school_name, presence: true, length: { maximum: 50 }
acts_as_attachable

@ -64,12 +64,31 @@
<div class="nav-border"><p id="nav-white"></p></div>
</ul>
<div class="fr edu-menu-panel ml15" style="height:60px;">
<% if User.current.logged? %>
<%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fr mt15 ml40" %>
<ul class="edu-menu-list edu-menu-lists" style="top:60px;">
<span class="bor-bottom-greyE currentName task-hide"><%= User.current.show_name %></span>
<li><%= link_to '我的课堂', user_path(User.current) %></li>
<li><%= link_to '我的实训', user_path(User.current, :type => 'a_shixun') %></li>
<li><%= link_to '我的实践课程', user_path(User.current, :type => 'a_path') %></li>
<% if User.current.partner.present? %>
<li><%= link_to '客户管理', partner_list_cooperate_path(User.current.partner) %></li>
<% end %>
<li><%= link_to '我的项目', user_path(User.current, :type => 'a_project') %></li>
<li><%= link_to '我的众包', user_path(User.current, :type => 'a_package') %></li>
<% if User.current.department_members.count > 0 %>
<li><%= link_to '学院统计', statistics_college_path(User.current.department_members.first.try(:department)) %></li>
<% end %>
<li><%= link_to '账号管理', my_account_path %></li>
<li class="bor-top-greyE"><%= link_to '退出', signout_path %></li>
</ul>
<% else %>
<span class="fr font-16 color-white mt13 ml40"><a href="<%= signin_path %>" class="color-white mr3">登录</a>/<a href="<%= user_join_path %>" class="color-white ml3">注册</a></span>
<% end %>
</div>
</div>
</div>
<script>
window.onload = function(){

@ -18,7 +18,10 @@
</ul>
</li>
<% end %>
<li class="<%= params[:controller] == "competitions" ? " active" : "" %>"><%= link_to "在线竞赛", competitions_path %></li>
<li class="<%= params[:controller] == "competitions" ? " active" : "" %>">
<%= link_to "在线竞赛", competitions_path %>
<img class="roundedRectangles" src="/images/educoder/roundedRectangle.png"/>
</li>
<li class="<%= params[:controller] == "libraries" ? " active" : "" %>"><%= link_to "教学案例", libraries_path %></li>
<li class="<%= params[:controller] == "forums" ? " active" : "" %>"><%= link_to "交流问答", forums_path %></li>
<% if User.current.ec_school.present? %>

@ -19,7 +19,10 @@
</ul>
</li>
<% end %>
<li class="<%= params[:controller] == "competitions" ? " active" : "" %>"><%= link_to "在线竞赛", competitions_path %></li>
<li class="<%= params[:controller] == "competitions" ? " active" : "" %>">
<%= link_to "在线竞赛", competitions_path %>
<img class="roundedRectangles" src="/images/educoder/roundedRectangle.png"/>
</li>
<li class="<%= params[:controller] == "libraries" ? " active" : "" %>"><%= link_to "教学案例", libraries_path %></li>
<li class="<%= params[:controller] == "forums" ? " active" : "" %>"><%= link_to "交流问答", forums_path %></li>
<!--<li><%#= link_to "活动竞赛", competitions_path %></li>-->

@ -1,6 +1,6 @@
<p class="lineh-25 font-22 mb20">上传教学案例</p>
<div class="library-form-container">
<%= form_for(@library) do |f| %>
<%= form_for(@library, html: { multipart: true }) do |f| %>
<% tag_ids = @library.library_tags.map(&:id) %>
<%= hidden_field_tag :apply_publish, false %>
<%= hidden_field_tag :tag_ids, tag_ids.join(',') %>
@ -20,12 +20,12 @@
<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>
<%= f.text_field :author_name, placeholder: '请输入姓名', class: 'greyInput winput-300-35 mr20 fl winput150', width: '163', size: 30 %>
<p style="height:20px;line-height:20px;"><span class="color-red none" id="author_name_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>
<%= f.text_field :author_school_name, placeholder: '请输入作者单位名称', class: 'greyInput winput-300-35 mr20 fl', width: '163', size: 30 %>
<p style="height:20px;line-height:20px;"><span class="color-red none" id="author_school_name_notice">请输入作者单位名称</span></p>
</li>
</div>
@ -61,38 +61,22 @@
<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? %>
<% cover_exists = @library.cover_id.present? && !@library.cover_id_changed? %>
<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"/>
<%= hidden_field_tag 'library[cover_id]', @library.cover_id %>
<%= hidden_field_tag 'cover_file_name', '', class: 'cover-file-name' %>
<input type="file" name="cover_file" accept="image/*" id="library-cover-file" style="display: none"/>
<div class="surfacePlot ml25 library-cover-select" data-tip-down="上传图片" onclick="$('#library-cover-file').click();">
<img src="/images/educoder/unite.png" class="marginuploading <%= cover_exists ? 'hidden' : '' %>" style="<%= cover_exists ? 'display:none' : '' %>"/>
<div class="library-cover-perview" style="<%= cover_exists ? '' : 'display:none' %>">
<% cover_url = cover_exists ? named_attachment_path(@library.cover.id, @library.cover.filename) : '' %>
<img src="<%= cover_url %>" width="120px" height="90px"/>
</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>
<p style="height:20px;line-height:20px;"><span class="color-red ml20 none" id="cover_file_notice">请上传封面</span></p>
</div>
</div>
<div class="padding30 bor-top-greyE">
@ -155,6 +139,9 @@
var submitForm = function(){
var title = $("input[name='library[title]']").val();
var content = $("textarea[name='library[content]']").val();
var author_name = $("input[name='library[author_name]']").val();
var author_school_name = $("input[name='library[author_school_name]']").val();
var cover_file = $("input[name='cover_file").val();
if (!title || title.length == 0) {
$("#title_notice").removeClass("none");
@ -168,6 +155,25 @@
}else{
$("#des_notice").addClass("none");
}
if (!author_name || author_name.length == 0) {
$("#author_name_notice").removeClass("none");
return
}else{
$("#author_name_notice").addClass("none");
}
if (!author_school_name || author_school_name.length == 0) {
$("#author_school_name_notice").removeClass("none");
return
}else{
$("#author_school_name_notice").addClass("none");
}
var coverId = $("input[name='library[cover_id]']").val();
if ((!coverId || coverId.length == 0) && (!cover_file || cover_file.length == 0)) {
$("#cover_file_notice").removeClass("none");
return
}else{
$("#cover_file_notice").addClass("none");
}
if($('.attachments_fields .attachment').length == 0){
$("#file_notice").removeClass("none");
@ -199,5 +205,26 @@
console.log('ids', ids)
$('#tag_ids').val(ids);
})
$("#library-cover-file").change(function (e) {
var file = e.target.files[0] || e.dataTransfer.files[0];
$('input.cover-file-name').val(document.getElementById("library-cover-file").files[0].name);
if (file) {
var reader = new FileReader();
reader.onload = function () {
$(".library-cover-perview img").attr("src", this.result);
$('.marginuploading').addClass('hidden').hide();
$('.library-cover-perview').show();
}
reader.readAsDataURL(file);
}
});
$('.library-cover-select').hover(function(){
$('.library-cover-select .marginuploading.hidden').show();
},function(){
$('.library-cover-select .marginuploading.hidden').hide();
});
});
</script>

@ -6,16 +6,14 @@
<%= 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? %>
<% if User.current.try(: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">

@ -31,5 +31,8 @@
</div>
<div class="-task-sidebars" style="right: 240px !important;">
<a href="/competitions">
<img src="/images/educoder/competition/lvmeng.png" width="150px" height="150px">
</a>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

@ -301,7 +301,10 @@ class NewHeader extends Component {
</li>
{/* <li><a href="/libraries">教学案例</a></li> */}
<li className={`${competitions === true ? 'active' : ''}`} ><a href="/competitions">在线竞赛</a></li>
<li className={`${competitions === true ? 'active' : ''}`} >
<a href="/competitions">在线竞赛</a>
<img className="roundedRectangles" src="/images/educoder/roundedRectangle.png"/>
</li>
<li className={`${competitions === true ? 'active' : ''}`} style={{display:project_packages_url===null||project_packages_url===undefined||project_packages_url===""?'none':'block'}} >
<a href="/crowdsourcing">
{project_packages_url===null||project_packages_url===undefined||project_packages_url===""?'':'众包'}

@ -52,7 +52,9 @@ class SiderBar extends Component {
</div>
<div className="-task-sidebars" style={{right: "240px"}}>
<a href="/competitions">
<img src={getImageUrl("/images/educoder/competition/lvmeng.png")} width="150px" height="150px" />
</a>
</div>
</div>

@ -1211,12 +1211,33 @@ html>body #ajax-indicator { position: fixed; }
}
.surfacePlot{
width:120px;
height:90px;
cursor: pointer;
width:122px;
height:92px;
background:rgba(250,250,250,1);
border:1px solid rgba(221,221,221,1);
}
.marginuploading{
margin: 27px 42px;
padding: 28px 43px;
position: absolute;
z-index: 10;
}
.surfacePlot:hover .marginuploading.hidden{
background: rgba(0,0,0, 0.1);
}
.roundedRectangles {
position: absolute;
top: 10px;
right: -22px;
}
.edu-menu-lists currentName{
text-align: left;
}
.edu-menu-lists li{
text-align: left;
}
Loading…
Cancel
Save