Merge branch 'szzh' into develop

memcached_alan v20150312
sw 10 years ago
commit c52eebe6f4

@ -25,8 +25,10 @@ gem 'rufus-scheduler'
#gem 'dalli', path: 'lib/dalli-2.7.2'
group :development do
gem 'grape-swagger'
gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git'
#gem 'grape-swagger-ui', git: 'https://github.com/guange2015/grape-swagger-ui.git'
#gem 'puma'
gem 'pry-rails'
gem 'pry-byebug'
gem 'better_errors', path: 'lib/better_errors'
gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler'
end
@ -50,8 +52,8 @@ group :test do
#end
end
gem 'rspec-rails' , '2.13.1'
gem 'guard-rspec','2.5.0'
# gem 'rspec-rails' , '2.13.1'
# gem 'guard-rspec','2.5.0'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
@ -95,7 +97,7 @@ if File.exist?(database_file)
adapters.each do |adapter|
case adapter
when 'mysql2'
gem "mysql2", "= 0.3.11", :platforms => [:mri, :mingw]
gem "mysql2", "= 0.3.18", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
when 'mysql'
gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw]

@ -40,6 +40,17 @@ module Mobile
{status: 0}
end
desc "忘记密码"
params do
requires :mail,type: String
end
post 'lost_password' do
us = UsersService.new
message = us.lost_password params
present :message, message
present :status, 0
end
end
end
end

@ -97,12 +97,10 @@ class AttachmentsController < ApplicationController
end
if candown || User.current.admin? || User.current.id == @attachment.author_id
@attachment.increment_download
if stale?(:etag => @attachment.digest)
# images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => (@attachment.image? ? 'inline' : 'attachment')
:disposition => 'attachment' #inline can open in browser
end
else

@ -21,6 +21,7 @@ class FilesController < ApplicationController
menu_item :files
before_filter :auth_login1, :only => [:index]
before_filter :logged_user_by_apptoken,:only => [:index]
before_filter :find_project_by_project_id#, :except => [:getattachtype]
before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search]
@ -98,6 +99,7 @@ class FilesController < ApplicationController
end
def index
@flag = params[:flag] || false
#sort_init 'filename', 'asc'
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
@ -143,11 +145,16 @@ class FilesController < ApplicationController
end
end
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder(sort).all
@containers = [ Project.includes(:attachments).find(@project.id)]
@containers += @project.versions.includes(:attachments).all
show_attachments @containers
ids = []
@containers.each do |c|
ids += c.attachments.pluck(:id)
end
@containers = [Struct.new(:attachments).new(Attachment.where('id in (?)',ids).reorder(sort))]
show_attachments @containers
respond_to do |format|
format.html

@ -107,17 +107,24 @@ class MembersController < ApplicationController
AppliedProject.deleteappiled(member.user_id, @project.id)
end
end
respond_to do |format|
format.html { redirect_to_settings_in_projects }
format.js { @members = members; @applied_members = applied_members; }
format.api {
@member = members.first
if @member.valid?
render :action => 'show', :status => :created, :location => membership_url(@member)
else
render_validation_errors(@member)
end
}
if params[:flag]
flash[:notice] = l(:label_invite_success)
respond_to do |format|
format.html { redirect_to invite_members_project_url(@project) }
end
else
respond_to do |format|
format.html { redirect_to_settings_in_projects }
format.js { @members = members; @applied_members = applied_members; }
format.api {
@member = members.first
if @member.valid?
render :action => 'show', :status => :created, :location => membership_url(@member)
else
render_validation_errors(@member)
end
}
end
end
elsif @course
course_info = []
@ -310,6 +317,7 @@ class MembersController < ApplicationController
end
def autocomplete
@flag = params[:flag] || false
respond_to do |format|
format.js
end

