Upload workflow improved
This commit is contained in:
parent
4ee670e438
commit
10e44d1aaf
3 changed files with 16 additions and 12 deletions
|
|
@ -24,37 +24,39 @@ class PackagesController < ApplicationController
|
|||
end
|
||||
|
||||
# POST target of the screenshots upload form.
|
||||
# Checks upload images and creates a new Screenshot record for it.
|
||||
# Receives uploaded images. Checks if they are valid. Asks for description.
|
||||
def upload_image
|
||||
# Remember the user by the cookie session
|
||||
create_user_token
|
||||
|
||||
@package = Package.find_by!(name: params[:name])
|
||||
# @images = params[:screenshot][:image]
|
||||
@images = []
|
||||
|
||||
successful_upload_count = 0
|
||||
|
||||
# Save the images already if they are valid.
|
||||
params[:screenshot][:image].each do |img|
|
||||
new_screenshot = @package.screenshots.new(image: img)
|
||||
|
||||
# Check if the image was valid
|
||||
@images.push new_screenshot
|
||||
if new_screenshot.valid?
|
||||
new_screenshot.uploaderhash = session[:token]
|
||||
new_screenshot.uploaderip = session[:ip]
|
||||
new_screenshot.version = @package.version
|
||||
new_screenshot.save
|
||||
successful_upload_count += 1
|
||||
# successful_upload_count += 1
|
||||
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
|
||||
else
|
||||
errors = new_screenshot.errors[:image].join(' and ')
|
||||
flash['alert'] = "Sorry - the image #{errors}"
|
||||
# else
|
||||
# errors = new_screenshot.errors[:image].join(' and ')
|
||||
# flash['alert'] = "Sorry - the image #{errors}"
|
||||
end
|
||||
|
||||
if successful_upload_count > 0
|
||||
flash['notice'] = "#{successful_upload_count} #{'screenshot'.pluralize(successful_upload_count)} uploaded successfully."
|
||||
end
|
||||
# if successful_upload_count > 0
|
||||
# flash['notice'] = "#{successful_upload_count} #{'screenshot'.pluralize(successful_upload_count)} uploaded successfully."
|
||||
# end
|
||||
end
|
||||
|
||||
redirect_to package_path
|
||||
# redirect_to package_path
|
||||
end
|
||||
|
||||
# Legacy action to upload an image along with metadata.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// TODO: Can be deleted?
|
||||
//
|
||||
// Button that reveals a dropdown/modal for users (for their own screenshots)
|
||||
.text-right
|
||||
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ div.row
|
|||
=@most_popular_package.description
|
||||
div.large-4.medium-12.small-12.columns.text-center
|
||||
h2 Your help needed
|
||||
a href=upload_package_by_name_path(@most_wanted_package.name)
|
||||
a href=upload_path(@most_wanted_package.name)
|
||||
img src="/images/dummy/no-screenshots-upload-one.svg" width="80%"
|
||||
p
|
||||
' We lack a screenshot for the #{@most_wanted_package.name} package. Can you
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue