Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 1 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 2 | #include "ui-stats.h" |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 3 | #include "html.h" |
| 4 | #include "ui-shared.h" |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 5 | |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 6 | struct authorstat { |
| 7 | long total; |
| 8 | struct string_list list; |
| 9 | }; |
| 10 | |
| 11 | #define DAY_SECS (60 * 60 * 24) |
| 12 | #define WEEK_SECS (DAY_SECS * 7) |
| 13 | |
| 14 | static void trunc_week(struct tm *tm) |
| 15 | { |
| 16 | time_t t = timegm(tm); |
| 17 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 18 | gmtime_r(&t, tm); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | static void dec_week(struct tm *tm) |
| 22 | { |
| 23 | time_t t = timegm(tm); |
| 24 | t -= WEEK_SECS; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 25 | gmtime_r(&t, tm); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | static void inc_week(struct tm *tm) |
| 29 | { |
| 30 | time_t t = timegm(tm); |
| 31 | t += WEEK_SECS; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 32 | gmtime_r(&t, tm); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static char *pretty_week(struct tm *tm) |
| 36 | { |
| 37 | static char buf[10]; |
| 38 | |
| 39 | strftime(buf, sizeof(buf), "W%V %G", tm); |
| 40 | return buf; |
| 41 | } |
| 42 | |
| 43 | static void trunc_month(struct tm *tm) |
| 44 | { |
| 45 | tm->tm_mday = 1; |
| 46 | } |
| 47 | |
| 48 | static void dec_month(struct tm *tm) |
| 49 | { |
| 50 | tm->tm_mon--; |
| 51 | if (tm->tm_mon < 0) { |
| 52 | tm->tm_year--; |
| 53 | tm->tm_mon = 11; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static void inc_month(struct tm *tm) |
| 58 | { |
| 59 | tm->tm_mon++; |
| 60 | if (tm->tm_mon > 11) { |
| 61 | tm->tm_year++; |
| 62 | tm->tm_mon = 0; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | static char *pretty_month(struct tm *tm) |
| 67 | { |
| 68 | static const char *months[] = { |
| 69 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 70 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
| 71 | }; |
| 72 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); |
| 73 | } |
| 74 | |
| 75 | static void trunc_quarter(struct tm *tm) |
| 76 | { |
| 77 | trunc_month(tm); |
Jason A. Donenfeld | bdae1d8 | 2013-03-03 23:21:33 -0500 | [diff] [blame] | 78 | while (tm->tm_mon % 3 != 0) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 79 | dec_month(tm); |
| 80 | } |
| 81 | |
| 82 | static void dec_quarter(struct tm *tm) |
| 83 | { |
| 84 | dec_month(tm); |
| 85 | dec_month(tm); |
| 86 | dec_month(tm); |
| 87 | } |
| 88 | |
| 89 | static void inc_quarter(struct tm *tm) |
| 90 | { |
| 91 | inc_month(tm); |
| 92 | inc_month(tm); |
| 93 | inc_month(tm); |
| 94 | } |
| 95 | |
| 96 | static char *pretty_quarter(struct tm *tm) |
| 97 | { |
| 98 | return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); |
| 99 | } |
| 100 | |
| 101 | static void trunc_year(struct tm *tm) |
| 102 | { |
| 103 | trunc_month(tm); |
| 104 | tm->tm_mon = 0; |
| 105 | } |
| 106 | |
| 107 | static void dec_year(struct tm *tm) |
| 108 | { |
| 109 | tm->tm_year--; |
| 110 | } |
| 111 | |
| 112 | static void inc_year(struct tm *tm) |
| 113 | { |
| 114 | tm->tm_year++; |
| 115 | } |
| 116 | |
| 117 | static char *pretty_year(struct tm *tm) |
| 118 | { |
| 119 | return fmt("%d", tm->tm_year + 1900); |
| 120 | } |
| 121 | |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 122 | static const struct cgit_period periods[] = { |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 123 | {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, |
| 124 | {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, |
| 125 | {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, |
| 126 | {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, |
| 127 | }; |
| 128 | |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 129 | /* Given a period code or name, return a period index (1, 2, 3 or 4) |
| 130 | * and update the period pointer to the correcsponding struct. |
| 131 | * If no matching code is found, return 0. |
| 132 | */ |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 133 | int cgit_find_stats_period(const char *expr, const struct cgit_period **period) |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 134 | { |
| 135 | int i; |
| 136 | char code = '\0'; |
| 137 | |
| 138 | if (!expr) |
| 139 | return 0; |
| 140 | |
| 141 | if (strlen(expr) == 1) |
| 142 | code = expr[0]; |
| 143 | |
| 144 | for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) |
| 145 | if (periods[i].code == code || !strcmp(periods[i].name, expr)) { |
| 146 | if (period) |
| 147 | *period = &periods[i]; |
Lukas Fleischer | 53bc747 | 2013-03-03 16:04:29 +0100 | [diff] [blame] | 148 | return i + 1; |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 149 | } |
| 150 | return 0; |
| 151 | } |
| 152 | |
Lars Hjemli | b47b7bd | 2009-08-24 11:02:48 +0200 | [diff] [blame] | 153 | const char *cgit_find_stats_periodname(int idx) |
| 154 | { |
| 155 | if (idx > 0 && idx < 4) |
| 156 | return periods[idx - 1].name; |
| 157 | else |
| 158 | return ""; |
| 159 | } |
| 160 | |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 161 | static void add_commit(struct string_list *authors, struct commit *commit, |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 162 | const struct cgit_period *period) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 163 | { |
| 164 | struct commitinfo *info; |
| 165 | struct string_list_item *author, *item; |
| 166 | struct authorstat *authorstat; |
| 167 | struct string_list *items; |
| 168 | char *tmp; |
| 169 | struct tm *date; |
| 170 | time_t t; |
Jason A. Donenfeld | a8b9ef8 | 2016-02-08 14:35:47 +0100 | [diff] [blame] | 171 | uintptr_t *counter; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 172 | |
| 173 | info = cgit_parse_commit(commit); |
| 174 | tmp = xstrdup(info->author); |
Lars Hjemli | 6d7552b | 2010-08-22 13:29:57 +0200 | [diff] [blame] | 175 | author = string_list_insert(authors, tmp); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 176 | if (!author->util) |
| 177 | author->util = xcalloc(1, sizeof(struct authorstat)); |
| 178 | else |
| 179 | free(tmp); |
| 180 | authorstat = author->util; |
| 181 | items = &authorstat->list; |
| 182 | t = info->committer_date; |
| 183 | date = gmtime(&t); |
| 184 | period->trunc(date); |
| 185 | tmp = xstrdup(period->pretty(date)); |
Lars Hjemli | 6d7552b | 2010-08-22 13:29:57 +0200 | [diff] [blame] | 186 | item = string_list_insert(items, tmp); |
Jason A. Donenfeld | a8b9ef8 | 2016-02-08 14:35:47 +0100 | [diff] [blame] | 187 | counter = (uintptr_t *)&item->util; |
John Keeping | bdcbe09 | 2016-02-08 14:12:35 +0000 | [diff] [blame] | 188 | if (*counter) |
| 189 | free(tmp); |
Jason A. Donenfeld | a8b9ef8 | 2016-02-08 14:35:47 +0100 | [diff] [blame] | 190 | (*counter)++; |
| 191 | |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 192 | authorstat->total++; |
| 193 | cgit_free_commitinfo(info); |
| 194 | } |
| 195 | |
| 196 | static int cmp_total_commits(const void *a1, const void *a2) |
| 197 | { |
| 198 | const struct string_list_item *i1 = a1; |
| 199 | const struct string_list_item *i2 = a2; |
| 200 | const struct authorstat *auth1 = i1->util; |
| 201 | const struct authorstat *auth2 = i2->util; |
| 202 | |
| 203 | return auth2->total - auth1->total; |
| 204 | } |
| 205 | |
| 206 | /* Walk the commit DAG and collect number of commits per author per |
| 207 | * timeperiod into a nested string_list collection. |
| 208 | */ |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 209 | static struct string_list collect_stats(const struct cgit_period *period) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 210 | { |
| 211 | struct string_list authors; |
| 212 | struct rev_info rev; |
| 213 | struct commit *commit; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 214 | const char *argv[] = {NULL, ctx.qry.head, NULL, NULL, NULL, NULL}; |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 215 | int argc = 3; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 216 | time_t now; |
| 217 | long i; |
| 218 | struct tm *tm; |
| 219 | char tmp[11]; |
| 220 | |
| 221 | time(&now); |
| 222 | tm = gmtime(&now); |
| 223 | period->trunc(tm); |
| 224 | for (i = 1; i < period->count; i++) |
| 225 | period->dec(tm); |
| 226 | strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); |
| 227 | argv[2] = xstrdup(fmt("--since=%s", tmp)); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 228 | if (ctx.qry.path) { |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 229 | argv[3] = "--"; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 230 | argv[4] = ctx.qry.path; |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 231 | argc += 2; |
| 232 | } |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 233 | init_revisions(&rev, NULL); |
| 234 | rev.abbrev = DEFAULT_ABBREV; |
| 235 | rev.commit_format = CMIT_FMT_DEFAULT; |
John Keeping | bfc14d0 | 2013-03-02 12:32:10 +0000 | [diff] [blame] | 236 | rev.max_parents = 1; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 237 | rev.verbose_header = 1; |
| 238 | rev.show_root_diff = 0; |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 239 | setup_revisions(argc, argv, &rev, NULL); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 240 | prepare_revision_walk(&rev); |
| 241 | memset(&authors, 0, sizeof(authors)); |
| 242 | while ((commit = get_revision(&rev)) != NULL) { |
| 243 | add_commit(&authors, commit, period); |
John Keeping | 865afe0 | 2014-07-27 11:56:19 +0100 | [diff] [blame] | 244 | free_commit_buffer(commit); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 245 | free_commit_list(commit->parents); |
John Keeping | 2eea471 | 2014-07-27 11:56:20 +0100 | [diff] [blame] | 246 | commit->parents = NULL; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 247 | } |
| 248 | return authors; |
| 249 | } |
| 250 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 251 | static void print_combined_authorrow(struct string_list *authors, int from, |
| 252 | int to, const char *name, |
| 253 | const char *leftclass, |
| 254 | const char *centerclass, |
| 255 | const char *rightclass, |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 256 | const struct cgit_period *period) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 257 | { |
| 258 | struct string_list_item *author; |
| 259 | struct authorstat *authorstat; |
| 260 | struct string_list *items; |
| 261 | struct string_list_item *date; |
| 262 | time_t now; |
| 263 | long i, j, total, subtotal; |
| 264 | struct tm *tm; |
| 265 | char *tmp; |
| 266 | |
| 267 | time(&now); |
| 268 | tm = gmtime(&now); |
| 269 | period->trunc(tm); |
| 270 | for (i = 1; i < period->count; i++) |
| 271 | period->dec(tm); |
| 272 | |
| 273 | total = 0; |
| 274 | htmlf("<tr><td class='%s'>%s</td>", leftclass, |
| 275 | fmt(name, to - from + 1)); |
| 276 | for (j = 0; j < period->count; j++) { |
| 277 | tmp = period->pretty(tm); |
| 278 | period->inc(tm); |
| 279 | subtotal = 0; |
| 280 | for (i = from; i <= to; i++) { |
| 281 | author = &authors->items[i]; |
| 282 | authorstat = author->util; |
| 283 | items = &authorstat->list; |
Lars Hjemli | 6d7552b | 2010-08-22 13:29:57 +0200 | [diff] [blame] | 284 | date = string_list_lookup(items, tmp); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 285 | if (date) |
Jason A. Donenfeld | a8b9ef8 | 2016-02-08 14:35:47 +0100 | [diff] [blame] | 286 | subtotal += (uintptr_t)date->util; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 287 | } |
Mark Lodato | e4ddc8f | 2010-09-04 11:30:18 -0400 | [diff] [blame] | 288 | htmlf("<td class='%s'>%ld</td>", centerclass, subtotal); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 289 | total += subtotal; |
| 290 | } |
Mark Lodato | e4ddc8f | 2010-09-04 11:30:18 -0400 | [diff] [blame] | 291 | htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Lukas Fleischer | bafab42 | 2013-03-04 08:52:33 +0100 | [diff] [blame] | 294 | static void print_authors(struct string_list *authors, int top, |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 295 | const struct cgit_period *period) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 296 | { |
| 297 | struct string_list_item *author; |
| 298 | struct authorstat *authorstat; |
| 299 | struct string_list *items; |
| 300 | struct string_list_item *date; |
| 301 | time_t now; |
| 302 | long i, j, total; |
| 303 | struct tm *tm; |
| 304 | char *tmp; |
| 305 | |
| 306 | time(&now); |
| 307 | tm = gmtime(&now); |
| 308 | period->trunc(tm); |
| 309 | for (i = 1; i < period->count; i++) |
| 310 | period->dec(tm); |
| 311 | |
| 312 | html("<table class='stats'><tr><th>Author</th>"); |
| 313 | for (j = 0; j < period->count; j++) { |
| 314 | tmp = period->pretty(tm); |
| 315 | htmlf("<th>%s</th>", tmp); |
| 316 | period->inc(tm); |
| 317 | } |
| 318 | html("<th>Total</th></tr>\n"); |
| 319 | |
| 320 | if (top <= 0 || top > authors->nr) |
| 321 | top = authors->nr; |
| 322 | |
| 323 | for (i = 0; i < top; i++) { |
| 324 | author = &authors->items[i]; |
| 325 | html("<tr><td class='left'>"); |
| 326 | html_txt(author->string); |
| 327 | html("</td>"); |
| 328 | authorstat = author->util; |
| 329 | items = &authorstat->list; |
| 330 | total = 0; |
| 331 | for (j = 0; j < period->count; j++) |
| 332 | period->dec(tm); |
| 333 | for (j = 0; j < period->count; j++) { |
| 334 | tmp = period->pretty(tm); |
| 335 | period->inc(tm); |
Lars Hjemli | 6d7552b | 2010-08-22 13:29:57 +0200 | [diff] [blame] | 336 | date = string_list_lookup(items, tmp); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 337 | if (!date) |
| 338 | html("<td>0</td>"); |
| 339 | else { |
Jason A. Donenfeld | a8b9ef8 | 2016-02-08 14:35:47 +0100 | [diff] [blame] | 340 | htmlf("<td>%lu</td>", (uintptr_t)date->util); |
| 341 | total += (uintptr_t)date->util; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 342 | } |
| 343 | } |
Mark Lodato | e4ddc8f | 2010-09-04 11:30:18 -0400 | [diff] [blame] | 344 | htmlf("<td class='sum'>%ld</td></tr>", total); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | if (top < authors->nr) |
| 348 | print_combined_authorrow(authors, top, authors->nr - 1, |
Mark Lodato | e4ddc8f | 2010-09-04 11:30:18 -0400 | [diff] [blame] | 349 | "Others (%ld)", "left", "", "sum", period); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 350 | |
| 351 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", |
| 352 | "total", "sum", "sum", period); |
| 353 | html("</table>"); |
| 354 | } |
| 355 | |
| 356 | /* Create a sorted string_list with one entry per author. The util-field |
| 357 | * for each author is another string_list which is used to calculate the |
| 358 | * number of commits per time-interval. |
| 359 | */ |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 360 | void cgit_show_stats(void) |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 361 | { |
| 362 | struct string_list authors; |
John Keeping | bd9fb03 | 2015-03-08 16:32:23 +0000 | [diff] [blame] | 363 | const struct cgit_period *period; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 364 | int top, i; |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 365 | const char *code = "w"; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 366 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 367 | if (ctx.qry.period) |
| 368 | code = ctx.qry.period; |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 369 | |
| 370 | i = cgit_find_stats_period(code, &period); |
| 371 | if (!i) { |
John Keeping | 892c544 | 2015-08-14 12:47:17 +0100 | [diff] [blame] | 372 | cgit_print_error_page(404, "Not found", |
| 373 | "Unknown statistics type: %c", code[0]); |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 374 | return; |
| 375 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 376 | if (i > ctx.repo->max_stats) { |
John Keeping | 892c544 | 2015-08-14 12:47:17 +0100 | [diff] [blame] | 377 | cgit_print_error_page(400, "Bad request", |
| 378 | "Statistics type disabled: %s", period->name); |
Lars Hjemli | fb2f3f6 | 2008-12-07 13:17:21 +0100 | [diff] [blame] | 379 | return; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 380 | } |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 381 | authors = collect_stats(period); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 382 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), |
| 383 | cmp_total_commits); |
| 384 | |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 385 | top = ctx.qry.ofs; |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 386 | if (!top) |
| 387 | top = 10; |
Lars Hjemli | 1b5c336 | 2011-03-07 00:00:24 +0100 | [diff] [blame] | 388 | |
John Keeping | 892c544 | 2015-08-14 12:47:17 +0100 | [diff] [blame] | 389 | cgit_print_layout_start(); |
Lars Hjemli | 1b5c336 | 2011-03-07 00:00:24 +0100 | [diff] [blame] | 390 | html("<div class='cgit-panel'>"); |
| 391 | html("<b>stat options</b>"); |
| 392 | html("<form method='get' action=''>"); |
| 393 | cgit_add_hidden_formfields(1, 0, "stats"); |
| 394 | html("<table><tr><td colspan='2'/></tr>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 395 | if (ctx.repo->max_stats > 1) { |
Lars Hjemli | 1b5c336 | 2011-03-07 00:00:24 +0100 | [diff] [blame] | 396 | html("<tr><td class='label'>Period:</td>"); |
| 397 | html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 398 | for (i = 0; i < ctx.repo->max_stats; i++) |
Lars Hjemli | 1b5c336 | 2011-03-07 00:00:24 +0100 | [diff] [blame] | 399 | html_option(fmt("%c", periods[i].code), |
| 400 | periods[i].name, fmt("%c", period->code)); |
| 401 | html("</select></td></tr>"); |
| 402 | } |
| 403 | html("<tr><td class='label'>Authors:</td>"); |
| 404 | html("<td class='ctrl'><select name='ofs' onchange='this.form.submit();'>"); |
| 405 | html_intoption(10, "10", top); |
| 406 | html_intoption(25, "25", top); |
| 407 | html_intoption(50, "50", top); |
| 408 | html_intoption(100, "100", top); |
| 409 | html_intoption(-1, "all", top); |
Lars Hjemli | 9acd1cf | 2011-05-30 22:21:22 +0000 | [diff] [blame] | 410 | html("</select></td></tr>"); |
Lars Hjemli | 1b5c336 | 2011-03-07 00:00:24 +0100 | [diff] [blame] | 411 | html("<tr><td/><td class='ctrl'>"); |
| 412 | html("<noscript><input type='submit' value='Reload'/></noscript>"); |
| 413 | html("</td></tr></table>"); |
| 414 | html("</form>"); |
| 415 | html("</div>"); |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 416 | htmlf("<h2>Commits per author per %s", period->name); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 417 | if (ctx.qry.path) { |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 418 | html(" (path '"); |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 419 | html_txt(ctx.qry.path); |
Lars Hjemli | c6a6aa2 | 2008-12-07 11:45:28 +0100 | [diff] [blame] | 420 | html("')"); |
| 421 | } |
| 422 | html("</h2>"); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 423 | print_authors(&authors, top, period); |
John Keeping | 892c544 | 2015-08-14 12:47:17 +0100 | [diff] [blame] | 424 | cgit_print_layout_end(); |
Lars Hjemli | f86a23f | 2008-12-06 17:38:19 +0100 | [diff] [blame] | 425 | } |
| 426 | |