Merge branch 'master' of bitbucket.org:signum/debshots

Conflicts:
	app/views/packages/upload.slim
This commit is contained in:
Christoph Haas 2015-02-10 09:16:34 +01:00
commit 18edade734
18 changed files with 199 additions and 55 deletions

View file

@ -296,3 +296,17 @@ a.black
text-shadow: 0 0 2px black;
}
}
/* Properties of a screenshot - shown in details view */
.property-title
{
font-weight: bolder;
font-size: 120%;
color: #808080;
}
.property
{
margin-left: 2em;
margin-bottom: 0.5em;
}

View file

@ -58,9 +58,26 @@ class PackagesController < ApplicationController
# TODO
raise "name not given" unless params[:name]
@package = Package.find_by(name: params[:name])
@new_screenshot = @package.screenshots.new
end
def upload_image
"uploaded"
#render text: params[:image].to_json
#render text: params.to_json
@package = Package.find_by(name: params[:name])
@new_screenshot = @package.screenshots.create(image: params[:image])
@new_screenshot.save
#raise
#@package.save
#new_screenshot.image = params[:image]
#render text: "File has been uploaded successfully"
redirect_to upload_package_by_name_path
end
private
#def user_params
# params.require(:screenshot).permit(:image)
#end
end

View file

@ -5,22 +5,11 @@ class Screenshot < ActiveRecord::Base
order('uploaddatetime DESC')
}
def image_url(size)
"#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png"
end
# Get the URL leading to a screenshot of this package
def url(size)
if self.approved
# TODO: Make the path configurable
basepath = "/screenshots/"
else
# TODO: Choose a path that makes unapproved screenshots unavailable
basepath = "/screenshots/unapproved/"
end
File.join(basepath, self.package.name[0], self.package.name, "#{self.id}_#{size}.png")
end
has_attached_file :image,
styles: { :large => "800x600>", :thumb => "160x120>" },
default_url: "/images/dummy/no-screenshots-upload-one.svg"
#path: :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename
validates_attachment_content_type :image, :content_type => /\Aimage\/png\Z/
# Return caption for full-screen screenshots.
# Takes the description of a screenshot if available.
@ -33,27 +22,24 @@ class Screenshot < ActiveRecord::Base
end
end
def image_file(size)
# Screenshot files are at e.g.
# .../public/screenshots/f/firefox/5871654_large.png
Rails.configuration.images_path.join(self.package.name[0], self.package.name, "#{self.id}_#{size}.png")
def uploader
# TODO: Implement the ownership of images
"Anonymous"
end
# Delete all image files related to this screenshot
def delete_all_images
Rails.configuration.image_sizes.each do |size,dimensions|
image_file = self.image_file(size)
Rails.logger.info "(before_destroy) Deleting screenshot image '#{image_file}' from disk"
if File.exist?(image_file)
File.delete(image_file)
else
Rails.logger.error "(before_destroy) File '#{image_file}' not found - could not delete it"
end
def status
text = ''
# Completes the sentence: "This image…"
if self.approved
text <<'is public'
else
text <<'has to be moderated before being publicly visible'
end
end
# Callback to delete image files from disk when a screenshot record gets destroyed
before_destroy do |screenshot|
screenshot.delete_all_images
if self.markedfordelete
text <<' (and was requested to be removed)'
end
text
end
end

View file

@ -2,7 +2,9 @@
a.black href=package_path(name: pkg.name)
div.grid-thumbnail
- if pkg.screenshots.any?
img src=pkg.screenshots[0].url('small')
// TODO: smarter search for the beste screenshot instead of taking the first one
- screenshot = pkg.screenshots.first
= image_tag(screenshot.image.url(:thumb, timestamp: false), alt: screenshot.caption)
- else
img.screenshot src="/images/dummy/no-screenshots-upload-one.svg"
div

View file

