diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 2a0f97613..c3ac15197 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -1,4 +1,90 @@ class HomeworkAttachController < ApplicationController + ############################### + def index + @homeworks = HomeworkAttach.all + respond_to do |format| + format.html # index.html.erb + format.json { render json: @homeworks } + end + end + + def add_users users + if users != nil && users.count > 0 + users.each do |user| + @homework.homework_users.build(:user_id => user.id) + @homework.save + end + end + end + + def create + if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) + user_id = params[:user_id] + bid_id = params[:bid_id] + sta = 0 + name = params[:new_form][:name] + description = params[:new_form][:description] + options = { + :user_id => user_id, + :state => sta, + :name => name, + :description => description, + :bid_id => bid_id + } + + @homework = HomeworkAttach.new(options) + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + @homework.save + respond_to do |format| + if @homework.save + format.html { redirect_to @homework, notice: 'Post was successfully created.' } + format.json { render json: @homework, status: :created, location: @homework } + else + format.html { render action: "new" } + format.json { render json: @homework.errors, status: :unprocessable_entity } + end + end + end + end + + def new + @homework = HomeworkAttach.new + @bid = Bid.find(params[:id]) + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @homework } + end + end + + def edit + @homework = HomeworkAttach.find(params[:id]) + end + + def update + @homework = HomeworkAttach.find(params[:id]) + respond_to do |format| + if @post.update_attributes(params[:homework]) + format.html { redirect_to @homework, notice: 'Homework was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @homework.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @homework = HomeworkAttach.find(params([:id])) + @homework.destroy + respond_to do |format| + format.html {render @homework} + format.json {render json: @homework} + end + end + #显示作业信息 def show @homework = HomeworkAttach.find(params[:id]) @@ -24,7 +110,7 @@ class HomeworkAttachController < ApplicationController end #删除留言 - def destroy + def destroy_jour @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) #@homework = HomeworkAttach.find(params[:id]) #@jours = @homework.journals_for_messages.order("created_on DESC") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9418f4749..228f57ab6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -28,7 +28,6 @@ module ApplicationHelper include AvatarHelper ## added by william include PraiseTreadHelper - # add by nyan include CoursesHelper extend Forwardable @@ -1330,7 +1329,7 @@ module ApplicationHelper def hubspot_head tags = javascript_include_tag('hubspot/messenger.min', 'hubspot/messenger-theme-future') - tags << stylesheet_link_tag('hubspot/messenger', 'hubspot/messenger-theme-future') + tags << stylesheet_link_tag('hubspot/messenger', 'hubspot/messenger-theme-future', 'hubspot/messenger-theme-flat') unless User.current.pref.warn_on_leaving_unsaved == '0' tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 97cca617e..45ebaf247 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -136,4 +136,15 @@ module CoursesHelper def find_by_extra_from_project extra Course.find_by_extra(try(extra)) end + #判断制定用户是不是当前课程的老师 + def is_course_teacher user,project + is_teacher = false + searchTeacherAndAssistant(project).each do |teacher| + if user == teacher + is_teacher = true + break + end + end + is_teacher + end end diff --git a/app/models/homework_user.rb b/app/models/homework_user.rb index da7e65afb..0adef62c4 100644 --- a/app/models/homework_user.rb +++ b/app/models/homework_user.rb @@ -2,5 +2,5 @@ class HomeworkUser < ActiveRecord::Base attr_accessible :homework_attach_id, :user_id belongs_to :homework_attach - has_one :user + belongs_to :user end diff --git a/app/models/project.rb b/app/models/project.rb index 1c672c5fc..20c5de89b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -122,7 +122,8 @@ class Project < ActiveRecord::Base after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} - after_save :create_board_sync #nyan + # 创建project之后默认创建一个board,之后的board去掉了board的概念 + after_save :create_board_sync before_destroy :delete_all_members def remove_references_before_destroy return if self.id.nil? diff --git a/app/models/user.rb b/app/models/user.rb index 8017ed5f8..c96e38595 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -73,7 +73,7 @@ class User < Principal ['none', :label_user_mail_option_none] ] - has_one :homework_user + belongs_to :homework_user has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} diff --git a/app/views/applied_project/_set_applied.js.erb b/app/views/applied_project/_set_applied.js.erb index e77592060..7403b963b 100644 --- a/app/views/applied_project/_set_applied.js.erb +++ b/app/views/applied_project/_set_applied.js.erb @@ -1,4 +1,13 @@ <% selector = ".#{applied_css(@project)}" %> $("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript applied_link(@project, User.current) %>")}); - - +if (window.Messenger) { + Messenger.options = { + extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right', + theme: 'flat' + } + Messenger().post({ + id: "label_apply_project_waiting", + message: "<%= l(:label_apply_project_waiting) %>", + showCloseButton: true, + }); +}; diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 35c414699..c9a8af0a4 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -1,23 +1,27 @@ +<% is_teacher = is_course_teacher User.current,@bid.courses.first.project %> <%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>
- +
<%= l(:label_task_plural)%>(<%= @homework_list.count%>)<%= l(:label_task_plural)%>(<%= @homework_list.count%>) + <%= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if( + User.current.admin? || + !(User.current.roles_for_project(@bid.courses.first).map(&:id) & ([7,9])).empty? ) || + (Rails.env.development?) %> +
<% end %> <% display_id = im_watching_student_id? @bid%> -<%= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;display: inline-block;" if( - User.current.admin? || - !(User.current.roles_for_project(@bid.courses.first).map(&:id) & ([7,9])).empty? ) || - (Rails.env.development?) %> <% @homework_list.each do |homework|%> <% if homework.attachments.any?%> @@ -25,16 +29,25 @@
<%= 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}个文件" %> + + +
+   作业   :  + <% attachments = homework.attachments.map %> + <% for attachment in attachments %> + <% if attachments.count > 1 && attachment != attachments.first %> +
+ <% for item in 1..7 %> +   + <% end %> + <% end %> + <%= link_to_attachment attachment , :download => true -%> <% end %> - <% break %> - <% end %> - <%= link_to filename , homework_attach_path(homework)%> +
+ <% if display_id %> + <%= link_to "互评>>" , homework_attach_path(homework)%> + <% end %> +
  @@ -48,7 +61,7 @@ <% sum = sum + star_reates.stars %> <% end %> <% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %> - <%= sum * 1.0 / stars_reates_count %> + <%= format("%.2f", sum * 1.0 / stars_reates_count) %> <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.attachments[0].created_on.to_s) %> @@ -58,20 +71,20 @@
  - <% if display_id %> - <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> - <% end %> + <% if display_id %> + <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> + <% end %>
