diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 900487364..d6c90ccf4 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -224,4 +224,11 @@ private referer = request.headers['Referer'] require_login unless referer =~ /softapplication/ end + + def renderTag + @attachmentNew = Attachment.find(params[:attchmentId]) + respond_to do |format| + format.js + end + end end diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 1ae04fa08..2273de4e4 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -732,9 +732,9 @@ class BidsController < ApplicationController def update @bid = Bid.find(params[:id]) @project = @bid.courses.first#Project.find(params[:course_id]) - if @bid.update_attributes(params[:bid]) + @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) + if @bid.update_attributes(params[:bid]) && @bid.save flash[:notice] = l(:label_update_homework_succeed) - #@project = Project.find(params[:course_id]) redirect_to project_homework_path(@project) else @bid.safe_attributes = params[:bid] diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb new file mode 100644 index 000000000..01578eab3 --- /dev/null +++ b/app/controllers/homework_attach_controller.rb @@ -0,0 +1,61 @@ +class HomeworkAttachController < ApplicationController + #显示作业信息 + def show + @homework = HomeworkAttach.find(params[:id]) + # 打分统计 + stars_reates = @homework. + rates(:quality) + stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + stars_status = stars_reates.select("stars, count(*) as scount"). + group("stars") + @stars_status_map = Hash.new(0.0) + stars_status.each do |star_status| + percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f + percent_m = format("%.2f", percent) + @stars_status_map["star#{star_status.stars.to_i}".to_sym] = + percent_m.to_s + "%" + end + @jours = @homework.journals_for_messages.order("created_on DESC") + @limit = 10 + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + end + + #删除留言 + def destroy + @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) + respond_to do |format| + format.js + end + end + + #添加留言 + def addjours + @homework = HomeworkAttach.find(params[:jour_id]) + @homework.addjours User.current.id, params[:new_form][:user_message],0 + @jours = @homework.journals_for_messages.order("created_on DESC") + @limit = 10 + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + respond_to do |format| + format.js + end + end + + #获取指定作业的平均得分 + def score + #stars_reates = @homework.rates(:quality) + #percent = 0 + #stars_reates.each do |star_reates| + # percent = percent + star_reates.stars + #end + #stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + #result = percent * 1.0 / stars_reates_count + #result + end +end + diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index fb743ab5c..d112ead50 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -2,9 +2,26 @@ class HomeworkAttach < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :user belongs_to :bid + has_many :journals_for_messages, :as => :jour, :dependent => :destroy + seems_rateable :allow_update => true, :dimensions => :quality safe_attributes "bid_id", "user_id" acts_as_attachable - + + def addjours user_id,message,status = 0 + jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status) + jfm.save + jfm + end + + def score + stars_reates = self.rates(:quality) + percent = 0 + stars_reates.each do |star_reates| + percent = percent + star_reates.stars + end + result = percent * 1.0 / stars_reates.count + result + end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 2c4f10886..575737401 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -21,6 +21,7 @@ class JournalsForMessage < ActiveRecord::Base belongs_to :jour, :polymorphic => true belongs_to :user + belongs_to :homework_attach belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id' acts_as_event :title => Proc.new {|o| "#{l(:label_my_message)}"}, diff --git a/app/views/attachments/_app_link.html.erb b/app/views/attachments/_app_link.html.erb index ecef4dda3..6934b76e1 100644 --- a/app/views/attachments/_app_link.html.erb +++ b/app/views/attachments/_app_link.html.erb @@ -1,10 +1,15 @@ -<% for attachment in attachments %><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> - <% if attachment.is_text? %> +<% for attachment in attachments %> + <% if attachments.count > 1 && attachment != attachments.first%> +
                 + <% end %> + <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), :controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename %> <% end %> <%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) + <% end -%> diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index f05c4e9b0..bdf65a96f 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -6,6 +6,7 @@ <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <% end %> diff --git a/app/views/attachments/renderTag.js.erb b/app/views/attachments/renderTag.js.erb new file mode 100644 index 000000000..7e45299d5 --- /dev/null +++ b/app/views/attachments/renderTag.js.erb @@ -0,0 +1,3 @@ +<%if @attachmentNew != nil%> +$("#div-attachments[" + @attachmentNew.id + "]").html('<%= j(render :partial => 'tags/tag', :locals => {:obj => @attachmentNew, :object_flag => "6"})%>'); +<%end%> diff --git a/app/views/attachments/upload.js.erb b/app/views/attachments/upload.js.erb index 82b79bb63..63492688a 100644 --- a/app/views/attachments/upload.js.erb +++ b/app/views/attachments/upload.js.erb @@ -11,4 +11,6 @@ fileSpan.find('a.remove-upload') "href": '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>' }) .off('click'); +var divattach = fileSpan.find('div.div_attachments'); +divattach.html('<%= j(render :partial => 'tags/tag', :locals => {:obj => @attachment, :object_flag => "6"})%>'); <% end %> diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 8f87a6b37..35c414699 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -25,8 +25,31 @@ <%= image_tag(url_to_avatar(homework.user), :class => "avatar")%> +    作业   :  + <% filename = "" %> + <% homework.attachments.map do |attachment| %> + <% filename = attachment.filename %> + <% if homework.attachments.count > 1%> + <% filename += "等#{homework.attachments.count}个文件" %> + <% end %> + <% break %> + <% end %> + <%= link_to filename , homework_attach_path(homework)%> + - + + diff --git a/app/views/bids/show_project.html.erb b/app/views/bids/show_project.html.erb index d22ddded6..02ef72e7c 100644 --- a/app/views/bids/show_project.html.erb +++ b/app/views/bids/show_project.html.erb @@ -60,7 +60,6 @@ $("#put-bid-form").hide(); } - <% if User.current.logged? %> @@ -89,15 +88,15 @@ - <% end %> + <% end %>