@ -180,6 +180,7 @@ class ProjectsController < ApplicationController
@project = Project.new
@project.safe_attributes = params[:project]
@project.organization_id = params[:organization_id]
@project.user_id = User.current.id
if validate_parent_id && @project.save
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
# Add current user as a project member if he is not admin
@ -333,30 +334,41 @@ class ProjectsController < ApplicationController
end
def send_mail_to_member
if !params[:mail].nil? && User.find_by_mail(params[:mail].to_s).nil?
if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil?
email = params[:mail]
Mailer.send_invite_in_project(email, @project, User.current).deliver
@is_zhuce =false
flash[:notice] = l(:notice_email_sent, :value => email)
else
@is_zhuce = true
end
respond_to do |format|
format.js
format.html{redirect_to invite_members_by_mail_project_url(@project)}
end
end
#发送邮件邀请新用户
def invite_members_by_mail
@is_zhuce =false
respond_to do |format|
format.html
format.js
if User.current.member_of?(@project) || User.current.admin?
@is_zhuce = false
respond_to do |format|
format.html
format.js
end
else
render_403
end
end
# 邀请Trustie注册用户
def invite_members
@member ||= @project.members.new
if User.current.member_of?(@project) || User.current.admin?
@member ||= @project.members.new
respond_to do |format|
format.html
end
else
render_403
end
end
def edit

@ -28,7 +28,8 @@ class WelcomeController < ApplicationController
# 企业版定制: params[:project]为传过来的参数
unless params[:organization].nil?
@organization = Organization.find params[:organization]
@organization_projects = Project.visible.joins(:project_status).joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").where("projects.organization_id = ?", @organization.id).order("score DESC").limit(10).all
# @organization_projects = Project.joins(:project_status).joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").where("projects.organization_id = ?", @organization.id).order("score DESC").limit(10).all
@organization_projects = @organization.projects.visible.joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").order("project_scores.score DESC").limit(10).all
@part_projects = @organization_projects.count < 9 ? find_miracle_project( 9 - @organization_projects.count, 3,"score desc") : []
# @cur_projects = Project.find(params[:organization])
# @organization = @cur_projects.enterprise_name

@ -490,6 +490,15 @@ module ApplicationHelper
s.html_safe
end
#项目成员列表复选框生成
def project_member_check_box_tags_ex name, principals
s = ''
principals.each do |principal|
s << "<li>#{ check_box_tag name, principal.id, false, :id => nil } #{h link_to principal.userInfo, user_path( principal.id)}</li>\n"
end
s.html_safe
end
#扩展的checkbox生成
def principals_check_box_tags_ex(name, principals)
s = ''
@ -1198,6 +1207,17 @@ module ApplicationHelper
html_safe
end
def wiki_simple_format_without_paragraph(text)
text.to_s.
gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br
gsub("&amp;nbsp", " "). #gsub(/<\/?.*?>/,"").
gsub(/&lt;\/?.*?&gt;/, "").
gsub("&quot;", "'").
html_safe
end
def lang_options_for_select(blank=true)
{ 'Chinese简体中文 '=> 'zh', :English => :en}
end

@ -48,7 +48,7 @@ module FilesHelper
def courses_check_box_tags(name,courses,current_course,attachment)
s = ''
courses.each do |course|
if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
if !course_contains_attachment?(course,attachment) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
s << "<label>#{ check_box_tag name, course.id, false, :id => nil } #{h course.name}</label>&nbsp;[#{get_course_term course}]<br/>"
end
end

@ -23,15 +23,22 @@ module MembersHelper
principal_count = scope.count
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
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, 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')
end
#获取项目可邀请的成员列表
def render_project_members project
scope = Principal.active.sorted.not_member_of(project).like(params[:q])
principals = paginateHelper scope,10
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :style => "margin-left: -40px;")
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
}
s + content_tag('ul', links,:class => 'wlist')
end
# add by nwb
@ -71,4 +78,18 @@ module MembersHelper
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

@ -283,6 +283,6 @@ module WatchersHelper
def exit_project_link(project)
link_to(l(:label_exit_project),exit_cur_project_path(project.id),
:remote => true, :confirm => l(:lable_sure_exit_project), :style => "color: #fff; display:block; padding: 0px 5px;margin-right:10px;height:22px;background:none repeat scroll 0% 0% #64BDD9;TES" )
:remote => true, :confirm => l(:lable_sure_exit_project), :style => "color: #fff; display:block; padding: 0px 5px; margin-right: 10px; height: 22px; line-height: 22px; background: none repeat scroll 0% 0% #64BDD9; TES" )
end
end