- <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> -

- <% options = {:author => true, :deletable => attach_delete(homework)} %> - <%= render :partial => 'attachments/links', - :locals => {:attachments => homework.attachments, :options => options} %> -

- <% end %> + <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> +

+ <% options = {:author => true, :deletable => attach_delete(homework)} %> + <%= render :partial => 'attachments/links', + :locals => {:attachments => homework.attachments, :options => options} %> +

+ <% end %>
diff --git a/app/views/bids/show_project.html.erb b/app/views/bids/show_project.html.erb index d5676c3c8..c14d2e14c 100644 --- a/app/views/bids/show_project.html.erb +++ b/app/views/bids/show_project.html.erb @@ -32,18 +32,16 @@ -
+
- <% if @bid.reward_type == 3 %> + <% if @bid.reward_type == Bid::Homework %> diff --git a/app/views/homework_attach/_app_link.html.erb b/app/views/homework_attach/_app_link.html.erb new file mode 100644 index 000000000..8adf5220e --- /dev/null +++ b/app/views/homework_attach/_app_link.html.erb @@ -0,0 +1,12 @@ + +<% 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 %> + <% end -%> diff --git a/app/views/homework_attach/_journal_reply_items.html.erb b/app/views/homework_attach/_journal_reply_items.html.erb index 85f7fa304..e9aad84ce 100644 --- a/app/views/homework_attach/_journal_reply_items.html.erb +++ b/app/views/homework_attach/_journal_reply_items.html.erb @@ -19,8 +19,8 @@ %> <% end %> <% if @user == User.current || User.current.admin? || reply.user.id == User.current.id %> - <%= link_to(l(:label_newfeedback_delete), {:controller => 'homework_attach', :action => 'destroy', :object_id => reply, :user_id => reply.user}, - :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) %> + <%= link_to(l(:label_newfeedback_delete), {:controller => 'homework_attach', :action => 'destroy_jour', :object_id => reply, :user_id => reply.user}, + :remote => true, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %> <% end %>

diff --git a/app/views/homework_attach/_showjour.html.erb b/app/views/homework_attach/_showjour.html.erb index dbd7f2547..939deff3b 100644 --- a/app/views/homework_attach/_showjour.html.erb +++ b/app/views/homework_attach/_showjour.html.erb @@ -54,8 +54,8 @@ {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.name}: '); $('##{ids} textarea') ;return false;"} %> <% if journal.user==User.current|| User.current.admin? %> - <%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy', :object_id => journal, :user_id => journal.user}, - :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) %> + <%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy_jour', :object_id => journal, :user_id => journal.user}, + :remote => true, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %> <% end %> diff --git a/app/views/homework_attach/destroy.js.erb b/app/views/homework_attach/destroy_jour.js.erb similarity index 100% rename from app/views/homework_attach/destroy.js.erb rename to app/views/homework_attach/destroy_jour.js.erb diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb new file mode 100644 index 000000000..073ab21b2 --- /dev/null +++ b/app/views/homework_attach/new.html.erb @@ -0,0 +1,33 @@ +

<%=raw l(:label_new_homework)%>

+
+ <%= form_for('new_form', :remote => true, :method => :post, + :url => {:controller => 'homework_attach', + :action => 'create', + :user_id => User.current.id, + :bid_id => @bid + }) do |f|%> +

+ 标题: + <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> +

+

+ 描述: + + <%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +

+
+ + <%= l(:label_attachment_plural) %> + +

+ <%= render :partial => 'attachments/form' %> +

+
+ + <%= submit_tag t(:label_new), :sta => 0, :class => "enterprise"%> + <%= submit_tag t(:label_memo_create), :sta => 1, :class => "enterprise"%> + +

+ <% end %> +
\ No newline at end of file diff --git a/app/views/homework_attach/show.html.erb b/app/views/homework_attach/show.html.erb index 1400176c2..d7c1e8eb0 100644 --- a/app/views/homework_attach/show.html.erb +++ b/app/views/homework_attach/show.html.erb @@ -18,7 +18,9 @@ - + @@ -26,9 +28,11 @@ + - @@ -49,7 +53,7 @@
<%= select_tag 'bid', options_for_select(select_option_helper(@option)), :name => 'bid', :class => 'grayline' %> -

<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %>
-

<%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason_homework), :style => "resize: none;", :class => 'noline' %>
作业基础信息<%=@count %>
发布人员:<%= link_to @homework.user, user_path(@homework.user)%> + 发布人员:<%= 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} %> + <%= render :partial => 'app_link', :locals => {:attachments => @homework.attachments, :options => options} %> + + 所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%> 所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%>
- + <% @homework.attachments.map do |attachment| %> <% if attachment.description != nil && attachment.description != "" %> @@ -67,16 +71,20 @@
-
作业得分:
+
+ 作业得分: +
得分比例
<% 100.step(20,-20) do |star| %> -
+
-
+
<%= @stars_status_map["star#{(star/20).to_s}".to_sym] %> @@ -85,7 +93,11 @@
-
最终得分
+
最终得分
+
+ <%= @homework.average(:quality).try(:avg).try(:round, 2).to_s %> + 分 +
<%= rating_for @homework, :static => true, dimension: :quality, class: 'rateable div_inline' %>
@@ -102,6 +114,18 @@
+ +
作业评论:
评分: @@ -121,5 +145,4 @@ <%= render :partial => 'showjour', :locals => {:jour => @jours} %>
-<%#= link_to '返回竞赛页面', show_softapplication_contest_path(@softapplication.contest) %>
diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb index 6aef01e1d..f4857bd22 100644 --- a/app/views/issues/_attributes.html.erb +++ b/app/views/issues/_attributes.html.erb @@ -2,7 +2,7 @@
作业描述:
作业描述: