Merge branch 'master' of git.workaround.org:chaas/debshots
This commit is contained in:
commit
773548afc3
22 changed files with 303 additions and 75 deletions
|
|
@ -953,5 +953,8 @@ a.black
|
|||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.description-verbatim-lines
|
||||
{
|
||||
line-height: 120%;
|
||||
// white-space: pre-line;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
// Place all the styles related to the Moderate controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
21
app/controllers/json_controller.rb
Normal file
21
app/controllers/json_controller.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class JsonController < ApplicationController
|
||||
# JSON information on a single package
|
||||
def package
|
||||
@p = Package.find_by_name! params[:name]
|
||||
end
|
||||
|
||||
# JSON information on all packages
|
||||
def packages
|
||||
@p = Package.all
|
||||
end
|
||||
|
||||
# JSON information on all screenshots
|
||||
def screenshots
|
||||
@s = Screenshot.includes(:package)
|
||||
end
|
||||
|
||||
# JSON list of packages that do not have screenshots
|
||||
def packages_without_screenshots
|
||||
@p = Package.without_screenshots.all
|
||||
end
|
||||
end
|
||||
|
|
@ -3,15 +3,11 @@ class PackagesController < ApplicationController
|
|||
protect_from_forgery :except => :legacy_uploadfile
|
||||
|
||||
def list
|
||||
@packages = query_packages
|
||||
@packages = @packages.paginate(page: params[:page], per_page: 6)
|
||||
render 'packages/index-list.slim'
|
||||
@packages = query_packages.paginate(page: params[:page], per_page: 6)
|
||||
end
|
||||
|
||||
def grid
|
||||
@packages = query_packages
|
||||
@packages = @packages.paginate(page: params[:page], per_page: 24)
|
||||
render 'packages/index-grid.slim'
|
||||
@packages = query_packages.paginate(page: params[:page], per_page: 24)
|
||||
end
|
||||
|
||||
def details
|
||||
|
|
@ -111,7 +107,14 @@ class PackagesController < ApplicationController
|
|||
thumbnail404
|
||||
return
|
||||
end
|
||||
@screenshot = @package.screenshots.first
|
||||
|
||||
# Called as /thumbnail-with-version/:name/:version
|
||||
if params[:version]
|
||||
@screenshot = @package.best_screenshot_for_version(params[:version])
|
||||
# Called as /thumbnail/:name
|
||||
else
|
||||
@screenshot = @package.screenshots.first
|
||||
end
|
||||
|
||||
# Return a 404 if the package has no screenshots or the image was not found
|
||||
unless @screenshot and @screenshot.image.path
|
||||
|
|
@ -119,11 +122,39 @@ class PackagesController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
# Send the thumbnail
|
||||
# TODO: Make sure it uses X-Sendfile correctly in production
|
||||
# Send the thumbnail (uses X-Sendfile or similar if possible)
|
||||
send_file @screenshot.image.path(:thumb), type: "image/png", disposition: 'inline'
|
||||
end
|
||||
|
||||
# Returns a large screenshot image if posssible.
|
||||
# If the package is not found it returns a dummy image along with status 404.
|
||||
# If the package is found but has no screenshots then it also returns a
|
||||
# dummy image along with status 404.
|
||||
def screenshot
|
||||
@package = Package.find_by(name: params[:name])
|
||||
unless @package
|
||||
screenshot404
|
||||
return
|
||||
end
|
||||
|
||||
# Called as /thumbnail-with-version/:name/:version
|
||||
if params[:version]
|
||||
@screenshot = @package.best_screenshot_for_version(params[:version])
|
||||
# Called as /thumbnail/:name
|
||||
else
|
||||
@screenshot = @package.screenshots.first
|
||||
end
|
||||
|
||||
# Return a 404 if the package has no screenshots or the image was not found
|
||||
unless @screenshot and @screenshot.image.path
|
||||
screenshot404
|
||||
return
|
||||
end
|
||||
|
||||
# Send the thumbnail (uses X-Sendfile or similar if possible)
|
||||
send_file @screenshot.image.path(:large), 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
|
||||
|
|
@ -147,9 +178,15 @@ class PackagesController < ApplicationController
|
|||
private
|
||||
|
||||
# Send a dummy thumbnail reading "No screenshot available. Sorry."
|
||||
# TODO: Make sure it uses X-Sendfile correctly in production
|
||||
def thumbnail404
|
||||
send_file Rails.root.join('public/images/dummy/no-screenshots-available.png'),
|
||||
send_file Rails.root.join('public/images/dummy/thumbnail404.png'),
|
||||
type: "image/png",
|
||||
disposition: 'inline',
|
||||
status: 404
|
||||
end
|
||||
|
||||
def screenshot404
|
||||
send_file Rails.root.join('public/images/dummy/screenshot404.png'),
|
||||
type: "image/png",
|
||||
disposition: 'inline',
|
||||
status: 404
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ class Package < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# Return the newest screenshot that is not newer than the given version.
|
||||
# This algorithm collects all image
|
||||
# versions of a package and determines the (second) newest version.
|
||||
# E.g. if there are version 1.0 and 2.0 and the user is looking for
|
||||
# a screenshot of version 1.5 then the 1.0 version is returned.
|
||||
# This way the user does not see a screenshot of version 2.0 because
|
||||
# 2.0 might contain features that were not there in version 1.5.
|
||||
def best_screenshot_for_version(version)
|
||||
sorted_screenshots = self.screenshots_sorted_by_version
|
||||
sorted_screenshots.each do |ss|
|
||||
|
|
@ -65,6 +71,8 @@ class Package < ActiveRecord::Base
|
|||
private
|
||||
|
||||
def version_compare(x,y)
|
||||
x ||= '0'
|
||||
y ||= '0'
|
||||
version_x = DebImporter::Version.new(x)
|
||||
version_y = DebImporter::Version.new(y)
|
||||
if version_x<version_y
|
||||
|
|
|
|||
7
app/views/json/package.json.jbuilder
Normal file
7
app/views/json/package.json.jbuilder
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
json.package @p.name
|
||||
|
||||
json.screenshots @p.screenshots do |s|
|
||||
json.small_image_url "#{request.protocol}#{request.host_with_port}#{s.image.url(:thumb, timestamp: false)}"
|
||||
json.large_image_url "#{request.protocol}#{request.host_with_port}#{s.image.url(:large, timestamp: false)}"
|
||||
json.version s.version
|
||||
end
|
||||
6
app/views/json/packages.json.jbuilder
Normal file
6
app/views/json/packages.json.jbuilder
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
json.cache! ['json_packages'], expires_in: 1.hour do
|
||||
json.packages @p do |p|
|
||||
json.extract! p, :maintainer, :name, :section, :maintainer_email, :homepage, :description
|
||||
json.url package_url(p.name)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
json.cache! ['json_packages'], expires_in: 1.hour do
|
||||
json.packages @p do |p|
|
||||
json.extract! p, :name
|
||||
end
|
||||
end
|
||||
10
app/views/json/screenshots.json.jbuilder
Normal file
10
app/views/json/screenshots.json.jbuilder
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
json.cache! ['json_screenshots'], expires_in: 1.hour do
|
||||
json.screenshots @s do |s|
|
||||
p = s.package
|
||||
json.extract! s, :version
|
||||
json.extract! p, :maintainer, :name, :section, :maintainer_email, :homepage, :description
|
||||
json.url package_url(p.name)
|
||||
json.small_image_url "#{request.protocol}#{request.host_with_port}#{s.image.url(:thumb, timestamp: false)}"
|
||||
json.large_image_url "#{request.protocol}#{request.host_with_port}#{s.image.url(:large, timestamp: false)}"
|
||||
end
|
||||
end
|
||||
19
app/views/packages/_long_description.slim
Normal file
19
app/views/packages/_long_description.slim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/ Converts long descriptions from Debian control files into
|
||||
/ proper HTML.
|
||||
/ See: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
|
||||
|
||||
- text.lines.each do |line|
|
||||
/ pre +++#{line}---
|
||||
- case line.rstrip
|
||||
- when '.'
|
||||
/ Empty line
|
||||
/ TODO: Technically wrong because this creates an empty paragraph:
|
||||
p
|
||||
- when /^(\s+)(.+)/
|
||||
/ Verbatim text
|
||||
div.description-verbatim-lines
|
||||
= (' ' * $1.to_s.length).html_safe
|
||||
= $2
|
||||
- else
|
||||
/ Normal text
|
||||
= line
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
'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)
|
||||
href=delete_screenshot_path(screenshot.id)
|
||||
onclick="return confirm('Really delete the screenshot?');"
|
||||
] Delete screenshot
|
||||
p Write a description for this screenshot:
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@
|
|||
.text-center
|
||||
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)
|
||||
- if screenshot.description
|
||||
.imgcaption =screenshot.description
|
||||
- if screenshot.version.present?
|
||||
.imgcaption
|
||||
em '(from version #{screenshot.version})
|
||||
- if user_signed_in?
|
||||
.imgcaption
|
||||
em =screenshot.adminstatus
|
||||
div
|
||||
- if screenshot.description
|
||||
.imgcaption =screenshot.description
|
||||
- if screenshot.version.present?
|
||||
em.imgcaption
|
||||
'(from version #{screenshot.version})
|
||||
- if user_signed_in?
|
||||
em.imgcaption Admin status: #{screenshot.adminstatus}
|
||||
|
||||
// Is the user an admin?
|
||||
- if user_signed_in?
|
||||
|
|
@ -44,7 +44,8 @@
|
|||
p.subtitle Description
|
||||
// TODO: split long_description by <p> tags
|
||||
- if @package.long_description.present?
|
||||
p =@package.long_description
|
||||
= render(partial: 'long_description', locals: {text: @package.long_description})
|
||||
/ p =@package.long_description
|
||||
- else
|
||||
p Sorry - no more information available.
|
||||
- if @package.homepage.present?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue