From 5d0b5812b373f9dab28730bf75192cbc3de160ea Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 21 Oct 2013 08:57:55 +0800 Subject: [PATCH] share completed with fq, xianbo --- app/controllers/projects_controller.rb | 11 +++- app/controllers/shares_controller.rb | 46 ++++++++++++---- app/helpers/shares_helper.rb | 14 +++++ app/models/project.rb | 1 + app/models/share.rb | 17 +++++- app/views/layouts/base_projects.html.erb | 6 +++ app/views/projects/share.html.erb | 40 ++++++++++++++ app/views/projects/show.html.erb | 2 +- app/views/shares/_form.html.erb | 52 ++++++++----------- app/views/shares/index.html.erb | 24 +++++---- app/views/shares/new.html.erb | 2 +- app/views/shares/succ.html.erb | 6 +++ config/environments/development.rb | 2 +- config/locales/zh.yml | 3 +- config/routes.rb | 4 +- .../stylesheets/application.css | 9 +++- 16 files changed, 178 insertions(+), 61 deletions(-) create mode 100644 app/views/projects/share.html.erb create mode 100644 app/views/shares/succ.html.erb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 53a0a259..783e8222 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 55b9e237..e019af50 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 e51aa8b8..f2cbc6ab 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 0e023da6..e45c8dc2 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 58f4f1aa..dd77b4a1 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 ecca9b5b..7493de1a 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -131,10 +131,16 @@ <%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %> <%= link_to l(:project_module_boards) ,project_boards_path(@project) %> + <%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %> + <%= link_to l(:label_module_share) ,share_show_path(@project) %> + + + <% if @project.identifier == 'trustie' %> <%=image_tag("/images/sidebar/tool_tag.png", weight:"15px", height:"15px") %> <%= link_to l(:label_project_tool_response) ,project_feedback_path(@project) %> + <% else %> <% end %> diff --git a/app/views/projects/share.html.erb b/app/views/projects/share.html.erb new file mode 100644 index 00000000..e3cb92fc --- /dev/null +++ b/app/views/projects/share.html.erb @@ -0,0 +1,40 @@ + + +

+ 进入测试平台 +

+ +<% @shares.each do |share| %> +
+ + + + + +
<%= image_tag(url_to_avatar(share.user), :class => "avatar")%> + + + + + + + + + + +
+ <%= h(share.project) if @project.nil? || @project.id != share.project.id %> + + <%= link_to_user(share.user) %> <%= l(:label_new_activity) %> + <%= share.title%> +

+ <%= share.description %><%= link_to "查看详情", share.url, {:target=>"_blank"} %> + +
+

+ + +

<%= h(share.created_on)%>
+
+
+<% end %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 130d343b..903ad70f 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -23,7 +23,7 @@

- <%= textilizable( truncate(e.event_description, length: 240 ) %> + <%= textilizable( stringCut240(e.event_description) ) %>

diff --git a/app/views/shares/_form.html.erb b/app/views/shares/_form.html.erb index 50f680f0..26297836 100644 --- a/app/views/shares/_form.html.erb +++ b/app/views/shares/_form.html.erb @@ -1,33 +1,23 @@ -<%= form_for(@share) do |f| %> - <% if @share.errors.any? %> -
-

<%= pluralize(@share.errors.count, "error") %> prohibited this share from being saved:

+
+ <%= form_for(@share) do |f| %> +
+ 分享到项目: + <%= f.select 'project_id', options_from_collection_for_select(@ps, "id", "name") %>
+
+ <%= f.text_field :title, :style => 'width: 399px;display: none;' %> +
-
    - <% @share.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
+
+ <%= f.text_area :description, :rows => 4, :style => 'width: 100%;resize: none;', :class => 'create-share' %> +
+
+ <%= f.label "Website:" %>
+ <%= f.text_field :url, :style => 'width: 100%;', :class => 'create-share' %> +
+ +
+ <%= f.submit :value=>"分享"%> +
<% end %> - -
- <%= f.label :created_on %>
- <%= f.text_field :created_on %> -
-
- <%= f.label :url %>
- <%= f.text_field :url %> -
-
- <%= f.label :title %>
- <%= f.text_field :title %> -
-
- <%= f.label :share_type %>
- <%= f.number_field :share_type %> -
-
- <%= f.submit %> -
-<% end %> +
+
diff --git a/app/views/shares/index.html.erb b/app/views/shares/index.html.erb index 7411bb25..5318a3b7 100644 --- a/app/views/shares/index.html.erb +++ b/app/views/shares/index.html.erb @@ -4,22 +4,24 @@ Created On Url - Title + Project_Name Share type - - - + Edit + project_id + user_id <% @shares.each do |share| %> - <%= share.created_on %> - <%= share.url %> - <%= share.title %> - <%= share.share_type %> - <%= link_to 'Show', share %> - <%= link_to 'Edit', edit_share_path(share) %> - <%= link_to 'Destroy', share, method: :delete, data: { confirm: 'Are you sure?' } %> + <%= share.created_on %> + <%= share.url %> + <%= share.title %> + <%= share.share_type %> + <%= link_to 'Show', share %> + <%= link_to 'Edit', edit_share_path(share) %> + <%= link_to 'Destroy', share, method: :delete, data: { confirm: 'Are you sure?' } %> + <%= share.project_id %> + <%= share.user_id%> <% end %> diff --git a/app/views/shares/new.html.erb b/app/views/shares/new.html.erb index 919a9f4b..21ac2842 100644 --- a/app/views/shares/new.html.erb +++ b/app/views/shares/new.html.erb @@ -1,4 +1,4 @@ -

New share

+

分享

<%= render 'form' %> diff --git a/app/views/shares/succ.html.erb b/app/views/shares/succ.html.erb new file mode 100644 index 00000000..e2599f97 --- /dev/null +++ b/app/views/shares/succ.html.erb @@ -0,0 +1,6 @@ +

+ 分享成功! +

+

+ <%= link_to "查看分享", share_show_path(Project.find_by_id(@share.project_id)) %> +

diff --git a/config/environments/development.rb b/config/environments/development.rb index bd92c555..9d3cbf24 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -9,7 +9,7 @@ RedmineApp::Application.configure do config.whiny_nils = true # 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 # Don't care if the mailer can't send diff --git a/config/locales/zh.yml b/config/locales/zh.yml index ee6c3a62..36cfc40c 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1635,4 +1635,5 @@ zh: label_ta: 助教 label_in_course: 在课程中 label_assign_homework: 中布置了作业 - label_noawards: 未评奖 \ No newline at end of file + label_noawards: 未评奖 + label_module_share: dts测试工具 diff --git a/config/routes.rb b/config/routes.rb index e9b12c86..e9556471 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do - resources :shares + resources :shares, only: [:new, :create, :destroy] #added by william 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_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' delete 'join_in/join', :to => 'courses#unjoin' delete 'attachment/:id', :to => 'attachments#delete_homework' diff --git a/public/themes/redpenny-master/stylesheets/application.css b/public/themes/redpenny-master/stylesheets/application.css index 0140d68b..ebd19e8b 100644 --- a/public/themes/redpenny-master/stylesheets/application.css +++ b/public/themes/redpenny-master/stylesheets/application.css @@ -1877,4 +1877,11 @@ a.font-user-after-color{ height:25px; line-height:23px; } -/*end*/ \ No newline at end of file +/*end*/ + +.create-share{ + border-radius: 5px; + padding-top: 3px; + margin-top: 5px; + margin-bottom: 5px; +}