Skip to content

Commit 019955c

Browse files
authored
Merge pull request #603 from ualbertalib/Remove-global-vars-from-profiles
Cleanup global variables in profiles controller
2 parents 1f269e0 + 5041793 commit 019955c

File tree

4 files changed

+52
-54
lines changed

4 files changed

+52
-54
lines changed

.rubocop.yml

-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,3 @@ Rails/BulkChangeTable:
3737
Rails/ThreeStateBooleanColumn:
3838
Exclude:
3939
- db/migrate/20181101154627_create_profiles.rb
40-
41-
# Below are cops that are currently disabled, where we should fix in the future
42-
# TODO: Fix ProfilesController so we don't need to use global vars
43-
Style/GlobalVars:
44-
Exclude:
45-
- app/controllers/profiles_controller.rb
+43-39
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,8 @@
11
# frozen_string_literal: true
22

33
class ProfilesController < ApplicationController
4-
$units = {access: "Access Services",
5-
archives: "Archives",
6-
bib: "Cataloguing Strategies",
7-
collections: "Collection Strategies",
8-
copyright: "Copyright",
9-
digital: "Digital Production & Preservation Services",
10-
digrepo: "Digital Repository & Data Services",
11-
dsc: "Digital Scholarship Centre",
12-
facilities: "Facilities",
13-
health: "Faculty Engagement (Health Sciences)",
14-
science: "Faculty Engagement (Natural + Applied Sciences)",
15-
humanities: "Faculty Engagement (Social Sciences + Humanities)",
16-
iss: "Information Services & User Engagement",
17-
admin: "Library Administration",
18-
lad: "Library Application Development",
19-
las: "Library Application Support",
20-
metadata: "Metadata Strategies",
21-
open: "Open Publishing & Digitization Services",
22-
rdm: "Research Data Management",
23-
researchimpact: "Research Impact",
24-
its: "Specialized Technical Support",
25-
special: "Special Collections",
26-
stratigic: "Strategic Partnerships",
27-
tl: "Teaching & Learning",
28-
ux: "User Experience"}
29-
$buildings = {augustana: "Augustana Campus Library",
30-
bsj: "Bibliothèque Saint-Jean",
31-
bpsc: "Bruce Peel Special Collections",
32-
cameron: "Cameron Library",
33-
sperber: "Sperber Library",
34-
rcrf: "Research & Collections Resource Facility",
35-
rutherford: "Rutherford Library",
36-
stjosephs: "St. Joseph's Library"}
4+
before_action :set_units, only: [:index, :show, :new, :edit]
5+
before_action :set_buildings, only: [:index, :show, :new, :edit]
376

387
# You'll have to define "cmsPassword" in secrets.yml, or this will fail. Thanks, ansible.
398
http_basic_authenticate_with name: Rails.application.secrets.cms_user, password: Rails.application.secrets.cms_password, except: [:index, :show]
@@ -42,14 +11,14 @@ def index
4211
path = request.url
4312
if path.include? "unit"
4413
@unit = params[:unit]
45-
@unitname = $units[params[:unit].to_sym]
14+
@unitname = @units[params[:unit].to_sym]
4615
@allunit = Profile.where(unit: @unit)
4716
@heads = @allunit.where(opt_in: true).order(:last_name)
4817
@staff = @allunit.where(opt_in: nil).order(:last_name)
4918
@profiles = @heads + @staff
5019
elsif path.include? "building"
5120
@building = params[:building]
52-
@buildingname = $buildings[params[:building].to_sym]
21+
@buildingname = @buildings[params[:building].to_sym]
5322
@profiles = Profile.where("campus_address=?", params[:building]).order(:first_name)
5423
else
5524
@profiles = Profile.order(:first_name)
@@ -66,14 +35,10 @@ def show
6635

6736
def new
6837
@profile = Profile.new
69-
@buildings = $buildings
70-
@units = $units
7138
end
7239

7340
def edit
7441
@profile = Profile.friendly.find(params[:id])
75-
@buildings = $buildings
76-
@units = $units
7742
end
7843

