增加了附件删除功能

修改用户主页中课程与项目之间的关系
用户课程页面中的作业进行了按课程分组
This commit is contained in:
baiyu 2013-09-18 22:56:01 +08:00
parent 960b59c807
commit c2302dc0c7
11 changed files with 52 additions and 4 deletions

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -9,11 +9,19 @@
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% 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] %>
<span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span>

View File

@ -0,0 +1 @@
$('#attachments_<%= j params[:attachment_id] %>').remove();

View File

@ -15,7 +15,7 @@
<tr>
<td colspan="2" width="580px" >
<p class="font_description">
<% options = {:author => true} %>
<% options = {:author => true, :deletable => attach_delete(homework)} %>
<%= render :partial => 'attachments/links',
:locals => {:attachments => homework.attachments, :options => options} %>
<% end %>

View File

@ -1,7 +1,10 @@
<!-- fq -->
<% if @bid.size > 0%>
<% for bid in @bid%>
<% @bid.each do |bids|%>
<h2><%= link_to(Project.find(bids[0]).name, project_path(bids[0])) %></h2>
<% for bid in bids[1]%>
<table width="90%" border="0" align="center" style="border-bottom: 1px dashed rgb(204, 204, 204); margin-bottom: 10px; margin-top: 30px;font-size:14px;">
<tr>
@ -42,6 +45,7 @@
</tr>
</table>
<% end %>
<% end %>
<% else %>

View File

@ -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
## 测试用

View File

@ -0,0 +1,5 @@
class AddTechnicalTitleToUserExtensions < ActiveRecord::Migration
def change
add_column :user_extensions, :technical_title, :string
end
end

View File

@ -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|

View File

@ -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'}