corps.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // ts/corps.ts
  2. var main = document.querySelector("main");
  3. (async () => {
  4. const loader = document.querySelector("#loader");
  5. loader.style.display = "block";
  6. try {
  7. await render();
  8. } catch (e) {
  9. main.textContent = e instanceof Error ? e.message : String(e);
  10. }
  11. loader.style.display = "none";
  12. })();
  13. async function render() {
  14. const corps = await fetch("corps.json").then((r) => r.json());
  15. corps.sort((a, b) => (a.headquartersAddress?.lines.find((line) => line.type === "SYSTEM").entity.naturalId ?? "￿").localeCompare(b.headquartersAddress?.lines.find((line) => line.type === "SYSTEM").entity.naturalId ?? "￿"));
  16. main.innerHTML = `<table>
  17. <thead>
  18. <tr>
  19. <th>code</th>
  20. <th>name</th>
  21. <th>shareholders</th>
  22. <th>HQ</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. ${corps.map(renderCorpRow).join("")}
  27. </tbody>
  28. </table>`;
  29. }
  30. function renderCorpRow(corp) {
  31. let hq = "";
  32. if (corp.headquartersAddress !== null) {
  33. const planet = corp.headquartersAddress.lines.find((line) => line.type === "PLANET").entity;
  34. hq = planet.name;
  35. if (planet.name !== planet.naturalId)
  36. hq += ` (${planet.naturalId})`;
  37. if (!corp.headquartersFinished)
  38. hq += " [unfinished]";
  39. }
  40. return `<tr>
  41. <td>${corp.code}</td>
  42. <td>${corp.name}</td>
  43. <td>${corp.shareholders.length}</td>
  44. <td>${hq}</td>
  45. </tr>`;
  46. }
  47. //# debugId=938663E409BCBBAE64756E2164756E21