<%= link_to homework.user, user_path(homework.user)%> 已提交  + 发布人:  <%= link_to homework.user, user_path(homework.user)%> + + 作业评分: + <% stars_reates = homework.rates(:quality) %> + <% sum = 0 %> + <% stars_reates.each do |star_reates| %> + <% sum = sum + star_reates.stars %> + <% end %> + <% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %> + <%= sum * 1.0 / stars_reates_count %> + <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.attachments[0].created_on.to_s) %> 迟交 @@ -36,7 +59,7 @@
  <% if display_id %> - <%= l(:label_bidding_user_studentcode) %> :<%= homework.user.user_extensions.student_id%> + <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> <% end %>
<%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason), :style => "resize: none;", :class => 'noline'%>
<%= submit_tag l(:button_add), :name => nil , :class => "enterprise", :onmouseout => "this.style.backgroundPosition = 'left top'", :onmouseover => "this.style.backgroundPosition = 'left -30px'"%> - <%= submit_tag l(:button_cancel), :name => nil, :onclick => "cancel();", + <%= submit_tag l(:button_cancel), :name => nil, :onclick => "cancel();", :type => 'button', :class => "enterprise", :onmouseout => "this.style.backgroundPosition = 'left top'", - :onmouseover => "this.style.backgroundPosition = 'left -30px'" %> + :onmouseover => "this.style.backgroundPosition = 'left -30px'" %>
diff --git a/app/views/homework_attach/_addjour.html.erb b/app/views/homework_attach/_addjour.html.erb new file mode 100644 index 000000000..a5e7bed66 --- /dev/null +++ b/app/views/homework_attach/_addjour.html.erb @@ -0,0 +1,93 @@ + + + + + +<%= form_for('new_form', :remote => true, :method => :post, + :url => {:controller => 'homework_attach', + :action => 'addjours', + :jour_id => homework_attach.id, + :sta => sta}) do |f|%> + +
+ <%= render :partial => 'words/pre_show', :locals => {:content => @content} %> +
+ + <% if User.current.logged? %> + + + + +
<%= f.text_area 'user_message', :rows => 3, :cols => 65, :value => "#{l(:label_leave_a_message)}", + :onfocus => "clearInfo('new_form_user_message','#{l(:label_leave_a_message)}')", + :onblur => "showInfo('new_form_user_message','#{l(:label_leave_a_message)}')", + :style => "resize: none;", :class => 'noline'%>
+ <%= f.text_field :reference_user_id, :style=>"display:none"%> + + + + +
<%= submit_tag l(:button_leave_meassge), + :name => nil , :class => "enterprise", + :onmouseout => "this.style.backgroundPosition = 'left top'", + :onmouseover => "this.style.backgroundPosition = 'left -31px'"%> + <%= submit_tag l(:button_clear), :name => nil, :class => "enterprise", + :onclick => "clearMessage('new_form_user_message');", + :onmouseout => "this.style.backgroundPosition = 'left top'", + :onmouseover => "this.style.backgroundPosition = 'left -31px'" %>
+ <% else %> +
+ <%= l(:label_user_login_tips) %> + <%= link_to l(:label_user_login_new), signin_path %> +
+ <% end %> +<% end %> diff --git a/app/views/homework_attach/_pre_show.html.erb b/app/views/homework_attach/_pre_show.html.erb new file mode 100644 index 000000000..1fb643183 --- /dev/null +++ b/app/views/homework_attach/_pre_show.html.erb @@ -0,0 +1,11 @@ + +<% unless content.nil?%> + + + + + + + +
<%= textilizable content %>
<%= hidden_field_tag 'reference_content', params[:reference_content], :value => content%>
+<% end %> diff --git a/app/views/homework_attach/_showjour.html.erb b/app/views/homework_attach/_showjour.html.erb new file mode 100644 index 000000000..f810082c9 --- /dev/null +++ b/app/views/homework_attach/_showjour.html.erb @@ -0,0 +1,64 @@ + +<% if jour.size > 0 %> + +<% end %> \ No newline at end of file diff --git a/app/views/homework_attach/addjours.js.erb b/app/views/homework_attach/addjours.js.erb new file mode 100644 index 000000000..e463237e5 --- /dev/null +++ b/app/views/homework_attach/addjours.js.erb @@ -0,0 +1,4 @@ +$('#message').html('<%= escape_javascript(render(:partial => 'showjour', :locals => {:jour =>@jour, :state => false} )) %>'); +$('#pre_show').html('<%= escape_javascript(render(:partial => 'pre_show', :locals => {:content => nil})) %>'); +$('#new_form_user_message').val(""); +$('#new_form_reference_user_id').val(""); \ No newline at end of file diff --git a/app/views/homework_attach/destroy.js.erb b/app/views/homework_attach/destroy.js.erb new file mode 100644 index 000000000..f3d9a7bef --- /dev/null +++ b/app/views/homework_attach/destroy.js.erb @@ -0,0 +1,11 @@ +<% if @journal_destroyed.nil? %> + alert('<%=l(:notice_failed_delete)%>'); +<% elsif (['Principal','Project', 'Bid', 'Contest', 'Softapplication','HomeworkAttach'].include? @journal_destroyed.jour_type)%> + var destroyedItem = $('#word_li_<%=@journal_destroyed.id%>') + destroyedItem.fadeOut(600,function(){ + destroyedItem.remove(); + }); +<% else %> + $('#message').html('<%= escape_javascript(render(:partial => 'showjour', :locals => {:jour => @jour, :state => false})) %>'); + $('#new_form_reference_user_id').val(""); +<% end %> diff --git a/app/views/homework_attach/show.html.erb b/app/views/homework_attach/show.html.erb new file mode 100644 index 000000000..1400176c2 --- /dev/null +++ b/app/views/homework_attach/show.html.erb @@ -0,0 +1,125 @@ + + +

