diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 53a0a2591..783e8222a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -43,7 +43,7 @@ class ProjectsController < ApplicationController before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise] before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, - :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond] + :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share] before_filter :authorize_global, :only => [:new, :create] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] #by young @@ -479,6 +479,15 @@ class ProjectsController < ApplicationController ##end render :layout => 'base' end + + def share + @shares = @project.shares.reverse + @base_courses_tag = @project.project_type + respond_to do |format| + format.html{render :layout => 'base_courses' if @base_courses_tag==1} + format.api + end + end def create diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb index 55b9e237d..e019af505 100644 --- a/app/controllers/shares_controller.rb +++ b/app/controllers/shares_controller.rb @@ -1,4 +1,6 @@ +# encoding: utf-8 class SharesController < ApplicationController + before_filter :require_login, :except => [:index] # GET /shares # GET /shares.json def index @@ -25,15 +27,31 @@ class SharesController < ApplicationController # GET /shares/new.json def new @share = Share.new + @user = User.current + @ps = @user.projects.all - #add by mkz 抓取参数传给share - - @share[:created_on] = params[:created_on] - @share[:title] = params[:title] - @share[:url] = params[:url] - @share[:share_type] = params[:share_type] - @share.save - # + projectName = params[:projectname] + userName = params[:username] + url = params[:url] + share_type = params[:share_type] + share_type ||= 0 #默认是测试结果分享 + description = params[:description] + + #deal params + if share_type == 0 && !params[:description].nil? + arr = params[:description].split(",") + # @share.description = @arr.join(",") + #description = "stcloud源代码测试平台:用户" << userName << "对项目" << projectName << "进行了测试。测试结果:" << "\n" + name = User.current.login.to_s.dup + description = name << "对项目进行了测试。测试结果:" << "\n" + description << "总缺陷数#{arr[0]},Fault数目#{arr[1]},Rule数目#{arr[2]},Question数目#{arr[3]},Safety数目#{arr[4]}。" + end + + @share[:title] = projectName + @share[:url] = url + @share[:share_type] = share_type + @share[:description] = description + respond_to do |format| format.html # new.html.erb @@ -50,10 +68,14 @@ class SharesController < ApplicationController # POST /shares.json def create @share = Share.new(params[:share]) - + if (@share.project_id.nil?) + flash[:notice] = l(:label_x_projects) + end + @share.user_id = User.current.id respond_to do |format| if @share.save - format.html { redirect_to @share, notice: 'Share was successfully created.' } + #format.html { redirect_to @share, notice: 'Share was successfully created.' } + format.html { render "succ", notice: 'Share was successfully created.' } format.json { render json: @share, status: :created, location: @share } else format.html { render action: "new" } @@ -66,7 +88,9 @@ class SharesController < ApplicationController # PUT /shares/1.json def update @share = Share.find(params[:id]) - + + @project = params[:project_id] + @share.user_id = User.current.id respond_to do |format| if @share.update_attributes(params[:share]) format.html { redirect_to @share, notice: 'Share was successfully updated.' } diff --git a/app/helpers/shares_helper.rb b/app/helpers/shares_helper.rb index e51aa8b87..f2cbc6ab9 100644 --- a/app/helpers/shares_helper.rb +++ b/app/helpers/shares_helper.rb @@ -1,2 +1,16 @@ module SharesHelper +def options_from_select_project(user) + @membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) + @option = [] + @membership.each do |membership| + unless(membership.project.project_type==1) + membership.member_roles.each{|role| + if(role.role_id == 3) + @option << membership.project + end + } + end + end + options_for_select(@option) +end end diff --git a/app/models/project.rb b/app/models/project.rb index 0e023da67..e45c8dc29 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -58,6 +58,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 :shares, :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 diff --git a/app/models/share.rb b/app/models/share.rb index 58f4f1aa1..dd77b4a1a 100644 --- a/app/models/share.rb +++ b/app/models/share.rb @@ -1,3 +1,18 @@ class Share < ActiveRecord::Base - attr_accessible :created_on, :share_type, :title, :url + include Redmine::SafeAttributes + attr_accessible :created_on, :share_type, :title, :url,:project_id,:user_id, :description + + validates_presence_of :project_id + + belongs_to :project + belongs_to :user + + safe_attributes 'project_id', + 'user_id', + 'url', + 'title', + 'share_type', + 'crated_on', + 'description' + end diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index ecca9b5b2..7493de1ab 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -131,10 +131,16 @@
+ 进入测试平台 +
+ +<% @shares.each do |share| %> +<%= image_tag(url_to_avatar(share.user), :class => "avatar")%> | +
+
|
+
- <%= textilizable( truncate(e.event_description, length: 240 ) %> + <%= textilizable( stringCut240(e.event_description) ) %>