Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup global variables in profiles controller #603

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,3 @@ Rails/BulkChangeTable:
Rails/ThreeStateBooleanColumn:
Exclude:
- db/migrate/20181101154627_create_profiles.rb

# Below are cops that are currently disabled, where we should fix in the future
# TODO: Fix ProfilesController so we don't need to use global vars
Style/GlobalVars:
Exclude:
- app/controllers/profiles_controller.rb
82 changes: 43 additions & 39 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
# frozen_string_literal: true

class ProfilesController < ApplicationController
$units = {access: "Access Services",
archives: "Archives",
bib: "Cataloguing Strategies",
collections: "Collection Strategies",
copyright: "Copyright",
digital: "Digital Production & Preservation Services",
digrepo: "Digital Repository & Data Services",
dsc: "Digital Scholarship Centre",
facilities: "Facilities",
health: "Faculty Engagement (Health Sciences)",
science: "Faculty Engagement (Natural + Applied Sciences)",
humanities: "Faculty Engagement (Social Sciences + Humanities)",
iss: "Information Services & User Engagement",
admin: "Library Administration",
lad: "Library Application Development",
las: "Library Application Support",
metadata: "Metadata Strategies",
open: "Open Publishing & Digitization Services",
rdm: "Research Data Management",
researchimpact: "Research Impact",
its: "Specialized Technical Support",
special: "Special Collections",
stratigic: "Strategic Partnerships",
tl: "Teaching & Learning",
ux: "User Experience"}
$buildings = {augustana: "Augustana Campus Library",
bsj: "Bibliothèque Saint-Jean",
bpsc: "Bruce Peel Special Collections",
cameron: "Cameron Library",
sperber: "Sperber Library",
rcrf: "Research & Collections Resource Facility",
rutherford: "Rutherford Library",
stjosephs: "St. Joseph's Library"}
before_action :set_units, only: [:index, :show, :new, :edit]
before_action :set_buildings, only: [:index, :show, :new, :edit]

# You'll have to define "cmsPassword" in secrets.yml, or this will fail. Thanks, ansible.
http_basic_authenticate_with name: Rails.application.secrets.cms_user, password: Rails.application.secrets.cms_password, except: [:index, :show]
Expand All @@ -42,14 +11,14 @@ def index
path = request.url
if path.include? "unit"
@unit = params[:unit]
@unitname = $units[params[:unit].to_sym]
@unitname = @units[params[:unit].to_sym]
@allunit = Profile.where(unit: @unit)
@heads = @allunit.where(opt_in: true).order(:last_name)
@staff = @allunit.where(opt_in: nil).order(:last_name)
@profiles = @heads + @staff
elsif path.include? "building"
@building = params[:building]
@buildingname = $buildings[params[:building].to_sym]
@buildingname = @buildings[params[:building].to_sym]
@profiles = Profile.where("campus_address=?", params[:building]).order(:first_name)
else
@profiles = Profile.order(:first_name)
Expand All @@ -66,14 +35,10 @@ def show

def new
@profile = Profile.new
@buildings = $buildings
@units = $units
end

def edit
@profile = Profile.friendly.find(params[:id])
@buildings = $buildings
@units = $units
end

def create
Expand Down Expand Up @@ -104,4 +69,43 @@ def destroy
def profile_params
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)
end

def set_buildings
@buildings = {augustana: "Augustana Campus Library",
bsj: "Bibliothèque Saint-Jean",
bpsc: "Bruce Peel Special Collections",
cameron: "Cameron Library",
sperber: "Sperber Library",
rcrf: "Research & Collections Resource Facility",
rutherford: "Rutherford Library",
stjosephs: "St. Joseph's Library"}
end

def set_units
@units = {access: "Access Services",
archives: "Archives",
bib: "Cataloguing Strategies",
collections: "Collection Strategies",
copyright: "Copyright",
digital: "Digital Production & Preservation Services",
digrepo: "Digital Repository & Data Services",
dsc: "Digital Scholarship Centre",
facilities: "Facilities",
health: "Faculty Engagement (Health Sciences)",
science: "Faculty Engagement (Natural + Applied Sciences)",
humanities: "Faculty Engagement (Social Sciences + Humanities)",
iss: "Information Services & User Engagement",
admin: "Library Administration",
lad: "Library Application Development",
las: "Library Application Support",
metadata: "Metadata Strategies",
open: "Open Publishing & Digitization Services",
rdm: "Research Data Management",
researchimpact: "Research Impact",
its: "Specialized Technical Support",
special: "Special Collections",
stratigic: "Strategic Partnerships",
tl: "Teaching & Learning",
ux: "User Experience"}
end
end
10 changes: 5 additions & 5 deletions app/views/profiles/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%li
%a.dropdown-item{"href" => "/staff"}
ALL STAFF
- $units.each_with_index do |(key, value), index|
- @units.each_with_index do |(key, value), index|
%li
%a.dropdown-item{"href" => "/staff/?unit="+"#{key}"}
= "#{value}"
Expand Down Expand Up @@ -60,13 +60,13 @@
%span.hidden
= profile.last_name
%td.hidden-xs.ual-unit
= link_to($units[profile.unit.to_sym], "/staff/?unit="+profile.unit)
= link_to(@units[profile.unit.to_sym], "/staff/?unit="+profile.unit)
%td.hidden-xs.ual-email
%a{ :href => "tel:#{profile.phone}"}
= profile.phone
%p
= mail_to profile.email, profile.email
%td.hidden-xs
= link_to($buildings[profile.campus_address.to_sym], "/locations/"+profile.campus_address)
%td.hidden-xs
= link_to(@buildings[profile.campus_address.to_sym], "/locations/"+profile.campus_address)


8 changes: 4 additions & 4 deletions app/views/profiles/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.a-profile.extra-top-margin
= link_to profiles_path, class: "staff-back" do
<span class="glyphicon glyphicon-chevron-left"></span> All Staff
<span class="glyphicon glyphicon-chevron-left"></span> All Staff
- @photo_link = "https://www2.library.ualberta.ca/2015assets/all-staff-photos/#{@profile.first_name.downcase}-#{@profile.last_name.downcase}.jpg"
= image_tag(@photo_link, :class=>"a-photo img-responsive")
%h2.fn
Expand All @@ -18,14 +18,14 @@
= link_to @profile.phone, "tel:"[email protected]
%span.adr
%span.street-address
Building:
= link_to($buildings[@profile.campus_address.to_sym], "/locations/"[email protected]_address)
Building:
= link_to(@buildings[@profile.campus_address.to_sym], "/locations/"[email protected]_address)
%ul
-if @profile.unit.presence
%li.unit
%h4.inline
Unit:
= link_to($units[@profile.unit.to_sym], "/staff/?unit="[email protected])
= link_to(@units[@profile.unit.to_sym], "/staff/?unit="[email protected])
-if @profile.expertise.presence
%li.expertise
%h4.inline
Expand Down
Loading