New upload review process partly finished

This commit is contained in:
Christoph Haas 2017-01-18 21:30:14 +01:00
parent 821364483e
commit 34d7eb649c
5 changed files with 70 additions and 24 deletions

View file

@ -19,49 +19,45 @@ class PackagesController < ApplicationController
end
end
# Show upload form for new images
def upload
@package = Package.find_by!(name: params[:name])
end
# POST target of the screenshots upload form.
# Receives uploaded images. Checks if they are valid. Asks for description.
def upload_image
def upload_review
# Remember the user by the cookie session
create_user_token
@package = Package.find_by!(name: params[:name])
# @images = params[:screenshot][:image]
@images = []
@valid_images = []
@invalid_images = []
# Save the images already if they are valid.
# params[:screenshot][:image].each do |img|
# successful_upload_count = 0
params[:file].each do |img|
params[:file].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
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
# else
# errors = new_screenshot.errors[:image].join(' and ')
# flash['alert'] = "Sorry - the image #{errors}"
@valid_images.push new_screenshot
else
@invalid_images.push new_screenshot
end
# if successful_upload_count > 0
# flash['notice'] = "#{successful_upload_count} #{'screenshot'.pluralize(successful_upload_count)} uploaded successfully."
# end
end
# redirect_to package_path
end
# Receive the descriptions from upload_review and update them
def upload_review2
# R
end
# Legacy action to upload an image along with metadata.
# This was used in Debshots 1.x as the default upload method.
# This method allows that old-style way to upload screenshots.

View file

@ -8,7 +8,7 @@ class Screenshot < ApplicationRecord
url: '/screenshots/:id_partition/:style.png'
validates_attachment_content_type :image, :content_type => 'image/png'
validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes
validate :validate_image_is_unique
# validate :validate_image_is_unique
validates :delete_reason, length: { in: 5..100 }, allow_nil: true
# Validator that checks if the image has already been uploaded.

View file

@ -8,7 +8,7 @@
' You are about to upload a screenshot for the #{@package.name}
' package. Thanks for your contribution.
= form_for :screenshot, url: upload_image_path, html: { multipart: true, id: 'file-form' } do |f|
= form_for :screenshot, url: upload_review_path, html: { multipart: true, id: 'file-form' } do |f|
.row
.small-6.columns
@ -30,16 +30,15 @@
.small-up-1.medium-up-3.large-up-4.grid-thumbnails
- @package.screenshots.all.each do |ss|
a.black.fancybox href=ss.image.url(:large, timestamp: false) rel='fancybox-thumb' title=ss.caption
= image_tag(ss.image.url(:thumb, timestamp: false), alt: ss.caption, class: 'thumbnail')
.column
a.black.fancybox href=ss.image.url(:large, timestamp: false) rel='fancybox-thumb' title=ss.caption
= image_tag(ss.image.url(:thumb, timestamp: false), alt: ss.caption, class: 'thumbnail')
// = render partial: 'packages/grid_thumbnail', locals: { pkg: pkg }
//- else
// ' There are no screenshots yet for #{@package.name}. Your upload will
// ' be the first.
// >>>>>>> 652c2d4126c628403bb8223ffd5f6fb633da95de
.small-5.columns.bigpanel

View file

@ -0,0 +1,50 @@
.row
h1 Your uploaded images
.row
p
' Thanks for your upload. Please check the images and add
' short one-line descriptions that describe each of the images.
- if @invalid_images.any?
.callout.warning
p
' However the following screenshots were not accepted:
ul
- @invalid_images.each do |image|
li
' #{image.image_file_name} (#{image.errors[:image].join(' and ')})
- if @valid_images.any?
= form_for :screenshot, url: upload_review2_path do |f|
- @valid_images.each do |screenshot|
.row
.small-4.columns
a.black.fancybox href=screenshot.image.url(:large, timestamp: false) title='Uploaded image'
= image_tag(screenshot.image.url(:large, timestamp: false), alt: 'Uploaded image')
.small-8.columns
em Your file name:
p
= screenshot.image_file_name
em Description:
p
= text_field_tag "description-#{screenshot.id}"
em Delete this image?
p
= check_box "delete-#{screenshot.id}", "Delete this image"
.row
button.button type="submit" id="file-submit"
= fa_stacked_icon "check", base: "circle-thin"
' Proceed
- else
.row
a.button href=upload_path Back to upload form

View file

@ -21,7 +21,8 @@ Debshots::Application.routes.draw do
get 'upload', to: redirect('/packages'), as: :upload_legacy # legacy upload form
post 'uploadfile' => 'packages#legacy_uploadfile', name: /[^\/]+/
get 'upload/:name' => 'packages#upload', as: :upload, name: /[^\/]+/
post 'upload_image/:name' => 'packages#upload_image', as: :upload_image, name: /[^\/]+/
post 'upload_review/:name' => 'packages#upload_review', as: :upload_review, name: /[^\/]+/
post 'upload_review2/:name' => 'packages#upload_review2', as: :upload_review2, name: /[^\/]+/
# TODO: "get" is probably the wrong method to delete a screenshot
get 'delete_screenshot/:id' => 'packages#delete_screenshot', as: :delete_screenshot
post 'update_screenshot_description/:name/:id' => 'packages#update_screenshot_description', as: :update_screenshot_description