[#369] change location in the tree page

This commit is contained in:
Alexander Machehin 2014-07-11 15:43:45 +06:00
parent 3bbf6b54f2
commit 202ac91644
6 changed files with 37 additions and 22 deletions

View File

@ -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();

View File

@ -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

View File

@ -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}}

View File

@ -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)' } ..

View File

@ -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

View File

@ -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