版本库异步加载

This commit is contained in:
huang 2016-10-19 15:18:26 +08:00
parent 89292054c8
commit 97172ed76f
3 changed files with 48 additions and 8 deletions

View File

@ -44,6 +44,7 @@ class ProjectsController < ApplicationController
end
end
helper :bids
include BidsHelper
helper :contests
@ -658,6 +659,23 @@ class ProjectsController < ApplicationController
end
#end
# 获取项目tree目录的最新提交记录
# 异步请求
# gpid, rev, ent_name, g
def repository_tree_changes
rev = params[:rev]
ent_name = params[:ent_name]
gpid = params[:gpid]
g = Gitlab.client
begin
result = g.rep_last_changes(gpid, :rev => rev, :path => ent_name)
# result.time = distance_of_time_in_words(result.time, Time.now)
rescue Exception => e
puts e
end
render :json => result
end
def update
@project.safe_attributes = params[:project]
@project.organization_id = params[:organization_id]

View File

@ -4,7 +4,7 @@
<% sub_path = entry.path[0] == "/" ? entry.path.sub("/", "") : entry.path %>
<% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(sub_path) %>
<% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %>
<% latest_changes = get_trees_last_changes(@project.gpid, @rev, ent_path, @g) %>
<%# latest_changes = get_trees_last_changes(@project.gpid, @rev, ent_path, @g) %>
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>">
<td style="padding-left: <%=18 * depth%>px;" class="filename_no_report hidden">
@ -16,7 +16,7 @@
:repository_id => @repository.identifier_param,
:path => to_path_param(ent_path),
:rev => @rev,
:latest_changes => latest_changes,
:depth => (depth + 1),
:parent_id => tr_id)) %>');">&nbsp;</span>
<% end %>
@ -26,21 +26,42 @@
</td>
<div id="children_tree">
<td class="tree-comments c_grey hidden">
<div class="hidden" title="<%= (latest_changes.message) if latest_changes %>">
<%= (latest_changes.message) if latest_changes %>
<div class="hidden" id="changes_message_<%= tr_id %>">
<%#= (latest_changes.message) if latest_changes %>
</div>
</td>
<td class="tree-author c_grey">
<div class="hidden" title="<%= (latest_changes.author_name) if latest_changes %>">
<%= (latest_changes.author_name) if latest_changes %>
<div class="hidden" id="changes_author_<%= tr_id %>">
<%#= (latest_changes.author_name) if latest_changes %>
</div>
</td>
<td class="tree-age c_grey">
<div class="hidden" title="<%= format_time(latest_changes.time) if latest_changes %>">
<div class="hidden" id="changes_time_<%= tr_id %>">
<%# 为了转换UTC时间时差8小时 %>
<%= distance_of_time_in_words(latest_changes.time, Time.now) if latest_changes %>
<%#= distance_of_time_in_words(latest_changes.time, Time.now) if latest_changes %>
<%#= link_to "", repository_tree_changes_project_path(@project, :rev => @rev, :ent_name => ent_name) %>
</div>
</td>
</div>
</tr>
<script>
$(document).ready(function(){
console.log("2222222222");
$.ajax({
url:"<%= repository_tree_changes_project_path(@project, :rev => @rev, :ent_name => ent_name, :gpid => @project.gpid) %>",
type: "GET",
data: "text",
success:function(data){
console.log(data);
$('#changes_message_<%=tr_id %>').html(data.message)
$('#changes_author_<%=tr_id %>').html(data.author_name)
$('#changes_time_<%=tr_id %>').html(data.time)
}
});
});
</script>
<% end %>

View File

@ -752,6 +752,7 @@ RedmineApp::Application.routes.draw do
match 'store_mine', :to => 'projects#store_mine', :as => 'store_mine'
get 'file', :action => 'file', :as => 'file'
get 'statistics', :action => 'statistics', :as => 'statistics'
get 'repository_tree_changes', :action => 'repository_tree_changes', :as => 'repository_tree_changes'
get 'feedback', :action => 'feedback', :as => 'project_feedback'
get 'watcherlist', :action=> 'watcherlist'