aboutsummaryrefslogtreecommitdiff
path: root/www/mrPreview.html
blob: 426ae7a4061213ac85daa5238b18344cd03e4054 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!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>
    const q = new URLSearchParams(window.location.search)
    let tagAddCount = 0
    let tagModifyCount = 0
    let tagRemoveCount = 0

    fetch(q.get('changes') || 'changes.json')
        .then(res => res.json())
        .then(changes => {
            renderChanges(changes)
        })
    function renderChanges(changes) {
        const content = document.getElementById('content')
        const headerText = document.createElement('p')
        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)

            let tagsModified = false
            let tagsAdded = false
            let tagsRemoved = false

            // 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')

                    tagsModified = true
                    tagModifyCount++
                }

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

                    tagsAdded = true
                    tagAddCount++
                }

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

                    tagsRemoved = true
                    tagRemoveCount++
                }

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

                table.appendChild(tr)
            }
            header.textContent = `${id} ${tagsAdded ? 'Added' : ''} ${tagsModified ? 'Modified' : ''} ${tagsRemoved ? 'Removed' : ''}`

            content.appendChild(table)
        }
        headerText.textContent = `${Object.keys(changes).length} features with changes. ${tagAddCount} new tags, ${tagRemoveCount} removed tags, ${tagModifyCount} changed tags.`
    }
</script>
</body>
</html>