report broken images
This commit is contained in:
parent
564ba9bdd9
commit
7358aae680
15 changed files with 199 additions and 18 deletions
26
app/controllers/broken_image_reports_controller.rb
Normal file
26
app/controllers/broken_image_reports_controller.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class BrokenImageReportsController < ApplicationController
|
||||
def new
|
||||
ids = params[:asset_ids]
|
||||
assets = SwfAsset.arel_table
|
||||
@swf_assets = SwfAsset.where(:has_image => true).where((
|
||||
assets[:id].in(ids[:biology]).and(assets[:type].eq('biology'))
|
||||
).or(
|
||||
assets[:id].in(ids[:object]).and(assets[:type].eq('object'))
|
||||
))
|
||||
end
|
||||
|
||||
def create
|
||||
swf_asset = SwfAsset.find params[:swf_asset_id]
|
||||
|
||||
if swf_asset.report_broken
|
||||
flash[:success] = "Thanks! This image will be reconverted soon. If it " +
|
||||
"looks the same after conversion, please consider sending a bug report."
|
||||
else
|
||||
flash[:alert] = "This image is already in line for reconversion. We'll " +
|
||||
"get to it soon, don't worry."
|
||||
end
|
||||
|
||||
redirect_to :back
|
||||
end
|
||||
end
|
||||
|
2
app/helpers/broken_image_reports_helper.rb
Normal file
2
app/helpers/broken_image_reports_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module BrokenImageReportsHelper
|
||||
end
|
|
@ -19,5 +19,12 @@ class AssetImageConversionRequest
|
|||
|
||||
@queue = :requested_asset_images_on_creation
|
||||
end
|
||||
|
||||
class OnBrokenImageReport < AssetImageConversionRequest
|
||||
@retry_limit = 5
|
||||
@retry_delay = 60
|
||||
|
||||
@queue = :reportedly_broken_asset_images
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,10 @@ class SwfAsset < ActiveRecord::Base
|
|||
FileUtils.rm path
|
||||
end
|
||||
FileUtils.rmdir swf_image_dir
|
||||
|
||||
self.converted_at = Time.now
|
||||
self.has_image = true
|
||||
self.save!
|
||||
end
|
||||
|
||||
def s3_key(size)
|
||||
|
@ -53,7 +57,11 @@ class SwfAsset < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def s3_path
|
||||
"#{type}/#{s3_partition_path}#{self.id}"
|
||||
"#{self['type']}/#{s3_partition_path}#{self.id}"
|
||||
end
|
||||
|
||||
def s3_url(size)
|
||||
"#{IMAGE_BUCKET.public_link}/#{s3_path}/#{size.join 'x'}.png"
|
||||
end
|
||||
|
||||
PARTITION_COUNT = 3
|
||||
|
@ -68,13 +76,11 @@ class SwfAsset < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def convert_swf_if_not_converted!
|
||||
if has_image?
|
||||
false
|
||||
else
|
||||
if needs_conversion?
|
||||
convert_swf!
|
||||
self.has_image = true
|
||||
save!
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -89,6 +95,24 @@ class SwfAsset < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def report_broken
|
||||
if image_pending_repair?
|
||||
return false
|
||||
end
|
||||
|
||||
Resque.enqueue(AssetImageConversionRequest::OnBrokenImageReport, self.type, self.id)
|
||||
self.reported_broken_at = Time.now
|
||||
self.save
|
||||
end
|
||||
|
||||
def needs_conversion?
|
||||
!has_image? || image_pending_repair?
|
||||
end
|
||||
|
||||
def image_pending_repair?
|
||||
reported_broken_at && (converted_at.nil? || reported_broken_at > converted_at)
|
||||
end
|
||||
|
||||
attr_accessor :item
|
||||
|
||||
has_one :contribution, :as => :contributed
|
||||
|
|
24
app/stylesheets/broken_image_reports/_new.sass
Normal file
24
app/stylesheets/broken_image_reports/_new.sass
Normal file
|
@ -0,0 +1,24 @@
|
|||
body.broken_image_reports-new
|
||||
|
||||
#report-assets
|
||||
li
|
||||
+border-radius(.5em)
|
||||
+inline-block
|
||||
border: 1px solid $soft-border-color
|
||||
margin: .5em
|
||||
padding: .5em
|
||||
text-align: center
|
||||
vertical-align: top
|
||||
width: 150px
|
||||
|
||||
img, span, input
|
||||
display: block
|
||||
width: 100%
|
||||
|
||||
img
|
||||
height: 150px
|
||||
width: 150px
|
||||
|
||||
span
|
||||
font-size: 85%
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
@import partials/jquery.jgrowl
|
||||
|
||||
@import broken_image_reports/new
|
||||
@import closet_hangers/index
|
||||
@import closet_hangers/petpage
|
||||
@import closet_lists/form
|
||||
|
|
31
app/views/broken_image_reports/new.html.haml
Normal file
31
app/views/broken_image_reports/new.html.haml
Normal file
|
@ -0,0 +1,31 @@
|
|||
- title 'Report broken image'
|
||||
|
||||
%p
|
||||
Thanks for helping us find broken image! Sometimes the converters don't get
|
||||
things quite right, and sometimes that can be fixed by just trying the
|
||||
conversion again. If reconversion doesn't seem to solve the issue, consider
|
||||
sending us a bug report at #{mail_to 'webmaster@openneo.net'}. Thanks!
|
||||
|
||||
%p
|
||||
Which of these images looked broken? We'll put it in line for reconversion.
|
||||
|
||||
%ul#report-assets
|
||||
- @swf_assets.each do |swf_asset|
|
||||
%li
|
||||
= link_to image_tag(swf_asset.s3_url([150, 150])), swf_asset.url
|
||||
- unless swf_asset.image_pending_repair?
|
||||
= form_tag(:action => :create) do
|
||||
= hidden_field_tag 'swf_asset_id', swf_asset.id
|
||||
= submit_tag 'Report as broken'
|
||||
|
||||
- if swf_asset.converted_at?
|
||||
%span.converted-at
|
||||
Converted
|
||||
= time_ago_in_words swf_asset.converted_at
|
||||
ago
|
||||
- else
|
||||
%span.reported-broken-at
|
||||
Reported
|
||||
= time_ago_in_words swf_asset.reported_broken_at
|
||||
ago
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
= link_to 'Image mode FAQ', image_mode_path,
|
||||
:id => 'preview-mode-note', :target => '_blank'
|
||||
= link_to 'Broken image?', '#', :id => 'report-broken-image',
|
||||
:target => '_blank', 'data-base-url' => '/FIXME'
|
||||
:target => '_blank', 'data-base-url' => new_broken_image_report_path
|
||||
- else
|
||||
= link_to(donate_path, :id => 'preview-mode-note', :target => '_blank') do
|
||||
%strong Image mode
|
||||
|
|
|
@ -20,6 +20,7 @@ OpenneoImpressItems::Application.routes.draw do |map|
|
|||
|
||||
match '/roulette' => 'roulettes#new', :as => :roulette
|
||||
|
||||
resources :broken_image_reports, :only => [:new, :create]
|
||||
resources :contributions, :only => [:index]
|
||||
resources :items, :only => [:index, :show] do
|
||||
collection do
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class AddConversionTimestampsToSwfAssets < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :swf_assets, :reported_broken_at, :timestamp
|
||||
add_column :swf_assets, :converted_at, :timestamp
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :swf_assets, :converted_at
|
||||
remove_column :swf_assets, :reported_broken_at
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110804134432) do
|
||||
ActiveRecord::Schema.define(:version => 20110807212936) do
|
||||
|
||||
create_table "auth_servers", :force => true do |t|
|
||||
t.string "short_name", :limit => 10, :null => false
|
||||
|
@ -165,6 +165,8 @@ ActiveRecord::Schema.define(:version => 20110804134432) do
|
|||
t.integer "body_id", :limit => 2, :null => false
|
||||
t.boolean "has_image", :default => false, :null => false
|
||||
t.boolean "image_requested", :default => false, :null => false
|
||||
t.datetime "reported_broken_at"
|
||||
t.datetime "converted_at"
|
||||
end
|
||||
|
||||
add_index "swf_assets", ["body_id"], :name => "swf_assets_body_id_and_object_id"
|
||||
|
|
|
@ -867,7 +867,7 @@ View.ReportBrokenImage = function (wardrobe) {
|
|||
|
||||
for(var i = 0; i < assets.length; i++) {
|
||||
if(i > 0) url += "&";
|
||||
url += "asset_ids[]=" + assets[i].id;
|
||||
url += "asset_ids[" + assets[i].type + "][]=" + assets[i].id;
|
||||
}
|
||||
|
||||
link.attr('href', url);
|
||||
|
|
|
@ -574,6 +574,38 @@ div.jGrowl div.jGrowl-closer {
|
|||
}
|
||||
}
|
||||
|
||||
/* line 4, ../../../app/stylesheets/broken_image_reports/_new.sass */
|
||||
body.broken_image_reports-new #report-assets li {
|
||||
-moz-border-radius: 0.5em;
|
||||
-webkit-border-radius: 0.5em;
|
||||
display: -moz-inline-box;
|
||||
-moz-box-orient: vertical;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
*display: inline;
|
||||
*vertical-align: auto;
|
||||
border: 1px solid #aaddaa;
|
||||
margin: 0.5em;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
vertical-align: top;
|
||||
width: 150px;
|
||||
}
|
||||
/* line 14, ../../../app/stylesheets/broken_image_reports/_new.sass */
|
||||
body.broken_image_reports-new #report-assets li img, body.broken_image_reports-new #report-assets li span, body.broken_image_reports-new #report-assets li input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
/* line 18, ../../../app/stylesheets/broken_image_reports/_new.sass */
|
||||
body.broken_image_reports-new #report-assets li img {
|
||||
height: 150px;
|
||||
width: 150px;
|
||||
}
|
||||
/* line 22, ../../../app/stylesheets/broken_image_reports/_new.sass */
|
||||
body.broken_image_reports-new #report-assets li span {
|
||||
font-size: 85%;
|
||||
}
|
||||
|
||||
/* line 2, ../../../app/stylesheets/partials/_secondary_nav.sass */
|
||||
body.closet_hangers-index #title {
|
||||
float: left;
|
||||
|
|
5
spec/controllers/broken_image_reports_controller_spec.rb
Normal file
5
spec/controllers/broken_image_reports_controller_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe BrokenImageReportsController do
|
||||
|
||||
end
|
15
spec/helpers/broken_image_reports_helper_spec.rb
Normal file
15
spec/helpers/broken_image_reports_helper_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the BrokenImageReportsHelper. For example:
|
||||
#
|
||||
# describe BrokenImageReportsHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# helper.concat_strings("this","that").should == "this that"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe BrokenImageReportsHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in a new issue