Fri, 06 Feb 2026 16:23:50 +0100
update uwproj
| 5 | 1 | /* Copyright 2025 Mike Becker. All rights reserved. |
| 2 | * | |
| 3 | * Redistribution and use in source and binary forms, with or without | |
| 4 | * modification, are permitted provided that the following conditions are met: | |
| 5 | * | |
| 6 | * 1. Redistributions of source code must retain the above copyright | |
| 7 | * notice, this list of conditions and the following disclaimer. | |
| 8 | * | |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer in the | |
| 11 | * documentation and/or other materials provided with the distribution. | |
| 12 | * | |
| 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
| 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 20 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| 21 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 | */ | |
| 24 | ||
| 25 | #include "html.h" | |
| 26 | ||
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
27 | #include <ranges> |
| 5 | 28 | #include <cstdio> |
|
52
e9edc3bd0301
add custom fragment indentation
Mike Becker <universe@uap-core.de>
parents:
50
diff
changeset
|
29 | #include <cassert> |
| 5 | 30 | |
| 13 | 31 | using namespace std::chrono; |
|
6
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
32 | |
| 5 | 33 | namespace html { |
| 7 | 34 | static constexpr const char* weekdays[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; |
| 35 | ||
| 5 | 36 | static unsigned indentation; |
|
52
e9edc3bd0301
add custom fragment indentation
Mike Becker <universe@uap-core.de>
parents:
50
diff
changeset
|
37 | static const char *tabs = " "; |
| 5 | 38 | static void indent(int change = 0) { |
| 39 | indentation += change; | |
|
52
e9edc3bd0301
add custom fragment indentation
Mike Becker <universe@uap-core.de>
parents:
50
diff
changeset
|
40 | assert(indentation <= max_indentation); |
|
22
a9230f197e61
fix inconsistent use of tabs and spaces in indentation
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
41 | fwrite(tabs, 4, indentation, stdout); |
| 5 | 42 | } |
| 43 | ||
| 44 | static std::string encode(const std::string &data) { | |
| 45 | std::string buffer; | |
| 46 | buffer.reserve(data.size()+16); | |
| 47 | for (const char &pos: data) { | |
| 48 | switch (pos) { | |
| 49 | case '&': | |
| 50 | buffer.append("&"); | |
| 51 | break; | |
| 52 | case '\"': | |
| 53 | buffer.append("""); | |
| 54 | break; | |
| 55 | case '\'': | |
| 56 | buffer.append("'"); | |
| 57 | break; | |
| 58 | case '<': | |
| 59 | buffer.append("<"); | |
| 60 | break; | |
| 61 | case '>': | |
| 62 | buffer.append(">"); | |
| 63 | break; | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
64 | case '#': |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
65 | buffer.append("#"); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
66 | break; |
| 5 | 67 | default: |
| 68 | buffer.append(&pos, 1); | |
| 69 | break; | |
| 70 | } | |
| 71 | } | |
| 72 | return buffer; | |
| 73 | } | |
| 74 | } | |
| 75 | ||
|
73
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
76 | void html::styles_and_script() { |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
77 | puts(R"( <style> |
| 5 | 78 | table.heatmap { |
| 79 | table-layout: fixed; | |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
80 | border-collapse: separate; |
|
62
89b12ef5e190
improve visuals of the new design
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
81 | border-spacing: 2px; |
| 5 | 82 | font-family: sans-serif; |
| 83 | } | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
84 | |
| 5 | 85 | table.heatmap td, table.heatmap th { |
| 86 | text-align: center; | |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
87 | font-size: 0.75rem; |
|
63
9ed068855450
further improve design by tweaking the borders
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
88 | border: solid 4px transparent; |
|
9ed068855450
further improve design by tweaking the borders
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
89 | border-radius: 3px; |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
90 | height: 1rem; |
| 5 | 91 | } |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
92 | |
| 5 | 93 | table.heatmap td { |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
94 | width: 1rem; |
| 5 | 95 | } |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
96 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
97 | table.heatmap td:hover, table.heatmap td.popup-open { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
98 | filter: hue-rotate(90deg); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
99 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
100 | |
| 5 | 101 | table.heatmap td.out-of-range { |
| 102 | background-color: gray; | |
| 103 | } | |
| 7 | 104 | |
| 105 | table.heatmap td.zero-commits { | |
|
62
89b12ef5e190
improve visuals of the new design
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
106 | background-color: #E3E3E3; |
| 7 | 107 | } |
| 108 | ||
| 109 | table.heatmap td.one-commit { | |
| 110 | background-color: #80E7A0; | |
| 111 | } | |
| 112 | ||
| 113 | table.heatmap td.up-to-5-commits { | |
| 114 | background-color: #30D350; | |
| 115 | } | |
| 116 | ||
| 117 | table.heatmap td.up-to-10-commits { | |
| 118 | background-color: #00BF00; | |
| 119 | } | |
| 120 | ||
| 121 | table.heatmap td.up-to-20-commits { | |
| 122 | background-color: #00A300; | |
| 123 | } | |
| 124 | ||
| 125 | table.heatmap td.commit-spam { | |
| 126 | background-color: #008000; | |
| 127 | } | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
128 | |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
129 | table.heatmap td[data-tags]:not([data-tags=""]) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
130 | border-color: gold; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
131 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
132 | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
133 | /* Popup styles */ |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
134 | .commit-popup { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
135 | position: absolute; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
136 | background-color: #fff; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
137 | border: 1px solid #ccc; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
138 | border-radius: 4px; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
139 | box-shadow: 0 2px 10px rgba(0,0,0,0.2); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
140 | padding: .2rem; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
141 | z-index: 1000; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
142 | width: 40ch; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
143 | font-family: sans-serif; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
144 | font-size: smaller; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
145 | display: none; |
|
58
f1093b290fbf
allow long words to break in the commit-popup - fixes #697
Mike Becker <universe@uap-core.de>
parents:
56
diff
changeset
|
146 | word-wrap: break-word; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
147 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
148 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
149 | .commit-popup h3 { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
150 | margin-top: 0; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
151 | border-bottom: 1px solid #eee; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
152 | padding-bottom: 5px; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
153 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
154 | |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
155 | .commit-popup h4 { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
156 | margin-top: .5em; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
157 | margin-bottom: .5em; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
158 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
159 | |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
160 | .commit-popup h5 { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
161 | margin-top: 0; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
162 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
163 | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
164 | .commit-popup ul { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
165 | margin: 0; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
166 | padding-left: 20px; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
167 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
168 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
169 | .commit-popup li { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
170 | margin-bottom: 5px; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
171 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
172 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
173 | .commit-popup .close-btn { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
174 | position: absolute; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
175 | top: 5px; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
176 | right: 8px; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
177 | cursor: pointer; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
178 | font-weight: bold; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
179 | } |
| 5 | 180 | </style> |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
181 | <script> |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
182 | document.addEventListener('DOMContentLoaded', function() { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
183 | // Create popup element |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
184 | const popup = document.createElement('div'); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
185 | popup.className = 'commit-popup'; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
186 | document.body.appendChild(popup); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
187 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
188 | // Add click event listeners to all commit cells |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
189 | const cells = document.querySelectorAll('table.heatmap td:not(.out-of-range, .zero-commits)'); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
190 | cells.forEach(cell => { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
191 | cell.addEventListener('click', function(e) { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
192 | const date = this.dataset.date; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
193 | const summaries = JSON.parse(this.dataset.summaries); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
194 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
195 | // Create popup content |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
196 | let content = '<span class="close-btn">×</span>'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
197 | if (Array.isArray(summaries)) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
198 | content += `<h3>${date}: ${summaries.length} commit${summaries.length !== 1 ? 's' : ''}</h3>`; |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
199 | if (this.dataset.tags) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
200 | content += `<h5>Tags: ${this.dataset.tags}</h5>`; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
201 | } |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
202 | content += '<ul>'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
203 | summaries.forEach(summary => { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
204 | content += `<li>${summary}</li>`; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
205 | }); |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
206 | content += '</ul>'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
207 | } else { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
208 | const repos = Object.keys(summaries).sort(); |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
209 | const tags = this.dataset.tags ? JSON.parse(this.dataset.tags) : {}; |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
210 | let total_commits = 0; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
211 | for (const repo of repos) total_commits += summaries[repo].length; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
212 | content += `<h3>${date}: ${total_commits} commit${total_commits !== 1 ? 's' : ''}</h3>`; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
213 | for (const repo of repos) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
214 | const commits = summaries[repo]; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
215 | if (repos.length > 1) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
216 | content += `<h4>${repo} (${commits.length} commit${commits.length !== 1 ? 's' : ''})</h4>`; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
217 | } else { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
218 | content += `<h4>${repo}</h4>`; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
219 | } |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
220 | if (tags[repo]) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
221 | content += `<h5>Tags: ${tags[repo]}</h5>`; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
222 | } |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
223 | content += '<ul>'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
224 | commits.forEach(commit => { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
225 | content += `<li>${commit}</li>`; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
226 | }); |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
227 | content += '</ul>'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
228 | } |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
229 | } |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
230 | popup.innerHTML = content; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
231 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
232 | // Position popup near the cell |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
233 | const rect = this.getBoundingClientRect(); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
234 | popup.style.left = rect.left + window.scrollX + 'px'; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
235 | popup.style.top = (rect.bottom + window.scrollY + 5) + 'px'; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
236 | popup.style.display = 'block'; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
237 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
238 | // Highlight the cell to which the popup belongs |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
239 | document.querySelectorAll('table.heatmap td.popup-open').forEach(old_cell => { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
240 | old_cell.classList.toggle("popup-open"); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
241 | }); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
242 | cell.classList.toggle("popup-open"); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
243 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
244 | // Add close button handler |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
245 | const closeBtn = popup.querySelector('.close-btn'); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
246 | if (closeBtn) { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
247 | closeBtn.addEventListener('click', function() { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
248 | popup.style.display = 'none'; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
249 | cell.classList.toggle("popup-open"); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
250 | }); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
251 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
252 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
253 | e.stopPropagation(); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
254 | }); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
255 | }); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
256 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
257 | // Close popup when clicking elsewhere |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
258 | document.addEventListener('click', function(e) { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
259 | if (!popup.contains(e.target)) { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
260 | popup.style.display = 'none'; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
261 | document.querySelectorAll('table.heatmap td.popup-open').forEach(cell => { |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
262 | cell.classList.toggle("popup-open"); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
263 | }); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
264 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
265 | }); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
266 | }); |
|
73
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
267 | </script>)"); |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
268 | } |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
269 | |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
270 | void html::open(bool fragment, unsigned char fragment_indent) { |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
271 | if (fragment) { |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
272 | indent(fragment_indent); |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
273 | puts("<div class=\"heatmap-content\">"); |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
274 | indentation++; |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
275 | } else { |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
276 | puts(R"(<!DOCTYPE html> |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
277 | <html> |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
278 | <head> |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
279 | <meta charset="UTF-8">)"); |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
280 | styles_and_script(); |
|
707f42bb0484
add --styles-and-script option to output default CSS and Javascript for page composition
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
281 | puts(R"( </head> |
|
20
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
282 | <body> |
|
41
19cc90878968
fix wrong escape in raw string
Mike Becker <universe@uap-core.de>
parents:
35
diff
changeset
|
283 | <div class="heatmap-content">)"); |
|
20
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
284 | indentation = 3; |
|
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
285 | } |
| 5 | 286 | } |
| 287 | ||
|
20
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
288 | void html::close(bool fragment) { |
|
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
289 | if (fragment) { |
|
52
e9edc3bd0301
add custom fragment indentation
Mike Becker <universe@uap-core.de>
parents:
50
diff
changeset
|
290 | indent(-1); |
|
20
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
291 | puts("</div>"); |
|
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
292 | } else { |
|
22
a9230f197e61
fix inconsistent use of tabs and spaces in indentation
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
293 | puts(" </div>\n </body>\n</html>"); |
|
20
8639ccd855ba
implement --fragment option
Mike Becker <universe@uap-core.de>
parents:
15
diff
changeset
|
294 | } |
| 5 | 295 | } |
| 296 | ||
|
46
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
297 | void html::chart_begin(const std::string& repo, const std::string& author) { |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
298 | indent(); |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
299 | printf("<div class=\"chart\" data-repo=\"%s\" data-author=\"%s\">\n", |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
300 | encode(repo).c_str(), encode(author).c_str()); |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
301 | indentation++; |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
302 | } |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
303 | |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
304 | void html::chart_end() { |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
305 | indent(-1); |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
306 | puts("</div>"); |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
307 | } |
|
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
308 | |
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
309 | void html::heading_repo(const std::string& repo) { |
| 5 | 310 | indent(); |
|
50
1ebab6df60c2
fix mix of positional and non-positional printf specifiers
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
311 | printf("<h1 data-repo=\"%1$s\">%1$s</h1>\n", encode(repo).c_str()); |
| 5 | 312 | } |
| 313 | ||
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
314 | void html::heading_author(const std::string& author, unsigned int total_commits) { |
| 5 | 315 | indent(); |
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
316 | printf("<h2 title=\"Total commits: %u\">%s</h2>\n", |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
317 | total_commits, |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
318 | encode(author).c_str()); |
| 5 | 319 | } |
| 320 | ||
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
321 | void html::table_begin(year y, const std::array<unsigned int, 12> &commits_per_month) { |
|
6
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
322 | static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
323 | // compute the column spans, first |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
324 | unsigned colspans[12] = {}; |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
325 | { |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
326 | unsigned total_cols = 0; |
| 13 | 327 | sys_days day{year_month_day{y, January, 1d}}; |
|
6
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
328 | for (unsigned col = 0; col < 12; ++col) { |
| 13 | 329 | while (total_cols < html::columns && year_month_day{day}.month() <= month{col + 1}) { |
|
6
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
330 | ++total_cols; |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
331 | ++colspans[col]; |
| 13 | 332 | day += days{7}; |
|
6
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
333 | } |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
334 | } |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
335 | } |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
336 | |
|
1040ba37d4c9
improve alignment of month headers
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
337 | // now render the table heading |
| 5 | 338 | indent(); |
| 339 | puts("<table class=\"heatmap\">"); | |
| 340 | indent(1); | |
| 341 | puts("<tr>"); | |
| 342 | indent(1); | |
| 343 | puts("<th></th>"); | |
| 344 | for (unsigned i = 0 ; i < 12 ; i++) { | |
| 345 | indent(); | |
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
346 | printf("<th scope=\"col\" title=\"Total commits: %u\" colspan=\"%d\">%s</th>\n", |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
42
diff
changeset
|
347 | commits_per_month[i], colspans[i], months[i]); |
| 5 | 348 | } |
| 349 | indent(-1); | |
| 350 | puts("</tr>"); | |
| 351 | } | |
| 352 | ||
| 353 | void html::table_end() { | |
|
46
7e099403e5b0
make charts identifiable with a query - fixes #608
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
354 | indent(-1); |
| 5 | 355 | puts("</table>"); |
| 356 | } | |
| 357 | ||
| 358 | void html::row_begin(unsigned int row) { | |
| 359 | indent(); | |
| 360 | puts("<tr>"); | |
| 361 | indent(1); | |
| 362 | printf("<th scope=\"row\">%s</th>\n", weekdays[row]); | |
| 363 | } | |
| 364 | ||
| 365 | void html::row_end() { | |
| 366 | indent(-1); | |
| 367 | puts("</tr>"); | |
| 368 | } | |
| 369 | ||
| 370 | void html::cell_out_of_range() { | |
| 371 | indent(); | |
| 372 | puts("<td class=\"out-of-range\"></td>"); | |
| 373 | } | |
| 374 | ||
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
375 | void html::cell(year_month_day ymd, bool hide_repo_names, const fm::commits &commits) { |
| 7 | 376 | const char *color_class; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
377 | if (commits.count() == 0) { |
| 7 | 378 | color_class = "zero-commits"; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
379 | } else if (commits.count() == 1) { |
| 7 | 380 | color_class = "one-commit"; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
381 | } else if (commits.count() <= 5) { |
| 7 | 382 | color_class = "up-to-5-commits"; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
383 | } else if (commits.count() <= 10) { |
| 7 | 384 | color_class = "up-to-10-commits"; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
385 | } else if (commits.count() <= 20) { |
| 7 | 386 | color_class = "up-to-20-commits"; |
| 387 | } else { | |
| 388 | color_class = "commit-spam"; | |
| 389 | } | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
390 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
391 | |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
392 | // Format date for display |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
393 | char date_str[32]; |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
394 | sprintf(date_str, "%s, %d-%02u-%02u", |
| 13 | 395 | weekdays[weekday(ymd).iso_encoding() - 1], |
| 7 | 396 | static_cast<int>(ymd.year()), |
| 397 | static_cast<unsigned>(ymd.month()), | |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
398 | static_cast<unsigned>(ymd.day())); |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
399 | |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
400 | // Utility function to escape strings in JSON |
|
71
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
401 | auto escape_json = [](std::string raw) static { |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
402 | using std::string_view_literals::operator ""sv; |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
403 | auto replace_all = [](std::string str, char chr, std::string_view repl) static { |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
404 | size_t pos = str.find(chr); |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
405 | if (pos == std::string::npos) return str; |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
406 | std::string result = std::move(str); |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
407 | do { |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
408 | result.replace(pos, 1, repl); |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
409 | pos += repl.length(); |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
410 | } while ((pos = result.find(chr, pos)) != std::string::npos); |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
411 | return result; |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
412 | }; |
|
39644afa3808
fix that backslashes in commit messages were not escaped in the JSON
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
413 | return replace_all(replace_all(std::move(raw), '\\', "\\\\"), '\"', "\\\""sv); |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
414 | }; |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
415 | |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
416 | // Build a JSON object of commit summaries |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
417 | auto add_summaries = [escape_json](std::string &json, const std::vector<std::string> &summaries) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
418 | // We have to iterate in reverse order to sort the summaries chronologically |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
419 | for (const auto &summary : summaries | std::views::reverse) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
420 | json += "\"" + escape_json(summary) + "\","; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
421 | } |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
422 | json.pop_back(); |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
423 | }; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
424 | std::string summaries_json; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
425 | if (hide_repo_names) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
426 | summaries_json += '['; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
427 | for (const auto &summaries: commits.summaries | std::views::values) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
428 | add_summaries(summaries_json, summaries); |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
429 | } |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
430 | summaries_json += ']'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
431 | } else { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
432 | summaries_json += '{'; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
433 | for (const auto &[repo, summaries] : commits.summaries) { |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
434 | summaries_json += "\"" + escape_json(repo) + "\":["; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
435 | add_summaries(summaries_json, summaries); |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
436 | summaries_json += "],"; |
|
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
437 | } |
|
60
9b1cbc665851
fix malformed JSON on days without commits in the combined view
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
438 | if (!commits.summaries.empty()) { |
|
9b1cbc665851
fix malformed JSON on days without commits in the combined view
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
439 | summaries_json.pop_back(); |
|
9b1cbc665851
fix malformed JSON on days without commits in the combined view
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
440 | } |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
441 | summaries_json += '}'; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
442 | } |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
443 | |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
444 | // Build a JSON object of tags |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
445 | std::string tags_json; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
446 | if (hide_repo_names) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
447 | for (const auto &tags_vector: commits.tags | std::views::values) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
448 | for (const auto &tag: tags_vector) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
449 | tags_json += escape_json(tag); |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
450 | tags_json += ' '; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
451 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
452 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
453 | if (!tags_json.empty()) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
454 | tags_json.pop_back(); |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
455 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
456 | } else { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
457 | tags_json += '{'; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
458 | for (const auto &[repo, tags_vector] : commits.tags) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
459 | tags_json += "\"" + escape_json(repo) + "\":\""; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
460 | for (const auto &tag: tags_vector) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
461 | tags_json += escape_json(tag); |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
462 | tags_json += ' '; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
463 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
464 | if (!tags_vector.empty()) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
465 | tags_json.pop_back(); |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
466 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
467 | tags_json += "\","; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
468 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
469 | // note: in contrast to summaries, we want an empty string here when there's nothing to report |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
470 | tags_json.pop_back(); |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
471 | if (!commits.tags.empty()) { |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
472 | tags_json += '}'; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
473 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
474 | } |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
475 | |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
476 | // Output |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
477 | indent(); |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
478 | printf("<td class=\"%s\" title=\"%s: %u %s\" data-date=\"%s\" data-summaries=\"%s\" data-tags=\"%s\"></td>\n", |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
479 | color_class, |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
480 | date_str, |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
481 | commits.count(), |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
482 | commits.count() == 1 ? "commit" : "commits", |
|
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
483 | date_str, |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
484 | encode(summaries_json).c_str(), |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
485 | encode(tags_json).c_str() |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
52
diff
changeset
|
486 | ); |
| 5 | 487 | } |