From ef004cc6cb8b8925cfba57482d9e722409ce58e2 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 6 Nov 2010 13:07:12 -0400 Subject: [PATCH] needed objects --- app/controllers/items_controller.rb | 17 +++++++++-- app/controllers/pets_controller.rb | 2 +- app/models/pet_type.rb | 22 +++++++++++++++ app/stylesheets/_layout.sass | 9 ++++++ app/stylesheets/items/_index.sass | 9 ------ app/views/items/needed.html.haml | 16 +++++++++++ config/routes.rb | 3 +- public/javascripts/items/show.js | 2 +- public/stylesheets/compiled/screen.css | 39 +++++++++++++------------- 9 files changed, 85 insertions(+), 34 deletions(-) create mode 100644 app/views/items/needed.html.haml diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 8dc76ffa..c8386e49 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,8 +1,6 @@ class ItemsController < ApplicationController before_filter :set_query - layout 'items' - def index if params.has_key?(:q) begin @@ -41,6 +39,21 @@ class ItemsController < ApplicationController @item = Item.find params[:id] end + def needed + if params[:color] && params[:species] + @pet_type = PetType.find_by_color_id_and_species_id( + params[:color], + params[:species] + ) + end + unless @pet_type + raise ActiveRecord::RecordNotFound, 'Pet type not found' + end + @items = @pet_type.needed_items.alphabetize + @pet_name = params[:name] + render :layout => 'application' + end + private def set_query diff --git a/app/controllers/pets_controller.rb b/app/controllers/pets_controller.rb index 165408a6..22892dde 100644 --- a/app/controllers/pets_controller.rb +++ b/app/controllers/pets_controller.rb @@ -16,7 +16,7 @@ class PetsController < ApplicationController @pet.save respond_to do |format| format.html do - destination = params[:destination] + destination = params[:destination] || params[:origin] destination = 'root' unless DESTINATIONS[destination] query_joiner = DESTINATIONS[destination] path = send("#{destination}_path") + query_joiner + @pet.wardrobe_query diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index fee2144a..a48491b2 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -68,6 +68,28 @@ class PetType < ActiveRecord::Base self.color.human_name + ' ' + self.species.human_name end + def needed_items + items = Item.arel_table + species_matchers = [ + "#{species_id},%", + "%,#{species_id},%", + "%,#{species_id}" + ] + species_condition = nil + species_matchers.each do |matcher| + condition = items[:species_support_ids].matches(matcher) + if species_condition + species_condition = species_condition.or(condition) + else + species_condition = condition + end + end + unneeded_item_ids = Item.select(items[:id]).joins(:parent_swf_asset_relationships => :object_asset). + where(SwfAsset.arel_table[:body_id].in([0, self.body_id])).map(&:id) + Item.where(items[:id].in(unneeded_item_ids).not). + where(species_condition) + end + def add_pet_state_from_biology!(biology) pet_state = PetState.from_pet_type_and_biology_info(self, biology) self.pet_states << pet_state diff --git a/app/stylesheets/_layout.sass b/app/stylesheets/_layout.sass index 1f6d5d38..2ccd3ae1 100644 --- a/app/stylesheets/_layout.sass +++ b/app/stylesheets/_layout.sass @@ -198,6 +198,15 @@ dd .current font-weight: bold +.object .nc-icon + height: 16px + position: absolute + right: ($object-width - $object-img-size) / 2 + $object-padding + top: $object-img-size - $nc-icon-size + width: 16px + &:hover + +opacity(0.5) + /* Fonts /* A font by Jos Buivenga (exljbris) -> www.exljbris.nl diff --git a/app/stylesheets/items/_index.sass b/app/stylesheets/items/_index.sass index 62369a0d..81631195 100644 --- a/app/stylesheets/items/_index.sass +++ b/app/stylesheets/items/_index.sass @@ -8,15 +8,6 @@ body.items-index form margin-bottom: 2em - .object .nc-icon - height: 16px - position: absolute - right: ($object-width - $object-img-size) / 2 + $object-padding - top: $object-img-size - $nc-icon-size - width: 16px - &:hover - +opacity(0.5) - #search-help +main_unit padding-right: 1% diff --git a/app/views/items/needed.html.haml b/app/views/items/needed.html.haml new file mode 100644 index 00000000..13063786 --- /dev/null +++ b/app/views/items/needed.html.haml @@ -0,0 +1,16 @@ +- title "Needed items for #{@pet_type.human_name}" +%h2 + = image_tag "http://pets.neopets.com/cpn/#{@pet_name}/1/1.png", + :class => 'inline-image' + %span.pet-name= @pet_name + can model… +%ul.buttons + %li + = form_tag load_pet_path do + = origin_tag 'needed_items' + = hidden_field_tag 'name', @pet_name + = submit_tag "I'm wearing one now!", :class => 'loud' + %li + = link_to 'What do I own?', 'http://www.neopets.com/closet.phtml', + :class => 'button', :target => '_blank' += render @items diff --git a/config/routes.rb b/config/routes.rb index 18ab77db..2ae00245 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,6 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/' => 'items#index', :as => :items match '/index.js' => 'items#index', :format => :js match '/items.json' => 'items#index', :format => :json - match '/items/:id' => 'items#show', :as => :item match '/item_zone_sets.js' => 'ItemZoneSets#index' match '/item_zone_sets.json' => 'ItemZoneSets#index' @@ -16,7 +15,7 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show' resources :contributions, :only => [:index] - resources :items, :only => [:index] do + resources :items, :only => [:index, :show] do collection do get :needed end diff --git a/public/javascripts/items/show.js b/public/javascripts/items/show.js index 474ac937..3abe4f45 100644 --- a/public/javascripts/items/show.js +++ b/public/javascripts/items/show.js @@ -175,7 +175,7 @@ function Item(id) { Item.LOAD_ERROR = new LoadError("$species_article $species wear a $item"); Item.createFromLocation = function () { - var item = new Item(parseInt(document.location.pathname.substr(1))), + var item = new Item(parseInt(document.location.pathname.substr(7), 10)), z = CURRENT_ITEM_ZONES_RESTRICT, zl = z.length; item.restricted_zones = []; for(i = 0; i < zl; i++) { diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index ea9ca518..176af9aa 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -327,6 +327,22 @@ dd { font-weight: bold; } +/* line 201, ../../../app/stylesheets/_layout.sass */ +.object .nc-icon { + height: 16px; + position: absolute; + right: 16px; + top: 64px; + width: 16px; +} +/* line 207, ../../../app/stylesheets/_layout.sass */ +.object .nc-icon:hover { + -moz-opacity: 0.5; + -webkit-opacity: 0.5; + -o-opacity: 0.5; + -khtml-opacity: 0.5; +} + /* Fonts */ /* A font by Jos Buivenga (exljbris) -> www.exljbris.nl */ @font-face { @@ -457,21 +473,6 @@ body.items-index form { margin-bottom: 2em; } /* line 11, ../../../app/stylesheets/items/_index.sass */ -body.items-index .object .nc-icon { - height: 16px; - position: absolute; - right: 16px; - top: 64px; - width: 16px; -} -/* line 17, ../../../app/stylesheets/items/_index.sass */ -body.items-index .object .nc-icon:hover { - -moz-opacity: 0.5; - -webkit-opacity: 0.5; - -o-opacity: 0.5; - -khtml-opacity: 0.5; -} -/* line 20, ../../../app/stylesheets/items/_index.sass */ body.items-index #search-help { float: left; width: 49%; @@ -481,15 +482,15 @@ body.items-index #search-help { body.items-index #search-help h2 { font-size: 125%; } -/* line 23, ../../../app/stylesheets/items/_index.sass */ +/* line 14, ../../../app/stylesheets/items/_index.sass */ body.items-index #search-help dl { text-align: left; } -/* line 25, ../../../app/stylesheets/items/_index.sass */ +/* line 16, ../../../app/stylesheets/items/_index.sass */ body.items-index #search-help dd { margin-bottom: 1em; } -/* line 28, ../../../app/stylesheets/items/_index.sass */ +/* line 19, ../../../app/stylesheets/items/_index.sass */ body.items-index #species-search-links { float: left; width: 49%; @@ -499,7 +500,7 @@ body.items-index #species-search-links { body.items-index #species-search-links h2 { font-size: 125%; } -/* line 31, ../../../app/stylesheets/items/_index.sass */ +/* line 22, ../../../app/stylesheets/items/_index.sass */ body.items-index #species-search-links img { height: 80px; width: 80px;