Skip to content

Commit

Permalink
Implement vcard qrcode, fixes #176
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Aug 24, 2023
1 parent 9ca846a commit 451fa2a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/assets/images/qr-code-scan-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/stylesheets/_employees.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.master-data-vcard-qrcode {
display: block;
width: 100px;
padding-bottom: 1em;

@media (min-width: $screen-md-min) {
padding-top: 20px;
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/employee_master_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def show

respond_to do |format|
format.html
format.vcf
format.svg { render plain: qr_code.as_svg }
format.vcf { render plain: vcard }
format.svg { render plain: qr_code.as_svg(fill: :white) }
format.png { render plain: qr_code.as_png(fill: :white) }
end
end

Expand Down Expand Up @@ -102,8 +103,13 @@ def sort_by_latest_employment(list)
end
end

def vcard(include: nil)
Employees::Vcard.new(@employee, include: include).render
end

def qr_code
RQRCode::QRCode.new(employee_master_datum_url(id: params[:id], format: :vcf))
vcf = vcard(include: %i[firstname lastname fullname phone_office phone_private email])
RQRCode::QRCode.new(vcf)
end

# Must be included after the #list_entries method is defined.
Expand Down
32 changes: 32 additions & 0 deletions app/presenters/employees/vcard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Employees
class Vcard
TEMPLATE_FILE = File.expand_path('vcard.vcf.haml', __dir__)

attr_reader :employee, :include

def initialize(employee, include: nil)
@employee = employee
@include = include
end

def render
Haml::Template.new(TEMPLATE_FILE).render(nil, :employee => self)
end

def method_missing(method_name, *args)
return employee.send(method_name, *args) if include.blank? || include.include?(method_name)
nil
end

def respond_to_missing?(method_name, include_private = false)
return employee.respond_to?(method_name, include_private)
super
end

private

def template
@template ||= File.read(TEMPLATE_FILE)
end
end
end
19 changes: 19 additions & 0 deletions app/presenters/employees/vcard.vcf.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-# Copyright (c) 2006-2023, Puzzle ITC GmbH. This file is part of
-# PuzzleTime and licensed under the Affero General Public License version 3
-# or later. See the COPYING file at the top-level directory or at
-# https://github.com/puzzle/puzzletime.
BEGIN:VCARD
VERSION:3.0
N:#{employee.lastname};#{employee.firstname};;;
FN:#{employee.firstname} #{employee.lastname}
- if employee.street.present? || employee.city.present? || employee.postal_code.present?
ADR;TYPE=HOME,PREF:;;#{employee.street};#{employee.city};;#{employee.postal_code};
- if employee.phone_office.present?
TEL;TYPE=WORK,VOICE:#{employee.phone_office}
- if employee.phone_private.present?
TEL;TYPE=CELL,PREF,VOICE:#{employee.phone_private}
EMAIL;TYPE=WORK,PREF:#{employee.email}
- if employee.birthday.present?
BDAY:#{employee.birthday.strftime('%Y%m%d')}
END:VCARD
3 changes: 2 additions & 1 deletion app/views/employee_master_data/_attrs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
%i.glyphicon.glyphicon-envelope
= link_to @employee.email, "mailto:#{@employee.email}"
.col-md-6
= link_to({format: :png}, target: :_blank) do
= image_tag('qr-code-scan-icon.svg', class: 'qr-code master-data-vcard-qrcode')
= link_to format: :vcf do
%img.master-data-vcard-qrcode{ class: 'qr-code', src: employee_master_datum_url(id: @employee.id, format: :svg) }
vCard herunterladen

.row
Expand Down
20 changes: 0 additions & 20 deletions app/views/employee_master_data/show.vcf.haml

This file was deleted.

0 comments on commit 451fa2a

Please sign in to comment.