From d99a1ad792ebbdfad4cdaada499c463b205229e5 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 4 Aug 2011 10:01:44 -0400 Subject: [PATCH] newest items --- app/controllers/items_controller.rb | 5 ++- app/models/item.rb | 2 + app/stylesheets/items/_index.sass | 3 +- app/views/items/index.html.haml | 45 ++++++++++--------- .../20110804134432_add_timestamps_to_items.rb | 13 ++++++ db/schema.rb | 4 +- public/stylesheets/compiled/screen.css | 8 ++-- 7 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20110804134432_add_timestamps_to_items.rb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index d7243dce..6b7ae582 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -32,7 +32,10 @@ class ItemsController < ApplicationController end else respond_to do |format| - format.html { render } + format.html { + @newest_items = Item.newest.limit(9) + render + } format.js { render :json => {:error => '$q required'}} end end diff --git a/app/models/item.rb b/app/models/item.rb index 87a66c0b..7d5f2de8 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -38,6 +38,8 @@ class Item < ActiveRecord::Base "LEFT JOIN #{SwfAsset.table_name} sa ON sa.type = 'object' AND sa.id = psa.swf_asset_id" ).where('sa.id IS NULL') + scope :newest, order(arel_table[:created_at].desc) + scope :spidered_longest_ago, order(["(#{Item.arel_table[:last_spidered].eq(nil).to_sql}) DESC", arel_table[:last_spidered].desc]) scope :sold_in_mall, where(:sold_in_mall => true) diff --git a/app/stylesheets/items/_index.sass b/app/stylesheets/items/_index.sass index 81631195..cbad0d86 100644 --- a/app/stylesheets/items/_index.sass +++ b/app/stylesheets/items/_index.sass @@ -8,7 +8,7 @@ body.items-index form margin-bottom: 2em - #search-help + #search-info +main_unit padding-right: 1% dl @@ -22,3 +22,4 @@ body.items-index img height: 80px width: 80px + diff --git a/app/views/items/index.html.haml b/app/views/items/index.html.haml index f02d4fa3..34647d1a 100644 --- a/app/views/items/index.html.haml +++ b/app/views/items/index.html.haml @@ -13,26 +13,31 @@ = render @items = will_paginate @items - else - #search-help - %h2 Find what you're looking for - %dl - %dt kreludor "altador cup" -background - %dd - returns any item with the word "kreludor" and the phrase "altador cup" - in it, but not the word "background" - %dt hat user:owns - %dd - returns - = link_to 'items that you own', your_items_path - with the word "hat" - %dt blue is:nc - %dd returns any NC Mall item with the word "blue" in it - %dt collar -is:pb - %dd returns any item with the word "collar" in it that isn't from a paint brush - %dt species:shoyru - %dd returns any item a Shoyru can wear - %dt type:hat - %dd returns any item that fills a "hat" zone + #search-info + #search-help + %h2 Find what you're looking for + %dl + %dt kreludor "altador cup" -background + %dd + returns any item with the word "kreludor" and the phrase "altador cup" + in it, but not the word "background" + %dt hat user:owns + %dd + returns + = link_to 'items that you own', your_items_path + with the word "hat" + %dt blue is:nc + %dd returns any NC Mall item with the word "blue" in it + %dt collar -is:pb + %dd returns any item with the word "collar" in it that isn't from a paint brush + %dt species:shoyru + %dd returns any item a Shoyru can wear + %dt type:hat + %dd returns any item that fills a "hat" zone + + #search-new-items + %h2 Newest items + = render @newest_items #species-search-links %h2 Can't decide? Search by species diff --git a/db/migrate/20110804134432_add_timestamps_to_items.rb b/db/migrate/20110804134432_add_timestamps_to_items.rb new file mode 100644 index 00000000..305e2475 --- /dev/null +++ b/db/migrate/20110804134432_add_timestamps_to_items.rb @@ -0,0 +1,13 @@ +class AddTimestampsToItems < ActiveRecord::Migration + def self.up + add_timestamps :objects + + timestamp_query = "(SELECT created_at FROM contributions WHERE contributed_id = objects.id AND contributed_type = 'Item')" + update "UPDATE objects SET created_at = #{timestamp_query}, updated_at = #{timestamp_query}" + end + + def self.down + remove_timestamps :objects + end +end + diff --git a/db/schema.rb b/db/schema.rb index b966ec98..3bbdc922 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 => 20110731021808) do +ActiveRecord::Schema.define(:version => 20110804134432) do create_table "auth_servers", :force => true do |t| t.string "short_name", :limit => 10, :null => false @@ -86,6 +86,8 @@ ActiveRecord::Schema.define(:version => 20110731021808) do t.text "species_support_ids", :limit => 16777215 t.boolean "sold_in_mall", :null => false t.datetime "last_spidered" + t.datetime "created_at" + t.datetime "updated_at" end add_index "objects", ["last_spidered"], :name => "objects_last_spidered" diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index 72e7bc6f..764bee4f 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -1638,21 +1638,21 @@ body.items-index form { margin-bottom: 2em; } /* line 11, ../../../app/stylesheets/items/_index.sass */ -body.items-index #search-help { +body.items-index #search-info { float: left; width: 49%; padding-right: 1%; } /* line 4, ../../../app/stylesheets/items/_index.sass */ -body.items-index #search-help h2 { +body.items-index #search-info h2 { font-size: 125%; } /* line 14, ../../../app/stylesheets/items/_index.sass */ -body.items-index #search-help dl { +body.items-index #search-info dl { text-align: left; } /* line 16, ../../../app/stylesheets/items/_index.sass */ -body.items-index #search-help dd { +body.items-index #search-info dd { margin-bottom: 1em; } /* line 19, ../../../app/stylesheets/items/_index.sass */