From 029eb1a19538484944abdde5b493d36f43b8f95b Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 16 May 2014 11:02:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 27 ++++ app/models/homework_attach.rb | 4 +- app/models/journals_for_message.rb | 1 + app/views/attachments/_app_link.html.erb | 9 +- app/views/bids/_homework_list.html.erb | 15 +- app/views/bids/show_project.html.erb | 7 +- app/views/homework_attach/show.html.erb | 148 ++++++++++++++++++ app/views/softapplications/_new_message.erb | 10 +- config/routes.rb | 2 +- 9 files changed, 208 insertions(+), 15 deletions(-) create mode 100644 app/controllers/homework_attach_controller.rb create mode 100644 app/views/homework_attach/show.html.erb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb new file mode 100644 index 000000000..cfa84071b --- /dev/null +++ b/app/controllers/homework_attach_controller.rb @@ -0,0 +1,27 @@ +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") + end + + def destroyjours + @homework = HomeworkAttach.find(params[:homework_id]) + JournalsForMessage.delete_message(params[:object_id]) + redirect_to homework_attach_path(@homework) + end +end + diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index fb743ab5c..b8e559dff 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -2,9 +2,11 @@ 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 - + 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/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 8f87a6b37..f3658cd2a 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -25,8 +25,19 @@ <%= 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)%> <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.attachments[0].created_on.to_s) %> 迟交 @@ -36,7 +47,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/show.html.erb b/app/views/homework_attach/show.html.erb new file mode 100644 index 000000000..93e3d0a70 --- /dev/null +++ b/app/views/homework_attach/show.html.erb @@ -0,0 +1,148 @@ +<%= render_flash_messages %> + +

<%= 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' %> + (您可以重新打分,打分结果以最后一次打分为主!) +
+ +
+ + +
+ <% if User.current.logged? %> + <% else %> + <% end %> +
+ + + +
+<%#= 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/config/routes.rb b/config/routes.rb index a5dc322cf..f0bdfede8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,7 +22,7 @@ RedmineApp::Application.routes.draw do resources :apply_project_masters delete 'apply_project_masters', :to => 'apply_project_masters#delete' - + resources :homework_attach resources :open_source_projects do collection do match 'search', via: [:get, :post]