@ -13,12 +13,25 @@
p.subtitle = @package.description
ul.small-block-grid-1.medium-block-grid-2.large-block-grid-2
- for screenshot in @package.screenshots
- @package.screenshots.each do |screenshot|
li
a.black.fancybox href=screenshot.url('large') rel='fancybox-thumb' title=screenshot.caption
img src=screenshot.url('large')
a.black.fancybox href=screenshot.image.url(:large, timestamp: false) rel='fancybox-thumb' title=screenshot.caption
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
.imgcaption =screenshot.caption
// Upload image
li
//a.button.radius.expand href=upload_package_by_name_path(name: @package.name) Upload a new screenshot
//= form_for @package, :url => upload_image_path, :html => { :multipart => true } do |form|
//= form.file_field :image
= form_for :screenshot, url: upload_image_path, html: { multipart: true } do |f|
= f.label :image, 'Upload new screenshot'
= f.file_field :image, id: 'fileupload', multiple: true
= f.submit 'Save'
//- raise
// TODO: Enable comments in a later version
// = partial '/package/comments'
@ -35,7 +48,19 @@
' The goal of Icedove is to produce a cross platform standalone mail
' application using the XUL user interface language.
a.button.radius.expand href=upload_package_by_name_path(name: @package.name) Upload a new screenshot
//a.button.radius.expand href=upload_package_by_name_path(name: @package.name) Upload a new screenshot
javascript:
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
// TODO: Enable comment form
//javascript:

View file

@ -20,8 +20,10 @@
=pkg.name
' >
- if pkg.screenshots.any?
a.black.fancybox title=pkg.screenshots.first.caption rel=pkg.id href=pkg.screenshots.first.url('large')
img.screenshot src=pkg.screenshots.first.url('large')
// TODO: smarter search for the beste screenshot instead of taking the first one
- screenshot = pkg.screenshots.first
a.black.fancybox title=screenshot.caption rel=pkg.id href=screenshot.image.url(:large, timestamp: false)
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
- if pkg.screenshots.length > 1
a.black href=package_path(name: pkg.name)
.text-center More screenshots…

View file

@ -4,11 +4,19 @@
p.subtitle = @package.description
.row.packagepage
.small-8.columns
.small-12.medium-7.large-8.columns
// First row contains the upload form
.row
.small-6.columns
input id="fileupload" type="file" name="files[]" data-url=upload_image_path(name: @package.name) multiple=true
//input id="fileupload" type="file" name="files[]" data-url=upload_image_path(name: @package.name) multiple=true
//= form_for @new_screenshot, :url => upload_image_path, :html => { :multipart => true } do |form|
// = form.file_field :image
// = form.submit 'Save'
= form_tag(upload_image_path, multipart: true)
= file_field_tag('image')
= submit_tag
a.button.radius.expand href=upload_package_by_name_path(name: @package.name)
' Click or drag a PNG screenshot file here
.small-6.columns
@ -17,8 +25,19 @@
.row
img src=screenshot.url('large')
- puts @package.screenshots
- @package.screenshots.each do |screenshot|
.listview
a.black.fancybox href=screenshot.image.url(:large, timestamp: false) rel='fancybox-thumb' title=screenshot.caption
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
// .imgcaption
// => screenshot.caption
// - if screenshot.uploader
// | (Uploaded by
// =< screenshot.uploader
// | )
.small-4.columns
.small-12.medium-5.large-4.columns
.bigpanel
p Thanks for uploading more screenshots. Please note:
ul

View file

@ -31,7 +31,7 @@ div.row
// TODO: load actual newest upload and cache it
// TODO: link to the package page
a.black href=package_path(@newest_uploaded_package.name)
img src=@newest_uploaded_package.screenshots[0].image_url('large')
img src=@newest_uploaded_package.screenshots.first.image.url(:large, timestamp: false)
p
strong
=@newest_uploaded_package.name
@ -43,7 +43,7 @@ div.row
// TODO: load actual most popular package and highest-rated screenshot and cache it
// TODO: link to the package page
a.black href=package_path(@most_popular_package.name)
img src=@most_popular_package.screenshots[0].image_url('large')
img src=@most_popular_package.screenshots.first.image.url(:large, timestamp: false)
p
strong
=@most_popular_package.name