// Owner portfolio workspace. All visible content is made with DOM text nodes. "use strict"; let DATA = null; let activeCategory = "all"; const view = document.getElementById("view"); function h(tag, attrs, ...kids) { const el = document.createElement(tag); for (const [key, value] of Object.entries(attrs || {})) { if (key === "on") { for (const [event, handler] of Object.entries(value)) el.addEventListener(event, handler); } else if (value !== null && value !== undefined) { el.setAttribute(key, value); } } for (const kid of kids.flat()) { if (kid === null || kid === undefined || kid === false) continue; el.append(kid instanceof Node ? kid : document.createTextNode(String(kid))); } return el; } const integer = value => Number(value).toLocaleString("en-US"); const money = value => "$" + Number(value).toLocaleString("en-US"); function businessName(name) { return name.toLowerCase().replace(/\b([a-z])/g, character => character.toUpperCase()) .replace(/\b(Llc|Lp|Inc|Co)\b/g, match => ({Llc: "LLC", Lp: "LP", Inc: "Inc", Co: "Co"})[match]); } function categoryFor(portfolio) { const properties = Array.isArray(portfolio.properties) ? portfolio.properties : []; const completeSample = properties.length > 0 && properties.length === portfolio.total_parcels; const uses = properties.map(property => property.use); if (completeSample && uses.every(use => use === "apartment")) return "apartment"; if (completeSample && portfolio.total_parcels > 1 && uses.every(use => use === "house")) return "rental"; return "others"; } function categoryLabel(category) { return { apartment: "Apartment complex owner", rental: "Rental portfolio owner", others: "Others", }[category]; } function categoryButton(category, label) { return h("button", { class: "category" + (activeCategory === category ? " on" : ""), type: "button", "data-category": category, "aria-pressed": String(activeCategory === category), on: {click: () => { activeCategory = category; showPortfolios(); }}, }, label); } function openProfileOnKey(event, id) { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); showProfile(id); } } function renderProjectTotals() { const totals = DATA.project_summary; return h("section", {class: "project-totals", tabindex: "0", role: "region", "aria-label": "Project totals"}, h("h2", {}, "Project totals"), h("div", {class: "totals-grid"}, h("div", {class: "total"}, h("div", {class: "n"}, integer(totals.properties)), h("div", {class: "l"}, "Properties")), h("div", {class: "total"}, h("div", {class: "n"}, integer(totals.distinct_owners)), h("div", {class: "l"}, "Distinct owners")), h("div", {class: "total"}, h("div", {class: "n"}, integer(totals.business_entities)), h("div", {class: "l"}, "Business entities & conglomerates")))); } function showPortfolios() { const portfolios = DATA.portfolios.filter(portfolio => activeCategory === "all" || categoryFor(portfolio) === activeCategory); const rows = portfolios.map(portfolio => h("tr", { class: "click", tabindex: "0", role: "button", "data-id": portfolio.id, "aria-label": `Open ${businessName(portfolio.name)} profile`, on: { click: () => showProfile(portfolio.id), keydown: event => openProfileOnKey(event, portfolio.id), }, }, h("td", {class: "num"}, integer(portfolio.total_parcels)), h("td", {class: "owner"}, businessName(portfolio.name)), h("td", {class: "num"}, money(portfolio.value)), h("td", {}, categoryLabel(categoryFor(portfolio))))); const count = portfolios.length === DATA.portfolios.length ? `${integer(portfolios.length)} business portfolios` : `${integer(portfolios.length)} of ${integer(DATA.portfolios.length)} business portfolios`; view.replaceChildren(renderProjectTotals(), h("section", {class: "panel", tabindex: "0", role: "region", "aria-label": "Owner portfolios"}, h("div", {class: "panel-head"}, h("h2", {}, "Owner portfolios"), h("span", {class: "thin"}, count), h("div", {class: "categories", "aria-label": "Portfolio category filters"}, categoryButton("all", "All"), categoryButton("apartment", "Apartment complex owner"), categoryButton("rental", "Rental portfolio owner"), categoryButton("others", "Others"))), h("div", {class: "table-wrap"}, h("table", {}, h("thead", {}, h("tr", {}, h("th", {class: "num sorted"}, "# of parcels"), h("th", {}, "Business name"), h("th", {class: "num"}, "Total assessed value"), h("th", {}, "Category"))), h("tbody", {}, rows))))); window.scrollTo(0, 0); } function sourceLink(url) { return h("a", {href: url, target: "_blank", rel: "noreferrer"}, url.replace(/^https:\/\//, "")); } function filingSection(filing) { if (!filing) return null; const officers = Array.isArray(filing.officers) ? filing.officers : []; const people = officers.map(officer => h("div", {class: "person"}, h("div", {}, h("span", {class: "who"}, officer.name), h("span", {class: "role"}, officer.title)), h("div", {class: "src"}, `${officer.source}, filed ${officer.filed} · `, sourceLink(officer.url)), officer.also_on && officer.also_on.length ? h("div", {class: "also"}, "Also an officer of: " + officer.also_on.map(businessName).join(", ")) : null)); return h("section", {class: "panel", id: "decision-makers", tabindex: "0", role: "region", "aria-label": "Decision-makers · state business filings"}, h("h3", {}, "Decision-makers · state business filings"), h("dl", {class: "record"}, h("dt", {}, "Entity ID"), h("dd", {class: "mono"}, filing.entity_id), h("dt", {}, "Status"), h("dd", {}, `${filing.status}, formed ${filing.formed}`), h("dt", {}, "Entity type"), h("dd", {}, filing.entity_type)), h("div", {class: "src"}, "Source: state business registry · ", sourceLink(filing.record_url)), people); } function showProfile(id) { const portfolio = DATA.portfolios.find(item => item.id === id); if (!portfolio) return showPortfolios(); const category = categoryFor(portfolio); const fields = h("dl", {class: "profile-fields"}, h("dt", {}, "# of parcels"), h("dd", {class: "num"}, integer(portfolio.total_parcels)), h("dt", {}, "Business name"), h("dd", {}, businessName(portfolio.name)), h("dt", {}, "Total assessed value"), h("dd", {class: "num"}, money(portfolio.value)), h("dt", {}, "Category"), h("dd", {}, categoryLabel(category))); view.replaceChildren( h("div", {class: "crumb"}, h("a", {href: "#portfolios", id: "back", on: {click: event => { event.preventDefault(); showPortfolios(); }}}, "Owner portfolios"), " › ", businessName(portfolio.name)), h("div", {class: "profile-head"}, h("h2", {}, businessName(portfolio.name))), h("div", {class: "cols"}, h("section", {class: "panel", tabindex: "0", role: "region", "aria-label": "Portfolio"}, h("h3", {}, "Portfolio"), fields, h("p", {class: "src"}, "Portfolio totals are grouped from public property records.")), filingSection(portfolio.filing))); window.scrollTo(0, 0); } fetch("/static/data.json").then(response => response.json()).then(data => { DATA = data; showPortfolios(); window.__ready = true; });