<%= notice %>

+ +
+ + + + + + + + + + + + + + + + + + + + + +
作业基础信息<%=@count %>
发布人员:<%= link_to @homework.user, user_path(@homework.user)%>发布时间:<%=format_time @homework.created_at %>
+ 作业下载: + <% options = {:author => true } %> + <%= render :partial => 'attachments/app_link', :locals => {:attachments => @homework.attachments, :options => options} %> + 所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%>
平均评分: + <%= rating_for @homework, :static => true, dimension: :quality, class: 'rateable div_inline' %> +
+ + +
+
+ +
+ + + + + + + + + <% @homework.attachments.map do |attachment| %> + <% if attachment.description != nil && attachment.description != "" %> + + + + <% end %> + <% end %> +
作业描述:
+
<%= attachment.description %>
+
+ + +
+
+ +
+
作业得分:
+
+
+
得分比例
+
+ <% 100.step(20,-20) do |star| %> +
+
+
+
+
+
+ <%= @stars_status_map["star#{(star/20).to_s}".to_sym] %> +
+ <% end %> +
+
+
+
最终得分
+
+ <%= rating_for @homework, :static => true, dimension: :quality, class: 'rateable div_inline' %> +
+
+
+
打分总人数
+
+ + <%= @homework.raters(:quality).count%> + +
+
+
+
+
+ +
+
作业评论:
+
评分: + <%= rating_for @homework, dimension: :quality, class: 'rateable div_inline' %> + (您可以重新打分,打分结果以最后一次打分为主!) +
+ +
+ + +
+ <%= render :partial => 'addjour', :locals => {:homework_attach => @homework, :sta => 0} %> +
+ + +
+ <%= render :partial => 'showjour', :locals => {:jour => @jours} %> +
+
+<%#= link_to '返回竞赛页面', show_softapplication_contest_path(@softapplication.contest) %> +
diff --git a/app/views/softapplications/_new_message.erb b/app/views/softapplications/_new_message.erb index 321c7911f..ff63a3675 100644 --- a/app/views/softapplications/_new_message.erb +++ b/app/views/softapplications/_new_message.erb @@ -15,7 +15,7 @@ } -<%= form_for('softapplication_message', +<%= form_for('softapplication_message', :remote => true, :method => :post, :url => {:controller => 'softapplications', :action => 'create_message', @@ -23,19 +23,19 @@ :sta => sta} ) do |f|%> -
+
<%= render :partial => 'pre_show', :locals => {:content => @content} %>
- + <% if User.current.logged? %>
<%= f.text_area 'message', :rows => 3, :cols => 65, :placeholder => l(:label_my_respond), :style => "resize: none;", :class => 'noline'%>
- + <%= f.text_field :reference_user_id, :style=>"display:none"%> - + diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 205143924..dc94b3571 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -47,7 +47,7 @@ <%= form_for "tag_for_save",:remote=>true,:url=>tag_path, :update => "tags_show", :complete => "$(\"#put-tag-form-#{obj.class}-#{obj.id}\").hide();" do |f| %> - <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length %> + <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length,:style=>"width: 100px;"%> <%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%> <%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%> <%= f.submit l(:button_project_tags_add),:class => "small" %> diff --git a/app/views/words/_message.html.erb b/app/views/words/_message.html.erb index 6b002746e..3e066a513 100644 --- a/app/views/words/_message.html.erb +++ b/app/views/words/_message.html.erb @@ -54,7 +54,7 @@ function checkMaxLength() { <%= link_to l(:label_projects_feedback_respond),'', {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.name}: '); $('##{ids} textarea') ;return false;"} %> - <% end %> + <% end %> <% if @user == User.current || User.current.admin? || journal.user.id == User.current.id %> <%= link_to(l(:label_newfeedback_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => user}, :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) %> diff --git a/config/routes.rb b/config/routes.rb index d93112c54..194776853 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,7 +22,8 @@ RedmineApp::Application.routes.draw do resources :apply_project_masters delete 'apply_project_masters', :to => 'apply_project_masters#delete' - + resources :homework_attach + match 'homework_attach/addjours', :controller => 'homework_attach', :action => 'addjours', :via => [:get,:post] resources :open_source_projects do collection do match 'search', via: [:get, :post] @@ -37,6 +38,7 @@ RedmineApp::Application.routes.draw do end mount SeemsRateable::Engine => '/rateable', :as => :rateable + namespace :zipdown do match 'assort' end @@ -458,9 +460,11 @@ RedmineApp::Application.routes.draw do get 'attachments/autocomplete' match 'attachments/autocomplete', :to => 'attachments#autocomplete', via: [:post] post 'attachments/relationfile', to: 'attachments#add_exist_file_to_project', as: 'attach_relation' + get 'attachments/renderTag/:attchmentId', :to => 'attachments#renderTag', :attchmentId => /\d+/ resources :attachments, :only => [:show, :destroy] do collection do match "updateType" , via: [:get, :post] + match "renderTag" , via: [:get, :post] end end diff --git a/public/images/edit.png b/public/images/edit.png new file mode 100644 index 000000000..8335716fd Binary files /dev/null and b/public/images/edit.png differ diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 3d1520f84..663183b9a 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -1,6 +1,17 @@ /* Redmine - project management software Copyright (C) 2006-2013 Jean-Philippe Lang */ +function postUpMsg(attachmentId) +{ + $.ajax({ + url: '/attachments/renderTag', + type: "GET", + data: { + attachmentId: attachmentId + } + + }) +} function addFile(inputEl, file, eagerUpload) { if ($('#attachments_fields').children().length < 10) { @@ -12,14 +23,15 @@ function addFile(inputEl, file, eagerUpload) { fileSpan.append( $('', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name), $('', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 255, 'placeholder': $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload), - $(' ').attr({ 'href': "#", 'class': 'remove-upload', 'data-confirm' : "您确定要删除吗?" }).click(removeFile).toggle(!eagerUpload) + $(' ').attr({ 'href': "#", 'class': 'remove-upload', 'data-confirm' : "您确定要删除吗?" }).click(removeFile).toggle(!eagerUpload), + $('
', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) ).appendTo('#attachments_fields'); - - if(eagerUpload) { - ajaxUpload(file, attachmentId, fileSpan, inputEl); - } - return attachmentId; + if(eagerUpload) { + ajaxUpload(file, attachmentId, fileSpan, inputEl); + + } + return attachmentId; } return null; } @@ -66,7 +78,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) { //gcm files count and add delete_all link - var count=$('#attachments_fields>span').length; + var count=$('#attachments_fields>span').length; $('#upload_file_count').html("已上传"+""+count+""+"个文件"); if(count>=1){ diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index d786101b1..1a1c1b2ea 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1829,7 +1829,7 @@ fieldset#notified_events .parent { padding-left: 20px; } span.required {color: #bb0000;} .summary {font-style: italic;} -#attachments_fields input.description {margin-left:4px; width:340px; } +#attachments_fields input.description {margin-left:4px; width:100px; } #attachments_fields span {display:block; white-space:nowrap; font-family:'微软雅黑';} #attachments_fields input.filename {border:0; height:1.8em; width:150px; color:#555; background-color:inherit; background:url(../images/attachment.png) no-repeat 1px 50%; padding-left:18px;}/*Modified by young*/ #attachments_fields .ajax-waiting input.filename {background:url(../images/hourglass.png) no-repeat 0px 50%;}