From c2302dc0c7372b8f7b49bb68f351c4e84a03204e Mon Sep 17 00:00:00 2001 From: baiyu <1554253403@qq.com> Date: Wed, 18 Sep 2013 22:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=BB=E9=A1=B5=E4=B8=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=B8=8E=E9=A1=B9=E7=9B=AE=E4=B9=8B=E9=97=B4=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=20=E7=94=A8=E6=88=B7=E8=AF=BE=E7=A8=8B=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=AD=E7=9A=84=E4=BD=9C=E4=B8=9A=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=BA=86=E6=8C=89=E8=AF=BE=E7=A8=8B=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 15 +++++++++++++++ app/controllers/users_controller.rb | 1 + app/helpers/attachments_helper.rb | 9 +++++++++ app/views/attachments/_links.html.erb | 8 ++++++++ app/views/attachments/delete.js.erb | 1 + app/views/bids/_homework_list.html.erb | 2 +- app/views/users/_my_homework.html.erb | 6 +++++- config/routes.rb | 1 + ...4629_add_technical_title_to_user_extensions.rb | 5 +++++ db/schema.rb | 5 ++++- lib/redmine.rb | 3 ++- 11 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 app/views/attachments/delete.js.erb create mode 100644 db/migrate/20130918004629_add_technical_title_to_user_extensions.rb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 686070e70..ebf3c3ba5 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -115,6 +115,21 @@ class AttachmentsController < ApplicationController format.js end end + + def delete_homework + @bid = @attachment.container.bid + # Make sure association callbacks are called + container = @attachment.container + @attachment.container.attachments.delete(@attachment) + if container.attachments.empty? + container.delete + end + + respond_to do |format| + format.html { redirect_to_referer_or respond_path(@bid) } + format.js + end + end private def find_project diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0596f9693..80838947f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -135,6 +135,7 @@ class UsersController < ApplicationController @memberships.each do |membership| @bid += membership.project.homeworks end + @bid = @bid.group_by {|bid| bid.courses.first.id} @state = 1 else @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index a4925343f..f61399c85 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -31,6 +31,15 @@ module AttachmentsHelper :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)} end end + + def attach_delete(project) + if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id) + true + else + false + end + + end def render_api_attachment(attachment, api) api.attachment do diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index d2ab22ced..81eb416af 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -9,11 +9,19 @@ <%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) <% if options[:deletable] %> + <% unless attachment.container_type == 'HomeworkAttach' %> <%= link_to image_tag('delete.png'), attachment_path(attachment), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :class => 'delete', :title => l(:button_delete) %> + <% else %> + <%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id}, + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => 'delete', + :title => l(:button_delete) %> + <% end %> <% end %> <% if options[:author] %> <%= h(attachment.author) %>, <%= format_time(attachment.created_on) %> diff --git a/app/views/attachments/delete.js.erb b/app/views/attachments/delete.js.erb new file mode 100644 index 000000000..3cfb5845f --- /dev/null +++ b/app/views/attachments/delete.js.erb @@ -0,0 +1 @@ +$('#attachments_<%= j params[:attachment_id] %>').remove(); diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 62f5005c2..3e9713bdd 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -15,7 +15,7 @@

- <% options = {:author => true} %> + <% options = {:author => true, :deletable => attach_delete(homework)} %> <%= render :partial => 'attachments/links', :locals => {:attachments => homework.attachments, :options => options} %> <% end %> diff --git a/app/views/users/_my_homework.html.erb b/app/views/users/_my_homework.html.erb index a075fb6d2..d78c5dc0c 100644 --- a/app/views/users/_my_homework.html.erb +++ b/app/views/users/_my_homework.html.erb @@ -1,7 +1,10 @@ <% if @bid.size > 0%> -<% for bid in @bid%> +<% @bid.each do |bids|%> +

<%= link_to(Project.find(bids[0]).name, project_path(bids[0])) %>

+ +<% for bid in bids[1]%> @@ -42,6 +45,7 @@
+<% end %> <% end %> <% else %> diff --git a/config/routes.rb b/config/routes.rb index 8b3da6bc8..4ea23e2b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -446,6 +446,7 @@ RedmineApp::Application.routes.draw do post 'join_in/join', :to => 'courses#join', :as => 'join' delete 'join_in/join', :to => 'courses#unjoin' + delete 'attachment/:id', :to => 'attachments#delete_homework' match 'new_join', :to => 'projects#new_join', :as => 'try_join' match 'projects/:id/respond', :to => 'projects#project_respond', :via => :post ## 测试用 diff --git a/db/migrate/20130918004629_add_technical_title_to_user_extensions.rb b/db/migrate/20130918004629_add_technical_title_to_user_extensions.rb new file mode 100644 index 000000000..7097e6aee --- /dev/null +++ b/db/migrate/20130918004629_add_technical_title_to_user_extensions.rb @@ -0,0 +1,5 @@ +class AddTechnicalTitleToUserExtensions < ActiveRecord::Migration + def change + add_column :user_extensions, :technical_title, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index a50bdc577..b8ca66994 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130913125835) do +ActiveRecord::Schema.define(:version => 20130918004629) do create_table "a_user_watchers", :force => true do |t| t.string "name" @@ -173,6 +173,8 @@ ActiveRecord::Schema.define(:version => 20130913125835) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "location" + t.string "term" + t.string "string" end create_table "custom_fields", :force => true do |t| @@ -692,6 +694,7 @@ ActiveRecord::Schema.define(:version => 20130913125835) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.integer "identity" + t.string "technical_title" end create_table "user_preferences", :force => true do |t| diff --git a/lib/redmine.rb b/lib/redmine.rb index 3cee326b9..96cca91b2 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -285,8 +285,9 @@ Redmine::MenuManager.map :course_menu do |menu| end Redmine::MenuManager.map :user_menu do |menu| menu.push :activity, {:controller => 'users', :action => 'show' } - menu.push :user_project, {:controller => 'users', :action => 'user_projects'} menu.push :user_course, {:controller => 'users', :action => 'user_courses'} + menu.push :user_project, {:controller => 'users', :action => 'user_projects'} + menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} menu.push :user_newfeedback, {:controller => 'users', :action => 'user_newfeedback'}