osint-lead-identificationPortfolio

js175 lines7.3 KB
Raw
1// Owner portfolio workspace. All visible content is made with DOM text nodes.
2"use strict";
3
4let DATA = null;
5let activeCategory = "all";
6const view = document.getElementById("view");
7
8function h(tag, attrs, ...kids) {
9 const el = document.createElement(tag);
10 for (const [key, value] of Object.entries(attrs || {})) {
11 if (key === "on") {
12 for (const [event, handler] of Object.entries(value)) el.addEventListener(event, handler);
13 } else if (value !== null && value !== undefined) {
14 el.setAttribute(key, value);
15 }
16 }
17 for (const kid of kids.flat()) {
18 if (kid === null || kid === undefined || kid === false) continue;
19 el.append(kid instanceof Node ? kid : document.createTextNode(String(kid)));
20 }
21 return el;
22}
23
24const integer = value => Number(value).toLocaleString("en-US");
25const money = value => "$" + Number(value).toLocaleString("en-US");
26
27function businessName(name) {
28 return name.toLowerCase().replace(/\b([a-z])/g, character => character.toUpperCase())
29 .replace(/\b(Llc|Lp|Inc|Co)\b/g,
30 match => ({Llc: "LLC", Lp: "LP", Inc: "Inc", Co: "Co"})[match]);
31}
32
33function categoryFor(portfolio) {
34 const properties = Array.isArray(portfolio.properties) ? portfolio.properties : [];
35 const completeSample = properties.length > 0 && properties.length === portfolio.total_parcels;
36 const uses = properties.map(property => property.use);
37 if (completeSample && uses.every(use => use === "apartment")) return "apartment";
38 if (completeSample && portfolio.total_parcels > 1 && uses.every(use => use === "house")) return "rental";
39 return "others";
40}
41
42function categoryLabel(category) {
43 return {
44 apartment: "Apartment complex owner",
45 rental: "Rental portfolio owner",
46 others: "Others",
47 }[category];
48}
49
50function categoryButton(category, label) {
51 return h("button", {
52 class: "category" + (activeCategory === category ? " on" : ""),
53 type: "button",
54 "data-category": category,
55 "aria-pressed": String(activeCategory === category),
56 on: {click: () => {
57 activeCategory = category;
58 showPortfolios();
59 }},
60 }, label);
61}
62
63function openProfileOnKey(event, id) {
64 if (event.key === "Enter" || event.key === " ") {
65 event.preventDefault();
66 showProfile(id);
67 }
68}
69
70function renderProjectTotals() {
71 const totals = DATA.project_summary;
72 return h("section", {class: "project-totals", tabindex: "0", role: "region", "aria-label": "Project totals"},
73 h("h2", {}, "Project totals"),
74 h("div", {class: "totals-grid"},
75 h("div", {class: "total"}, h("div", {class: "n"}, integer(totals.properties)),
76 h("div", {class: "l"}, "Properties")),
77 h("div", {class: "total"}, h("div", {class: "n"}, integer(totals.distinct_owners)),
78 h("div", {class: "l"}, "Distinct owners")),
79 h("div", {class: "total"}, h("div", {class: "n"}, integer(totals.business_entities)),
80 h("div", {class: "l"}, "Business entities & conglomerates"))));
81}
82
83function showPortfolios() {
84 const portfolios = DATA.portfolios.filter(portfolio =>
85 activeCategory === "all" || categoryFor(portfolio) === activeCategory);
86 const rows = portfolios.map(portfolio => h("tr", {
87 class: "click",
88 tabindex: "0",
89 role: "button",
90 "data-id": portfolio.id,
91 "aria-label": `Open ${businessName(portfolio.name)} profile`,
92 on: {
93 click: () => showProfile(portfolio.id),
94 keydown: event => openProfileOnKey(event, portfolio.id),
95 },
96 },
97 h("td", {class: "num"}, integer(portfolio.total_parcels)),
98 h("td", {class: "owner"}, businessName(portfolio.name)),
99 h("td", {class: "num"}, money(portfolio.value)),
100 h("td", {}, categoryLabel(categoryFor(portfolio)))));
101
102 const count = portfolios.length === DATA.portfolios.length
103 ? `${integer(portfolios.length)} business portfolios`
104 : `${integer(portfolios.length)} of ${integer(DATA.portfolios.length)} business portfolios`;
105 view.replaceChildren(renderProjectTotals(),
106 h("section", {class: "panel", tabindex: "0", role: "region", "aria-label": "Owner portfolios"},
107 h("div", {class: "panel-head"}, h("h2", {}, "Owner portfolios"),
108 h("span", {class: "thin"}, count),
109 h("div", {class: "categories", "aria-label": "Portfolio category filters"},
110 categoryButton("all", "All"),
111 categoryButton("apartment", "Apartment complex owner"),
112 categoryButton("rental", "Rental portfolio owner"),
113 categoryButton("others", "Others"))),
114 h("div", {class: "table-wrap"},
115 h("table", {}, h("thead", {}, h("tr", {},
116 h("th", {class: "num sorted"}, "# of parcels"),
117 h("th", {}, "Business name"),
118 h("th", {class: "num"}, "Total assessed value"),
119 h("th", {}, "Category"))),
120 h("tbody", {}, rows)))));
121 window.scrollTo(0, 0);
122}
123
124function sourceLink(url) {
125 return h("a", {href: url, target: "_blank", rel: "noreferrer"}, url.replace(/^https:\/\//, ""));
126}
127
128function filingSection(filing) {
129 if (!filing) return null;
130 const officers = Array.isArray(filing.officers) ? filing.officers : [];
131 const people = officers.map(officer => h("div", {class: "person"},
132 h("div", {}, h("span", {class: "who"}, officer.name),
133 h("span", {class: "role"}, officer.title)),
134 h("div", {class: "src"}, `${officer.source}, filed ${officer.filed} · `,
135 sourceLink(officer.url)),
136 officer.also_on && officer.also_on.length
137 ? h("div", {class: "also"}, "Also an officer of: " + officer.also_on.map(businessName).join(", "))
138 : null));
139 return h("section", {class: "panel", id: "decision-makers", tabindex: "0", role: "region", "aria-label": "Decision-makers · state business filings"},
140 h("h3", {}, "Decision-makers · state business filings"),
141 h("dl", {class: "record"},
142 h("dt", {}, "Entity ID"), h("dd", {class: "mono"}, filing.entity_id),
143 h("dt", {}, "Status"), h("dd", {}, `${filing.status}, formed ${filing.formed}`),
144 h("dt", {}, "Entity type"), h("dd", {}, filing.entity_type)),
145 h("div", {class: "src"}, "Source: state business registry · ", sourceLink(filing.record_url)),
146 people);
147}
148
149function showProfile(id) {
150 const portfolio = DATA.portfolios.find(item => item.id === id);
151 if (!portfolio) return showPortfolios();
152 const category = categoryFor(portfolio);
153 const fields = h("dl", {class: "profile-fields"},
154 h("dt", {}, "# of parcels"), h("dd", {class: "num"}, integer(portfolio.total_parcels)),
155 h("dt", {}, "Business name"), h("dd", {}, businessName(portfolio.name)),
156 h("dt", {}, "Total assessed value"), h("dd", {class: "num"}, money(portfolio.value)),
157 h("dt", {}, "Category"), h("dd", {}, categoryLabel(category)));
158 view.replaceChildren(
159 h("div", {class: "crumb"}, h("a", {href: "#portfolios", id: "back", on: {click: event => {
160 event.preventDefault();
161 showPortfolios();
162 }}}, "Owner portfolios"), " › ", businessName(portfolio.name)),
163 h("div", {class: "profile-head"}, h("h2", {}, businessName(portfolio.name))),
164 h("div", {class: "cols"},
165 h("section", {class: "panel", tabindex: "0", role: "region", "aria-label": "Portfolio"}, h("h3", {}, "Portfolio"), fields,
166 h("p", {class: "src"}, "Portfolio totals are grouped from public property records.")),
167 filingSection(portfolio.filing)));
168 window.scrollTo(0, 0);
169}
170
171fetch("/static/data.json").then(response => response.json()).then(data => {
172 DATA = data;
173 showPortfolios();
174 window.__ready = true;
175});