From 202ac91644bec98df61a7350c213df55e7a7c724 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 11 Jul 2014 15:43:45 +0600 Subject: [PATCH] [#369] change location in the tree page --- .../controllers/git_tree_controller.js | 44 ++++++++++++------- .../projects/git/trees_controller.rb | 2 + .../projects/git/base/_whereami.html.haml | 2 +- app/views/projects/git/trees/_show.html.haml | 5 +-- .../projects/git/trees/show.json.jbuilder | 4 +- config/routes.rb | 2 +- 6 files changed, 37 insertions(+), 22 deletions(-) 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 da5e50369..7162a72b4 100644 --- a/app/assets/javascripts/angular-new/controllers/git_tree_controller.js +++ b/app/assets/javascripts/angular-new/controllers/git_tree_controller.js @@ -1,7 +1,6 @@ -RosaABF.controller('GitTreeCtrl', ['$scope', '$http', function($scope, $http) { +RosaABF.controller('GitTreeCtrl', ['$scope', '$http', '$location', function($scope, $http, $location) { $scope.project = null; $scope.treeish = null; - $scope.path = null; $scope.root_path = null; $scope.tree = null; $scope.breadcrumb = null; @@ -10,28 +9,21 @@ RosaABF.controller('GitTreeCtrl', ['$scope', '$http', function($scope, $http) { $scope.init = function(project, treeish, path, root_path) { $scope.project = project; $scope.treeish = treeish; + $scope.root_path = root_path; $scope.path = path; - $scope.path_path = root_path; - $scope.getTree(); + //$scope.getTree(); }; - $scope.getTree = function($event, path, more) { + $scope.refresh = function(more) { $scope.processing = true; - more = typeof more !== 'undefined' ? more : false; - if(path) { $scope.path = path; } - if($scope.path) { - var treeish = $scope.treeish+'/'+$scope.path; - } - else { - var treeish = $scope.treeish; - } - var params = {format: 'json'}; + var params = { format: 'json', path: $scope.path }; + if(more) { params.page = $scope.next_page; } - $http.get(Routes.tree_path($scope.project, treeish, params)).then(function(res) { + $http.get(Routes.tree_path($scope.project, $scope.treeish, params)).then(function(res) { $scope.path = res.data.path; $scope.root_path = res.data.root_path; $scope.breadcrumb = res.data.breadcrumb; @@ -44,6 +36,28 @@ RosaABF.controller('GitTreeCtrl', ['$scope', '$http', function($scope, $http) { } $scope.processing = false; }); + }; + + $scope.$on('$locationChangeSuccess', function(event) { + $scope.path = $location.search()['path']; + $scope.refresh(); + }); + + $scope.getTree = function($event, path, more) { + if($scope.processing && $event) { + return $event.preventDefault(); + } + + more = typeof more !== 'undefined' ? more : false; + if(path && path !== '') { $scope.path = path; } + else { $scope.path = null; } + + if(more) { + $scope.refresh(more); + } + else { + $location.search('path', $scope.path); + } if($event) { $event.preventDefault(); diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index f4dbf2054..eb414455d 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -14,6 +14,8 @@ class Projects::Git::TreesController < Projects::Git::BaseController @tree = @tree / @path if @path.present? @commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, max_count: 1).first raise Grit::NoSuchPathError unless @commit + else + @tree = @tree / @path if @path.present? end end diff --git a/app/views/projects/git/base/_whereami.html.haml b/app/views/projects/git/base/_whereami.html.haml index 15c77c021..cbc5dfbff 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= 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 c8ee17f3f..3ecddb86f 100644 --- a/app/views/projects/git/trees/_show.html.haml +++ b/app/views/projects/git/trees/_show.html.haml @@ -4,15 +4,14 @@ .files .pull-left= render 'whereami' .pull-right= render 'fork' - - root_path = @path.present? ? File.join([@path, ".."].compact) : 'null' %table.table.table-hover %thead %tr %th= t 'layout.projects.filename' %th.col-md-8= t 'layout.projects.message' %th= t 'layout.projects.age' - %tbody - %tr{ 'ng-show' => 'path && !processing' } + %tbody{ 'ng-hide' => 'processing' } + %tr{ 'ng-show' => 'path' } %td %span= fa_icon 'folder', class: 'text-primary' %a{ 'ng-href' => '{{root_path}}', 'ng-click' => 'getTree($event, root_path)' } .. diff --git a/app/views/projects/git/trees/show.json.jbuilder b/app/views/projects/git/trees/show.json.jbuilder index 256f368bc..6647b95c4 100644 --- a/app/views/projects/git/trees/show.json.jbuilder +++ b/app/views/projects/git/trees/show.json.jbuilder @@ -62,7 +62,7 @@ else end json.path @path - json.root_path @path.present? ? File.join([@path, ".."].compact) : nil + json.root_path @path.present? ? @path.split('/')[0...-1].join('/') : nil params[:page].to_i - json.next_page page.next if @tree.contents.count >= Project::CONTENT_LIMIT*(page+1) + json.next_page page.next if @tree && @tree.contents.count >= Project::CONTENT_LIMIT*(page+1) end diff --git a/config/routes.rb b/config/routes.rb index dd1db55ff..5d4b48f30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -361,7 +361,7 @@ Rosa::Application.routes.draw do constraints Rosa::Constraints::Treeish do # Tree get '/' => "git/trees#show", as: :project - get '/tree/:treeish(/*path)' => "git/trees#show", as: :tree, format: false + get '/tree/:treeish' => "git/trees#show", as: :tree, format: false # Tags get '/tags' => "git/trees#tags", as: :tags # Branches