Dropdown on details page allows image management for users and admins
This commit is contained in:
parent
263f6cd33f
commit
16999260ca
8 changed files with 75 additions and 35 deletions
|
|
@ -90,6 +90,15 @@ class PackagesController < ApplicationController
|
|||
send_file @screenshot.image.path(:thumb), type: "image/png", disposition: 'inline'
|
||||
end
|
||||
|
||||
# Receives a form with a simple text field 'description' so that users can update
|
||||
# the description of their screenshot.
|
||||
def update_screenshot_description
|
||||
@screenshot = Screenshot.find(params[:id])
|
||||
@screenshot.description = params[:description]
|
||||
@screenshot.save!
|
||||
redirect_to package_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Send a dummy thumbnail reading "No screenshot available. Sorry."
|
||||
|
|
|
|||
|
|
@ -1,2 +1,19 @@
|
|||
module PackagesHelper
|
||||
|
||||
# Return a query of all screenshots that the current user may see
|
||||
# Consists of:
|
||||
# - approved (public) screenshots
|
||||
# - screenshots uploaded by the user (determined by cookie session)
|
||||
# - all screenshots if the user is logged in
|
||||
def screenshots_visible_to_user(package)
|
||||
if user_signed_in?
|
||||
# User is an admin
|
||||
package.screenshots
|
||||
else
|
||||
package.screenshots.where(
|
||||
"approved=true OR uploaderhash=?", session[:token]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,15 +36,4 @@ class Package < ActiveRecord::Base
|
|||
def self.screenshots_approved
|
||||
self.screenshots.find_by(approved: true)
|
||||
end
|
||||
|
||||
# Return a query of all screenshots that the current user may see
|
||||
# Consists of:
|
||||
# - approved (public) screenshots
|
||||
# - screenshots uploaded by the user (determined by cookie session)
|
||||
def screenshots_visible_to_user(token)
|
||||
self.screenshots.where(
|
||||
# "approved=true"
|
||||
"approved=true OR uploaderhash=?", token
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,10 +20,14 @@ class Screenshot < ActiveRecord::Base
|
|||
# Currently this check makes sure that the same screenshot is not uploaded
|
||||
# twice for the same package. However it allows the screenshot to be uploaded
|
||||
# for two different packages. Restricting that further may happen later.
|
||||
|
||||
# TODO: will fail if screenshot is updated because it finds its own image
|
||||
def validate_image_is_unique
|
||||
# Look for images with the same checksum / image_fingerprint
|
||||
if Screenshot.find_by(image_fingerprint: image_fingerprint, package_id: self.package.id)
|
||||
errors.add(:image, "has already been uploaded for this package")
|
||||
if screenshot=Screenshot.find_by(image_fingerprint: image_fingerprint, package_id: self.package.id)
|
||||
unless screenshot.id == self.id
|
||||
errors.add(:image, "has already been uploaded for this package")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
14
app/views/packages/_admin_dropdown.slim
Normal file
14
app/views/packages/_admin_dropdown.slim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Button that reveals a dropdown/modal for admins
|
||||
.text-center
|
||||
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
|
||||
'Admin
|
||||
.dropdown-pane data-dropdown=true id="admin-info-#{screenshot.id}"
|
||||
a.button.small.alert[
|
||||
href=delete_screenshot_path(@package.name, screenshot.id)
|
||||
onclick="return confirm('Really delete the screenshot?');"
|
||||
] Delete screenshot
|
||||
|
||||
p Uploader IP=#{screenshot.uploaderip}
|
||||
p Uploader Token=#{session[:token]}
|
||||
p Uploaded #{screenshot.age_days} (#{screenshot.created_at})
|
||||
p Status: #{screenshot.status}
|
||||
17
app/views/packages/_user_dropdown.slim
Normal file
17
app/views/packages/_user_dropdown.slim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Button that reveals a dropdown/modal for users (for their own screenshots)
|
||||
.text-center
|
||||
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
|
||||
'Manage your screenshot
|
||||
.dropdown-pane data-dropdown=true id="admin-info-#{screenshot.id}"
|
||||
a.button.small.alert[
|
||||
href=delete_screenshot_path(@package.name, screenshot.id)
|
||||
onclick="return confirm('Really delete the screenshot?');"
|
||||
] Delete screenshot
|
||||
p Write a description for this screenshot:
|
||||
= form_tag(update_screenshot_description_path(screenshot.package.name, screenshot.id))
|
||||
.input-group
|
||||
= text_field_tag 'description', nil, class: 'input-group-field', maxlength: 40
|
||||
.input-group-button
|
||||
=submit_tag 'OK', class: 'button success'
|
||||
p
|
||||
i =screenshot.status
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
.small-7.medium-7.columns.packagepage
|
||||
p.subtitle = @package.description
|
||||
- if @package.screenshots_visible_to_user(session[:token]).count > 0
|
||||
- @package.screenshots_visible_to_user(session[:token]).each do |screenshot|
|
||||
- if screenshots_visible_to_user(@package).count > 0
|
||||
- screenshots_visible_to_user(@package).each do |screenshot|
|
||||
.row.listview
|
||||
.small-12.columns
|
||||
.text-center
|
||||
|
|
@ -16,21 +16,12 @@
|
|||
// TODO: Show information only if admin
|
||||
- if user_signed_in?
|
||||
// Button that reveals a dropdown/modal for admins
|
||||
.text-center
|
||||
button.small.dropdown.warning.button type="button" data-toggle="admin-info-#{screenshot.id}"
|
||||
'Admin
|
||||
.dropdown-pane data-dropdown=true id="admin-info-#{screenshot.id}"
|
||||
a.button.tiny.alert[
|
||||
href=delete_screenshot_path(@package.name, screenshot.id)
|
||||
onclick="return confirm('Really delete the screenshot?');"
|
||||
] Delete screenshot
|
||||
|
||||
p Uploader IP=#{screenshot.uploaderip}
|
||||
p Uploaded #{screenshot.age_days} (#{screenshot.created_at})
|
||||
p Status: #{screenshot.status}
|
||||
= render(partial: 'admin_dropdown', locals: {screenshot: screenshot})
|
||||
- elsif screenshot.uploaderhash == session[:token]
|
||||
= render(partial: 'user_dropdown', locals: {screenshot: screenshot})
|
||||
|
||||
// Anonymous users can see their own screenshots
|
||||
- if not screenshot.approved
|
||||
/ - if not screenshot.approved
|
||||
|
||||
- else
|
||||
.row.listview
|
||||
|
|
@ -99,12 +90,10 @@
|
|||
' If you don't use english by default please start your application
|
||||
' from a shell using after setting "export LANG=C".
|
||||
|
||||
// TODO: Enable comment form
|
||||
//javascript:
|
||||
// $('#comment-summary').on( 'input', function() {
|
||||
// //$('#comment-content,#comment-author').fadeIn();
|
||||
// $('form.comment > *').fadeIn();
|
||||
// });
|
||||
|
||||
// TODO: allow to remove own uploads
|
||||
|
||||
// TODO: allow non-upload to report (request removal)
|
||||
|
||||
javascript:
|
||||
$(function () {
|
||||
|
|
@ -121,7 +110,6 @@ javascript:
|
|||
// Files have been selected. Tell the user what's going on and
|
||||
// submit the upload form.
|
||||
$('#fileupload').change( function () {
|
||||
// $('#upload-image').attr('src', '/images/dummy/please-wait.svg');
|
||||
upload_enabled = false;
|
||||
$('#upload-image').html('Please wait...');
|
||||
$('form').submit();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ Debshots::Application.routes.draw do
|
|||
get 'upload', to: redirect('/packages')
|
||||
get 'upload/:name' => 'packages#upload', as: :upload_package_by_name
|
||||
post 'upload_image/:name' => 'packages#upload_image', as: :upload_image, name: /[^\/]+/
|
||||
# TODO: "get" is probably the wrong method to delete a screenshot
|
||||
get 'delete_screenshot/:name/:id' => 'packages#delete_screenshot', as: :delete_screenshot
|
||||
post 'update_screenshot_description/:name/:id' => 'packages#update_screenshot_description', as: :update_screenshot_description
|
||||
get 'about' => 'welcome#about'
|
||||
get 'thumbnail/:name' => 'packages#thumbnail', as: :thumbnail_image, name: /[^\/]+/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue