Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/fm_archives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def show
return
end

@table_key = @record.class.table_name.delete_prefix("fm_")
@table_label = TABLES.dig(@table_key, :label)
load_backlinks
load_portal_records
end
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/fm_people_to_organization_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ def kind

def summary
org_id = data["OrgID"]
FmOrganization.find_by(fm_id: org_id)&.data&.dig("OrgName").presence || org_id
FmOrganization.find_by(fm_id: org_id)&.name || org_id
end
end
4 changes: 2 additions & 2 deletions app/decorators/fm_personnel_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def program
project = FmProject.find_by(fm_id: data["ProjectID"])
return data["ProjectID"] unless project

organization = FmOrganization.find_by(fm_id: project.data["OrgID"])&.data&.dig("OrgName")
[ project.data["ProjectName"].presence || project.fm_id, organization ].compact_blank.join(" at ")
organization = FmOrganization.find_by(fm_id: project.data["OrgID"])&.name
[ project.name, organization ].compact_blank.join(" at ")
end
end
30 changes: 24 additions & 6 deletions app/helpers/filemaker_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,31 @@ def filemaker_portal_link(record)
link_to text, path, class: button_classes(:primary)
end

# An archive field's link to the record it names, struck through when the archive has no such record.
def fm_archive_reference_link(fm_id, table)
key = table.delete_prefix("fm_")
model = FmArchivesController::TABLES.dig(key, :model)
return tag.span(fm_id, class: "line-through opacity-60", title: "No FM record found") if model && !model.exists?(fm_id: fm_id)
# The archive record an ID field points at, or an unsaved placeholder when the archive has none.
def fm_archive_record(fm_id, table)
model = FmArchivesController::TABLES.fetch(table.delete_prefix("fm_"))[:model]
model.find_by(fm_id: fm_id) || model.new(fm_id: fm_id, data: {})
end

# A record's FileMaker ID, linked to its archive page, or struck through when the archive lacks it.
def fm_archive_id_tag(record)
unless record.persisted?
return tag.span(record.fm_id, class: "ml-1 font-mono text-xs font-normal text-gray-400 line-through", title: "No FM record found")
end

link_to record.fm_id, fm_archive_record_path(record), class: "ml-1 font-mono text-xs font-normal text-primary hover:underline"
end

# What a record is, linked to its archive page, or a not-found note when the archive lacks it.
def fm_archive_summary_tag(record)
return tag.span("Not found in FM data", class: "text-gray-500 italic") unless record.persisted?

summary = record.class.decorator_class? ? record.decorate.try(:summary).presence : nil
link_to summary || record.name, fm_archive_record_path(record), class: "text-primary hover:underline"
end

link_to fm_id, fm_archive_path(fm_id, table: key), class: "text-primary hover:underline"
def fm_archive_record_path(record)
fm_archive_path(record.fm_id, table: record.class.table_name.delete_prefix("fm_"))
end

# The portal's name for a related table's counterpart, when the archive's label doesn't already lead with it.
Expand Down
43 changes: 43 additions & 0 deletions app/models/concerns/fm_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module FmArchive
PORTAL_COUNTERPARTS = {}.freeze
PORTAL_FIELDS = {}.freeze
USER_LOOKUP_FIELDS = [].freeze
CONTEXT_LINK_MAP = {}.freeze
PREFIX_LINK_MAP = {}.freeze

included do
before_validation :set_defaults
Expand Down Expand Up @@ -62,8 +64,49 @@ def records_listed_under(_label)
[]
end

# The archive table a field's ID points at. A polymorphic field, mapped to nil in FM_LINKS, resolves
# by the record's Context or by the ID's prefix.
def reference_table(key)
value = data[key]
return if value.blank? || !self.class::FM_LINKS.key?(key)

self.class::FM_LINKS[key] || self.class::CONTEXT_LINK_MAP[data["Context"]] || self.class::PREFIX_LINK_MAP[value.to_s[0]]
end

# Each table words its names its own way, so records from different tables never share one.
def name
fm_id
end

private

def fm_value(*fields)
fields.lazy.filter_map { |field| data&.dig(field).to_s.squish.presence }.first
end

def fm_join(*fields)
fm_words(*fields.map { |field| fm_value(field) })
end

def fm_words(*parts)
parts.compact_blank.join(" ").presence
end

def fm_with(preposition, value)
"#{preposition} #{value}" if value.present?
end

def fm_dollars(*fields)
amounts = fields.filter_map { |field| Float(fm_value(field)&.delete("$,"), exception: false) }
MoneyFormatter.dollars_from_cents((amounts.sum * 100).round) if amounts.any?
end

