Skip to content
Permalink
Browse files

Merge c9ba3dd into 0f674f2

  • Loading branch information
moralsh committed Nov 16, 2019
2 parents 0f674f2 + c9ba3dd commit 26718eebe68306add73d847aa83e447f43c724c9
@@ -6,10 +6,13 @@
}

.badge {
margin-bottom: 0.5em;
margin-top: 0.5em;
margin-right: 6px;
padding-top: 6px;
padding-bottom: 6px;
&.team-member-badge {
margin-right: 1em;
margin-bottom: 0.5em;
margin-top: 0.5em;
vertical-align: top;
color: $gray;
background-color: $gray-lighter;
.avatar-thumbnail {
@@ -27,8 +30,6 @@
&.team-senior-member-badge {
background-color: $dark-green;
color: white;
padding-top: 6px;
padding-bottom: 6px;
vertical-align: top;
span.team-subtext {
font-style: oblique;
@@ -49,8 +50,6 @@
&.officer-badge {
background-color: $dark-blue;
color: white;
padding-top: 6px;
padding-bottom: 6px;
vertical-align: top;
span.team-subtext {
font-style: oblique;
@@ -77,6 +76,15 @@
color: white;
}
}

&.delegate-badge {
background-color: $dark-red;
color: white;
vertical-align: top;
a {
color: white;
}
}
}

.team-member-name {
@@ -9,6 +9,7 @@ $bright-blue: #007bff;
$past-member-color: #fecd55;
$green: #c4e8b5;
$dark-green: #245011;
$dark-red: #701203;
$orange: #fc4a0a;
$orange-bg: #ffeca8;

@@ -31,4 +31,58 @@ def return_podium_class(result)
end
end
end

def delegate_badge(kind)
content_tag(:span, class: "badge delegate-badge") do
link_to(t("enums.user.delegate_status." + kind), "/delegates", title: t("enums.user.delegate_status." + kind), data: { toggle: "tooltip", placement: "bottom" })
end
end

def officer_badge(team)
content_tag(:span, class: "badge officer-badge") do
link_to(team, "/teams-committees#officers", title: t('about.structure.officers.name'), data: { toggle: "tooltip", placement: "bottom" })
end
end

def team_badge(team, kind, extra)
content_tag(:span, class: "badge team-" + kind + "-badge") do
link_to(team.acronym + extra, "/teams-committees#" + team.acronym, title: team.name, data: { toggle: "tooltip", placement: "bottom" })
end
end

def all_user_badges(user)
# Checks if person is any kind of Delegate, officer, Board member, any Team leader, any team sennior member,
# any team member and display all the badges in that order
badges = []
if user.any_kind_of_delegate? # Delegates
if user.senior_delegate?
badges.push(delegate_badge("senior_delegate"))
elsif user.full_delegate?
badges.push(delegate_badge("delegate"))
else
badges.push(delegate_badge("candidate_delegate"))
end
end

user.current_teams.select { |team| Team.all_officers.include? team }.map(&:name).each do |team| # Officers
badges.push(officer_badge(team))
end
if Team.wfc.current_members.select(&:team_leader).map(&:user).include?(user)
badges.push(officer_badge(t('about.structure.treasurer.name')))
end

if user.board_member? # Board
badges.push(team_badge(Team.board, "member", ""))
end

# Team Leaders and Senior Members
badges.push(user.teams_where_is_leader.map { |team| team_badge(team, "leader", " " + t('about.structure.leader')) })
badges.push(user.teams_where_is_senior_member.map { |team| team_badge(team, "senior-member", " " + t('about.structure.senior_member')) })
all_teams = Team.all_official + Team.all_councils # Team members
badges.push(user.current_teams.select { |t| all_teams.include?(t) }
.reject { |t| user.team_leader?(t) || user.team_senior_member?(t) }
.map { |team| team_badge(team, "member", "") })

badges.join.html_safe
end
end
@@ -12,6 +12,9 @@
(<%= t 'persons.show.previously' %> <%= @previous_persons.map { |person| "#{person.name} - #{person.country.name}" }.join(', ') %>)
</h4>
<% end %>
<div class="positions-container">
<%= all_user_badges(@person.user) %>
</div>
<% if @person.user&.avatar %>
<%= image_tag @person.user.avatar.url, class: "avatar" %>
<% end %>
@@ -5,7 +5,7 @@

<p><%= t("about.structure.committees") %></p>

<h3><%= t("about.structure.officers.name") %></h3>
<h3 id="officers"><%= t("about.structure.officers.name") %></h3>
<p><%= t("about.structure.officers.description") %></p>
<br />

@@ -21,7 +21,7 @@
</div>

<% ([Team.board] + Team.all_official + Team.all_councils).each do |team| %>
<h3><%= team.name %> <%= team != Team.board ? "(" + team.acronym + ")" : "" %> <span class="badge team-email"><%= mail_to team.email %></span></h3>
<h3 id="<%= team.acronym %>"><%= team.name %> <%= team != Team.board ? "(" + team.acronym + ")" : "" %> <span class="badge team-email"><%= mail_to team.email %></span></h3>
<p><%= t("about.structure.#{team.friendly_id}.description") %></p>
<br />

@@ -24,4 +24,128 @@
end
end
end

describe "#delegate_badge" do
it "Returns a Delegate badge when passed delegate" do
string = helper.delegate_badge("delegate")
expect(string).to eq "<span class=\"badge delegate-badge\"><a title=\"" +
t("enums.user.delegate_status.delegate") +
"\" data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/delegates\">" +
t("enums.user.delegate_status.delegate") + "</a></span>"
end

it "Returns a Senior Delegate badge when passed senior_delegate" do
string = helper.delegate_badge("senior_delegate")
expect(string).to eq "<span class=\"badge delegate-badge\"><a title=\"" +
t("enums.user.delegate_status.senior_delegate") +
"\" data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/delegates\">" +
t("enums.user.delegate_status.senior_delegate") + "</a></span>"
end

it "Returns a Candidate Delegate badge when passed candadate_delegate" do
string = helper.delegate_badge("candidate_delegate")
expect(string).to eq "<span class=\"badge delegate-badge\"><a title=\"" +
t("enums.user.delegate_status.candidate_delegate") +
"\" data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/delegates\">" +
t("enums.user.delegate_status.candidate_delegate") + "</a></span>"
end

it "links to the delegates page" do
string = helper.delegate_badge("delegate")
expect(string).to include("href=\"/delegates\">")
end
end

describe "#officer_badge" do
it "Returns a Chair Badge when team is chair" do
string = helper.officer_badge(Team.chair.name)
expect(string).to eq "<span class=\"badge officer-badge\"><a title=\"WCA Officers\" " \
"data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/teams-committees#officers\">" +
t('about.structure.chair.name') + "</a></span>"
end

it "Returns a Vice Chair Badge when team is vice_chair" do
string = helper.officer_badge(Team.vice_chair.name)
expect(string).to eq "<span class=\"badge officer-badge\"><a title=\"WCA Officers\" " \
"data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/teams-committees#officers\">" +
t('about.structure.vice_chair.name') + "</a></span>"
end

it "Returns a Secretary Badge when team is secretary" do
string = helper.officer_badge(Team.secretary.name)
expect(string).to eq "<span class=\"badge officer-badge\"><a title=\"WCA Officers\" " \
"data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/teams-committees#officers\">" +
t('about.structure.secretary.name') + "</a></span>"
end

it "Returns an Executive Director Badge when team is executive_director" do
string = helper.officer_badge(Team.executive_director.name)
expect(string).to eq "<span class=\"badge officer-badge\"><a title=\"WCA Officers\" " \
"data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/teams-committees#officers\">" +
t('about.structure.executive_director.name') + "</a></span>"
end

it "Returns Treasurer Badge when Treasurer position is passed" do
string = helper.officer_badge(t('about.structure.treasurer.name'))
expect(string).to eq "<span class=\"badge officer-badge\"><a title=\"WCA Officers\" " \
"data-toggle=\"tooltip\" data-placement=\"bottom\" href=\"/teams-committees#officers\">" +
t('about.structure.treasurer.name') + "</a></span>"
end

it "links to the officers section on the teams-committees page" do
string = helper.officer_badge(Team.chair.name)
expect(string).to include("href=\"/teams-committees#officers\">")
end
end

describe "#team_badge" do
it "Returns a Leader badge when leader is passed" do
string = helper.team_badge(Team.wst, "leader", "")
expect(string).to include("team-leader-badge")
end

it "Returns a Senior Member badge when senior_member is passed" do
string = helper.team_badge(Team.wst, "senior_member", "")
expect(string).to include("team-senior_member-badge")
end

it "Returns a Member badge when member is passed" do
string = helper.team_badge(Team.wst, "member", "")
expect(string).to include("team-member-badge")
end

it "Returns extra text and team acronym in the badge when both are passed" do
string = helper.team_badge(Team.wst, "leader", " " + t('about.structure.leader'))
expect(string).to include(Team.wst.acronym + " " + t('about.structure.leader'))
end

it "links to the given team section on the teams-committees page" do
string = helper.team_badge(Team.wst, "member", "")
expect(string).to include("href=\"/teams-committees#WST\">")
end
end

describe "#all_user_badges" do
it "gives no badge if the user has no teams, committees, councils or delegate positions" do
user_no_teams = FactoryBot.create(:user, name: "John Doe")
string = all_user_badges(user_no_teams)
expect(string).to eq ""
end

it "Returns as many badges as diferent teams the user is on" do
busy_member = FactoryBot.create :user, name: "Feliks Park"
FactoryBot.create(:team_member, team_id: Team.wec.id, user_id: busy_member.id, start_date: Date.today-1, team_senior_member: true)
FactoryBot.create(:team_member, team_id: Team.wst.id, user_id: busy_member.id, start_date: Date.today-1, team_leader: true)
string = all_user_badges(busy_member)
expect(string).to include("WEC")
expect(string).to include("WST")
end

it "Returns as many officers positions as the user has" do
officer_member = FactoryBot.create :user, :chair, :executive_director
string = all_user_badges(officer_member)
expect(string).to include(t('about.structure.executive_director.name'))
expect(string).to include(t('about.structure.chair.name'))
end
end
end

0 comments on commit 26718ee

Please sign in to comment.
You can’t perform that action at this time.