Skip to content

Commit

Permalink
make view display nil properties of person as -, create picture contr…
Browse files Browse the repository at this point in the history
…oller and remove picture_path method from people_controller, use new picture controller to load pictures correctly in view
  • Loading branch information
RandomTannenbaum committed Feb 23, 2024
1 parent 9583046 commit 89f79d8
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
10 changes: 0 additions & 10 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
class PeopleController < CrudController
include ExportController

helper_method :picture_path

self.permitted_attrs = %i[birthdate location
marital_status updated_by name nationality nationality2 title
competence_notes company_id email department_id shortname]
Expand Down Expand Up @@ -42,12 +40,4 @@ def export
type: 'application/vnd.oasis.opendocument.text',
disposition: content_disposition('attachment', filename)
end

def picture_path
if @person.picture.file
@person.picture.url
else
"/default_avatar.png"
end
end
end
6 changes: 6 additions & 0 deletions app/controllers/picture_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PictureController < ApplicationController
def show
picture_url = @person.picture.file.nil? ? default_avatar_path : @person.picture.url
send_file(picture_url, disposition: 'inline')
end
end
2 changes: 2 additions & 0 deletions app/helpers/picture_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PictureHelper
end
4 changes: 2 additions & 2 deletions app/views/people/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
= form_with model: @person do |form|
%div.d-flex.justify-content-between
%div.pe-5
%img.rounded-circle{src: picture_path, width: '141', height: '141'}
-# = form.file_field :picture
%img.rounded-circle{src: "/api/people/#{@person.id}/picture", width: '141', height: '141'}
= form.file_field :picture
%div.pe-5.d-flex
%table
%tbody
Expand Down
20 changes: 15 additions & 5 deletions app/views/people/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
%turbo-frame{id: "#{dom_id @person}"}
%div.d-flex.justify-content-between
%div
-# %img.rounded-circle{src: @person.picture, width: '141', height: '141'}
%img.rounded-circle{src: "/api/people/#{@person.id}/picture", width: '141', height: '141'}
%div.mt-3= link_to "Bearbeiten", edit_person_path
%div.pe-5
%table
Expand All @@ -21,12 +21,19 @@
%tr
%td= @person.title
%th.fw-light Funktion
- @person.person_roles.each do |person_role|
- unless @person.person_roles.empty?
- @person.person_roles.each do |person_role|
%tr
%td= "#{person_role.role.name} #{person_role.person_role_level.level} #{person_role.percent.to_i}%"
- else
%tr
%td= "#{person_role.role.name} #{person_role.person_role_level.level} #{person_role.percent.to_i}%"
%td -
%th.fw-light Organisationseinheit
%tr
%td= @person.department&.name
- unless @person.department.nil?
%td= @person.department.name
- else
%td -
%th.fw-light Firma
%tr
%td= @person.company.name
Expand All @@ -47,7 +54,10 @@
%td= @person.marital_status
%th.fw-light Kürzel
%tr
%td= @person.shortname
- unless @person.shortname.nil?
%td= @person.shortname
- else
%td -
%div
%div.fw-light Sprachen
%div.border.border-dark-subtle.mt-1.p-2.rounded
Expand Down
Binary file removed public/default_avatar.png
Binary file not shown.
15 changes: 15 additions & 0 deletions spec/helpers/picture_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the PictureHelper. For example:
#
# describe PictureHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe PictureHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/requests/picture_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe "Pictures", type: :request do

end

0 comments on commit 89f79d8

Please sign in to comment.