@ -41,7 +41,7 @@ class Project < ActiveRecord::Base
has_many :principals, :through => :member_principals, :source => :principal
has_many :enabled_modules, :dependent => :delete_all
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_many :issues, :dependent => :destroy, :include => [:status, :tracker],:order => "id ASC"
has_many :issues, :dependent => :destroy, :include => [:status, :tracker],:order => "issues.id ASC"
has_many :issue_changes, :through => :issues, :source => :journals
has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
has_many :time_entries, :dependent => :delete_all

@ -1,4 +1,3 @@
#coding=utf-8
class CoursesService
include ApplicationHelper
include CoursesHelper
@ -355,19 +354,19 @@ class CoursesService
latest_course_dynamics = []
latest_news = course.news.order("created_on desc").first
unless latest_news.nil?
latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => '最近更新了通知' }#l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)}
latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)}
end
latest_message = course.journals_for_messages.order("created_on desc").first
unless latest_message.nil?
latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => '最近更新了留言'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
end
latest_attachment = course.attachments.order("created_on desc").first
unless latest_attachment.nil?
latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => '最近更新了课件'}#l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)}
latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)}
end
latest_bid = course.homeworks.order('updated_on DESC').first
unless latest_bid.nil?
latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => '最近更新了作业'}#l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)}
latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)}
end
#每个作业中的最新留言
messages = []
@ -382,7 +381,7 @@ class CoursesService
end
latest_bid_message = messages.first
unless latest_bid_message.nil?
latest_course_dynamics << {:type => 2,:time => latest_bid_message.created_on,:message => '最近更新了留言'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
latest_course_dynamics << {:type => 4,:time => latest_bid_message.created_on,:message => '最近更新了作业'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)}
end
#每个作业中学生最后提交的作业
homeworks = []

