项目积分存数据库

有项目积分引起的系列bug
This commit is contained in:
z9hang 2014-08-06 11:46:38 +08:00
parent 1ca6447478
commit 05186c8590
12 changed files with 28 additions and 5 deletions

View File

@ -27,6 +27,7 @@ class CalendarsController < ApplicationController
include QueriesHelper include QueriesHelper
helper :sort helper :sort
include SortHelper include SortHelper
helper :project_score
def show def show
if params[:year] and params[:year].to_i > 1900 if params[:year] and params[:year].to_i > 1900

View File

@ -26,6 +26,7 @@ class DocumentsController < ApplicationController
before_filter :authorize_document before_filter :authorize_document
helper :attachments helper :attachments
helper :project_score
def index def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'

View File

@ -24,6 +24,7 @@ class FilesController < ApplicationController
helper :sort helper :sort
include SortHelper include SortHelper
helper :project_score
def index def index
#sort_init 'filename', 'asc' #sort_init 'filename', 'asc'

View File

@ -29,6 +29,7 @@ class GanttsController < ApplicationController
helper :sort helper :sort
include SortHelper include SortHelper
include Redmine::Export::PDF include Redmine::Export::PDF
helper :project_score
def show def show
@gantt = Redmine::Helpers::Gantt.new(params) @gantt = Redmine::Helpers::Gantt.new(params)

View File

@ -26,6 +26,8 @@ class IssueCategoriesController < ApplicationController
before_filter :authorize before_filter :authorize
accept_api_auth :index, :show, :create, :update, :destroy accept_api_auth :index, :show, :create, :update, :destroy
helper :project_score
def index def index
respond_to do |format| respond_to do |format|
format.html { redirect_to_settings_in_projects } format.html { redirect_to_settings_in_projects }

View File

@ -28,6 +28,7 @@ class MessagesController < ApplicationController
helper :watchers helper :watchers
helper :attachments helper :attachments
include AttachmentsHelper include AttachmentsHelper
helper :project_score
REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)

View File

@ -494,10 +494,10 @@ class ProjectsController < ApplicationController
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id) user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id)
Rails.logger.debug "UserGrade created: #{user_grades.to_json}" Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
if params[:project][:is_public] == '1' #if params[:project][:is_public] == '1'
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type) project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}" Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
end #end
@project.members << m @project.members << m
@project.project_infos << project_info @project.project_infos << project_info
#end #end

View File

@ -207,6 +207,7 @@ class RepositoriesController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to settings_project_path(@project, :tab => 'repositories') redirect_to settings_project_path(@project, :tab => 'repositories')
end end
end end
def destroy def destroy

View File

@ -29,6 +29,7 @@ class VersionsController < ApplicationController
helper :custom_fields helper :custom_fields
helper :projects helper :projects
helper :project_score
def index def index
respond_to do |format| respond_to do |format|

View File

@ -44,6 +44,7 @@ class WikiController < ApplicationController
include AttachmentsHelper include AttachmentsHelper
helper :watchers helper :watchers
include Redmine::Export::PDF include Redmine::Export::PDF
helper :project_score
# List of pages, sorted alphabetically and by parent (hierarchy) # List of pages, sorted alphabetically and by parent (hierarchy)
def index def index

View File

@ -67,7 +67,20 @@ module ProjectScoreHelper
#项目得分 #项目得分
def project_scores project def project_scores project
(issue_score project) + (news_score project) + (document_score project) + (changesets_score project) + (board_message_score project) result = (issue_score project) + (news_score project) + (document_score project) + (changesets_score project) + (board_message_score project)
pss = ProjectStatus.where("project_id = '#{project.id}'")
if pss.nil? || pss.count == 0
ps = ProjectStatus.new
ps.grade = result
ps.project = project
ps.watchers_count = project.watcher_users.count
ps.save
else
ps = pss.first
ps.grade = result
ps.save
end
result
end end
end end

View File

@ -1,5 +1,5 @@
class ProjectStatus < ActiveRecord::Base class ProjectStatus < ActiveRecord::Base
attr_accessible :changesets_count, :watchers_count, :project_id, :project_type attr_accessible :changesets_count, :watchers_count, :project_id, :project_type,:grade
belongs_to :project belongs_to :project
belongs_to :watchers belongs_to :watchers
belongs_to :changesets belongs_to :changesets