diff --git a/app/controllers/broken_image_reports_controller.rb b/app/controllers/broken_image_reports_controller.rb new file mode 100644 index 00000000..8d4f3dc6 --- /dev/null +++ b/app/controllers/broken_image_reports_controller.rb @@ -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 + diff --git a/app/helpers/broken_image_reports_helper.rb b/app/helpers/broken_image_reports_helper.rb new file mode 100644 index 00000000..a0337f99 --- /dev/null +++ b/app/helpers/broken_image_reports_helper.rb @@ -0,0 +1,2 @@ +module BrokenImageReportsHelper +end diff --git a/app/models/asset_image_conversion_request.rb b/app/models/asset_image_conversion_request.rb index 0ebc550a..accdd863 100644 --- a/app/models/asset_image_conversion_request.rb +++ b/app/models/asset_image_conversion_request.rb @@ -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 diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index 1957b633..9fda5106 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -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 diff --git a/app/stylesheets/broken_image_reports/_new.sass b/app/stylesheets/broken_image_reports/_new.sass new file mode 100644 index 00000000..f725497a --- /dev/null +++ b/app/stylesheets/broken_image_reports/_new.sass @@ -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% + diff --git a/app/stylesheets/screen.sass b/app/stylesheets/screen.sass index c4f32713..4fe359e8 100644 --- a/app/stylesheets/screen.sass +++ b/app/stylesheets/screen.sass @@ -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 diff --git a/app/views/broken_image_reports/new.html.haml b/app/views/broken_image_reports/new.html.haml new file mode 100644 index 00000000..b4e9c653 --- /dev/null +++ b/app/views/broken_image_reports/new.html.haml @@ -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 + diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index ac4d33d2..55ffecb9 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 4cdbe6c8..5deb758d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20110807212936_add_conversion_timestamps_to_swf_assets.rb b/db/migrate/20110807212936_add_conversion_timestamps_to_swf_assets.rb new file mode 100644 index 00000000..127d6f4c --- /dev/null +++ b/db/migrate/20110807212936_add_conversion_timestamps_to_swf_assets.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 3bbdc922..51a99b0d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -156,15 +156,17 @@ ActiveRecord::Schema.define(:version => 20110804134432) do end create_table "swf_assets", :id => false, :force => true do |t| - t.string "type", :limit => 7, :null => false - t.integer "id", :limit => 3, :null => false - t.text "url", :limit => 16777215, :null => false - t.integer "zone_id", :limit => 1, :null => false - t.text "zones_restrict", :null => false - t.datetime "created_at", :null => false - 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.string "type", :limit => 7, :null => false + t.integer "id", :limit => 3, :null => false + t.text "url", :limit => 16777215, :null => false + t.integer "zone_id", :limit => 1, :null => false + t.text "zones_restrict", :null => false + t.datetime "created_at", :null => false + 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" diff --git a/public/javascripts/outfits/edit.js b/public/javascripts/outfits/edit.js index a687e35b..5b51084f 100644 --- a/public/javascripts/outfits/edit.js +++ b/public/javascripts/outfits/edit.js @@ -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); diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index 6a1f4eb6..79ecbc01 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -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; diff --git a/spec/controllers/broken_image_reports_controller_spec.rb b/spec/controllers/broken_image_reports_controller_spec.rb new file mode 100644 index 00000000..8b39ee89 --- /dev/null +++ b/spec/controllers/broken_image_reports_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe BrokenImageReportsController do + +end diff --git a/spec/helpers/broken_image_reports_helper_spec.rb b/spec/helpers/broken_image_reports_helper_spec.rb new file mode 100644 index 00000000..2724cbc8 --- /dev/null +++ b/spec/helpers/broken_image_reports_helper_spec.rb @@ -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