-rw-r--r-- | ui-shared.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/ui-shared.c b/ui-shared.c index f18b2c7..5e03a7a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -582,112 +582,118 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page) | |||
582 | url = fmt("%s/%s", ctx.qry.repo, page); | 582 | url = fmt("%s/%s", ctx.qry.repo, page); |
583 | if (ctx.qry.path) | 583 | if (ctx.qry.path) |
584 | url = fmt("%s/%s", url, ctx.qry.path); | 584 | url = fmt("%s/%s", url, ctx.qry.path); |
585 | html_hidden("url", url); | 585 | html_hidden("url", url); |
586 | } | 586 | } |
587 | 587 | ||
588 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 588 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
589 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 589 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
590 | html_hidden("h", ctx.qry.head); | 590 | html_hidden("h", ctx.qry.head); |
591 | 591 | ||
592 | if (ctx.qry.sha1) | 592 | if (ctx.qry.sha1) |
593 | html_hidden("id", ctx.qry.sha1); | 593 | html_hidden("id", ctx.qry.sha1); |
594 | if (ctx.qry.sha2) | 594 | if (ctx.qry.sha2) |
595 | html_hidden("id2", ctx.qry.sha2); | 595 | html_hidden("id2", ctx.qry.sha2); |
596 | if (ctx.qry.showmsg) | 596 | if (ctx.qry.showmsg) |
597 | html_hidden("showmsg", "1"); | 597 | html_hidden("showmsg", "1"); |
598 | 598 | ||
599 | if (incl_search) { | 599 | if (incl_search) { |
600 | if (ctx.qry.grep) | 600 | if (ctx.qry.grep) |
601 | html_hidden("qt", ctx.qry.grep); | 601 | html_hidden("qt", ctx.qry.grep); |
602 | if (ctx.qry.search) | 602 | if (ctx.qry.search) |
603 | html_hidden("q", ctx.qry.search); | 603 | html_hidden("q", ctx.qry.search); |
604 | } | 604 | } |
605 | } | 605 | } |
606 | 606 | ||
607 | const char *fallback_cmd = "repolist"; | 607 | const char *fallback_cmd = "repolist"; |
608 | 608 | ||
609 | char *hc(struct cgit_cmd *cmd, const char *page) | 609 | char *hc(struct cgit_cmd *cmd, const char *page) |
610 | { | 610 | { |
611 | return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active"); | 611 | return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active"); |
612 | } | 612 | } |
613 | 613 | ||
614 | void cgit_print_pageheader(struct cgit_context *ctx) | 614 | static void print_header(struct cgit_context *ctx) |
615 | { | 615 | { |
616 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | ||
617 | |||
618 | if (!cmd && ctx->repo) | ||
619 | fallback_cmd = "summary"; | ||
620 | |||
621 | html("<div id='cgit'>"); | ||
622 | html("<table id='header'>\n"); | 616 | html("<table id='header'>\n"); |
623 | html("<tr>\n"); | 617 | html("<tr>\n"); |
624 | html("<td class='logo' rowspan='2'><a href='"); | 618 | html("<td class='logo' rowspan='2'><a href='"); |
625 | if (ctx->cfg.logo_link) | 619 | if (ctx->cfg.logo_link) |
626 | html_attr(ctx->cfg.logo_link); | 620 | html_attr(ctx->cfg.logo_link); |
627 | else | 621 | else |
628 | html_attr(cgit_rooturl()); | 622 | html_attr(cgit_rooturl()); |
629 | html("'><img src='"); | 623 | html("'><img src='"); |
630 | html_attr(ctx->cfg.logo); | 624 | html_attr(ctx->cfg.logo); |
631 | html("' alt='cgit logo'/></a></td>\n"); | 625 | html("' alt='cgit logo'/></a></td>\n"); |
632 | 626 | ||
633 | html("<td class='main'>"); | 627 | html("<td class='main'>"); |
634 | if (ctx->repo) { | 628 | if (ctx->repo) { |
635 | cgit_index_link("index", NULL, NULL, NULL, 0); | 629 | cgit_index_link("index", NULL, NULL, NULL, 0); |
636 | html(" : "); | 630 | html(" : "); |
637 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 631 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
638 | html("</td><td class='form'>"); | 632 | html("</td><td class='form'>"); |
639 | html("<form method='get' action=''>\n"); | 633 | html("<form method='get' action=''>\n"); |
640 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); | 634 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); |
641 | html("<select name='h' onchange='this.form.submit();'>\n"); | 635 | html("<select name='h' onchange='this.form.submit();'>\n"); |
642 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 636 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
643 | html("</select> "); | 637 | html("</select> "); |
644 | html("<input type='submit' name='' value='switch'/>"); | 638 | html("<input type='submit' name='' value='switch'/>"); |
645 | html("</form>"); | 639 | html("</form>"); |
646 | } else | 640 | } else |
647 | html_txt(ctx->cfg.root_title); | 641 | html_txt(ctx->cfg.root_title); |
648 | html("</td></tr>\n"); | 642 | html("</td></tr>\n"); |
649 | 643 | ||
650 | html("<tr><td class='sub'>"); | 644 | html("<tr><td class='sub'>"); |
651 | if (ctx->repo) { | 645 | if (ctx->repo) { |
652 | html_txt(ctx->repo->desc); | 646 | html_txt(ctx->repo->desc); |
653 | html("</td><td class='sub right'>"); | 647 | html("</td><td class='sub right'>"); |
654 | html_txt(ctx->repo->owner); | 648 | html_txt(ctx->repo->owner); |
655 | } else { | 649 | } else { |
656 | if (ctx->cfg.root_desc) | 650 | if (ctx->cfg.root_desc) |
657 | html_txt(ctx->cfg.root_desc); | 651 | html_txt(ctx->cfg.root_desc); |
658 | else if (ctx->cfg.index_info) | 652 | else if (ctx->cfg.index_info) |
659 | html_include(ctx->cfg.index_info); | 653 | html_include(ctx->cfg.index_info); |
660 | } | 654 | } |
661 | html("</td></tr></table>\n"); | 655 | html("</td></tr></table>\n"); |
656 | } | ||
657 | |||
658 | void cgit_print_pageheader(struct cgit_context *ctx) | ||
659 | { | ||
660 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | ||
661 | |||
662 | if (!cmd && ctx->repo) | ||
663 | fallback_cmd = "summary"; | ||
664 | |||
665 | html("<div id='cgit'>"); | ||
666 | if (!ctx->cfg.noheader) | ||
667 | print_header(ctx); | ||
662 | 668 | ||
663 | html("<table class='tabs'><tr><td>\n"); | 669 | html("<table class='tabs'><tr><td>\n"); |
664 | if (ctx->repo) { | 670 | if (ctx->repo) { |
665 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), | 671 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), |
666 | ctx->qry.head); | 672 | ctx->qry.head); |
667 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 673 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
668 | ctx->qry.sha1, NULL); | 674 | ctx->qry.sha1, NULL); |
669 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 675 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
670 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); | 676 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); |
671 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 677 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
672 | ctx->qry.sha1, NULL); | 678 | ctx->qry.sha1, NULL); |
673 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 679 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
674 | ctx->qry.head, ctx->qry.sha1); | 680 | ctx->qry.head, ctx->qry.sha1); |
675 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 681 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
676 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 682 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
677 | if (ctx->repo->max_stats) | 683 | if (ctx->repo->max_stats) |
678 | cgit_stats_link("stats", NULL, hc(cmd, "stats"), | 684 | cgit_stats_link("stats", NULL, hc(cmd, "stats"), |
679 | ctx->qry.head, NULL); | 685 | ctx->qry.head, NULL); |
680 | if (ctx->repo->readme) | 686 | if (ctx->repo->readme) |
681 | reporevlink("about", "about", NULL, | 687 | reporevlink("about", "about", NULL, |
682 | hc(cmd, "about"), ctx->qry.head, NULL, | 688 | hc(cmd, "about"), ctx->qry.head, NULL, |
683 | NULL); | 689 | NULL); |
684 | html("</td><td class='form'>"); | 690 | html("</td><td class='form'>"); |
685 | html("<form class='right' method='get' action='"); | 691 | html("<form class='right' method='get' action='"); |
686 | if (ctx->cfg.virtual_root) | 692 | if (ctx->cfg.virtual_root) |
687 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 693 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
688 | ctx->qry.path, NULL)); | 694 | ctx->qry.path, NULL)); |
689 | html("'>\n"); | 695 | html("'>\n"); |
690 | cgit_add_hidden_formfields(1, 0, "log"); | 696 | cgit_add_hidden_formfields(1, 0, "log"); |
691 | html("<select name='qt'>\n"); | 697 | html("<select name='qt'>\n"); |
692 | html_option("grep", "log msg", ctx->qry.grep); | 698 | html_option("grep", "log msg", ctx->qry.grep); |
693 | html_option("author", "author", ctx->qry.grep); | 699 | html_option("author", "author", ctx->qry.grep); |