[#369] add tree content pagination
This commit is contained in:
parent
388617c248
commit
66e21de2b7
|
@ -1,9 +1,11 @@
|
|||
RosaABF.controller('GitTreeCtrl', ['$scope', '$http', function($scope, $http) {
|
||||
$scope.project = null;
|
||||
$scope.treeish = null;
|
||||
$scope.path = null;
|
||||
$scope.root_path = null;
|
||||
$scope.tree = null;
|
||||
$scope.project = null;
|
||||
$scope.treeish = null;
|
||||
$scope.path = null;
|
||||
$scope.root_path = null;
|
||||
$scope.tree = null;
|
||||
$scope.breadcrumb = null;
|
||||
$scope.processing = false;
|
||||
|
||||
$scope.init = function(project, treeish, path, root_path) {
|
||||
$scope.project = project;
|
||||
|
@ -13,7 +15,10 @@ RosaABF.controller('GitTreeCtrl', ['$scope', '$http', function($scope, $http) {
|
|||
$scope.getTree();
|
||||
};
|
||||
|
||||
$scope.getTree = function($event, path) {
|
||||
$scope.getTree = function($event, path, more) {
|
||||
$scope.processing = true;
|
||||
more = typeof more !== 'undefined' ? more : false;
|
||||
|
||||
if(path) { $scope.path = path; }
|
||||
if($scope.path) {
|
||||
var treeish = $scope.treeish+'/'+$scope.path;
|
||||
|
@ -21,11 +26,23 @@ RosaABF.controller('GitTreeCtrl', ['$scope', '$http', function($scope, $http) {
|
|||
else {
|
||||
var treeish = $scope.treeish;
|
||||
}
|
||||
$http.get(Routes.tree_path($scope.project, treeish, {format: 'json'})).then(function(res) {
|
||||
$scope.path = res.data.path;
|
||||
$scope.root_path = res.data.root_path;
|
||||
$scope.tree = res.data.tree;
|
||||
$scope.path_breadcrumb = res.data.tree_breadcrumb;
|
||||
var params = {format: 'json'};
|
||||
if(more) {
|
||||
params.page = $scope.next_page;
|
||||
}
|
||||
|
||||
$http.get(Routes.tree_path($scope.project, treeish, params)).then(function(res) {
|
||||
$scope.path = res.data.path;
|
||||
$scope.root_path = res.data.root_path;
|
||||
$scope.breadcrumb = res.data.breadcrumb;
|
||||
$scope.next_page = res.data.next_page;
|
||||
if(more) {
|
||||
$scope.tree.push.apply($scope.tree, res.data.tree);
|
||||
}
|
||||
else {
|
||||
$scope.tree = res.data.tree;
|
||||
}
|
||||
$scope.processing = false;
|
||||
});
|
||||
|
||||
if($event) {
|
||||
|
|
|
@ -55,17 +55,16 @@ module GitHelper
|
|||
res.html_safe
|
||||
end
|
||||
|
||||
def iterate_path(path, &block)
|
||||
p '*'*60, "path == #{path}", '*'*60
|
||||
path.split(File::SEPARATOR).inject('') do |a, e|
|
||||
p '*'*60, "a == #{a}; e = #{e}", '*'*60
|
||||
if e != '.' && e != '..'
|
||||
a = File.join(a, e)
|
||||
a = a[1..-1] if a[0] == File::SEPARATOR
|
||||
block.call(a, e) if a.length > 1
|
||||
def iterate_path(path)
|
||||
tree = []
|
||||
path.split("\/").each do |name|
|
||||
if tree.last
|
||||
tree << [File.join(tree.try(:last).try(:first), name), name]
|
||||
else
|
||||
tree << [name, name]
|
||||
end
|
||||
a
|
||||
end
|
||||
tree
|
||||
end
|
||||
|
||||
def branch_selector_options(project)
|
||||
|
|
|
@ -5,6 +5,8 @@ module Git
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
CONTENT_LIMIT = 200
|
||||
|
||||
has_attached_file :srpm
|
||||
|
||||
validates_attachment_size :srpm, less_than_or_equal_to: 500.megabytes
|
||||
|
@ -88,14 +90,16 @@ module Git
|
|||
[repo.commits(treeish, options[:per_page], skip), options[:page], last_page]
|
||||
end
|
||||
|
||||
def tree_info(tree, treeish = nil, path = nil)
|
||||
def tree_info(tree, treeish = nil, path = nil, page = 0)
|
||||
return [] unless tree
|
||||
grouped = tree.contents.sort_by{|c| c.name.downcase}.group_by(&:class)
|
||||
[
|
||||
contents = [
|
||||
grouped[Grit::Tree],
|
||||
grouped[Grit::Blob],
|
||||
grouped[Grit::Submodule]
|
||||
].compact.flatten.map do |node|
|
||||
].compact.flatten
|
||||
range = page*CONTENT_LIMIT..CONTENT_LIMIT+page*(CONTENT_LIMIT)-1
|
||||
contents[range].map do |node|
|
||||
node_path = File.join([path.present? ? path : nil, node.name].compact)
|
||||
[
|
||||
node,
|
||||
|
|
|
@ -25,4 +25,3 @@
|
|||
%hr
|
||||
%btn.center-block.btn.btn-primary{ 'ng-show' => 'getCurActivity().next_page_link', 'ng-click' => "load_more()" }
|
||||
= t('layout.activity_feed.load_messages')
|
||||
{{activity_tab.content.next_page_link}}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
%ol.breadcrumb
|
||||
%li= link_to @project.name, tree_path(@project, treeish: @treeish), 'ng-click' => "getTree($event)"
|
||||
%li{ 'ng-repeat' => 'path in tree_breadcrumb.elements' }
|
||||
%a{ 'ng-href' => '{{path.url}}', 'ng-click' => 'getTree($event, path.path)' } {{path.name}}
|
||||
%li.active {{path.last}}
|
||||
%li= link_to @project.name, tree_path(@project, treeish: @treeish), 'ng-click' => "getTree($event, '/')"
|
||||
%li{ 'ng-repeat' => 'el in breadcrumb.paths' }
|
||||
%a{ href: '#', 'ng-click' => 'getTree($event, el.path)' } {{el.name}}
|
||||
%li.active {{breadcrumb.last}}
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
%thead
|
||||
%tr
|
||||
%th= t 'layout.projects.filename'
|
||||
%th.col-md-9= t 'layout.projects.message'
|
||||
%th.col-md-8= t 'layout.projects.message'
|
||||
%th= t 'layout.projects.age'
|
||||
%tbody
|
||||
%tr{ 'ng-show' => 'path' }
|
||||
%tr{ 'ng-show' => 'path && !processing' }
|
||||
%td
|
||||
%span= fa_icon 'folder', class: 'text-primary'
|
||||
%a{ 'ng-href' => '{{root_path}}', 'ng-click' => 'getTree(root_path)' } ..
|
||||
%a{ 'ng-href' => '{{root_path}}', 'ng-click' => 'getTree($event, root_path)' } ..
|
||||
%td
|
||||
%td
|
||||
%tr{ 'ng-repeat' => 'el in tree' }
|
||||
|
@ -36,3 +36,8 @@
|
|||
%span{ 'am-time-ago' => 'el.commit.committed_date', title: "{{issue.committed_date | amDateFormat:'ddd, LLL'}}" }
|
||||
%td{ 'ng-hide' => 'el.commit' }
|
||||
%td{ 'ng-hide' => 'el.commit' }
|
||||
|
||||
%hr
|
||||
%btn.center-block.btn.btn-primary{ 'ng-show' => 'next_page', 'ng-disabled' => 'processing',
|
||||
'ng-click' => 'getTree($event, null, true)' }
|
||||
= t 'layout.activity_feed.load_more'
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
json.project do
|
||||
json.(@project, :id, :name)
|
||||
json.fullname '!!!!!!!!!' #@project.name_with_owner
|
||||
|
||||
json.owner do
|
||||
json.(@project.owner, :id, :name, :uname)
|
||||
end
|
||||
end
|
||||
page = params[:page].to_i
|
||||
|
||||
json.tree do
|
||||
json.array!@project.tree_info(@tree, @treeish, @path).each do |node, node_path, commit|
|
||||
json.array!@project.tree_info(@tree, @treeish, @path, page).each do |node, node_path, commit|
|
||||
if node.is_a? Grit::Submodule
|
||||
url = submodule_url(node, @treeish)
|
||||
json.submodule do
|
||||
|
@ -42,26 +35,22 @@ json.tree do
|
|||
end
|
||||
end
|
||||
|
||||
json.tree_breadcrumb do
|
||||
json.breadcrumb do
|
||||
if @path.present?
|
||||
paths = File.split(@path)
|
||||
if paths.size > 1 && paths.first != '.'
|
||||
json.elements do
|
||||
json.array! paths.first.split(File::SEPARATOR).each do |a, name|
|
||||
if name != '.' && name != '..'
|
||||
path = File.join(a, name)
|
||||
path = path[1..-1] if path[0] == File::SEPARATOR
|
||||
if path.length > 1
|
||||
json.name path
|
||||
json.path name
|
||||
end
|
||||
end
|
||||
if paths.size > 1 and paths.first != '.'
|
||||
json.paths do
|
||||
json.array! iterate_path2(paths.first).each do |el|
|
||||
json.path el.first
|
||||
json.name el.last
|
||||
end
|
||||
end
|
||||
json.last paths.last
|
||||
end
|
||||
json.last paths.last
|
||||
end
|
||||
end
|
||||
|
||||
json.path @path
|
||||
json.root_path @path.present? ? File.join([@path, ".."].compact) : nil
|
||||
params[:page].to_i
|
||||
json.next_page page.next if @tree.contents.count >= Project::CONTENT_LIMIT*(page+1)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
en:
|
||||
layout:
|
||||
autoreload_page: Update page automatically
|
||||
autoreload_log: Update log every
|
||||
autoreload_log: Update log every
|
||||
word_wrap: Word wrap
|
||||
read_more: Read more
|
||||
load_more: Load more
|
||||
turned_on: on
|
||||
turned_off: off
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@ ru:
|
|||
layout:
|
||||
autoreload_page: Автоматически обновлять страницу
|
||||
word_wrap: Перенос строк
|
||||
autoreload_log: Обновлять лог каждые
|
||||
autoreload_log: Обновлять лог каждые
|
||||
read_more: Читать дальше
|
||||
load_more: Загрузить далее
|
||||
turned_on: включены
|
||||
turned_off: выключены
|
||||
|
||||
|
|
Loading…
Reference in New Issue