summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c154
1 files changed, 86 insertions, 68 deletions
diff --git a/ui-shared.c b/ui-shared.c
index aa65988..bb08c4a 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -4,12 +4,13 @@
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cmd.h"
10#include "html.h" 11#include "html.h"
11 12
12const char cgit_doctype[] = 13const char cgit_doctype[] =
13"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
14" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
15 16
@@ -385,13 +386,13 @@ void cgit_print_docstart(struct cgit_context *ctx)
385 html("</head>\n"); 386 html("</head>\n");
386 html("<body>\n"); 387 html("<body>\n");
387} 388}
388 389
389void cgit_print_docend() 390void cgit_print_docend()
390{ 391{
391 html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); 392 html("</div>\n</body>\n</html>\n");
392} 393}
393 394
394int print_branch_option(const char *refname, const unsigned char *sha1, 395int print_branch_option(const char *refname, const unsigned char *sha1,
395 int flags, void *cb_data) 396 int flags, void *cb_data)
396{ 397{
397 char *name = (char *)refname; 398 char *name = (char *)refname;
@@ -462,103 +463,120 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
462 html_hidden("qt", ctx.qry.grep); 463 html_hidden("qt", ctx.qry.grep);
463 if (ctx.qry.search) 464 if (ctx.qry.search)
464 html_hidden("q", ctx.qry.search); 465 html_hidden("q", ctx.qry.search);
465 } 466 }
466} 467}
467 468
469char *hc(struct cgit_cmd *cmd, const char *page)
470{
471 return (strcmp(cmd->name, page) ? NULL : "active");
472}
473
468void cgit_print_pageheader(struct cgit_context *ctx) 474void cgit_print_pageheader(struct cgit_context *ctx)
469{ 475{
470 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 476 struct cgit_cmd *cmd = cgit_get_cmd(ctx);
471 int header = 0;
472 char *url;
473 477
474 html("<table id='layout' summary=''>\n"); 478 html("<table id='header'>\n");
475 html("<tr><td id='sidebar'>\n"); 479 html("<tr>\n");
476 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 480 html("<td class='logo' rowspan='2'><a href='");
477 html("<tr><td class='sidebar'>\n<a href='"); 481 if (ctx->cfg.logo_link)
478 html_attr(cgit_rooturl()); 482 html_attr(ctx->cfg.logo_link);
479 htmlf("'><img src='%s' alt='cgit'/></a>\n", 483 else
480 ctx->cfg.logo); 484 html_attr(cgit_rooturl());
481 html("</td></tr>\n<tr><td class='sidebar'>\n"); 485 html("'><img src='");
482 if (ctx->repo) { 486 html_attr(ctx->cfg.logo);
483 html("<h1 class='first'>"); 487 html("'/></a></td>\n");
484 html_txt(strrpart(ctx->repo->name, 20));
485 html("</h1>\n");
486 html_txt(ctx->repo->desc);
487 if (ctx->repo->owner) {
488 html("<h1>owner</h1>\n");
489 html_txt(ctx->repo->owner);
490 }
491 html("<h1>navigate</h1>\n");
492 reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head,
493 NULL, NULL);
494 cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL,
495 0, NULL, NULL);
496 cgit_tree_link("tree", NULL, "menu", ctx->qry.head,
497 ctx->qry.sha1, NULL);
498 cgit_commit_link("commit", NULL, "menu", ctx->qry.head,
499 ctx->qry.sha1);
500 cgit_diff_link("diff", NULL, "menu", ctx->qry.head,
501 ctx->qry.sha1, ctx->qry.sha2, NULL);
502 cgit_patch_link("patch", NULL, "menu", ctx->qry.head,
503 ctx->qry.sha1);
504
505 for_each_ref(print_archive_ref, &header);
506
507 if (ctx->repo->clone_url || ctx->cfg.clone_prefix) {
508 html("<h1>clone</h1>\n");
509 if (ctx->repo->clone_url)
510 url = ctx->repo->clone_url;
511 else
512 url = fmt("%s%s", ctx->cfg.clone_prefix,
513 ctx->repo->url);
514 html("<a class='menu' href='");
515 html_attr(url);
516 html("' title='");
517 html_attr(url);
518 html("'>\n");
519 html_txt(strrpart(url, 20));
520 html("</a>\n");
521 }
522 488
523 html("<h1>branch</h1>\n"); 489 html("<td class='main'>");
490 if (ctx->repo) {
491/*
492 html("<a href='");
493 html_attr(cgit_rooturl());
494 html("'>index</a> : ");
495*/
496 reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"),
497 ctx->qry.head, NULL, NULL);
498 html(" : ");
499 html_txt(ctx->qry.page);
500 html("</td><td class='form'>");
524 html("<form method='get' action=''>\n"); 501 html("<form method='get' action=''>\n");
525 add_hidden_formfields(0, 1, ctx->qry.page); 502 add_hidden_formfields(0, 1, ctx->qry.page);
526 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
527 html("<select name='h' onchange='this.form.submit();'>\n"); 503 html("<select name='h' onchange='this.form.submit();'>\n");
528 for_each_branch_ref(print_branch_option, ctx->qry.head); 504 for_each_branch_ref(print_branch_option, ctx->qry.head);
529 html("</select>\n"); 505 html("</select> ");
530 // html("</td><td>"); 506 html("<input type='submit' name='' value='switch'/>");
531 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 507 html("</form>");
532 // html("</td></tr></table>"); 508 } else
533 html("</form>\n"); 509 html_txt(ctx->cfg.root_title);
510 html("</td>\n");
511
512 html("<tr><td class='sub'");
513 if (ctx->repo) {
514 html(" colspan='2'>");
515 html_txt(ctx->repo->desc);
516 }
517/*
518 else if (ctx->cfg.root_subtitle)
519 html_txt(ctx->cfg.root_subtitle);
520*/
521 else {
522 html(">");
523 html_txt("a fast webinterface for the git dscm");
524 }
525 html("</td></tr>\n");
534 526
535 html("<h1>search</h1>\n"); 527 html("</tr>\n");
536 html("<form method='get' action='"); 528 html("</table>\n");
529
530 html("<table class='tabs'><tr><td>\n");
531 if (ctx->repo) {
532 reporevlink(NULL, "summary", NULL, hc(cmd, "summary"),
533 ctx->qry.head, NULL, NULL);
534 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
535 ctx->qry.sha1, NULL);
536 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
537 NULL, NULL, 0, NULL, NULL);
538 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
539 ctx->qry.sha1, NULL);
540 cgit_commit_link("commit", NULL, hc(cmd, "commit"),
541 ctx->qry.head, ctx->qry.sha1);
542 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
543 ctx->qry.sha1, ctx->qry.sha2, NULL);
544 html("</td><td class='form'>");
545 html("<form class='right' method='get' action='");
537 if (ctx->cfg.virtual_root) 546 if (ctx->cfg.virtual_root)
538 html_attr(cgit_fileurl(ctx->qry.repo, "log", 547 html_attr(cgit_fileurl(ctx->qry.repo, "log",
539 ctx->qry.path, NULL)); 548 ctx->qry.path, NULL));
540 html("'>\n"); 549 html("'>\n");
541 add_hidden_formfields(1, 0, "log"); 550 add_hidden_formfields(1, 0, "log");
542 html("<select name='qt'>\n"); 551 html("<select name='qt'>\n");
543 html_option("grep", "log msg", ctx->qry.grep); 552 html_option("grep", "log msg", ctx->qry.grep);
544 html_option("author", "author", ctx->qry.grep); 553 html_option("author", "author", ctx->qry.grep);
545 html_option("committer", "committer", ctx->qry.grep); 554 html_option("committer", "committer", ctx->qry.grep);
546 html("</select>\n"); 555 html("</select>\n");
547 html("<input class='txt' type='text' name='q' value='"); 556 html("<input class='txt' type='text' size='10' name='q' value='");
548 html_attr(ctx->qry.search); 557 html_attr(ctx->qry.search);
549 html("'/>\n"); 558 html("'/>\n");
559 html("<input type='submit' value='search'/>\n");
550 html("</form>\n"); 560 html("</form>\n");
551 } else { 561 } else {
552 if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info)) 562 html("<a class='active' href='");
553 html(default_info); 563 html_attr(cgit_rooturl());
564 html("'>index</a>\n");
565 html("</td><td class='form'>");
566 html("<form method='get' action='");
567 html_attr(cgit_rooturl());
568 html("'>\n");
569 html("<input type='text' name='q' size='10' value='");
570 html_attr(ctx->qry.search);
571 html("'/>\n");
572 html("<input type='submit' value='search'/>\n");
573 html("</form>");
554 } 574 }
555 575 html("</td></tr></table>\n");
556 html("</td></tr></table></td>\n"); 576 html("<div class='content'>");
557
558 html("<td id='content'>\n");
559} 577}
560 578
561void cgit_print_filemode(unsigned short mode) 579void cgit_print_filemode(unsigned short mode)
562{ 580{
563 if (S_ISDIR(mode)) 581 if (S_ISDIR(mode))
564 html("d"); 582 html("d");