# "Subject — detail", where the detail carries the table's own wording.
def fm_phrase(subject, detail)
return detail&.upcase_first || fm_id if subject.blank?
[ subject, detail ].compact_blank.join(" — ")
end

def set_defaults
self.data ||= {}
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/fm_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ class FmActivity < ApplicationRecord
"ID" => "fm_rolodexes",
"LinkID" => "fm_payments"
}.freeze

def name
fm_phrase(fm_value("Subject"), fm_words(fm_value("Type") || "Activity", fm_with("with", fm_value("FullName") || fm_join("FirstName", "LastName"))))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ class FmAddress < ApplicationRecord
"RolodexID" => "fm_rolodexes",
"OrgID" => "fm_organizations"
}.freeze

def name
[ fm_value("AddrsLine1"), fm_value("AddrsCity") ].compact.join(", ").presence || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ class FmAllocation < ApplicationRecord
HAS_MANY = {
"fm_participants" => { via: "AllocRecID", label: "Participants" }
}.freeze

def name
fm_words(fm_value("Year"), "allocation", fm_with("of", fm_dollars("AmountGeneral", "AmountSupplies", "AmountExhibit")), fm_with("to", fm_value("ProjectID"))).upcase_first
end
end
4 changes: 4 additions & 0 deletions app/models/fm_ancillary_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ class FmAncillaryData < ApplicationRecord
FM_LINKS = {
"RolodexID" => "fm_rolodexes"
}.freeze

def name
fm_phrase(fm_value("FlagText"), fm_words(fm_value("Flag"), "flag"))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_art_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ class FmArtPurchase < ApplicationRecord
"ArtRegistryID" => "fm_art_registries",
"BuyerID" => "fm_rolodexes"
}.freeze

def name
fm_phrase(fm_value("ArtTitle"), fm_words("purchased", fm_with("for", fm_dollars("AmountPaid"))))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_art_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ class FmArtRegistry < ApplicationRecord
"fm_art_purchases" => { via: "ArtRegistryID", label: "Art Purchases" },
"fm_exhibited_items" => { via: "ArtRegistryItemID", label: "Exhibited Items" }
}.freeze

def name
fm_phrase(fm_value("ArtTitle"), fm_with("by", fm_join("ArtistFirstName", "ArtistLastName")))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ class FmCampaign < ApplicationRecord
"fm_donor_developers" => { via: "CampaignID", label: "Donor Developers" },
"fm_solicitations" => { via: "CampaignID", label: "Solicitations" }
}.freeze

def name
fm_value("Campaign") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_committee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ class FmCommittee < ApplicationRecord
"fm_committee_meetings" => { via: "CommitteeID", label: "Meetings" },
"fm_committee_members" => { via: "CommitteeID", label: "Members" }
}.freeze

def name
fm_value("CommitteeName") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_committee_meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class FmCommitteeMeeting < ApplicationRecord
FM_LINKS = {
"CommitteeID" => "fm_committees"
}.freeze

def name
fm_words("Committee", fm_value("CommitteeID"), "meeting", fm_with("on", fm_value("MeetingDate")))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_committee_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ class FmCommitteeMember < ApplicationRecord
"CommitteeID" => "fm_committees",
"MemberID" => "fm_rolodexes"
}.freeze

def name
fm_phrase(fm_value("MemberID"), fm_words(fm_value("Role") || "Member", "of committee", fm_value("CommitteeID")))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ class FmContact < ApplicationRecord
FM_LINKS = {
"ContacteeID" => "fm_rolodexes"
}.freeze

def name
fm_phrase(fm_value("RecordID"), fm_words("contact", fm_with("for", fm_value("ContacteeID"))))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_donor_developer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ class FmDonorDeveloper < ApplicationRecord
HAS_MANY = {
"fm_solicitations" => { via: "DonorDevRecID", label: "Solicitations" }
}.freeze

def name
fm_phrase(fm_value("NameListing"), fm_words("donor developer", fm_with("for", fm_value("CampaignID"))))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_email_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class FmEmailAddress < ApplicationRecord
FM_LINKS = {
"OrgID" => "fm_organizations"
}.freeze

def name
fm_value("EmailAddress") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ class FmEvent < ApplicationRecord
"fm_volunteers" => { via: "EventID", label: "Volunteers" },
"fm_quotations" => { via: "EventID", label: "Quotations" }
}.freeze

def name
fm_value("Title") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_exhibited_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ class FmExhibitedItem < ApplicationRecord
"ArtRegistryItemID" => "fm_art_registries",
"EventID" => "fm_events"
}.freeze

