forked from MapComplete/MapComplete
Chore: remove unused code
This commit is contained in:
parent
cc96df94e9
commit
08db091537
2 changed files with 6 additions and 58 deletions
|
@ -1,27 +1,26 @@
|
|||
import BaseUIElement from "../BaseUIElement"
|
||||
import { Utils } from "../../Utils"
|
||||
import Translations from "../i18n/Translations"
|
||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default class Table extends BaseUIElement {
|
||||
private readonly _header: BaseUIElement[]
|
||||
private readonly _contents: BaseUIElement[][]
|
||||
private readonly _contentStyle: string[][]
|
||||
private readonly _sortable: boolean
|
||||
|
||||
constructor(
|
||||
header: (BaseUIElement | string)[],
|
||||
contents: (BaseUIElement | string)[][],
|
||||
options?: {
|
||||
contentStyle?: string[][]
|
||||
sortable?: false | boolean
|
||||
}
|
||||
) {
|
||||
super()
|
||||
this._contentStyle = options?.contentStyle ?? [["min-width: 9rem"]]
|
||||
this._header = header?.map(Translations.W)
|
||||
this._contents = contents.map((row) => row.map(Translations.W))
|
||||
this._sortable = options?.sortable ?? false
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
|
@ -46,26 +45,8 @@ export default class Table extends BaseUIElement {
|
|||
protected InnerConstructElement(): HTMLElement {
|
||||
const table = document.createElement("table")
|
||||
|
||||
/**
|
||||
* Sortmode: i: sort column i ascending;
|
||||
* if i is negative : sort column (-i - 1) descending
|
||||
*/
|
||||
const sortmode = new UIEventSource<number>(undefined)
|
||||
const self = this
|
||||
const headerElems = Utils.NoNull(
|
||||
(this._header ?? []).map((elem, i) => {
|
||||
if (self._sortable) {
|
||||
elem.onClick(() => {
|
||||
const current = sortmode.data
|
||||
if (current == i) {
|
||||
sortmode.setData(-1 - i)
|
||||
} else {
|
||||
sortmode.setData(i)
|
||||
}
|
||||
})
|
||||
}
|
||||
return elem.ConstructElement()
|
||||
})
|
||||
(this._header ?? []).map((elem) => elem.ConstructElement())
|
||||
)
|
||||
if (headerElems.length > 0) {
|
||||
const thead = document.createElement("thead")
|
||||
|
@ -81,11 +62,11 @@ export default class Table extends BaseUIElement {
|
|||
}
|
||||
|
||||
for (let i = 0; i < this._contents.length; i++) {
|
||||
let row = this._contents[i]
|
||||
const row = this._contents[i]
|
||||
const tr = document.createElement("tr")
|
||||
for (let j = 0; j < row.length; j++) {
|
||||
try {
|
||||
let elem = row[j]
|
||||
const elem = row[j]
|
||||
if (elem?.ConstructElement === undefined) {
|
||||
continue
|
||||
}
|
||||
|
@ -114,29 +95,6 @@ export default class Table extends BaseUIElement {
|
|||
table.appendChild(tr)
|
||||
}
|
||||
|
||||
sortmode.addCallback((sortCol) => {
|
||||
if (sortCol === undefined) {
|
||||
return
|
||||
}
|
||||
const descending = sortCol < 0
|
||||
const col = descending ? -sortCol - 1 : sortCol
|
||||
let rows: HTMLTableRowElement[] = Array.from(table.rows)
|
||||
rows.splice(0, 1) // remove header row
|
||||
rows = rows.sort((a, b) => {
|
||||
const ac = a.cells[col]?.textContent?.toLowerCase()
|
||||
const bc = b.cells[col]?.textContent?.toLowerCase()
|
||||
if (ac === bc) {
|
||||
return 0
|
||||
}
|
||||
return ac < bc !== descending ? -1 : 1
|
||||
})
|
||||
for (let j = rows.length; j > 1; j--) {
|
||||
table.deleteRow(j)
|
||||
}
|
||||
for (const row of rows) {
|
||||
table.appendChild(row)
|
||||
}
|
||||
})
|
||||
|
||||
return table
|
||||
}
|
||||
|
|
|
@ -50,16 +50,6 @@ export default abstract class BaseUIElement {
|
|||
|
||||
return this
|
||||
}
|
||||
|
||||
public ScrollIntoView() {
|
||||
if (this._constructedHtmlElement === undefined) {
|
||||
return
|
||||
}
|
||||
this._constructedHtmlElement?.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "start",
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Adds all the relevant classes, space separated
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue