Skip to content

Commit

Permalink
Add index and show for people
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin481 committed Jan 26, 2024
1 parent 9fa521e commit e6d1b5c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::API
class ApplicationController < ActionController::Base
end
48 changes: 3 additions & 45 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,12 @@
# frozen_string_literal: true

class PeopleController < CrudController
include ExportController

self.permitted_attrs = %i[birthdate location
marital_status updated_by name nationality nationality2 title
competence_notes company_id email department_id shortname]

self.nested_models = %i[advanced_trainings activities projects
educations language_skills person_roles
people_skills categories]

self.permitted_relationships = %i[person_roles people_skills]
class PeopleController < ApplicationController

def index
people = fetch_entries
render json: people, each_serializer: PeopleSerializer
@people = Person.all
end

def show
if format_odt?
export
return
end
@person = Person.includes(projects: :project_technologies,
person_roles: [:role, :person_role_level]).find(params.fetch(:id))
super
end

private

def fetch_entries
Person.includes(:company).list
end

def person
@person ||= Person.find(params[:person_id])
end

def export
anon = params[:anon].presence || 'false'
odt_file = Odt::Cv.new(entry, params).export
filename = if anon == 'true'
'CV_Puzzle_ITC_anonymized.odt'
else
filename(entry.name, 'CV_Puzzle_ITC')
end

send_data odt_file.generate,
type: 'application/vnd.oasis.opendocument.text',
disposition: content_disposition('attachment', filename)
@person = Person.find(params[:id])
end
end
3 changes: 3 additions & 0 deletions app/views/people/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @people.each do |person| %>
<h1> <%= person.name %> </h1>
<% end %>
7 changes: 7 additions & 0 deletions app/views/people/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
<h1> <%= @person.name %>'s Profile </h1>
<div>
<h5> That person is from <%= @person.location %> </h5>
</div>
</div>
<%= link_to "Person bearbeiten", edit_person_path %>

0 comments on commit e6d1b5c

Please sign in to comment.