@ -80,6 +80,28 @@ class UsersService
{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
end
#忘记密码
def lost_password params
user = ::User.find_by_mail(params[:mail].to_s)
# user not found or not active
unless user && user.active?
raise l(:notice_account_unknown_email,:locale => 'zh')
end
# user cannot change its password
unless user.change_password_allowed?
raise l(:notice_can_t_change_password,:locale => user.language)
return
end
# create a new token for password recovery
token = Token.new(:user => user, :action => "recovery")
if token.save
Thread.new do
Mailer.lost_password(token).deliver
end
return l(:notice_account_lost_email_sent,:locale => user.language)
end
end
#编辑用户
#gender 1female 0male 其他male
def edit_user params

@ -36,7 +36,7 @@
<% end %>
</tbody>
</table>
<% if @versions.first.attachments.any?%>
<% if !@versions.first.nil? && @versions.first.attachments.any?%>
<% options = {:author => true, :deletable => true } %>
<%= render :partial => 'attachments/links', :locals => {:attachments => @versions.first.attachments, :options => options, :is_float => true} %>
<% end %>

@ -1,6 +1,6 @@
<span id="attachments_fields" xmlns="http://www.w3.org/1999/html">
<% if defined?(container) && container && container.saved_attachments %>
<% container.attachments.each_with_index do |attachment, i| %>
<% container.saved_attachments.each_with_index do |attachment, i| %>
<span id="attachments_p<%= i %>" class="attachment">
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>

@ -34,7 +34,8 @@
<%= 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',
:class => 'delete delete-homework-icon',
:remote => true,
:title => l(:button_delete) %>
<% else %>
<%= link_to image_tag('delete.png'), attachment_path(attachment),

@ -172,9 +172,9 @@
<tr>
<td style="text-align: left" colspan="2">
<span class="font_lighter">
<%= l(:label_create_time) %>
<%= l(:label_end_time) %>
:&nbsp;
<%=format_time bid.created_on %>
<%= bid.deadline %>
</span>
<span style="float: right">
<% if betweentime(bid.deadline) < 0 %>

@ -28,7 +28,7 @@
</div>
<% if @grouped.empty? %>
<p class="nodata">
<p class="nodata" style="margin-top: 30px;">
<%= l(:label_no_data) %>
</p>
<% end %>

@ -1,38 +1,45 @@
<div class="project_r_h">
<h2 class="project_h2"><%=h @document.title %></h2>
<h2 class="project_h2"><%= l(:project_module_documents) %></h2>
</div>
<div class="frame-wiki">
<div class="frame-wiki">
<div class="contextual">
<% if User.current.allowed_to?(:edit_documents, @project) %>
<%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
<% end %>
<% if User.current.allowed_to?(:delete_documents, @project) %>
<%= delete_link document_path(@document) %>
<% end %>
</div>
<p style="padding-top: 5px">
<%= h @document.title %>
</p>
<p>
<em><%#=h @document.category.name %>
<br />
<%= format_date @document.created_on %></em>
</p>
<div class="wiki">
<%= textilizable @document, :description, :attachments => @document.attachments %>
</div>
<div class="contextual">
<% if User.current.allowed_to?(:edit_documents, @project) %>
<%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
<% end %>
<% if User.current.allowed_to?(:delete_documents, @project) %>
<%= delete_link document_path(@document) %>
<% end %>
</div>
<p><em><%#=h @document.category.name %><br />
<%= format_date @document.created_on %></em></p>
<div class="wiki">
<%= textilizable @document, :description, :attachments => @document.attachments %>
</div>
<div style="border-top:solid 1px #C6E9F1;"></div>
<h3><%= l(:label_attachment_plural) %></h3>
<%= link_to_attachments @document %>
<div style="border-top:solid 1px #C6E9F1;"></div>
<h3><%= l(:label_attachment_plural) %></h3>
<%= link_to_attachments @document %>
<% if authorize_for('documents', 'add_attachment') %>
<p><%= link_to l(:label_attachment_new), {}, :onclick => "$('#add_attachment_form').show(); return false;",
:id => 'attach_files_link' %></p>
<%= form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
<div class="box">
<p><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_add) %>
<% end %>
<% end %>
<% if authorize_for('documents', 'add_attachment') %>
<p>
<%= link_to l(:label_attachment_new), {}, :onclick => "$('#add_attachment_form').show(); return false;",
:id => 'attach_files_link' %>
</p>
<%= form_tag({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %>
<div class="box">
<p>
<%= render :partial => 'attachments/form' %>
</p>
</div>
<%= submit_tag l(:button_add) %>
<% end %>
<% end %>
<% html_title @document.title -%>
<% html_title @document.title -%>
</div>

@ -11,7 +11,7 @@
<%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @project) %>
<%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @project) %>
<p></p>
<div id="upload_file_div" class="relation_file_div hidden">
<div id="upload_file_div" class="relation_file_div <%= !@flag.nil?&&@flag=="true" ? '' : 'hidden'%>">
<%= render :partial => 'new', locals: {project: @project} %>
</div>
<div id="relation_file_div" class="relation_file_div hidden">

@ -1,5 +1,5 @@
<div class="project_r_h">
<h2 class="project_h2"><%=l(:label_attachment_new)%></h2>
<h2 class="project_h2"><%= l(:label_course_file) %></h2>
</div>
<%= error_messages_for 'attachment' %>
@ -8,11 +8,10 @@
<% if @versions.any? %>
<p><label for="version_id"><%=l(:field_version)%></label>
<%= select_tag "version_id", content_tag('option', '') +
options_from_collection_for_select(@versions, "id", "name") %></p>
<%= select_tag "version_id", content_tag('option', '') + options_from_collection_for_select(@versions, "id", "name") %></p>
<% end %>
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
<p><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form' %></p>
</div>
<%= submit_tag l(:button_add) %>
<% end %>

@ -1,6 +1,6 @@
$(function(){
$("#button1").click(function(){
myTips(<%= l(:label_feedback_success)%>,"success");
myTips(<%= l(:label_forums_feedback_success)%>,"success");
});
})

@ -2,7 +2,7 @@
<h2 class="project_h2">问题跟踪</h2>
</div>
<div class="problem_top">
<% if @project.enabled_modules.where("name = 'issue_tracking'").count > 0 %>
<% unless @project.enabled_modules.where("name = 'issue_tracking'").empty? %>
<span>
<% if User.current.member_of?(@project) %>
<%= link_to l(:label_issue_new), {:controller => 'issues', :action => 'new', :copy_from => nil}, :param => :project_id, :caption => :label_issue_new,

@ -5,4 +5,6 @@
per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="spacer">
<%= raw(t 'views.pagination.truncate') %>
</span>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save