diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Give every summary section the same columns
The ref rows always spanned five columns and the log three to five, so
with the default config the log and clone rows stopped 160px short of
the table's edge, and with any config the log rows did on a phone,
where they alone lost their counts. A column no cell began in also
made the summary and refs pages invalid HTML.
Diffstat (limited to 'source/ui-refs.c')
| -rw-r--r-- | source/ui-refs.c | 64 |
1 file changed, 38 insertions, 26 deletions
diff --git a/source/ui-refs.c b/source/ui-refs.c index 38a5773..c8e8f3f 100644 --- a/source/ui-refs.c +++ b/source/ui-refs.c @@ -76,18 +76,30 @@ static void collect_branches(struct reflist *list) refs_for_each_remote_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); } -static void print_branch_header(void) +/* + * The age is the last cell of a ref row, so in a table wider than a ref row + * needs, as on a summary whose log shows counts, it stretches across the + * columns left over. + */ +static const char *age_colspan(int columns) +{ + if (columns <= REF_COLUMNS) + return ""; + return cgit_fmt(" colspan='%d'", columns - REF_COLUMNS + 1); +} + +static void print_branch_header(int columns) { html( "<tbody class='branches'>\n" "<tr class='nohover'><th class='left' scope='col'>Branch</th>" "<th class='left' scope='col'>Commit message</th>" "<th class='left col-author' scope='col'>Author</th>" - "<th colspan='2' class='left' scope='col'>Age</th></tr>\n" ); + htmlf("<th%s class='left' scope='col'>Age</th></tr>\n", age_colspan(columns)); } -static int print_branch(struct refinfo *ref) +static int print_branch(struct refinfo *ref, int columns) { struct commitinfo *info = ref->commit; const char *name = ref->refname; @@ -107,13 +119,13 @@ static int print_branch(struct refinfo *ref) ); html_txt(info->author); cgit_close_filter(ctx.repo->email_filter); - html("</td><td colspan='2'>"); + htmlf("</td><td%s>", age_colspan(columns)); cgit_print_age(info->committer_date, info->committer_tz, -1); } else { // The object link sits in the message column, and the empty // tail cells keep the row as wide as the header. cgit_object_link(ref->object, 0); - html("</td><td class='col-author'></td><td colspan='2'>"); + htmlf("</td><td class='col-author'></td><td%s>", age_colspan(columns)); } html("</td></tr>\n"); return 0; @@ -126,18 +138,18 @@ static void collect_tags(struct reflist *list) refs_for_each_tag_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); } -static void print_tag_header(void) +static void print_tag_header(int columns) { html( "<tbody class='tags'>\n" "<tr class='nohover'><th class='left' scope='col'>Tag</th>" "<th class='left' scope='col'>Download</th>" "<th class='left col-author' scope='col'>Author</th>" - "<th colspan='2' class='left' scope='col'>Age</th></tr>\n" ); + htmlf("<th%s class='left' scope='col'>Age</th></tr>\n", age_colspan(columns)); } -static int print_tag(struct refinfo *ref) +static int print_tag(struct refinfo *ref, int columns) { struct taginfo *info = NULL; const char *name = ref->refname; @@ -176,7 +188,7 @@ static int print_tag(struct refinfo *ref) html_txt(ref->commit->author); cgit_close_filter(ctx.repo->email_filter); } - html("</td><td colspan='2'>"); + htmlf("</td><td%s>", age_colspan(columns)); if (info) { if (info->tagger_date > 0) cgit_print_age(info->tagger_date, info->tagger_tz, -1); @@ -188,9 +200,9 @@ static int print_tag(struct refinfo *ref) return 0; } -static void print_refs_link(const char *path) +static void print_refs_link(const char *path, int columns) { - html("<tr class='nohover'><td colspan='5'>"); + htmlf("<tr class='nohover'><td colspan='%d'>", columns); cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); html("</td></tr>\n"); } @@ -199,7 +211,7 @@ static void print_ref_pager(int ofs, int pagesize, int count, const char *path) { char *url; - html("<tr class='nohover'><td colspan='5' class='refs-pager'>"); + htmlf("<tr class='nohover'><td colspan='%d' class='refs-pager'>", REF_COLUMNS); if (ofs > 0) { int prev_ofs = ofs > pagesize ? ofs - pagesize : 0; @@ -243,7 +255,7 @@ static void print_branches_page(int pagesize) struct ref_page page; int i; - print_branch_header(); + print_branch_header(REF_COLUMNS); collect_branches(&list); cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_date); @@ -253,7 +265,7 @@ static void print_branches_page(int pagesize) page = page_bounds(pagesize, list.count); for (i = page.start; i < page.end; i++) - print_branch(list.refs[i]); + print_branch(list.refs[i], REF_COLUMNS); if (page.size < list.count) print_ref_pager(page.start, page.size, list.count, "heads"); @@ -275,9 +287,9 @@ static void print_tags_page(int pagesize) page = page_bounds(pagesize, list.count); - print_tag_header(); + print_tag_header(REF_COLUMNS); for (i = page.start; i < page.end; i++) - print_tag(list.refs[i]); + print_tag(list.refs[i], REF_COLUMNS); if (page.size < list.count) print_ref_pager(page.start, page.size, list.count, "tags"); @@ -286,12 +298,12 @@ static void print_tags_page(int pagesize) cgit_free_reflist_inner(&list); } -void cgit_print_branches(int maxcount) +void cgit_print_branches(int maxcount, int columns) { struct reflist list; int i; - print_branch_header(); + print_branch_header(columns); collect_branches(&list); if (maxcount <= 0 || maxcount > list.count) @@ -305,16 +317,16 @@ void cgit_print_branches(int maxcount) cgit_qsort(list.refs, maxcount, sizeof(*list.refs), cmp_name); for (i = 0; i < maxcount; i++) - print_branch(list.refs[i]); + print_branch(list.refs[i], columns); if (maxcount < list.count) - print_refs_link("heads"); + print_refs_link("heads", columns); html("</tbody>\n"); cgit_free_reflist_inner(&list); } -void cgit_print_tags(int maxcount) +void cgit_print_tags(int maxcount, int columns) { struct reflist list; int i; @@ -325,12 +337,12 @@ void cgit_print_tags(int maxcount) cgit_qsort(list.refs, list.count, sizeof(*list.refs), cmp_date); if (maxcount <= 0 || maxcount > list.count) maxcount = list.count; - print_tag_header(); + print_tag_header(columns); for (i = 0; i < maxcount; i++) - print_tag(list.refs[i]); + print_tag(list.refs[i], columns); if (maxcount < list.count) - print_refs_link("tags"); + print_refs_link("tags", columns); html("</tbody>\n"); cgit_free_reflist_inner(&list); @@ -346,8 +358,8 @@ void cgit_print_refs(void) } else if (ctx.qry.path && starts_with(ctx.qry.path, "tags")) { print_tags_page(ctx.cfg.max_ref_count); } else { - cgit_print_branches(ctx.cfg.max_ref_count); - cgit_print_tags(ctx.cfg.max_ref_count); + cgit_print_branches(ctx.cfg.max_ref_count, REF_COLUMNS); + cgit_print_tags(ctx.cfg.max_ref_count, REF_COLUMNS); } html("</table>\n"); cgit_print_layout_end(); |
