代码优化

文件目录动态获取接口
文件目录显示样式
This commit is contained in:
huang 2016-04-19 09:34:55 +08:00
parent 200307ec9f
commit adc17c5038
5 changed files with 54 additions and 21 deletions

View File

@ -123,7 +123,7 @@ module ApplicationHelper
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1)
else
score = course_contributor_score.homework_journal_num.to_i + 1
course_contributor_score.update_attributes(:homework_journal_num => score)
course_contributor_score.update_column(:homework_journal_num, score)
end
# 课程留言
when "Course"
@ -131,42 +131,42 @@ module ApplicationHelper
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1)
else
score = course_contributor_score.journal_num.to_i + 1
course_contributor_score.update_attributes(:journal_num => score)
course_contributor_score.update_column(:journal_num, score)
end
when "Message"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1)
else
score = course_contributor_score.message_num.to_i + 1
course_contributor_score.update_attributes(:message_num => score)
course_contributor_score.update_column(:message_num, score)
end
when "MessageReply"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1)
else
score = course_contributor_score.message_reply_num.to_i + 1
course_contributor_score.update_attributes(:message_reply_num => score)
course_contributor_score.update_column(:message_reply_num, score)
end
when "NewReply"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1)
else
score = course_contributor_score.news_reply_num.to_i + 1
course_contributor_score.update_attributes(:news_reply_num => score)
course_contributor_score.update_column(:news_reply_num, score)
end
when "News"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1)
else
score = course_contributor_score.news_num.to_i + 1
course_contributor_score.update_attributes(:news_num => score)
course_contributor_score.update_column(:news_num, score)
end
when "Attachment"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1)
else
score = course_contributor_score.resource_num.to_i + 1
course_contributor_score.update_attributes(:resource_num => score)
course_contributor_score.update_column(:resource_num, score)
end
end
end
@ -178,38 +178,38 @@ module ApplicationHelper
when "HomeworkCommon"
unless course_contributor_score.nil?
score = course_contributor_score.homework_journal_num.to_i - 1
course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:homework_journal_num, score < 0 ? 0 : score)
end
# 课程留言
when "Course"
unless course_contributor_score.nil?
score = course_contributor_score.journal_num.to_i - 1
course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:journal_num, score < 0 ? 0 : score)
end
when "Message"
unless course_contributor_score.nil?
score = course_contributor_score.message_num.to_i - 1
course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:message_num, score < 0 ? 0 : score)
end
when "MessageReply"
unless course_contributor_score.nil?
score = course_contributor_score.message_reply_num.to_i - 1
course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:message_reply_num, score < 0 ? 0 : score)
end
when "NewReply"
unless course_contributor_score.nil?
score = course_contributor_score.news_reply_num.to_i - 1
course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:news_reply_num, score < 0 ? 0 : score)
end
when "News"
unless course_contributor_score.nil?
score = course_contributor_score.news_num.to_i - 1
course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:news_num, score < 0 ? 0 : score)
end
when "Attachment"
unless course_contributor_score.nil?
score = course_contributor_score.resource_num.to_i - 1
course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score)
course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score)
end
end
end

View File

@ -41,6 +41,17 @@ module RepositoriesHelper
identifiers.include?(iden) ? false :true
end
# 获取文件目录的最新动态
def get_trees_last_changes(project_id, rev)
g = Gitlab.client
begin
tree_changes = g.rep_last_changes(project_id, :rev => rev)
tree_changes
rescue
logger.error("faile to get tress activities!")
end
end
# 获取diff内容行号
def diff_line_num content
content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i

View File

@ -3,6 +3,8 @@
depth = params[:depth].to_i %>
<% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(entry.path) %>
<% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %>
<% get_trees_last_changes(@project.id, @rev) %>
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>">
<td style="padding-left: <%=18 * depth%>px;" class="<%=
@repository.report_last_commit ? "filename" : "filename_no_report" %>">
@ -23,11 +25,11 @@
</td>
<!--<td class="size"><%#= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>-->
<!--<td class="size"><%#= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>-->
<% if @repository.report_last_commit %>
<td class="revision"><%= link_to_revision(entry.changeset, @repository) if entry.changeset %></td>
<td class="age"><%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td>
<td class="author"><%= entry.author %></td>
<td class="comments"><%=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %></td>
<% end %>
<%# if @repository.report_last_commit %>
<td class="tree-age c_grey">一个月前<%#= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td>
<td class="tree-author c_grey">huang<%#= entry.author %></td>
<td class="tree-comments c_grey">修改版本库<%#=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %></td>
<%# end %>
</tr>
<% end %>

View File

@ -106,6 +106,23 @@ class Gitlab::Client
end
alias_method :repo_rep_stats, :rep_stats
# Gets a tree activities of project repository.
#
# @example
# Gitlab.commits('viking')
# Gitlab.repo_commits('gitlab', :ref_name => 'api')
#
# @param [Integer] project The ID of a project.
# @param [Hash] options A customizable set of options.
# @option options [String] :ref_name The branch or tag name of a project repository.
# @option options [String] :creator The user name of a project repository.
# @option options [Integer] :period Statistics over time. 1:total 2one month 3one week
# @return [Array<Gitlab::ObjectifiedHash>]
def rep_last_changes(project, options={})
get("/projects/#{project}/repository/rep_last_changes", :query => options)
end
alias_method :repo_rep_stats, :rep_stats
# Get the diff of a commit in a project.
#
# @example

View File

@ -593,6 +593,9 @@ img.ui-datepicker-trigger {
.repos_files ul:hover{ background:#ffffdd;}
.repos_t_c li{ text-align:center;}
.pic_stats{display:block; background:url(../images/public_icon.png) 0px -548px no-repeat; width:20px; height:15px;}
.tree-age{width:10%; text-align:right;}
.tree-author{width:10%; text-align:right;}
.tree-comments{width:20%; text-align:right;}
/* 里程碑 */
@ -816,7 +819,7 @@ div.changeset { border-bottom: 1px solid #ddd; }
tr.entry { border: 1px solid #DDD; }
tr.entry td { white-space: nowrap; }
tr.entry td.filename { width: 30%; }
tr.entry td.filename_no_report { width: 70%; }
tr.entry td.filename_no_report { width: 60%; }
tr.entry td.size { text-align: right; font-size: 90%; }
tr.entry td.revision, tr.entry td.author { text-align: center; }
tr.entry td.age { text-align: right; }