Skip to content

Commit

Permalink
Merge pull request #13569 from hellcp-work/inline-file-selector
Browse files Browse the repository at this point in the history
Move file upload to the package show
  • Loading branch information
hennevogel committed Jan 13, 2023
2 parents 597291b + e33e0a8 commit 2d24d85
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/api/app/assets/javascripts/webui/add_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(document).ready(function() {
$('#filechooser').on('change', function() {
this.form.submit();
});
});
1 change: 1 addition & 0 deletions src/api/app/assets/javascripts/webui/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@
//= require webui/nav_tabs.js
//= require webui/write_and_preview.js
//= require webui/badge.js
//= require webui/add_file.js
15 changes: 0 additions & 15 deletions src/api/app/assets/javascripts/webui/packages.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
$(function ($) {
// There are three input fields on the package add file view: filename, url and choose file
// and only one of them is required.
// We just set HTML5 required tags on all of them and set to false with JS
// when one of them is set.
var $inputs = $('.package-add-file input');
$inputs.on('change', function () {
var otherInputWithValueExists = $inputs.not(this).filter(function() {
return !!this.value;
}).length > 0;

if(!otherInputWithValueExists) {
$inputs.prop('required', !$(this).val().length);
}
});

$('body').on('click', '.expand-diffs', function () {
var forPackage = $(this).data('package');
var details = $('details.card[data-package="' + forPackage + '"]');
Expand Down
7 changes: 6 additions & 1 deletion src/api/app/views/webui/package/_files_view.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
%i This package has no files yet
- if user_can_modify_package
.pt-4
= form_tag(project_package_files_path(project, package), multipart: true, class: 'd-inline me-1') do
= file_field_tag 'file', class: 'd-none', id: 'filechooser'
%label.btn-link{ for: 'filechooser' }
%i.fas.fa-hard-drive.text-primary
Add a local file
= link_to(new_project_package_files_path(project, package)) do
%i.fas.fa-plus-circle.text-primary
Add File
Add empty file or service
= render DeleteConfirmationDialogComponent.new(modal_id: 'delete-file-modal',
method: :post,
options: { modal_title: 'Do you really want to remove this file?' })
Expand Down
7 changes: 2 additions & 5 deletions src/api/app/views/webui/packages/files/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
.mb-3.package-add-file
%label{ for: :filename }
%strong Filename:
= text_field_tag :filename, '', size: 80, maxlength: 200, class: 'form-control',
required: true, placeholder: 'Taken from uploaded file if empty...'
= text_field_tag :filename, '', size: 80, maxlength: 200, class: 'form-control'
%small.form-text.text-muted
If only a filename is provided, an empty file is created (touched).
.mb-3.package-add-file
%label{ for: :file_url }
%strong File URL:
= text_field_tag :file_url, '', size: 80, maxlength: 200, class: 'form-control', required: true, type: :url
= text_field_tag :file_url, '', size: 80, maxlength: 200, class: 'form-control', type: :url
%small.form-text.text-muted
URLs to src.rpm files will get extracted. URLs to git repositories will get stored in a tar ball.
.mb-3.package-add-file
= file_field_tag 'file', class: 'form-control', id: 'file', required: true
= submit_tag 'Add File', class: 'btn btn-sm btn-primary', id: :submit_button
4 changes: 2 additions & 2 deletions src/api/spec/features/webui/packages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
login user

visit package_show_path(project: user.home_project, package: package)
click_link('Add File')
click_link('Add empty file or service')

fill_in 'Filename', with: 'new_file'
click_button('Add File')
Expand All @@ -199,7 +199,7 @@
login user

visit package_show_path(project: user.home_project, package: package)
click_link('Add File')
click_link('Add empty file or service')

fill_in 'Filename', with: 'inv/alid'
click_button('Add File')
Expand Down

0 comments on commit 2d24d85

Please sign in to comment.