diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 51b7fa804..a25b346ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -353,14 +353,13 @@ class ApplicationController < ActionController::Base url end - def redirect_back_or_default(default) + def redirect_back_or_default(default, options={}) back_url = params[:back_url].to_s if back_url.present? begin uri = URI.parse(back_url) # do not redirect user to another host or to the login or register page - #by young - if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) && (uri.path!='/') + if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) redirect_to(back_url) return end @@ -368,6 +367,9 @@ class ApplicationController < ActionController::Base logger.warn("Could not redirect to invalid URL #{back_url}") # redirect to default end + elsif options[:referer] + redirect_to_referer_or default + return end redirect_to default false diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 32878a2cd..dfe8b9b0b 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -735,12 +735,12 @@ class BidsController < ApplicationController @homework.save_attachments(params[:attachments]) render_attachment_warning_if_needed(@homework) - - if @homework.save - @homework_flag = l(:label_bidding_homework_succeed) - else - @homework_flag = l(:label_bidding_homework_failed) - end + + @homework_flag = if @homework.save + l(:label_bidding_homework_succeed) + else + l(:label_bidding_homework_failed) + end if @homework.attachments.empty? @homework.delete @@ -754,7 +754,9 @@ class BidsController < ApplicationController @homework_list = @bid.homeworks respond_to do |format| format.html{ - redirect_to project_for_bid_path, notice: @homework_flag.to_s + #redirect_to project_for_bid_path, notice: @homework_flag.to_s + flash[:notice] = @homework_flag.to_s + redirect_back_or_default(project_for_bid_path) } format.js end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 71c9b0e7e..0182f2121 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -144,7 +144,6 @@ class TagsController < ApplicationController @taggable_type = numbers_to_object_type(params[:taggable_type]) @obj = get_object(@taggable_id,params[:taggable_type]) - logger.debug "==========================================#{@obj}" @object_flag = params[:taggable_type] # if can_remove_tag?(User.current,@taggable_id,@taggable_type) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 34734bf54..31168595e 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -102,7 +102,8 @@ class WelcomeController < ApplicationController def fake @fake_filter = true end - + + # 骗子方法 def _fake instance_variables.map { |variable| if variable.to_s =~ /Count$/ diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 18b884ab4..7bdb19188 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1474,12 +1474,8 @@ module ApplicationHelper def hadcommittedhomework(cur,curb) - @attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") - @attaches.each do |attach| - if attach.user_id == cur - return true - end - end + attaches = HomeworkAttach.where(bid_id: curb) + attaches.map(&:user_id).include? cur end def render_dynamic_nav diff --git a/app/models/bid.rb b/app/models/bid.rb index d5177116e..fd389c15f 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -1,11 +1,20 @@ ####by fq =begin bid一类多用,根据reward_type字段分类 -reward == 1 企业众包需求 -reward == 2 创新竞赛 -reward == 3 课程中布置的作业 +reward_type == 1 企业众包需求 +reward_type == 2 创新竞赛 +reward_type == 3 课程中布置的作业 + +homework_type作业类型 +homework_type == 1 文件提交 +homework_type == 2 Project提交 =end class Bid < ActiveRecord::Base + Enterprise = 1 + Contest = 2 + Homework = 3 + HomeworkFile = 1 + HomeworkProject = 2 attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password include Redmine::SafeAttributes diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 101779297..69f65e488 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -14,6 +14,9 @@ <%= l(:label_user_create_project_homework) %> <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %> + <%# 提交作业按钮,上传文件的作业直接显示上传框,关联项目的作业跳转到新页面 %> + <%= link_to l(:label_commit_homework), 'javascript:void(0);', onclick: "$('#bid-submit-homework-#{bid.id}').toggle();" if bid.homework_type==Bid::HomeworkFile %> + <%= link_to(l(:label_commit_homework), respond_path(bid), :class => 'bid_path', target: "_blank") if bid.homework_type==Bid::HomeworkProject %> <% if (User.current.admin?||User.current.id==bid.author_id) %> <%= link_to( l(:button_edit), @@ -29,7 +32,6 @@ ) %> <% end %> - @@ -62,6 +64,11 @@ <%= bid.description %> + <%# 提交作业partial %> + + <%= render partial: 'homeworkupload', locals: {bid: bid} %> + + <%= l(:label_create_time) %> :  <%=format_time bid.created_on %> <%= l(:field_deadline) %> :  <%=bid.deadline %> diff --git a/app/views/projects/_homeworkupload.html.erb b/app/views/projects/_homeworkupload.html.erb new file mode 100644 index 000000000..e6176b3ad --- /dev/null +++ b/app/views/projects/_homeworkupload.html.erb @@ -0,0 +1,22 @@ +<% if hadcommittedhomework(User.current.id, bid.id) %> + <%#= l(:label_bidding_homework_committed) %> + 作业已经提交 +<% else %> + <% if bid.reward_type==Bid::Homework && + bid.homework_type==Bid::HomeworkFile %> + <%= form_for HomeworkAttach.new, :url => {:controller => 'bids', :action => 'add_homework', id: bid.id, back_url: request.url() }, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %> +
+
+ + 作业文件上传 + +

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

+
+
+ <%= submit_tag l(:button_create), :onclick => "return true" %> + <% end %> + + <% end %> +<% end %> diff --git a/public/stylesheets/nyan.css b/public/stylesheets/nyan.css index 7fefa1a63..7c1110c36 100644 --- a/public/stylesheets/nyan.css +++ b/public/stylesheets/nyan.css @@ -58,6 +58,9 @@ .hidden { display: none; } +.font_color_orange{ + color: #E8770D; +} * { font-family: Helvetica, Tahoma, Arial, "Microsoft YaHei", "微软雅黑", SimSun, "宋体", STXihei, "华文细黑", Heiti, "黑体", sans-serif;