From e028276d34571cd5128021ab5daf3088eb538be2 Mon Sep 17 00:00:00 2001 From: Kia Mei Somabes Date: Fri, 13 Jul 2018 12:41:24 +0800 Subject: [PATCH] Add download directory in menu Add subdirectory params for RepositoriesController#archive --- app/controllers/projects/repositories_controller.rb | 2 +- app/helpers/projects_helper.rb | 8 ++++++++ app/helpers/workhorse_helper.rb | 1 + app/views/projects/buttons/_download.html.haml | 8 +++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb index 4eeaeb860ee..86298ef6274 100644 --- a/app/controllers/projects/repositories_controller.rb +++ b/app/controllers/projects/repositories_controller.rb @@ -23,7 +23,7 @@ class Projects::RepositoriesController < Projects::ApplicationController append_sha = false if @filename == shortname end - send_git_archive @repository, ref: @ref, format: params[:format], append_sha: append_sha + send_git_archive @repository, ref: @ref, subdirectory: params[:subdirectory], format: params[:format], append_sha: append_sha rescue => ex logger.error("#{self.class.name}: #{ex}") git_not_found! diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index f2abb241753..f5cae40aa86 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -26,6 +26,14 @@ module ProjectsHelper image_tag(src, width: opts[:size], class: classes, alt: '', "data-src" => avatar) end + + def is_directory + @path.empty? ? false : true + end + + def get_directory_path + @path ? "#{@path}/" : '' + end def author_content_tag(author, opts = {}) default_opts = { author_class: 'author', tooltip: false, by_username: false } diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb index bb5b1555dc4..7c49a6e1c6d 100644 --- a/app/helpers/workhorse_helper.rb +++ b/app/helpers/workhorse_helper.rb @@ -31,6 +31,7 @@ module WorkhorseHelper # Archive a Git repository and send it through Workhorse def send_git_archive(repository, **kwargs) + kwargs.delete(:subdirectory) if kwargs[:subdirectory].nil? headers.store(*Gitlab::Workhorse.send_git_archive(repository, **kwargs)) head :ok end diff --git a/app/views/projects/buttons/_download.html.haml b/app/views/projects/buttons/_download.html.haml index 4eb53faa6ff..7d22a4044e4 100644 --- a/app/views/projects/buttons/_download.html.haml +++ b/app/views/projects/buttons/_download.html.haml @@ -8,8 +8,14 @@ %span.sr-only= _('Select Archive Format') = sprite_icon("arrow-down") %ul.dropdown-menu.dropdown-menu-right{ role: 'menu' } + - if is_directory + %li.dropdown-header + #{ _('Directory') } + %li + = link_to project_archive_path(project, subdirectory: get_directory_path, id: tree_join(ref, archive_prefix), format: 'zip'), rel: 'nofollow', download: '' do + %span= _('Download zip') %li.dropdown-header - #{ _('Source code') } + #{ _('Repository') } %li = link_to project_archive_path(project, id: tree_join(ref, archive_prefix), format: 'zip'), rel: 'nofollow', download: '' do %span= _('Download zip')