aboutsummaryrefslogtreecommitdiff
path: root/www/mrPreview.html
blob: a034a41b656db177ceea7af00962dd8fe153910f (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>                                                                                                        
<html>
<head>
    <meta charset='utf-8' />
    <title>MapRoulette Preview</title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }

        tr:nth-child(odd) {
            background-color: #eee
        }
        tr:nth-child(even) {
            background-color: #ddd;
        }

        .modify {
            background-color: orange;
        }
        .add {
            background-color: lightgreen;
        }
        .remove {
            background-color: red;
        }
        .row {
            margin: 10px;
            border-width: 1px;
            border-color: black;
            border-style: solid;
        }
    </style>
</head>
<body>
    <div id="content"></div>
<script>
    fetch('changes.json')
        .then(res => res.json())
        .then(changes => {
            renderChanges(changes)
        })
    function renderChanges(changes) {
        const content = document.getElementById('content')
        const headerText = document.createElement('p')
        headerText.textContent = `${Object.keys(changes).length} features with changes`
        content.appendChild(headerText)

        for (const [id, change] of Object.entries(changes)) {
            const header = document.createElement('h2')
            header.textContent = id
            content.appendChild(header)

            const table = document.createElement('table')

            // table header
            const headerRow = document.createElement('tr')

            const headerTag = document.createElement('th')
            headerTag.textContent = 'Tag'
            headerRow.appendChild(headerTag)

            const headerBefore = document.createElement('th')
            headerBefore.textContent = 'Before'
            headerRow.appendChild(headerBefore)

            const headerAfter = document.createElement('th')
            headerAfter.textContent = 'After'
            headerRow.appendChild(headerAfter)

            table.appendChild(headerRow)

            // properties
            const distinctKeys = [...new Set([...Object.keys(change.before.properties), ...Object.keys(change.after.properties)])]
            for (const key of distinctKeys) {
                const tr = document.createElement('tr')

                const tdKey = document.createElement('td')
                tdKey.textContent = key

                const tdBefore = document.createElement('td')
                const beforeValue = change.before.properties[key]
                tdBefore.textContent = beforeValue

                const tdAfter = document.createElement('td')
                const afterValue = change.after.properties[key]
                tdAfter.textContent = afterValue

                if (beforeValue && afterValue && beforeValue !== afterValue) {
                    tdBefore.classList.add('modify')
                    tdAfter.classList.add('modify')
                }

                if (!beforeValue && afterValue) {
                    tdAfter.classList.add('add')
                }

                if (beforeValue && !afterValue) {
                    tdAfter.classList.add('remove')
                }

                tr.appendChild(tdKey)
                tr.appendChild(tdBefore)
                tr.appendChild(tdAfter)

                table.appendChild(tr)
            }

            content.appendChild(table)
        }
    }
</script>
</body>
</html>