7944
def create
@@ -104,4 +69,43 @@ def destroy
10469
def profile_params
10570
params.require(:profile).permit(:first_name, :last_name, :job_title, :unit, :email, :phone, :campus_address, :expertise, :introduction, :publications, :staff_since, :liason, :links, :orcid, :committees, :personal_interests, :opt_in)
10671
end
72+
73+
def set_buildings
74+
@buildings = {augustana: "Augustana Campus Library",
75+
bsj: "Bibliothèque Saint-Jean",
76+
bpsc: "Bruce Peel Special Collections",
77+
cameron: "Cameron Library",
78+
sperber: "Sperber Library",
79+
rcrf: "Research & Collections Resource Facility",
80+
rutherford: "Rutherford Library",
81+
stjosephs: "St. Joseph's Library"}
82+
end
83+
84+
def set_units
85+
@units = {access: "Access Services",
86+
archives: "Archives",
87+
bib: "Cataloguing Strategies",
88+
collections: "Collection Strategies",
89+
copyright: "Copyright",
90+
digital: "Digital Production & Preservation Services",
91+
digrepo: "Digital Repository & Data Services",
92+
dsc: "Digital Scholarship Centre",
93+
facilities: "Facilities",
94+
health: "Faculty Engagement (Health Sciences)",
95+
science: "Faculty Engagement (Natural + Applied Sciences)",
96+
humanities: "Faculty Engagement (Social Sciences + Humanities)",
97+
iss: "Information Services & User Engagement",
98+
admin: "Library Administration",
99+
lad: "Library Application Development",
100+
las: "Library Application Support",
101+
metadata: "Metadata Strategies",
102+
open: "Open Publishing & Digitization Services",
103+
rdm: "Research Data Management",
104+
researchimpact: "Research Impact",
105+
its: "Specialized Technical Support",
106+
special: "Special Collections",
107+
stratigic: "Strategic Partnerships",
108+
tl: "Teaching & Learning",
109+
ux: "User Experience"}
110+
end
107111
end

app/views/profiles/index.html.haml

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
%li
2121
%a.dropdown-item{"href" => "/staff"}
2222
ALL STAFF
23-
- $units.each_with_index do |(key, value), index|
23+
- @units.each_with_index do |(key, value), index|
2424
%li
2525
%a.dropdown-item{"href" => "/staff/?unit="+"#{key}"}
2626
= "#{value}"
@@ -60,13 +60,13 @@
6060
%span.hidden
6161
= profile.last_name
6262
%td.hidden-xs.ual-unit
63-
= link_to($units[profile.unit.to_sym], "/staff/?unit="+profile.unit)
63+
= link_to(@units[profile.unit.to_sym], "/staff/?unit="+profile.unit)
6464
%td.hidden-xs.ual-email
6565
%a{ :href => "tel:#{profile.phone}"}
6666
= profile.phone
6767
%p
6868
= mail_to profile.email, profile.email
69-
%td.hidden-xs
70-
= link_to($buildings[profile.campus_address.to_sym], "/locations/"+profile.campus_address)
71-
69+
%td.hidden-xs
70+
= link_to(@buildings[profile.campus_address.to_sym], "/locations/"+profile.campus_address)
71+
7272

app/views/profiles/show.html.haml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.a-profile.extra-top-margin
22
= link_to profiles_path, class: "staff-back" do
3-
<span class="glyphicon glyphicon-chevron-left"></span> All Staff
3+
<span class="glyphicon glyphicon-chevron-left"></span> All Staff
44
- @photo_link = "https://www2.library.ualberta.ca/2015assets/all-staff-photos/#{@profile.first_name.downcase}-#{@profile.last_name.downcase}.jpg"
55
= image_tag(@photo_link, :class=>"a-photo img-responsive")
66
%h2.fn
@@ -18,14 +18,14 @@
1818
= link_to @profile.phone, "tel:"+@profile.phone
1919
%span.adr
2020
%span.street-address
21-
Building:
22-
= link_to($buildings[@profile.campus_address.to_sym], "/locations/"+@profile.campus_address)
21+
Building:
22+
= link_to(@buildings[@profile.campus_address.to_sym], "/locations/"+@profile.campus_address)
2323
%ul
2424
-if @profile.unit.presence
2525
%li.unit
2626
%h4.inline
2727
Unit:
28-
= link_to($units[@profile.unit.to_sym], "/staff/?unit="+@profile.unit)
28+
= link_to(@units[@profile.unit.to_sym], "/staff/?unit="+@profile.unit)
2929
-if @profile.expertise.presence
3030
%li.expertise
3131
%h4.inline

0 commit comments

Comments
 (0)