def name
fm_phrase(fm_value("ItemName"), fm_words("exhibited", fm_with("at", fm_value("EventID"))))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_expenditure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ class FmExpenditure < ApplicationRecord
FM_LINKS = {
"ProjectID" => "fm_projects"
}.freeze

def name
fm_phrase(fm_value("Name", "Description"), fm_words(fm_dollars("Amount"), "expense"))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_form_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class FmFormField < ApplicationRecord
FM_KEY_COLUMN = "FieldNo"

FM_LINKS = {}.freeze

def name
fm_words(fm_value("FieldNameFM", "FieldNameWP"), "form field").upcase_first
end
end
4 changes: 4 additions & 0 deletions app/models/fm_form_letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ class FmFormLetter < ApplicationRecord
FM_LINKS = {
"SignatureID" => "fm_rolodexes"
}.freeze

def name
fm_value("DocumentName") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_form_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ class FmFormSubmission < ApplicationRecord
"PaymentID" => "fm_payments",
"ParticRecID" => "fm_participants"
}.freeze

def name
fm_phrase(fm_join("FirstName", "LastName") || fm_value("OrgName"), fm_value("FormTitle") || "form submission")
end
end
4 changes: 4 additions & 0 deletions app/models/fm_forms_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ class FmFormsList < ApplicationRecord
HAS_MANY = {
"fm_form_submissions" => { via: "FormID", label: "Form Submissions" }
}.freeze

def name
fm_value("FormTitle") || fm_id
end
end
6 changes: 6 additions & 0 deletions app/models/fm_funding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ class FmFunding < ApplicationRecord
"fm_match_donations" => { via: "FundingID", label: "Match Donations" },
"fm_reportings" => { via: "FundingRecordID", label: "Reporting Obligations" }
}.freeze

def name
granted = fm_dollars("AmountGranted")
detail = granted ? "#{granted} grant" : fm_words(fm_dollars("RequestAmount"), "funding request")
fm_phrase(fm_value("NameTemp", "Purpose"), detail)
end
end
4 changes: 4 additions & 0 deletions app/models/fm_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ class FmGroup < ApplicationRecord
HAS_MANY = {
"fm_group_members" => { via: "GroupID", label: "Members" }
}.freeze

def name
fm_value("GroupName") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_group_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ class FmGroupMember < ApplicationRecord
"GroupID" => "fm_groups",
"ContactID" => "fm_rolodexes"
}.freeze

def name
fm_phrase(fm_value("ContactID"), fm_words("member of group", fm_value("GroupID")))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ class FmInvoice < ApplicationRecord
HAS_MANY = {
"fm_line_items" => { via: "InvoiceNo", label: "Line Items" }
}.freeze

def name
fm_phrase(fm_words("Invoice", fm_value("InvoiceNo")), fm_value("Name", "Company"))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ class FmLineItem < ApplicationRecord
FM_LINKS = {
"InvoiceNo" => "fm_invoices"
}.freeze

def name
fm_phrase(fm_value("Description"), fm_words("line item", fm_with("on invoice", fm_value("InvoiceNo"))))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_match_donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ class FmMatchDonation < ApplicationRecord
"FundingID" => "fm_fundings",
"RefDonationID" => "fm_payments"
}.freeze

def name
fm_words(fm_value("Match"), "match", fm_with("of", fm_dollars("Amount")), fm_with("for", fm_value("DonationID"))).upcase_first
end
end
4 changes: 4 additions & 0 deletions app/models/fm_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ class FmNote < ApplicationRecord
"Organizations" => "fm_organizations",
"Rolodex" => "fm_rolodexes"
}.freeze

def name
fm_phrase(fm_value("Subject"), fm_words(fm_value("Context")&.singularize, "note"))
end
end
4 changes: 4 additions & 0 deletions app/models/fm_organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ class FmOrganization < ApplicationRecord
"fm_invoices" => { via: "OrgID", label: "Invoices" },
"fm_people_to_organizations" => { via: "OrgID", label: "People Affiliations" }
}.freeze

def name
fm_value("OrgName") || fm_id
end
end
4 changes: 4 additions & 0 deletions app/models/fm_participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ class FmParticipant < ApplicationRecord
HAS_MANY = {
"fm_payments" => { via: "ParticRecID", label: "Payments" }
}.freeze

def name
fm_phrase(fm_value("Name"), fm_words(fm_value("Role") || "Participant", fm_with("at", fm_value("EventID"))))
end
end
Loading
Loading