From b0cc4c2396cc477aaadb57ead018204267229dc5 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 3 May 2015 16:57:42 -0500 Subject: [PATCH] swf links --- app/assets/javascripts/outfits/edit.js | 22 +++++++++-------- app/assets/stylesheets/application.css.sass | 1 + .../broken_image_reports/_new.sass | 24 ++++--------------- app/assets/stylesheets/outfits/_edit.sass | 24 ++++++++++--------- .../stylesheets/partials/_assets-list.sass | 18 ++++++++++++++ app/assets/stylesheets/swf_assets/_links.sass | 10 ++++++++ .../broken_image_reports_controller.rb | 8 +------ app/controllers/swf_assets_controller.rb | 4 ++++ app/models/swf_asset.rb | 8 +++++++ app/views/outfits/edit.html.haml | 2 ++ app/views/swf_assets/links.html.haml | 8 +++++++ config/locales/en.yml | 5 ++++ config/routes.rb | 6 ++++- 13 files changed, 92 insertions(+), 48 deletions(-) create mode 100644 app/assets/stylesheets/partials/_assets-list.sass create mode 100644 app/assets/stylesheets/swf_assets/_links.sass create mode 100644 app/views/swf_assets/links.html.haml diff --git a/app/assets/javascripts/outfits/edit.js b/app/assets/javascripts/outfits/edit.js index d2738f70..543d9795 100644 --- a/app/assets/javascripts/outfits/edit.js +++ b/app/assets/javascripts/outfits/edit.js @@ -1090,20 +1090,22 @@ View.PreviewAdapterForm = function (wardrobe) { } } -View.ReportBrokenImage = function (wardrobe) { - var link = $('#report-broken-image'); - var baseURL = link.attr('data-base-url'); +View.AssetLinks = function (wardrobe) { + var links = $('#swf-links, #report-broken-image'); function updateLink() { - var assets = wardrobe.outfits.getVisibleAssets(); - var url = baseURL + "?"; + links.each(function() { + var link = $(this); + var assets = wardrobe.outfits.getVisibleAssets(); + var url = link.attr('data-base-url') + "?"; - for(var i = 0; i < assets.length; i++) { - if(i > 0) url += "&"; - url += "asset_ids[" + assets[i].type + "][]=" + assets[i].id; - } + for(var i = 0; i < assets.length; i++) { + if(i > 0) url += "&"; + url += "asset_ids[" + assets[i].type + "][]=" + assets[i].id; + } - link.attr('href', url); + link.attr('href', url); + }); } wardrobe.outfits.bind('updateWornItems', updateLink); diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 17db2115..fecda275 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -28,4 +28,5 @@ @import static/donate @import static/image_mode @import static/terms +@import swf_assets/links @import users/top_contributors diff --git a/app/assets/stylesheets/broken_image_reports/_new.sass b/app/assets/stylesheets/broken_image_reports/_new.sass index a79b0eb1..c66622a9 100644 --- a/app/assets/stylesheets/broken_image_reports/_new.sass +++ b/app/assets/stylesheets/broken_image_reports/_new.sass @@ -1,26 +1,12 @@ +@import partials/assets-list + 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 + +assets-list - img, span, input - display: block - width: 100% - - img - height: 150px - width: 150px - - span - font-size: 85% + span + font-size: 85% .manual a display: block diff --git a/app/assets/stylesheets/outfits/_edit.sass b/app/assets/stylesheets/outfits/_edit.sass index 7e46d66d..6ffa641d 100644 --- a/app/assets/stylesheets/outfits/_edit.sass +++ b/app/assets/stylesheets/outfits/_edit.sass @@ -168,17 +168,19 @@ body.outfits-edit button font-size: 75% width: 100% - #preview-mode a - font-size: 75% - margin-top: .5em - text-align: center - text-decoration: none - width: 100% - em - font-style: normal - text-decoration: underline - #preview-mode-note, #report-broken-image - display: none + #preview-mode + a + display: block + font-size: 75% + margin-top: .5em + text-align: center + text-decoration: none + width: 100% + em + font-style: normal + text-decoration: underline + #report-broken-image + display: none #preview-sidebar float: left diff --git a/app/assets/stylesheets/partials/_assets-list.sass b/app/assets/stylesheets/partials/_assets-list.sass new file mode 100644 index 00000000..ca3c8390 --- /dev/null +++ b/app/assets/stylesheets/partials/_assets-list.sass @@ -0,0 +1,18 @@ +=assets-list + 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 diff --git a/app/assets/stylesheets/swf_assets/_links.sass b/app/assets/stylesheets/swf_assets/_links.sass new file mode 100644 index 00000000..38b162b3 --- /dev/null +++ b/app/assets/stylesheets/swf_assets/_links.sass @@ -0,0 +1,10 @@ +@import partials/assets-list + +body.swf_assets-links + #swf-assets + +assets-list + + li + span + font-size: 75% + word-wrap: break-word diff --git a/app/controllers/broken_image_reports_controller.rb b/app/controllers/broken_image_reports_controller.rb index 364d608c..e911b5bb 100644 --- a/app/controllers/broken_image_reports_controller.rb +++ b/app/controllers/broken_image_reports_controller.rb @@ -1,12 +1,6 @@ class BrokenImageReportsController < ApplicationController def new - ids = params[:asset_ids] - assets = SwfAsset.arel_table - @swf_assets = SwfAsset.where(:has_image => true).where(( - assets[:remote_id].in(ids[:biology]).and(assets[:type].eq('biology')) - ).or( - assets[:remote_id].in(ids[:object]).and(assets[:type].eq('object')) - )) + @swf_assets = SwfAsset.from_wardrobe_link_params(params[:asset_ids]).where(:has_image => true) end def create diff --git a/app/controllers/swf_assets_controller.rb b/app/controllers/swf_assets_controller.rb index 0af82690..fd303509 100644 --- a/app/controllers/swf_assets_controller.rb +++ b/app/controllers/swf_assets_controller.rb @@ -60,5 +60,9 @@ class SwfAssetsController < ApplicationController @swf_asset = SwfAsset.find params[:id] render :json => @swf_asset end + + def links + @swf_assets = SwfAsset.from_wardrobe_link_params(params[:asset_ids]) + end end diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index 1fb2d8f4..986956c5 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -237,6 +237,14 @@ class SwfAsset < ActiveRecord::Base self.url = "#{NEOPETS_ASSET_SERVER}/#{data['url']}" end + def self.from_wardrobe_link_params(ids) + where(( + arel_table[:remote_id].in(ids[:biology]).and(arel_table[:type].eq('biology')) + ).or( + arel_table[:remote_id].in(ids[:object]).and(arel_table[:type].eq('object')) + )) + end + before_create do uri = URI.parse url begin diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index 2ece6631..fdbb1e52 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -37,6 +37,8 @@ = link_to t('.preview.big_picture'), 'javascript:void(0)', id: 'toggle-big-picture' = link_to t('.preview.download'), 'javascript:void(0)', id: 'preview-mode-download' + = link_to t('.preview.swf_links'), 'javascript:void(0)', id: 'swf-links', + target: '_blank', 'data-base-url' => links_swf_assets_path = link_to t('.preview.mode.image.report_broken'), 'javascript:void(0)', :id => 'report-broken-image', :target => '_blank', 'data-base-url' => new_broken_image_report_path #preview-sidebar diff --git a/app/views/swf_assets/links.html.haml b/app/views/swf_assets/links.html.haml new file mode 100644 index 00000000..e3dda75d --- /dev/null +++ b/app/views/swf_assets/links.html.haml @@ -0,0 +1,8 @@ +- title t('.title') + +%ul#swf-assets + - @swf_assets.each do |swf_asset| + %li + = link_to swf_asset.url do + = image_tag(swf_asset.image_url([150, 150])) + %span= swf_asset.url diff --git a/config/locales/en.yml b/config/locales/en.yml index c8474a8b..0197b1a6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -564,6 +564,7 @@ en: Flash and Javascript (but not Java!) are required to preview outfits. big_picture: Big Picture download: Download + swf_links: SWF Links mode: flash: name: Flash @@ -816,6 +817,10 @@ en: Please try again later! neopia_error: "We couldn't load that pet: \"%{message}\". Try again later?" + swf_assets: + links: + title: Links to SWFs + users: index: not_found: We don't have a user named %{name}. Is it spelled correctly? diff --git a/config/routes.rb b/config/routes.rb index d87e82ef..c943e878 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,7 +32,11 @@ OpenneoImpressItems::Application.routes.draw do end resources :outfits, :only => [:show, :create, :update, :destroy] resources :pet_attributes, :only => [:index] - resources :swf_assets, :only => [:index, :show] + resources :swf_assets, :only => [:index, :show] do + collection do + get :links + end + end resources :zones, only: [:index] scope 'import' do