Implement SubprojectAddresses in Subprojects
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
module SubprojectAddressesHelper
|
module SubprojectAddressesHelper
|
||||||
def subproject_address_form_fields
|
def subproject_address_form_fields
|
||||||
[:streetname, :zipcode, :city, :country]
|
[:streetname, :zipcode, :city, :country, :subproject_id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -4,6 +4,6 @@ module SubprojectsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def subproject_view_fields
|
def subproject_view_fields
|
||||||
[:subproject_name, :project, :client, :owner, :builder]
|
[:subproject_name, :project, :client, :owner, :builder, :subproject_address]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
class Subproject < ApplicationRecord
|
class Subproject < ApplicationRecord
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
has_one :subproject_address, dependent: :destroy
|
||||||
|
|
||||||
belongs_to :client, class_name: 'Client', optional: true
|
belongs_to :client, class_name: 'Client', optional: true
|
||||||
belongs_to :owner, class_name: 'Client', optional: true
|
belongs_to :owner, class_name: 'Client', optional: true
|
||||||
belongs_to :builder, class_name: 'Client', optional: true
|
belongs_to :builder, class_name: 'Client', optional: true
|
||||||
|
belongs_to :subproject_addresses, optional: true
|
||||||
|
|
||||||
accepts_nested_attributes_for :client, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
accepts_nested_attributes_for :client, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
||||||
accepts_nested_attributes_for :owner, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
accepts_nested_attributes_for :owner, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
||||||
accepts_nested_attributes_for :builder, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
accepts_nested_attributes_for :builder, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
||||||
|
accepts_nested_attributes_for :subproject_addresses, allow_destroy: true, reject_if: ->(attrs) { attrs['id'].present? || attrs.values.all?(&:blank?) }
|
||||||
|
|
||||||
|
|
||||||
validates :subproject_name, presence: true
|
validates :subproject_name, presence: true
|
||||||
validate :client_presence_check
|
validate :client_presence_check
|
||||||
|
|||||||
@@ -19,4 +19,9 @@
|
|||||||
<%= subproject_address.country %>
|
<%= subproject_address.country %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Subproject_ID:</strong>
|
||||||
|
<%= subproject_address.subproject_id %>
|
||||||
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<p style="color: green"><%= notice %></p>
|
<p style="color: green"><%= notice %></p>
|
||||||
|
|
||||||
|
<% content_for :title, "Adresse" %>
|
||||||
|
|
||||||
|
<h1>Adresse</h1>
|
||||||
|
|
||||||
<%= render @subproject_address %>
|
<%= render @subproject_address %>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
<%= link_to value.name, project_path(value) %>
|
<%= link_to value.name, project_path(value) %>
|
||||||
<% elsif attrib == :client || attrib == :owner || attrib == :builder %>
|
<% elsif attrib == :client || attrib == :owner || attrib == :builder %>
|
||||||
<%= link_to "#{value&.company_name} (#{value&.lastname}, #{value&.firstname})", client_path(value&.id) %>
|
<%= link_to "#{value&.company_name} (#{value&.lastname}, #{value&.firstname})", client_path(value&.id) %>
|
||||||
|
<% elsif attrib == :subproject_address %>
|
||||||
|
<% if value.present? %>
|
||||||
|
<%= link_to "#{value.streetname}, #{value.zipcode} #{value.city}, #{value.country}", subproject_address_path(value) %>
|
||||||
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= value.is_a?(Date) ? l(value) : value %>
|
<%= value.is_a?(Date) ? l(value) : value %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSubprojectRelationToSubprojectAddresses < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
add_column :subproject_addresses, :subproject_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
3
db/schema.rb
generated
3
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_07_22_152542) do
|
ActiveRecord::Schema[8.0].define(version: 2025_07_23_134650) do
|
||||||
create_table "clients", force: :cascade do |t|
|
create_table "clients", force: :cascade do |t|
|
||||||
t.string "company_name"
|
t.string "company_name"
|
||||||
t.string "firstname"
|
t.string "firstname"
|
||||||
@@ -44,6 +44,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_22_152542) do
|
|||||||
t.text "notes"
|
t.text "notes"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "subproject_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "subprojects", force: :cascade do |t|
|
create_table "subprojects", force: :cascade do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user