From 221ca3c1fa985c02243a3c650c828023c1011484 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 7 Aug 2012 14:35:17 -0400 Subject: [PATCH] Improve user page navigation menu Add counts to edits, blocks, and traces; don't show blocks if there are none; and move OAuth to the settings page. --- app/assets/stylesheets/common.css.scss | 4 +++ app/models/changeset.rb | 2 +- app/models/trace.rb | 2 +- app/views/user/account.html.erb | 9 +++--- app/views/user/view.html.erb | 31 ++++++++++--------- .../20120808231205_add_counter_caches.rb | 19 ++++++++++++ db/structure.sql | 17 +++++----- 7 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20120808231205_add_counter_caches.rb diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index 27fd53c72..c32144128 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -887,6 +887,10 @@ p#contributorGuidance { /* Rules for the account settings page */ +#accountForm { + margin-top: 20px; +} + #accountForm td { padding-bottom: 10px; } diff --git a/app/models/changeset.rb b/app/models/changeset.rb index b76d0c5a7..adb41b204 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -1,7 +1,7 @@ class Changeset < ActiveRecord::Base require 'xml/libxml' - belongs_to :user + belongs_to :user, :counter_cache => true has_many :changeset_tags diff --git a/app/models/trace.rb b/app/models/trace.rb index b72fda07d..bc47aa8e0 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -1,7 +1,7 @@ class Trace < ActiveRecord::Base self.table_name = "gpx_files" - belongs_to :user + belongs_to :user, :counter_cache => true has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :delete_all has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :delete_all diff --git a/app/views/user/account.html.erb b/app/views/user/account.html.erb index 488966491..cdd3160e8 100644 --- a/app/views/user/account.html.erb +++ b/app/views/user/account.html.erb @@ -1,4 +1,8 @@

<%= t 'user.account.my settings' %>

