Skip to content

Commit

Permalink
Add contributor rank and admin title as user fields
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTG committed Nov 28, 2024
1 parent c0b9880 commit adac0ed
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 56 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
22 changes: 11 additions & 11 deletions app/assets/stylesheets/application.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ form.edit_user .form-actions {
/** Stats **/

.rank_icon {
margin-bottom: -4px;
margin-bottom: -3px;
height: 15px;
width: 15px;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
22 changes: 0 additions & 22 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/models/user_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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
8 changes: 4 additions & 4 deletions app/views/locations/_render_last_updated.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions app/views/locations/_render_machine_conditions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 4 additions & 5 deletions app/views/locations/_render_scores.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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") : ''
12 changes: 4 additions & 8 deletions app/views/users/profile.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]_title.blank? || [email protected]_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;'}
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241127051246_add_contributor_rank_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddContributorRankToUsers < ActiveRecord::Migration[7.2]
def change
add_column :users, :contributor_rank, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241127054132_add_admin_rank_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdminRankToUsers < ActiveRecord::Migration[7.2]
def change
add_column :users, :admin_rank, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241127215612_fix_admin_rank_column_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FixAdminRankColumnName < ActiveRecord::Migration[7.2]
def change
rename_column :users, :admin_rank, :admin_title
end
end
7 changes: 6 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);


Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit adac0ed

Please sign in to comment.