Browse Source

initial version

pull/2/head
rodley82 2 weeks ago
parent
commit
f3a78f3bd6
  1. 2
      app/admin/users_admin.rb
  2. 21
      app/models/user.rb
  3. 5
      db/migrate/20260224131848_add_label_to_users.rb
  4. 3
      db/schema.rb

2
app/admin/users_admin.rb

@ -12,6 +12,7 @@ Trestle.resource(:users) do
# Customize the table columns shown on the index view.
table do
column :name
column :label
column :created_at, align: :center
actions do |toolbar, instance, admin|
toolbar.edit if admin && admin.actions.include?(:edit)
@ -19,6 +20,7 @@ Trestle.resource(:users) do
toolbar.link 'CV', instance, action: :generate, method: :get, style: :primary, icon: "fa fa-file-pdf", target: "_blank"
toolbar.link 'CLS', instance, action: :generate_cls, method: :get, style: :secondary, icon: "fa", target: "_blank"
toolbar.link 'JSON', instance, action: :generate_json, method: :get, style: :secondary, icon: "fa", target: "_blank"
# TODO: Add a new action to clone the user and all its associations passing a "cloned" label to the new user.
end
end

21
app/models/user.rb

@ -2,4 +2,25 @@ class User < ApplicationRecord
has_many :work_experiences
has_many :skills
has_many :education_entries
has_many :cover_letters
def clone!(label:)
self.class.transaction do
cloned_user = dup
cloned_user.label = label
cloned_user.save!
self.class.reflect_on_all_associations(:has_many).each do |association|
next if association.options[:through]
public_send(association.name).find_each do |record|
cloned_record = record.dup
cloned_record[association.foreign_key] = cloned_user.id
cloned_record.save!
end
end
cloned_user
end
end
end

5
db/migrate/20260224131848_add_label_to_users.rb

@ -0,0 +1,5 @@
class AddLabelToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :label, :string
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_11_04_003755) do
ActiveRecord::Schema[7.0].define(version: 2026_02_24_131848) do
create_table "cover_letters", force: :cascade do |t|
t.string "title"
t.string "company_name"
@ -62,6 +62,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_11_04_003755) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title"
t.string "label"
end
create_table "work_experiences", force: :cascade do |t|

Loading…
Cancel
Save