diff --git a/app/assets/javascripts/angular-new/controllers/git_tree_controller.js b/app/assets/javascripts/angular-new/controllers/git_tree_controller.js index d981782d1..da5e50369 100644 --- a/app/assets/javascripts/angular-new/controllers/git_tree_controller.js +++ b/app/assets/javascripts/angular-new/controllers/git_tree_controller.js @@ -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) { diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index 6006fd3ac..d750b3ba7 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -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) diff --git a/app/models/concerns/git.rb b/app/models/concerns/git.rb index 3565ea25e..a19fb1917 100644 --- a/app/models/concerns/git.rb +++ b/app/models/concerns/git.rb @@ -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, diff --git a/app/views/home/_activity_tab.html.haml b/app/views/home/_activity_tab.html.haml index 7c1da5894..4ef150eeb 100644 --- a/app/views/home/_activity_tab.html.haml +++ b/app/views/home/_activity_tab.html.haml @@ -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}} diff --git a/app/views/projects/git/base/_whereami.html.haml b/app/views/projects/git/base/_whereami.html.haml index e0ec97d18..15c77c021 100644 --- a/app/views/projects/git/base/_whereami.html.haml +++ b/app/views/projects/git/base/_whereami.html.haml @@ -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}} diff --git a/app/views/projects/git/trees/_show.html.haml b/app/views/projects/git/trees/_show.html.haml index e308f0588..c8ee17f3f 100644 --- a/app/views/projects/git/trees/_show.html.haml +++ b/app/views/projects/git/trees/_show.html.haml @@ -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' diff --git a/app/views/projects/git/trees/show.json.jbuilder b/app/views/projects/git/trees/show.json.jbuilder index b8907eb28..fa7c320db 100644 --- a/app/views/projects/git/trees/show.json.jbuilder +++ b/app/views/projects/git/trees/show.json.jbuilder @@ -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) diff --git a/config/locales/layout.en.yml b/config/locales/layout.en.yml index d4fefe67b..eceb18d95 100644 --- a/config/locales/layout.en.yml +++ b/config/locales/layout.en.yml @@ -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 diff --git a/config/locales/layout.ru.yml b/config/locales/layout.ru.yml index 8dae4c389..88af75c1d 100644 --- a/config/locales/layout.ru.yml +++ b/config/locales/layout.ru.yml @@ -2,8 +2,9 @@ ru: layout: autoreload_page: Автоматически обновлять страницу word_wrap: Перенос строк - autoreload_log: Обновлять лог каждые + autoreload_log: Обновлять лог каждые read_more: Читать дальше + load_more: Загрузить далее turned_on: включены turned_off: выключены