-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
57 lines (48 loc) · 1.49 KB
/
view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class TableView {
constructor() {
this.$root = document.querySelector('tbody')
}
renderTable(data) {
this.$root.innerHTML = null
this.$root.append(
...data.map(this.createRow.bind(this))
)
}
createRow(rowData, id) {
const { numReports, parentType, title, link, body, apiLink } = rowData
const row = document.createElement('tr')
row.setAttribute('data-row', id)
row.setAttribute('data-location', apiLink)
const checkbox = document.createElement('input')
checkbox.setAttribute('type', 'checkbox')
checkbox.setAttribute('data-delete', id)
const checkColumn = document.createElement('td')
checkColumn.appendChild(checkbox)
const numberColumns = [
numReports, parentType
]
.map((text) => {
const $el = document.createElement('td')
$el.textContent = text
return $el
})
const textRows = [
title,
body
]
.map(() => document.createElement('td'))
.map($el => {
$el.className = 'text-row'
return $el
})
textRows[0].innerHTML = `<a href='${link}' target='_blank'>${title}</a>`
textRows[1].textContent = body
row.append(
checkColumn,
...numberColumns,
...textRows
)
return row
}
}
export default TableView