diff --git a/app/assets/images/rank/Rank_1.png b/app/assets/images/rank/GlobalAdministrator.png similarity index 100% rename from app/assets/images/rank/Rank_1.png rename to app/assets/images/rank/GlobalAdministrator.png diff --git a/app/assets/images/rank/Rank_3.png b/app/assets/images/rank/GrandChampMapper.png similarity index 100% rename from app/assets/images/rank/Rank_3.png rename to app/assets/images/rank/GrandChampMapper.png diff --git a/app/assets/images/rank/Rank_4.png b/app/assets/images/rank/LegendaryMapper.png similarity index 100% rename from app/assets/images/rank/Rank_4.png rename to app/assets/images/rank/LegendaryMapper.png diff --git a/app/assets/images/rank/Rank_2.png b/app/assets/images/rank/RegionalAdministrator.png similarity index 100% rename from app/assets/images/rank/Rank_2.png rename to app/assets/images/rank/RegionalAdministrator.png diff --git a/app/assets/images/rank/Rank_5.png b/app/assets/images/rank/SuperMapper.png similarity index 100% rename from app/assets/images/rank/Rank_5.png rename to app/assets/images/rank/SuperMapper.png diff --git a/app/assets/stylesheets/application.scss.erb b/app/assets/stylesheets/application.scss.erb index faf5ea158..25f0e4340 100644 --- a/app/assets/stylesheets/application.scss.erb +++ b/app/assets/stylesheets/application.scss.erb @@ -618,7 +618,7 @@ form.edit_user .form-actions { /** Stats **/ .rank_icon { - margin-bottom: -4px; + margin-bottom: -3px; height: 15px; width: 15px; } @@ -629,11 +629,11 @@ form.edit_user .form-actions { width: 20px; } -.rank_icon_1:hover:after, -.rank_icon_2:hover:after, -.rank_icon_3:hover:after, -.rank_icon_4:hover:after, -.rank_icon_5:hover:after { +.rank_icon_GlobalAdministrator:hover:after, +.rank_icon_RegionalAdministrator:hover:after, +.rank_icon_GrandChampMapper:hover:after, +.rank_icon_LegendaryMapper:hover:after, +.rank_icon_SuperMapper:hover:after { position: absolute; line-height: 14px; font-size: 16px; @@ -646,27 +646,27 @@ form.edit_user .form-actions { text-align: center; } -.rank_icon_1:hover:after { +.rank_icon_GlobalAdministrator:hover:after { content: "Global Administrator"; width: 180px; } -.rank_icon_2:hover:after { +.rank_icon_RegionalAdministrator:hover:after { content: "Regional Administrator"; width: 190px; } -.rank_icon_3:hover:after { +.rank_icon_GrandChampMapper:hover:after { content: "Grand Champ Mapper"; width: 190px; } -.rank_icon_4:hover:after { +.rank_icon_LegendaryMapper:hover:after { content: "Legendary Mapper"; width: 160px; } -.rank_icon_5:hover:after { +.rank_icon_SuperMapper:hover:after { content: "Super Mapper"; width: 130px; } diff --git a/app/models/user.rb b/app/models/user.rb index dd01474f6..85def942c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,19 +150,6 @@ def contributor_rank_int end end - def contributor_rank - case contributor_rank_int - when nil - nil - when 5 - 'Super Mapper' - when 4 - 'Legendary Mapper' - when 3 - 'Grand Champ Mapper' - end - end - def admin_rank_int if region_id == 1 || username == 'pbm' 1 @@ -171,15 +158,6 @@ def admin_rank_int end end - def admin_title - case admin_rank_int - when 1 - 'Global Administrator' - when 2 - 'Regional Administrator' - end - end - def as_json(options = {}) super({ only: [:id] }.merge(options)) end diff --git a/app/models/user_submission.rb b/app/models/user_submission.rb index 961d88b49..87bb084ef 100644 --- a/app/models/user_submission.rb +++ b/app/models/user_submission.rb @@ -4,6 +4,8 @@ class UserSubmission < ApplicationRecord belongs_to :location, optional: true belongs_to :machine, optional: true + after_commit :update_contributor_rank + geocoded_by :lat_and_lon, latitude: :lat, longitude: :lon scope :region, ->(name) { where(region_id: Region.find_by_name(name.downcase).id) } @@ -27,4 +29,16 @@ def user_email def lat_and_lon [lat, lon].join(', ') end + + def update_contributor_rank + if user + if user.contributor_rank.blank? && user.user_submissions_count.between?(51, 250) + user.contributor_rank = 'Super Mapper' + elsif user.contributor_rank == 'Super Mapper' && user.user_submissions_count&.between?(251, 500) + user.contributor_rank = 'Legendary Mapper' + elsif user.contributor_rank == 'Legendary Mapper' && user.user_submissions_count > 500 + user.contributor_rank = 'Grand Champ Mapper' + end + end + end end diff --git a/app/views/locations/_render_last_updated.html.haml b/app/views/locations/_render_last_updated.html.haml index 053323c99..f05f12de7 100644 --- a/app/views/locations/_render_last_updated.html.haml +++ b/app/views/locations/_render_last_updated.html.haml @@ -9,10 +9,10 @@ - if !l.last_updated_by_user.flag.blank? =image_tag("https://flagcdn.com/24x18/#{l.last_updated_by_user.flag}.png", :class => "user_flag_updated") - user = l.last_updated_by_user - - rank_int = user.admin? ? user.admin_rank_int : user.contributor_rank_int - - if rank_int.present? - %span{:class => "rank_icon_#{rank_int}"} - = image_tag("rank/Rank_#{rank_int}.png", :class => "rank_icon") + - if !user.admin_title.blank? || !user.contributor_rank.blank? + - rank = user.admin_title.present? ? user.admin_title.gsub(' ', '') : user.contributor_rank.gsub(' ', '') + %span{:class => "rank_icon_#{rank}"} + =image_tag("rank/#{rank}.png", :class => "rank_icon") - if l.date_last_updated < 2.years.ago - dateDiff = distance_of_time_in_words(Time.now, l.date_last_updated) diff --git a/app/views/locations/_render_machine_conditions.html.haml b/app/views/locations/_render_machine_conditions.html.haml index 65c32addd..558ed5fce 100644 --- a/app/views/locations/_render_machine_conditions.html.haml +++ b/app/views/locations/_render_machine_conditions.html.haml @@ -25,11 +25,11 @@ = link_to mcx.user.username, "#{request.scheme}://#{request.host_with_port}/users/#{mcx.user.username}/profile", :class => 'bold' - if !mcx.user.flag.blank? =image_tag("https://flagcdn.com/24x18/#{mcx.user.flag}.png", :class => "user_flag") - - user = mcx.user - - rank_int = user.admin? ? user.admin_rank_int : user.contributor_rank_int - - if rank_int.present? - %span{:class => "rank_icon_#{rank_int} rank_icon_past_comment"} - = image_tag("rank/Rank_#{rank_int}.png", :class => "rank_icon") + - if !mcx.user.admin_title.blank? || !mcx.user.contributor_rank.blank? + - rank = mcx.user.admin_title.present? ? mcx.user.admin_title.gsub(' ', '') : mcx.user.contributor_rank.gsub(' ', '') + %span{:class => "rank_icon_#{rank} rank_icon_past_comment"} + =image_tag("rank/#{rank}.png", :class => "rank_icon") + - else DELETED USER - if !mcx.updated_at.nil? diff --git a/app/views/locations/_render_scores.html.haml b/app/views/locations/_render_scores.html.haml index b94f625b5..9696a120d 100644 --- a/app/views/locations/_render_scores.html.haml +++ b/app/views/locations/_render_scores.html.haml @@ -5,11 +5,10 @@ = link_to msx.user.username, "#{request.scheme}://#{request.host_with_port}/users/#{msx.user.username}/profile", :class => 'bold' - if !msx.user.flag.blank? =image_tag("https://flagcdn.com/24x18/#{msx.user.flag}.png", :class => "user_flag") - - user = msx.user - - rank_int = user.admin? ? user.admin_rank_int : user.contributor_rank_int - - if rank_int.present? - %span{:class => "rank_icon_#{rank_int} rank_icon_past_comment"} - = image_tag("rank/Rank_#{rank_int}.png", :class => "rank_icon") + - if !msx.user.admin_title.blank? || !msx.user.contributor_rank.blank? + - rank = msx.user.admin_title.present? ? msx.user.admin_title.gsub(' ', '') : msx.user.contributor_rank.gsub(' ', '') + %span{:class => "rank_icon_#{rank} rank_icon_past_comment"} + =image_tag("rank/#{rank}.png", :class => "rank_icon") - else DELETED USER %span.high_score_date=msx.created_at ? msx.created_at.strftime("%b %d, %Y") : '' diff --git a/app/views/users/profile.html.haml b/app/views/users/profile.html.haml index 5b514313f..c74d45701 100644 --- a/app/views/users/profile.html.haml +++ b/app/views/users/profile.html.haml @@ -5,16 +5,12 @@ =link_to @user.username, profile_user_path(@user.id) %span.render_user_flag{:style => 'height: 21px;'} = render :partial => 'users/render_user_flag', :locals => {:user => @user} - - if @user.admin_rank_int + - if !@user.admin_title.blank? || !@user.contributor_rank.blank? + - rank = @user.admin? ? @user.admin_title : @user.contributor_rank %div.red.bold.center.font18 - #{@user.admin_title} + #{rank} %span - =image_tag("rank/Rank_#{@user.admin_rank_int}.png", :class => "rank_icon_profile rank_icon_#{@user.admin_rank_int}") - - elsif @user.contributor_rank_int - %div.red.bold.center.font18 - #{@user.contributor_rank} - %span - =image_tag("rank/Rank_#{@user.contributor_rank_int}.png", :class => "rank_icon_profile rank_icon_#{@user.contributor_rank_int}") + =image_tag("rank/#{rank.gsub(' ', '')}.png", :class => "rank_icon_profile rank_icon_#{rank.gsub(' ', '')}") %div.center.font16.semiBold Member since: #{@user.created_at.strftime('%b %d, %Y')} - if current_user && (@user.id == current_user.id) %div.font14{:style => 'padding: 0 10px;'} diff --git a/db/migrate/20241127051246_add_contributor_rank_to_users.rb b/db/migrate/20241127051246_add_contributor_rank_to_users.rb new file mode 100644 index 000000000..e342301f0 --- /dev/null +++ b/db/migrate/20241127051246_add_contributor_rank_to_users.rb @@ -0,0 +1,5 @@ +class AddContributorRankToUsers < ActiveRecord::Migration[7.2] + def change + add_column :users, :contributor_rank, :string + end +end diff --git a/db/migrate/20241127054132_add_admin_rank_to_users.rb b/db/migrate/20241127054132_add_admin_rank_to_users.rb new file mode 100644 index 000000000..b38fcd03b --- /dev/null +++ b/db/migrate/20241127054132_add_admin_rank_to_users.rb @@ -0,0 +1,5 @@ +class AddAdminRankToUsers < ActiveRecord::Migration[7.2] + def change + add_column :users, :admin_rank, :string + end +end diff --git a/db/migrate/20241127215612_fix_admin_rank_column_name.rb b/db/migrate/20241127215612_fix_admin_rank_column_name.rb new file mode 100644 index 000000000..26aaa6a37 --- /dev/null +++ b/db/migrate/20241127215612_fix_admin_rank_column_name.rb @@ -0,0 +1,5 @@ +class FixAdminRankColumnName < ActiveRecord::Migration[7.2] + def change + rename_column :users, :admin_rank, :admin_title + end +end diff --git a/db/structure.sql b/db/structure.sql index e9d3870fc..d6b139d9e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -932,7 +932,9 @@ CREATE TABLE public.users ( num_machines_removed integer, num_locations_suggested integer, num_lmx_comments_left integer, - num_msx_scores_added integer + num_msx_scores_added integer, + contributor_rank character varying, + admin_title character varying ); @@ -1793,6 +1795,9 @@ ALTER TABLE ONLY public.active_storage_attachments SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES +('20241127215612'), +('20241127054132'), +('20241127051246'), ('20241126054618'), ('20241117183403'), ('20241112193702'),