Skip to content

Commit

Permalink
Introduce full directory support.
Browse files Browse the repository at this point in the history
Other minor improvements.
  • Loading branch information
Alwahsh committed Apr 17, 2015
1 parent 02c6493 commit 341284e
Show file tree
Hide file tree
Showing 24 changed files with 442 additions and 198 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ group :development, :test do

gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'better_errors'
gem 'binding_of_caller'
end

gem 'better_errors', group: :development

group :test do
gem 'faker'
gem 'capybara'
Expand Down
20 changes: 20 additions & 0 deletions app/assets/stylesheets/_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
body{
.wrapper{
article.project{
div.breadcrumb{
margin-top: 0.1em;
font-weight: bold;
a{
text-decoration: none;
}
a:hover{
text-decoration: underline;
}
}
section.album{
div{
@include cf();
Expand All @@ -37,6 +47,16 @@
max-width: 100%;
height: auto;
}
span.name{
display: block;
box-shadow: 0 0 0.3em 0.2em $dark_geometry_gray;
}
a{
color: $map_blue;
text-decoration: none;
}
text-align: center;
word-wrap: break-word;
}
}
}
Expand Down
83 changes: 46 additions & 37 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def unfollow
# GET /user/project/blob/branch_or_commit_oid/destination
def blob
oid = @project.branch_commit(params[:oid]).oid
blob = @project.blob oid, params[:destination]
@image = { data: blob.text, name: params[:destination] }
@dest = params[:destination]
blob = @project.blob oid, @dest
@image = { data: blob.text, name: @dest }
@comments = Comment.where(
polycomment_type: 'blob',
polycomment_id: blob.oid
Expand All @@ -116,26 +117,17 @@ def branches
end

def show
@images = []
@oid = 'master'
barerepo = @project.barerepo
@branches = barerepo.branches
unless barerepo.empty?
headtree = barerepo.lookup barerepo.last_commit.tree_id
# TODO: what if there are trees inside this tree?
headtree.each do |blob|
@images.push({
name: blob[:name],
url: @project.imageurl(blob[:name])
})
end
end

@images, @directories = @project.browse_tree
@comments = Comment.where(
polycomment_type: 'project',
polycomment_id: @project.id
)
@comments = pg @comments, 10
@comment = Comment.new
@comment_type = 'project'
@ajax = params[:page].nil? || params[:page] == 1
end

Expand Down Expand Up @@ -169,10 +161,8 @@ def commit
redirect_to(user_project_path(@project.user, @project)) unless commit
barerepo = @project.barerepo
barerepo.diff(commit.parents.first, commit).deltas.each do |delta|
link = File.join @project.urlbase, 'master', delta.new_file[:path]
data = barerepo.read(delta.new_file[:oid]).data
@images.push({ link: link,
data: data,
@images.push({
data: barerepo.read(delta.new_file[:oid]).data,
name: delta.new_file[:path] })
end
@comments = Comment.where(
Expand All @@ -199,23 +189,22 @@ def create_branch

# GET /tree/tree_id
def tree
@images = []
@oid = params[:oid]
tree = @project.branch_tree @oid
redirect_to(user_project_path(@project.user, @project)) unless tree
barerepo = @project.barerepo
tree.each do |blob|
data = barerepo.read(blob[:oid]).data
@images.push({ data: data, name: blob[:name] })
end
@oid = params[:oid] || 'master'
@dest = params[:destination]
tree = @project.branch_tree @oid, @dest
redirect_to(user_project_path(
@project.user, @project, @project.uniqueurl
)) unless tree
@images, @directories = @project.browse_tree tree, params[:destination]
@comments = Comment.where(
polycomment_type: 'commit',
polycomment_type: 'tree',
polycomment_id: tree.oid
)
@comment_type = 'tree'
@comments = pg @comments, 10
@comment = Comment.new
@id = tree.oid
render 'commit'
render 'show'
end

def file_history
Expand All @@ -237,12 +226,27 @@ def file_history
end
end

def create_directory
branch = params[:branch] || 'master'
new_dest = @project.create_directory(
branch,
params[:destination],
params[:directory],
@user.git_author_params
)
if user_signed_in? && new_dest
flash[:notice] = "Successfully added #{params[:dir_name]}!"
redirect_to project_tree_path(@project, branch, new_dest)
else
flash[:alert] = 'An error prevented your directory from being created'
redirect_to project_newfile_path(@project, branch)
end
end

def newfile
@cur = params[:oid] || 'master'
@cur = 'master' unless @project.branch? @cur
@all = @project.barerepo.branches
return if @project.branch? params[:oid]
flash[:alert] = 'You need to be on a valid branch to upload a new file'
redirect_to :back
end

def update
Expand All @@ -255,6 +259,7 @@ def file_upload
if params[:file]
if user_signed_in? && @project.add_images(
branch,
params[:destination],
params[:file],
@user.git_author_params
)
Expand All @@ -272,19 +277,23 @@ def file_upload
end

def file_update
if @project.add_images(
if @project.update_image(
params[:branch],
[params[:file]],
params[:destination],
params[:file],
@user.git_author_params,
params[:message],
params[:image_path]
params[:message]
)
flash[:notice] = "#{params[:image_path]} has been updated! Shiny!"
else
flash[:alert] = "Unable to update #{params[:image_path]}. " \
'The server ponies are sad.'
end
redirect_to project_blob_path @project, params[:image_path], params[:branch]
redirect_to project_blob_path(
@project,
params[:branch],
params[:destination]
)
end

def file_delete
Expand Down
64 changes: 56 additions & 8 deletions app/helpers/paths_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def project_network_path(project)
network_user_project_path project.user, project, project.uniqueurl
end

def project_newfile_path(project, branch)
newfile_user_project_path project.user, project, project.uniqueurl, branch
end

def project_fork_path(project)
fork_user_project_path project.user, project, project.uniqueurl
end
Expand All @@ -66,13 +62,65 @@ def project_create_branch_path(project)
create_branch_user_project_path project.user, project, project.uniqueurl
end

def project_tree_path(project, oid)
tree_user_project_path(project.user, project, project.uniqueurl, oid)
def project_tree_path(project,
oid = params[:oid],
destination = params[:destination])
oid ||= 'master'
tree_user_project_path(
project.user,
project,
project.uniqueurl,
oid,
destination
)
end

def project_blob_path(project, destination, branch)
branch ||= 'master'
def project_blob_path(
project,
oid = params[:oid],
destination = params[:destination]
)
oid ||= 'master'
blob_user_project_path(
project.user,
project,
project.uniqueurl,
oid,
destination
)
end

def project_file_upload_path(project,
oid = params[:oid],
destination = params[:destination]
)
file_upload_user_project_path(
project.user,
project,
project.uniqueurl,
oid,
destination
)
end

def project_file_update_path(project,
branch = params[:oid],
destination = params[:destination]
)
file_update_user_project_path(
project.user,
project,
project.uniqueurl,
branch,
destination
)
end

def project_create_directory_path(project,
branch = params[:oid],
destination = params[:destination]
)
create_directory_user_project_path(
project.user,
project,
project.uniqueurl,
Expand Down
22 changes: 22 additions & 0 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,26 @@ def nested_projects(roots, project)
end
end
end

def breadcrumb
res = link_to(@project.name,
project_tree_path(@project, params[:oid], ''))
dest = ''
arr = params[:destination].split('/')
arr.each_with_index do |dir, i|
if i == 0
dest = dir
else
dest = File.join(dest, dir)
end
res += ' / '
if i == arr.size - 1
res += dir
else
res += link_to(dir,
project_tree_path(@project, params[:oid], dest))
end
end
res
end
end
Loading

0 comments on commit 341284e

Please sign in to comment.