share completed with fq, xianbo

This commit is contained in:
yanxd 2013-10-21 08:57:55 +08:00
parent dde65a5895
commit 5d0b5812b3
16 changed files with 178 additions and 61 deletions

View File

@ -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 :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, 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 :authorize_global, :only => [:new, :create]
before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar]
#by young #by young
@ -479,6 +479,15 @@ class ProjectsController < ApplicationController
##end ##end
render :layout => 'base' render :layout => 'base'
end 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 def create

View File

@ -1,4 +1,6 @@
# encoding: utf-8
class SharesController < ApplicationController class SharesController < ApplicationController
before_filter :require_login, :except => [:index]
# GET /shares # GET /shares
# GET /shares.json # GET /shares.json
def index def index
@ -25,15 +27,31 @@ class SharesController < ApplicationController
# GET /shares/new.json # GET /shares/new.json
def new def new
@share = Share.new @share = Share.new
@user = User.current
@ps = @user.projects.all
#add by mkz 抓取参数传给share projectName = params[:projectname]
userName = params[:username]
@share[:created_on] = params[:created_on] url = params[:url]
@share[:title] = params[:title] share_type = params[:share_type]
@share[:url] = params[:url] share_type ||= 0 #默认是测试结果分享
@share[:share_type] = params[:share_type] description = params[:description]
@share.save
# #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| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
@ -50,10 +68,14 @@ class SharesController < ApplicationController
# POST /shares.json # POST /shares.json
def create def create
@share = Share.new(params[:share]) @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| respond_to do |format|
if @share.save 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 } format.json { render json: @share, status: :created, location: @share }
else else
format.html { render action: "new" } format.html { render action: "new" }
@ -66,7 +88,9 @@ class SharesController < ApplicationController
# PUT /shares/1.json # PUT /shares/1.json
def update def update
@share = Share.find(params[:id]) @share = Share.find(params[:id])
@project = params[:project_id]
@share.user_id = User.current.id
respond_to do |format| respond_to do |format|
if @share.update_attributes(params[:share]) if @share.update_attributes(params[:share])
format.html { redirect_to @share, notice: 'Share was successfully updated.' } format.html { redirect_to @share, notice: 'Share was successfully updated.' }

View File

@ -1,2 +1,16 @@
module SharesHelper 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 end

View File

@ -58,6 +58,7 @@ class Project < ActiveRecord::Base
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :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 :students_for_courses, :dependent => :destroy
has_many :student, :through => :students_for_courses, :source => :user has_many :student, :through => :students_for_courses, :source => :user
# has_one :cour, :class_name => 'Course', :foreign_key => :extra, :dependent => :destroy # has_one :cour, :class_name => 'Course', :foreign_key => :extra, :dependent => :destroy

View File

@ -1,3 +1,18 @@
class Share < ActiveRecord::Base 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 end

View File

@ -131,10 +131,16 @@
<td align="left" width="190px" valign="left"><%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %> <td align="left" width="190px" valign="left"><%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %>
<%= link_to l(:project_module_boards) ,project_boards_path(@project) %> <%= link_to l(:project_module_boards) ,project_boards_path(@project) %>
</td> </td>
<td align="left" width="190px" valign="left"><%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %>
<%= link_to l(:label_module_share) ,share_show_path(@project) %>
</td>
</tr>
<tr>
<% if @project.identifier == 'trustie' %> <% if @project.identifier == 'trustie' %>
<td align="left" width="190px" valign="left"><%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %> <td align="left" width="190px" valign="left"><%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %>
<%= link_to l(:label_project_tool_response) ,project_feedback_path(@project) %> <%= link_to l(:label_project_tool_response) ,project_feedback_path(@project) %>
</td> </td>
<% else %> <% else %>
<% end %> <% end %>
</tr> </tr>

View File

@ -0,0 +1,40 @@
<!-- <h3>测试结果</h3> -->
<p id="stcloud">
<a href="http://www.trustie.net/webdts/" style="float:right" target="_blank">进入测试平台</a>
</p>
<% @shares.each do |share| %>
<div class="issue-note">
<table width="660px" border="0" align="center" style="font-size: 14px;">
<tr>
<td colspan="2" valign="top" width="50" ><%= image_tag(url_to_avatar(share.user), :class => "avatar")%></td>
<td>
<table width="580px" border="0">
<tr>
<td colspan="2" valign="top">
<strong> <%= h(share.project) if @project.nil? || @project.id != share.project.id %></strong>
<span class="font_lighter">
<%= link_to_user(share.user) %> <%= l(:label_new_activity) %>
</span> <%= share.title%>
<br/> <br/>
<%= share.description %><%= link_to "查看详情", share.url, {:target=>"_blank"} %>
</td>
</tr>
<tr>
<td colspan="2" width="580px" >
<p class="font_description">
<!-- modify by nyan -->
</p></td>
</tr>
<tr>
<td align="left"><a class="font_lighter"> <%= h(share.created_on)%></a></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<% end %>

View File