+ +<%= link_to t('user.account.return to profile'), :controller => 'user', :action => 'view', :display_name => @user.display_name %> | +<%= link_to t('user.view.oauth settings'), :controller => 'oauth_clients', :action => 'index' %> + <%= error_messages_for 'user' %> <%= form_for :user, :html => { :multipart => true } do |f| %> @@ -132,8 +136,3 @@ <%= raw t 'user.account.public editing note.text' %> <%= button_to t('user.account.make edits public button'), :action => :go_public %> <% end %> -
-
-<%= link_to t('user.account.return to profile'), :controller => 'user', :action => 'view', :display_name => @user.display_name %> -
-
diff --git a/app/views/user/view.html.erb b/app/views/user/view.html.erb index e8034510b..95b66e864 100644 --- a/app/views/user/view.html.erb +++ b/app/views/user/view.html.erb @@ -5,36 +5,37 @@
<% if @user and @this_user.id == @user.id %> - <%= link_to t('user.view.my diary'), :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %> - | - <%= link_to t('user.view.new diary entry'), :controller => 'diary_entry', :action => 'new' %> - | - <%= link_to t('user.view.my comments' ), :controller => 'diary_entry', :action => 'comments', :display_name => @this_user.display_name %> - | <%= link_to t('user.view.my edits'), :controller => 'changeset', :action => 'list', :display_name => @user.display_name %> + <%= number_with_delimiter(@this_user.changesets.size) %> | <%= link_to t('user.view.my traces'), :controller => 'trace', :action=>'mine' %> + <%= number_with_delimiter(@this_user.traces.size) %> | - <%= link_to t('user.view.my settings'), :controller => 'user', :action => 'account', :display_name => @user.display_name %> + <%= link_to t('user.view.my diary'), :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %> | - <%= link_to t('user.view.oauth settings'), :controller => 'oauth_clients', :action => 'index' %> + <%= link_to t('user.view.my comments' ), :controller => 'diary_entry', :action => 'comments', :display_name => @this_user.display_name %> | - <%= link_to t('user.view.blocks on me'), :controller => 'user_blocks', :action => 'blocks_on', :display_name => @user.display_name %> + <%= link_to t('user.view.my settings'), :controller => 'user', :action => 'account', :display_name => @user.display_name %> + <% if @user.active_blocks.count > 0 %> + | + <%= link_to t('user.view.blocks on me'), :controller => 'user_blocks', :action => 'blocks_on', :display_name => @user.display_name %> + <%= number_with_delimiter(@this_user.active_blocks.count) %> + <% end %> <% if @user and @user.moderator? %> | <%= link_to t('user.view.blocks by me'), :controller => 'user_blocks', :action => 'blocks_by', :display_name => @user.display_name %> <% end %> <% else %> + <%= link_to t('user.view.edits'), :controller => 'changeset', :action => 'list', :display_name => @this_user.display_name %> + <%= number_with_delimiter(@this_user.changesets.size) %> + | + <%= link_to t('user.view.traces'), :controller => 'trace', :action => 'list', :display_name => @this_user.display_name %> + <%= number_with_delimiter(@this_user.traces.size) %> + | <%= link_to t('user.view.send message'), :controller => 'message', :action => 'new', :display_name => @this_user.display_name %> | - <%= link_to t('user.view.diary'), :controller => 'diary_entry', :action => 'list', :display_name => @this_user.display_name %> - | <%= link_to t('user.view.comments'), :controller => 'diary_entry', :action => 'comments', :display_name => @this_user.display_name %> | - <%= link_to t('user.view.edits'), :controller => 'changeset', :action => 'list', :display_name => @this_user.display_name %> - | - <%= link_to t('user.view.traces'), :controller => 'trace', :action => 'list', :display_name => @this_user.display_name %> - | <% if @user and @user.is_friends_with?(@this_user) %> <%= link_to t('user.view.remove as friend'), :controller => 'user', :action => 'remove_friend', :display_name => @this_user.display_name %> <% else %> diff --git a/db/migrate/20120808231205_add_counter_caches.rb b/db/migrate/20120808231205_add_counter_caches.rb new file mode 100644 index 000000000..a26f204da --- /dev/null +++ b/db/migrate/20120808231205_add_counter_caches.rb @@ -0,0 +1,19 @@ +class AddCounterCaches < ActiveRecord::Migration + def self.up + add_column :users, :changesets_count, :integer, :null => false, :default => 0 + add_column :users, :traces_count, :integer, :null => false, :default => 0 + + Changeset.group(:user_id).pluck(:user_id).each do |user_id| + User.reset_counters(user_id, :changesets) + end + + Trace.group(:user_id).pluck(:user_id).each do |user_id| + User.reset_counters(user_id, :traces) + end + end + + def self.down + remove_column :users, :changesets_count + remove_column :users, :traces_count + end +end diff --git a/db/structure.sql b/db/structure.sql index 42e9733b1..e0427e1d7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -44,8 +44,7 @@ SET search_path = public, pg_catalog; CREATE TYPE format_enum AS ENUM ( 'html', - 'markdown', - 'text' + 'markdown' ); @@ -101,7 +100,7 @@ CREATE TYPE user_status_enum AS ENUM ( CREATE FUNCTION maptile_for_point(bigint, bigint, integer) RETURNS integer LANGUAGE c STRICT - AS '/srv/www/master.osm.compton.nu/db/functions/libpgosm.so', 'maptile_for_point'; + AS '/srv/www/next.osm.compton.nu/db/functions/libpgosm.so', 'maptile_for_point'; -- @@ -110,7 +109,7 @@ CREATE FUNCTION maptile_for_point(bigint, bigint, integer) RETURNS integer CREATE FUNCTION tile_for_point(integer, integer) RETURNS bigint LANGUAGE c STRICT - AS '/srv/www/master.osm.compton.nu/db/functions/libpgosm.so', 'tile_for_point'; + AS '/srv/www/next.osm.compton.nu/db/functions/libpgosm.so', 'tile_for_point'; -- @@ -119,7 +118,7 @@ CREATE FUNCTION tile_for_point(integer, integer) RETURNS bigint CREATE FUNCTION xid_to_int4(xid) RETURNS integer LANGUAGE c IMMUTABLE STRICT - AS '/srv/www/master.osm.compton.nu/db/functions/libpgosm.so', 'xid_to_int4'; + AS '/srv/www/next.osm.compton.nu/db/functions/libpgosm.so', 'xid_to_int4'; SET default_tablespace = ''; @@ -1000,11 +999,13 @@ CREATE TABLE users ( status user_status_enum DEFAULT 'pending'::user_status_enum NOT NULL, terms_agreed timestamp without time zone, consider_pd boolean DEFAULT false NOT NULL, + openid_url character varying(255), preferred_editor character varying(255), terms_seen boolean DEFAULT false NOT NULL, - openid_url character varying(255), + image_fingerprint character varying(255), description_format format_enum DEFAULT 'html'::format_enum NOT NULL, - image_fingerprint character varying(255) + changesets_count integer DEFAULT 0 NOT NULL, + traces_count integer DEFAULT 0 NOT NULL ); @@ -2263,6 +2264,8 @@ INSERT INTO schema_migrations (version) VALUES ('20120328090602'); INSERT INTO schema_migrations (version) VALUES ('20120404205604'); +INSERT INTO schema_migrations (version) VALUES ('20120808231205'); + INSERT INTO schema_migrations (version) VALUES ('21'); INSERT INTO schema_migrations (version) VALUES ('22'); -- 2.39.5