From 10e44d1aafb299e2051595902bdf60450da19bbc Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Tue, 1 Nov 2016 09:16:52 +0100 Subject: [PATCH] Upload workflow improved --- app/controllers/packages_controller.rb | 24 +++++++++++++----------- app/views/packages/_user_dropdown.slim | 2 ++ app/views/welcome/home.slim | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 36e8f89..d1bf376 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -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. diff --git a/app/views/packages/_user_dropdown.slim b/app/views/packages/_user_dropdown.slim index 289e733..642e7c3 100644 --- a/app/views/packages/_user_dropdown.slim +++ b/app/views/packages/_user_dropdown.slim @@ -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}" diff --git a/app/views/welcome/home.slim b/app/views/welcome/home.slim index 6909ed2..d90a61f 100644 --- a/app/views/welcome/home.slim +++ b/app/views/welcome/home.slim @@ -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