@ -23,7 +23,7 @@
<td colspan="2" width="580px" > <td colspan="2" width="580px" >
<p class="font_description"> <p class="font_description">
<!-- modify by nyan --> <!-- modify by nyan -->
<%= textilizable( truncate(e.event_description, length: 240 ) %> <%= textilizable( stringCut240(e.event_description) ) %>
</p></td> </p></td>
</tr> </tr>
<tr> <tr>

View File

@ -1,33 +1,23 @@
<%= form_for(@share) do |f| %> <div id="share_new" style = "width: 431px; center" >
<% if @share.errors.any? %> <%= form_for(@share) do |f| %>
<div id="error_explanation"> <div>
<h2><%= pluralize(@share.errors.count, "error") %> prohibited this share from being saved:</h2> 分享到项目:
<%= f.select 'project_id', options_from_collection_for_select(@ps, "id", "name") %></div>
<div class="field">
<%= f.text_field :title, :style => 'width: 399px;display: none;' %>
</div>
<ul> <div class="field">
<% @share.errors.full_messages.each do |msg| %> <%= f.text_area :description, :rows => 4, :style => 'width: 100%;resize: none;', :class => 'create-share' %>
<li><%= msg %></li> </div>
<% end %> <div class="field">
</ul> <%= f.label "Website:" %><br/>
</div> <%= f.text_field :url, :style => 'width: 100%;', :class => 'create-share' %>
</div>
<div class="actions" style=" padding-top: 10px; float:right">
<%= f.submit :value=>"分享"%>
</div>
<% end %> <% end %>
<br/>
<div class="field"> </div>
<%= f.label :created_on %><br />
<%= f.text_field :created_on %>
</div>
<div class="field">
<%= f.label :url %><br />
<%= f.text_field :url %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :share_type %><br />
<%= f.number_field :share_type %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -4,22 +4,24 @@
<tr> <tr>
<th>Created On</th> <th>Created On</th>
<th>Url</th> <th>Url</th>
<th>Title</th> <th>Project_Name</th>
<th>Share type</th> <th>Share type</th>
<th></th> <th>Edit</th>
<th></th> <th>project_id</th>
<th></th> <th>user_id</th>
</tr> </tr>
<% @shares.each do |share| %> <% @shares.each do |share| %>
<tr> <tr>
<td><%= share.created_on %></td> <th><%= share.created_on %></th>
<td><%= share.url %></td> <th><%= share.url %></th>
<td><%= share.title %></td> <th><%= share.title %></th>
<td><%= share.share_type %></td> <th><%= share.share_type %></th>
<td><%= link_to 'Show', share %></td> <th><%= link_to 'Show', share %>
<td><%= link_to 'Edit', edit_share_path(share) %></td> <%= link_to 'Edit', edit_share_path(share) %>
<td><%= link_to 'Destroy', share, method: :delete, data: { confirm: 'Are you sure?' } %></td> <%= link_to 'Destroy', share, method: :delete, data: { confirm: 'Are you sure?' } %></th>
<th><%= share.project_id %></th>
<th><%= share.user_id%></th>
</tr> </tr>
<% end %> <% end %>
</table> </table>

View File

@ -1,4 +1,4 @@
<h1>New share</h1> <h1>分享</h1>
<%= render 'form' %> <%= render 'form' %>

View File

@ -0,0 +1,6 @@
<p>
分享成功!
</p>
<p>
<%= link_to "查看分享", share_show_path(Project.find_by_id(@share.project_id)) %>
</p>

View File

@ -9,7 +9,7 @@ RedmineApp::Application.configure do
config.whiny_nils = true config.whiny_nils = true
# Show full error reports and disable caching # Show full error reports and disable caching
#config.action_controller.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
# Don't care if the mailer can't send # Don't care if the mailer can't send

View File

@ -1635,4 +1635,5 @@ zh:
label_ta: 助教 label_ta: 助教
label_in_course: 在课程中 label_in_course: 在课程中
label_assign_homework: 中布置了作业 label_assign_homework: 中布置了作业
label_noawards: 未评奖 label_noawards: 未评奖
label_module_share: dts测试工具

View File

@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RedmineApp::Application.routes.draw do RedmineApp::Application.routes.draw do
resources :shares resources :shares, only: [:new, :create, :destroy]
#added by william #added by william
get "tags/index" get "tags/index"
@ -459,6 +459,8 @@ RedmineApp::Application.routes.draw do
match 'calls/:id/show_bid_project', :to => 'bids#show_bid_project', :as => 'show_bid_project' match 'calls/:id/show_bid_project', :to => 'bids#show_bid_project', :as => 'show_bid_project'
match 'calls/:id/show_bid_user', :to => 'bids#show_bid_user', :as => 'show_bid_user' match 'calls/:id/show_bid_user', :to => 'bids#show_bid_user', :as => 'show_bid_user'
match 'project/:id/share', :to => 'projects#share', :as => 'share_show' #share
post 'join_in/join', :to => 'courses#join', :as => 'join' post 'join_in/join', :to => 'courses#join', :as => 'join'
delete 'join_in/join', :to => 'courses#unjoin' delete 'join_in/join', :to => 'courses#unjoin'
delete 'attachment/:id', :to => 'attachments#delete_homework' delete 'attachment/:id', :to => 'attachments#delete_homework'

View File

@ -1877,4 +1877,11 @@ a.font-user-after-color{
height:25px; height:25px;
line-height:23px; line-height:23px;
} }
/*end*/ /*end*/
.create-share{
border-radius: 5px;
padding-top: 3px;
margin-top: 5px;
margin-bottom: 5px;
}