import { Dialog } from "../../dialog/dialog"; import { createCheckboxOption } from "../../other/utils"; var categoryMap = { "Aircraft": "Aircraft", "Helicopter": "Helicopter", "GroundUnit": "Ground units", "NavyUnit": "Naval units" } export abstract class UnitDataFile { protected data: any; protected dialog!: Dialog; constructor() { } buildCategoryCoalitionTable() { const categories = this.#getCategoriesFromData(); const coalitions = ["blue", "neutral", "red"]; let headersHTML: string = ``; let matrixHTML: string = ``; categories.forEach((category: string, index) => { matrixHTML += `${categoryMap[category as keyof typeof categoryMap]}`; coalitions.forEach((coalition: string) => { if (index === 0) headersHTML += `${coalition[0].toUpperCase() + coalition.substring(1)}`; const optionIsValid = this.data[category].hasOwnProperty(coalition); let checkboxHTML = createCheckboxOption(``, category, optionIsValid, () => { }, { "disabled": !optionIsValid, "name": "category-coalition-selection", "readOnly": !optionIsValid, "value" : `${category}:${coalition}` }).outerHTML; if (optionIsValid) checkboxHTML = checkboxHTML.replace(`"checkbox"`, `"checkbox" checked`); // inner and outerHTML screw default checked up matrixHTML += `${checkboxHTML}`; }); matrixHTML += ""; }); const table = this.dialog.getElement().querySelector("table.categories-coalitions"); (table.tHead).innerHTML = ` ${headersHTML}`; (table.querySelector(`tbody`)).innerHTML = matrixHTML; } #getCategoriesFromData() { const categories = Object.keys(this.data); categories.sort(); return categories; } getData() { return this.data; } }