diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 91d3538b8..b7951fbe6 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -65,8 +65,6 @@ class BidsController < ApplicationController end def fork - @new_bid = Bid.new - @new_bid.safe_attributes = params[:bid] @courses = [] @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) @membership.each do |membership| @@ -99,7 +97,14 @@ class BidsController < ApplicationController end redirect_to respond_path(@homework) else - @homework.safe_attributes = params[:bid] + @bid.safe_attributes = params[:bid] + @courses = [] + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + if membership.project.project_type == 1 + @courses << membership.project + end + end render :action => 'fork' end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 67c0edb23..e9e35cbd1 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -109,7 +109,7 @@ class ProjectsController < ApplicationController # @project_pages = Paginator.new @project_count, @limit, params['page'] # @offset ||= @project_pages.offset # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all - + @project_type = params[:project_type] @offset, @limit = api_offset_and_limit({:limit => 10}) @projects_status = ProjectStatus.visible # @projects.each do |project| @@ -124,13 +124,13 @@ class ProjectsController < ApplicationController # @projects.each do |project| # ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count) # end - #@projects_status = Project.visible.like(params[:name]) if params[:name].present? + # @projects_status = Project.visible.like(params[:name]) if params[:name].present? @project_count = @projects_status.count @project_pages = Paginator.new @project_count, @limit, params['page'] @offset ||= @project_pages.reverse_offset - #@projects = @projects.offset(@offset).limit(@limit).order('created_on DESC').all + # @projects = @projects.offset(@offset).limit(@limit).order('created_on DESC').all if params[:project_sort_type].present? case params[:project_sort_type] when '0' @@ -347,7 +347,7 @@ class ProjectsController < ApplicationController @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.safe_attributes = params[:project][:course] @course.tea_id = User.current.id - @course.save + # @course.save # project = ProjectInfo.create(:user_id => User.current.id, :project_id => @project.id) # project_status = ProjectStatus.create(:project_id => @project.id) end @@ -358,42 +358,96 @@ class ProjectsController < ApplicationController if @course_tag == '1' @project.identifier = @course.extra end - - if validate_parent_id && @project.save - @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') - # Add current user as a project member if he is not admin - unless User.current.admin? - r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first - m = Member.new(:user => User.current, :roles => [r]) - project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) - if params[:project][:is_public] == '1' || @course_tag=="1" - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0) - end - @project.members << m - @project.project_infos << project - end - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_create) - if params[:continue] - attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} - redirect_to new_project_path(attrs, :course => '0') - #Added by young - - elsif params[:course_continue] - redirect_to new_project_path(:course => '1') - #Ended by young - else - redirect_to settings_project_path(@project) + if @course_tag == '1' + if@course.save + if validate_parent_id && @project.save + @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') + # Add current user as a project member if he is not admin + unless User.current.admin? + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) + if params[:project][:is_public] == '1' || @course_tag=="1" + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0) + end + @project.members << m + @project.project_infos << project end - } - format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + if params[:continue] + attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} + redirect_to new_project_path(attrs, :course => '0') + #Added by young + + elsif params[:course_continue] + redirect_to new_project_path(:course => '1') + #Ended by young + else + redirect_to settings_project_path(@project) + end + } + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } + end + else + @course.destroy + respond_to do |format| + format.html { render :action => 'new', :layout => 'base'}#Added by young + format.api { render_validation_errors(@project) } + end + end + else + if validate_parent_id && @project.save + @project.delete + respond_to do |format| + format.html { render :action => 'new', :layout => 'base'}#Added by young + format.api { render_validation_errors(@project) } + end + else + respond_to do |format| + format.html { render :action => 'new', :layout => 'base'}#Added by young + format.api { render_validation_errors(@project) } + end + end end else - respond_to do |format| - format.html { render :action => 'new', :layout => 'base'}#Added by young - format.api { render_validation_errors(@project) } - end + if validate_parent_id && @project.save + @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') + # Add current user as a project member if he is not admin + unless User.current.admin? + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) + if params[:project][:is_public] == '1' || @course_tag=="1" + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0) + end + @project.members << m + @project.project_infos << project + end + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + if params[:continue] + attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} + redirect_to new_project_path(attrs, :course => '0') + #Added by young + + elsif params[:course_continue] + redirect_to new_project_path(:course => '1') + #Ended by young + else + redirect_to settings_project_path(@project) + end + } + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } + end + else + respond_to do |format| + format.html { render :action => 'new', :layout => 'base'}#Added by young + format.api { render_validation_errors(@project) } + end + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 54ab7b76b..c16ff2f57 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1012,6 +1012,11 @@ module ApplicationHelper def error_messages_for(*objects) html = "" + # modified by fq + if objects.first.is_a?(Array) + objects = objects.first + end + # end objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact errors = objects.map {|o| o.errors.full_messages}.flatten if errors.any? diff --git a/app/models/course.rb b/app/models/course.rb index 276cc7652..a216798f0 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,11 +1,11 @@ class Course < ActiveRecord::Base include Redmine::SafeAttributes - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password belongs_to :project, :class_name => 'Project', :foreign_key => :extra # 定义一个project方法, 该方法通过extra来调用project表 belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 has_many :bid - validates_presence_of :state, :term + validates_presence_of :password, :term safe_attributes 'extra', 'time', 'name', @@ -13,7 +13,7 @@ class Course < ActiveRecord::Base 'code', 'location', 'tea_id', - 'state', + 'password', 'term' diff --git a/app/models/project.rb b/app/models/project.rb index 53e407246..9d3eb4a3d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -55,7 +55,7 @@ class Project < ActiveRecord::Base has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy - has_many :students_for_courses, :dependent => :destroy + # has_many :students_for_courses, :dependent => :destroy has_many :student, :through => :students_for_courses, :source => :user # has_one :cour, :class_name => 'Course', :foreign_key => :extra, :dependent => :destroy @@ -72,7 +72,7 @@ class Project < ActiveRecord::Base ##added by xianbo has_one :course, :dependent => :destroy ,:order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" accepts_nested_attributes_for :course - ##end + ##end # Custom field for the project issues has_and_belongs_to_many :issue_custom_fields, :class_name => 'IssueCustomField', diff --git a/app/views/bids/_fork_form.html.erb b/app/views/bids/_fork_form.html.erb index b84404527..c910a399a 100644 --- a/app/views/bids/_fork_form.html.erb +++ b/app/views/bids/_fork_form.html.erb @@ -11,7 +11,7 @@ :onChange => "show('bid_reward_type', 'bid_budget', '"+l(:label_bids_reward_what)+"','"+l(:label_bids_new_money)+"','"+l(:label_bids_new_credit)+"','"+l(:label_bids_new_content)+"')" %> <%= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;", :placeholder => l(:label_bids_reward_what) %>
--> -<%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%> +
<%= f.text_field :deadline, :value => nil,:required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>
<%= f.select :homework_type, homework_type_option %>
diff --git a/app/views/bids/fork.html.erb b/app/views/bids/fork.html.erb index d87221aca..592e71386 100644 --- a/app/views/bids/fork.html.erb +++ b/app/views/bids/fork.html.erb @@ -1,7 +1,7 @@<%= render :partial=>"avatar/avatar_form",:locals=> {source:@project} %>
-<% end %> +<%= 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;" %>
diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 8a8ae2a40..4739fd387 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -52,6 +52,6 @@
<%=link_to image_tag(url_to_avatar(@user), :class => "avatar"), user_path(@user)%> |
|