commit
de192761b8
@ -1,49 +1,49 @@
|
|||||||
module Mobile
|
module Mobile
|
||||||
require_relative 'middleware/error_handler'
|
require_relative 'middleware/error_handler'
|
||||||
require_relative 'apis/auth'
|
require_relative 'apis/auth'
|
||||||
require_relative 'apis/users'
|
require_relative 'apis/users'
|
||||||
require_relative 'apis/courses'
|
require_relative 'apis/courses'
|
||||||
require_relative 'apis/watches'
|
require_relative 'apis/watches'
|
||||||
require_relative 'apis/upgrade'
|
require_relative 'apis/upgrade'
|
||||||
require_relative 'apis/homeworks'
|
require_relative 'apis/homeworks'
|
||||||
require_relative 'apis/comments'
|
require_relative 'apis/comments'
|
||||||
class API < Grape::API
|
class API < Grape::API
|
||||||
version 'v1', using: :path
|
version 'v1', using: :path
|
||||||
format :json
|
format :json
|
||||||
content_type :json, "application/json;charset=UTF-8"
|
content_type :json, "application/json;charset=UTF-8"
|
||||||
use Mobile::Middleware::ErrorHandler
|
use Mobile::Middleware::ErrorHandler
|
||||||
|
|
||||||
helpers do
|
helpers do
|
||||||
def logger
|
def logger
|
||||||
API.logger
|
API.logger
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate!
|
def authenticate!
|
||||||
raise('Unauthorized. Invalid or expired token.') unless current_user
|
raise('Unauthorized. Invalid or expired token.') unless current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
def current_user
|
||||||
token = ApiKey.where(access_token: params[:token]).first
|
token = ApiKey.where(access_token: params[:token]).first
|
||||||
if token && !token.expired?
|
if token && !token.expired?
|
||||||
@current_user = User.find(token.user_id)
|
@current_user = User.find(token.user_id)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mount Apis::Auth
|
mount Apis::Auth
|
||||||
mount Apis::Users
|
mount Apis::Users
|
||||||
mount Apis::Courses
|
mount Apis::Courses
|
||||||
mount Apis::Watches
|
mount Apis::Watches
|
||||||
mount Apis::Upgrade
|
mount Apis::Upgrade
|
||||||
mount Apis::Homeworks
|
mount Apis::Homeworks
|
||||||
mount Apis::Comments
|
mount Apis::Comments
|
||||||
|
|
||||||
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
|
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
|
||||||
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,59 +1,59 @@
|
|||||||
class AppliedProjectController < ApplicationController
|
class AppliedProjectController < ApplicationController
|
||||||
|
|
||||||
#申请加入项目
|
#申请加入项目
|
||||||
def applied_join_project
|
def applied_join_project
|
||||||
@user_id = params[:user_id]
|
@user_id = params[:user_id]
|
||||||
@project = Project.find_by_id(params[:project_id])
|
@project = Project.find_by_id(params[:project_id])
|
||||||
if params[:project_join]
|
if params[:project_join]
|
||||||
if @project
|
if @project
|
||||||
user = User.find @user_id
|
user = User.find @user_id
|
||||||
if user.member_of?(@project)
|
if user.member_of?(@project)
|
||||||
@status = 3
|
@status = 3
|
||||||
else
|
else
|
||||||
@applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
@applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
||||||
if @applieds.count == 0
|
if @applieds.count == 0
|
||||||
appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
||||||
Mailer.run.applied_project(appliedproject)
|
Mailer.run.applied_project(appliedproject)
|
||||||
@status = 2
|
@status = 2
|
||||||
else
|
else
|
||||||
@status = 1
|
@status = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@status = 0
|
@status = 0
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
@applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
||||||
if @applieds.count == 0
|
if @applieds.count == 0
|
||||||
appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
||||||
Mailer.run.applied_project(appliedproject)
|
Mailer.run.applied_project(appliedproject)
|
||||||
end
|
end
|
||||||
|
|
||||||
#redirect_to project_path(params[:project_id])
|
#redirect_to project_path(params[:project_id])
|
||||||
#redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true}
|
#redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true}
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||||
format.js { render :partial => 'set_applied'}
|
format.js { render :partial => 'set_applied'}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#取消申请
|
#取消申请
|
||||||
def unapplied_join_project
|
def unapplied_join_project
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
#@applied = AppliedProject.find(params[:id])
|
#@applied = AppliedProject.find(params[:id])
|
||||||
#@applied.destroy
|
#@applied.destroy
|
||||||
|
|
||||||
AppliedProject.deleteappiled(params[:user_id], params[:project_id])
|
AppliedProject.deleteappiled(params[:user_id], params[:project_id])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||||
format.js { render :partial => 'set_applied' }
|
format.js { render :partial => 'set_applied' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,62 +1,62 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#
|
#
|
||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module AccountHelper
|
module AccountHelper
|
||||||
|
|
||||||
def email_activation_register(user, &block)
|
def email_activation_register(user, &block)
|
||||||
token = Token.new(:user => user, :action => "register")
|
token = Token.new(:user => user, :action => "register")
|
||||||
if user.save and token.save
|
if user.save and token.save
|
||||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||||
Mailer.run.register(token)
|
Mailer.run.register(token)
|
||||||
#flash[:notice] = l(:notice_account_register_done)
|
#flash[:notice] = l(:notice_account_register_done)
|
||||||
#render action: 'email_valid', locals: {:mail => user.mail}
|
#render action: 'email_valid', locals: {:mail => user.mail}
|
||||||
else
|
else
|
||||||
yield if block_given?
|
yield if block_given?
|
||||||
end
|
end
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
def automatically_register(user, &block)
|
def automatically_register(user, &block)
|
||||||
# Automatic activation
|
# Automatic activation
|
||||||
user.activate
|
user.activate
|
||||||
user.last_login_on = Time.now
|
user.last_login_on = Time.now
|
||||||
if user.save
|
if user.save
|
||||||
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
|
||||||
#self.logged_user = user
|
#self.logged_user = user
|
||||||
#flash[:notice] = l(:notice_account_activated)
|
#flash[:notice] = l(:notice_account_activated)
|
||||||
#redirect_to my_account_url
|
#redirect_to my_account_url
|
||||||
else
|
else
|
||||||
yield if block_given?
|
yield if block_given?
|
||||||
end
|
end
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
def administrator_manually__register(user, &block)
|
def administrator_manually__register(user, &block)
|
||||||
if user.save
|
if user.save
|
||||||
UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0)
|
UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0)
|
||||||
# Sends an email to the administrators
|
# Sends an email to the administrators
|
||||||
Mailer.run.account_activation_request(user)
|
Mailer.run.account_activation_request(user)
|
||||||
#account_pending
|
#account_pending
|
||||||
else
|
else
|
||||||
yield if block_given?
|
yield if block_given?
|
||||||
end
|
end
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#
|
#
|
||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module ActivitiesHelper
|
module ActivitiesHelper
|
||||||
def sort_activity_events(events)
|
def sort_activity_events(events)
|
||||||
events_by_group = events.group_by(&:event_group)
|
events_by_group = events.group_by(&:event_group)
|
||||||
sorted_events = []
|
sorted_events = []
|
||||||
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
|
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
|
||||||
if group_events = events_by_group.delete(event.event_group)
|
if group_events = events_by_group.delete(event.event_group)
|
||||||
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
|
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
|
||||||
sorted_events << [e, i > 0] unless e.event_description.nil?
|
sorted_events << [e, i > 0] unless e.event_description.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sorted_events
|
sorted_events
|
||||||
end
|
end
|
||||||
def sort_activity_events_course(events)
|
def sort_activity_events_course(events)
|
||||||
events_by_group = events.group_by(&:event_group)
|
events_by_group = events.group_by(&:event_group)
|
||||||
sorted_events = []
|
sorted_events = []
|
||||||
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
|
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
|
||||||
if group_events = events_by_group.delete(event.event_group)
|
if group_events = events_by_group.delete(event.event_group)
|
||||||
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
|
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
|
||||||
sorted_events << e unless e.event_description.nil?
|
sorted_events << e unless e.event_description.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sorted_events
|
sorted_events
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,96 +1,123 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#
|
#
|
||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module MembersHelper
|
module MembersHelper
|
||||||
def render_principals_for_new_members(project)
|
def render_principals_for_new_members(project)
|
||||||
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||||
principal_count = scope.count
|
principal_count = scope.count
|
||||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young
|
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young
|
||||||
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||||
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
||||||
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
||||||
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||||
}
|
}
|
||||||
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
||||||
end
|
end
|
||||||
|
|
||||||
#获取项目可邀请的成员列表
|
#获取项目可邀请的成员列表
|
||||||
def render_project_members project
|
def render_project_members project
|
||||||
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
if params[:q] && params[:q] != ""
|
||||||
principals = paginateHelper scope,10
|
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||||
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :style => "margin-left: -40px;")
|
else
|
||||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
scope = []
|
||||||
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q],:flag => true, :format => 'js')), :remote => true
|
end
|
||||||
}
|
principals = paginateHelper scope,10
|
||||||
s + content_tag('ul', links,:class => 'wlist')
|
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5')
|
||||||
end
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
||||||
|
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q],:flag => true, :format => 'js')), :remote => true
|
||||||
# add by nwb
|
}
|
||||||
# 课程可添加的成员列表
|
s + content_tag('ul', links,:class => 'wlist', :id => "course_member_pagination_links" )
|
||||||
def render_principals_for_new_course_members(course)
|
end
|
||||||
if params[:q] && params[:q] != ""
|
|
||||||
scope = Principal.active.sorted.not_member_of_course(course).like(params[:q])
|
# add by nwb
|
||||||
else
|
# 课程可添加的成员列表
|
||||||
scope = []
|
def render_principals_for_new_course_members(course)
|
||||||
end
|
if params[:q] && params[:q] != ""
|
||||||
principals = paginateHelper scope,10
|
scope = Principal.active.sorted.not_member_of_course(course).like(params[:q])
|
||||||
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
else
|
||||||
|
scope = []
|
||||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true) {|text, parameters, options|
|
end
|
||||||
link_to text, autocomplete_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
principals = paginateHelper scope,10
|
||||||
}
|
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
||||||
|
|
||||||
s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links")
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true) {|text, parameters, options|
|
||||||
end
|
link_to text, autocomplete_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||||
|
}
|
||||||
|
|
||||||
# 当前申请加入的成员名单
|
s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links")
|
||||||
def render_principals_for_applied_members(project)
|
end
|
||||||
scope = project.applied_projects.map(&:user)
|
|
||||||
principal_count = scope.count
|
# 项目配置中添加成员列表
|
||||||
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
def render_principals_for_new_project_members(project)
|
||||||
offset ||= principal_pages.offset
|
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||||
principals = scope[offset, 10]
|
principals = paginateHelper scope,10
|
||||||
#principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
||||||
#principals = ApplicationController.new.paginateHelper scope,10
|
|
||||||
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true) {|text, parameters, options|
|
||||||
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
link_to text, appliedproject_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||||
|
}
|
||||||
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
|
||||||
link_to text, appliedproject_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
s + content_tag('ul', links,:class => 'wlist',:id => "course_member_pagination_links")
|
||||||
}
|
end
|
||||||
|
|
||||||
s + content_tag('div', content_tag('ul', links), :class => 'applied_new')
|
# 新申请加入项目成员列表
|
||||||
end
|
def render_principals_for_applied_members_new project
|
||||||
|
scope = project.applied_projects.map(&:user)
|
||||||
private
|
principals = paginateHelper scope,10
|
||||||
def paginateHelper obj, pre_size=20
|
s = content_tag('ul', principals_check_box_tags_li('membership[user_ids][]', principals), :class => 'mb5')
|
||||||
@obj_count = obj.count
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
||||||
@obj_pages = Redmine::Pagination::Paginator.new @obj_count, pre_size, params['page']
|
link_to text, appliedproject_project_memberships_path(project, parameters.merge(:q => params[:q],:flag => true, :format => 'js')), :remote => true
|
||||||
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
}
|
||||||
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
s + content_tag('ul', links,:class => 'wlist', :id => "course_member_pagination_links" )
|
||||||
elsif obj.kind_of? Array
|
end
|
||||||
obj[@obj_pages.offset, @obj_pages.per_page]
|
|
||||||
else
|
# 当前申请加入的成员名单
|
||||||
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
def render_principals_for_applied_members(project)
|
||||||
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
scope = project.applied_projects.map(&:user)
|
||||||
end
|
principal_count = scope.count
|
||||||
end
|
principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
|
||||||
|
offset ||= principal_pages.offset
|
||||||
end
|
principals = scope[offset, 10]
|
||||||
|
#principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
|
||||||
|
#principals = ApplicationController.new.paginateHelper scope,10
|
||||||
|
|
||||||
|
s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
||||||
|
|
||||||
|
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
|
||||||
|
link_to text, appliedproject_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
|
||||||
|
}
|
||||||
|
|
||||||
|
s + content_tag('div', content_tag('ul', links), :class => 'applied_new')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def paginateHelper obj, pre_size=20
|
||||||
|
@obj_count = obj.count
|
||||||
|
@obj_pages = Redmine::Pagination::Paginator.new @obj_count, pre_size, params['page']
|
||||||
|
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
||||||
|
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
||||||
|
elsif obj.kind_of? Array
|
||||||
|
obj[@obj_pages.offset, @obj_pages.per_page]
|
||||||
|
else
|
||||||
|
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
||||||
|
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module OwnerTypeHelper
|
module OwnerTypeHelper
|
||||||
MEMO = 1
|
MEMO = 1
|
||||||
FORUM = 2
|
FORUM = 2
|
||||||
MESSAGE = 3
|
MESSAGE = 3
|
||||||
NEWS = 4
|
NEWS = 4
|
||||||
COMMENT = 5
|
COMMENT = 5
|
||||||
BID = 6
|
BID = 6
|
||||||
JOURNALSFORMESSAGE = 7
|
JOURNALSFORMESSAGE = 7
|
||||||
end
|
end
|
@ -1,95 +1,95 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Document < ActiveRecord::Base
|
class Document < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
||||||
include UserScoreHelper
|
include UserScoreHelper
|
||||||
after_save :be_user_score # user_score
|
after_save :be_user_score # user_score
|
||||||
after_destroy :down_user_score
|
after_destroy :down_user_score
|
||||||
acts_as_attachable :delete_permission => :delete_documents
|
acts_as_attachable :delete_permission => :delete_documents
|
||||||
after_create :send_mail
|
after_create :send_mail
|
||||||
# 被ForgeActivity虚拟关联
|
# 被ForgeActivity虚拟关联
|
||||||
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
|
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
|
||||||
# end
|
# end
|
||||||
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
|
||||||
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
||||||
#:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
|
#:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
|
||||||
:author => Proc.new {|o| User.find(o.user_id)},
|
:author => Proc.new {|o| User.find(o.user_id)},
|
||||||
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
|
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
|
||||||
acts_as_activity_provider :find_options => {:include => :project},
|
acts_as_activity_provider :find_options => {:include => :project},
|
||||||
:is_public => 'documents.is_public'
|
:is_public => 'documents.is_public'
|
||||||
|
|
||||||
validates_presence_of :project, :title, :category
|
validates_presence_of :project, :title, :category
|
||||||
validates_length_of :title, :maximum => 60
|
validates_length_of :title, :maximum => 60
|
||||||
after_create :act_as_forge_activity
|
after_create :act_as_forge_activity
|
||||||
scope :visible, lambda {|*args|
|
scope :visible, lambda {|*args|
|
||||||
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_attributes 'category_id', 'title', 'description','is_public'
|
safe_attributes 'category_id', 'title', 'description','is_public'
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_documents, project)
|
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_right?(project,user=User.current)
|
def has_right?(project,user=User.current)
|
||||||
user.admin? || user.member_of?(project) || self.is_public==1
|
user.admin? || user.member_of?(project) || self.is_public==1
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(attributes=nil, *args)
|
def initialize(attributes=nil, *args)
|
||||||
super
|
super
|
||||||
if new_record?
|
if new_record?
|
||||||
self.category ||= DocumentCategory.default
|
self.category ||= DocumentCategory.default
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def updated_on
|
def updated_on
|
||||||
unless @updated_on
|
unless @updated_on
|
||||||
a = attachments.last
|
a = attachments.last
|
||||||
@updated_on = (a && a.created_on) || created_on
|
@updated_on = (a && a.created_on) || created_on
|
||||||
end
|
end
|
||||||
@updated_on
|
@updated_on
|
||||||
end
|
end
|
||||||
|
|
||||||
# update user score
|
# update user score
|
||||||
def be_user_score
|
def be_user_score
|
||||||
UserScore.project(:push_document, self.user,self,{ document_id: self.id })
|
UserScore.project(:push_document, self.user,self,{ document_id: self.id })
|
||||||
update_document(self.user,1)
|
update_document(self.user,1)
|
||||||
update_document(self.user,2,self.project)
|
update_document(self.user,2,self.project)
|
||||||
end
|
end
|
||||||
|
|
||||||
def down_user_score
|
def down_user_score
|
||||||
update_document(self.user,1)
|
update_document(self.user,1)
|
||||||
update_document(self.user,2,self.project)
|
update_document(self.user,2,self.project)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Time 2015-03-02 10:51:16
|
# Time 2015-03-02 10:51:16
|
||||||
# Author lizanle
|
# Author lizanle
|
||||||
# Description 新创建的document要在公共表ForgeActivity中记录
|
# Description 新创建的document要在公共表ForgeActivity中记录
|
||||||
def act_as_forge_activity
|
def act_as_forge_activity
|
||||||
self.forge_acts << ForgeActivity.new(:user_id => self.user_id,
|
self.forge_acts << ForgeActivity.new(:user_id => self.user_id,
|
||||||
:project_id => self.project_id)
|
:project_id => self.project_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_mail
|
def send_mail
|
||||||
Mailer.run.document_added(self) if Setting.notified_events.include?('document_added')
|
Mailer.run.document_added(self) if Setting.notified_events.include?('document_added')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue