-rw-r--r-- | ui-shared.c | 166 |
1 files changed, 119 insertions, 47 deletions
diff --git a/ui-shared.c b/ui-shared.c index 1418010..1d66940 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -364,48 +364,54 @@ void cgit_print_docend() | |||
364 | { | 364 | { |
365 | html("</td></tr></table>"); | 365 | html("</td>\n</tr>\n<table>\n</body>\n</html>\n"); |
366 | html("</body>\n</html>\n"); | ||
367 | } | 366 | } |
368 | 367 | ||
369 | void cgit_print_pageheader(char *title, int show_search) | 368 | int print_branch_option(const char *refname, const unsigned char *sha1, |
369 | int flags, void *cb_data) | ||
370 | { | 370 | { |
371 | html("<table id='layout'>"); | 371 | char *name = (char *)refname; |
372 | html("<tr><td id='header'><a href='"); | 372 | html_option(name, name, cgit_query_head); |
373 | html_attr(cgit_rooturl()); | 373 | return 0; |
374 | html("'>"); | 374 | } |
375 | html_txt(cgit_root_title); | 375 | |
376 | html("</a></td><td id='logo'>"); | 376 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
377 | html("<a href='"); | 377 | int flags, void *cb_data) |
378 | html_attr(cgit_logo_link); | 378 | { |
379 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 379 | struct tag *tag; |
380 | html("</td></tr>"); | 380 | struct taginfo *info; |
381 | html("<tr><td id='crumb'>"); | 381 | struct object *obj; |
382 | if (cgit_query_repo) { | 382 | char buf[256], *url; |
383 | html_txt(cgit_repo->name); | 383 | unsigned char fileid[20]; |
384 | html(" ("); | 384 | int *header = (int *)cb_data; |
385 | html_txt(cgit_query_head); | 385 | |
386 | html(") : "); | 386 | if (prefixcmp(refname, "refs/archives")) |
387 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, | 387 | return 0; |
388 | NULL, NULL); | 388 | strncpy(buf, refname+14, sizeof(buf)); |
389 | html(" "); | 389 | obj = parse_object(sha1); |
390 | cgit_log_link("log", NULL, NULL, cgit_query_head, | 390 | if (!obj) |
391 | cgit_query_sha1, cgit_query_path, 0); | 391 | return 1; |
392 | html(" "); | 392 | if (obj->type == OBJ_TAG) { |
393 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, | 393 | tag = lookup_tag(sha1); |
394 | cgit_query_sha1, NULL); | 394 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
395 | html(" "); | 395 | return 0; |
396 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, | 396 | hashcpy(fileid, tag->tagged->sha1); |
397 | cgit_query_sha1); | 397 | } else if (obj->type != OBJ_BLOB) { |
398 | html(" "); | 398 | return 0; |
399 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, | ||
400 | cgit_query_sha1, cgit_query_sha2, | ||
401 | cgit_query_path); | ||
402 | } else { | 399 | } else { |
403 | html_txt("Index of repositories"); | 400 | hashcpy(fileid, sha1); |
404 | } | 401 | } |
405 | html("</td>"); | 402 | if (!*header) { |
406 | html("<td id='search'>"); | 403 | html("<p><h1>download</h1>"); |
407 | if (show_search) { | 404 | *header = 1; |
408 | html("<form method='get' action='"); | 405 | } |
409 | html_attr(cgit_currurl()); | 406 | url = cgit_pageurl(cgit_query_repo, "blob", |
410 | html("'>"); | 407 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
408 | buf)); | ||
409 | html_link_open(url, NULL, "menu"); | ||
410 | html_txt(strlpart(buf, 20)); | ||
411 | html_link_close(); | ||
412 | return 0; | ||
413 | } | ||
414 | |||
415 | void add_hidden_formfields(int incl_head, int incl_search) | ||
416 | { | ||
411 | if (!cgit_virtual_root) { | 417 | if (!cgit_virtual_root) { |
@@ -416,4 +422,6 @@ void cgit_print_pageheader(char *title, int show_search) | |||
416 | } | 422 | } |
417 | if (cgit_query_head) | 423 | |
424 | if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) | ||
418 | html_hidden("h", cgit_query_head); | 425 | html_hidden("h", cgit_query_head); |
426 | |||
419 | if (cgit_query_sha1) | 427 | if (cgit_query_sha1) |
@@ -422,3 +430,60 @@ void cgit_print_pageheader(char *title, int show_search) | |||
422 | html_hidden("id2", cgit_query_sha2); | 430 | html_hidden("id2", cgit_query_sha2); |
423 | html("<select name='qt'>"); | 431 | |
432 | if (incl_search) { | ||
433 | if (cgit_query_grep) | ||
434 | html_hidden("qt", cgit_query_grep); | ||
435 | if (cgit_query_search) | ||
436 | html_hidden("q", cgit_query_search); | ||
437 | } | ||
438 | } | ||
439 | |||
440 | void cgit_print_pageheader(char *title, int show_search) | ||
441 | { | ||
442 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | ||
443 | int header = 0; | ||
444 | |||
445 | html("<div id='sidebar'>\n"); | ||
446 | html("<a href='"); | ||
447 | html_attr(cgit_rooturl()); | ||
448 | htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", | ||
449 | cgit_logo); | ||
450 | html("<div class='infobox'>"); | ||
451 | if (cgit_query_repo) { | ||
452 | html("<h1>"); | ||
453 | html_txt(strrpart(cgit_repo->name, 20)); | ||
454 | html("</h1>\n"); | ||
455 | html_txt(cgit_repo->desc); | ||
456 | if (cgit_repo->owner) { | ||
457 | html("<p>\n<h1>owner</h1>\n"); | ||
458 | html_txt(cgit_repo->owner); | ||
459 | } | ||
460 | html("<p>\n<h1>navigate</h1>\n"); | ||
461 | reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, | ||
462 | NULL, NULL); | ||
463 | cgit_log_link("log", NULL, "menu", cgit_query_head, | ||
464 | cgit_query_sha1, cgit_query_path, 0); | ||
465 | cgit_tree_link("tree", NULL, "menu", cgit_query_head, | ||
466 | cgit_query_sha1, NULL); | ||
467 | cgit_commit_link("commit", NULL, "menu", cgit_query_head, | ||
468 | cgit_query_sha1); | ||
469 | cgit_diff_link("diff", NULL, "menu", cgit_query_head, | ||
470 | cgit_query_sha1, cgit_query_sha2, | ||
471 | cgit_query_path); | ||
472 | |||
473 | for_each_ref(print_archive_ref, &header); | ||
474 | |||
475 | html("<p>\n<h1>branch</h1>\n"); | ||
476 | html("<form method='get' action=''>\n"); | ||
477 | add_hidden_formfields(0, 1); | ||
478 | html("<select name='h' onchange='this.form.submit();'>\n"); | ||
479 | for_each_branch_ref(print_branch_option, cgit_query_head); | ||
480 | html("</select>\n"); | ||
481 | html("</form>\n"); | ||
482 | |||
483 | html("<p>\n<h1>search</h1>\n"); | ||
484 | html("<form method='get' action='"); | ||
485 | html_attr(cgit_pageurl(cgit_query_repo, "log", NULL)); | ||
486 | html("'>\n"); | ||
487 | add_hidden_formfields(1, 0); | ||
488 | html("<select name='qt'>\n"); | ||
424 | html_option("grep", "log msg", cgit_query_grep); | 489 | html_option("grep", "log msg", cgit_query_grep); |
@@ -426,11 +491,18 @@ void cgit_print_pageheader(char *title, int show_search) | |||
426 | html_option("committer", "committer", cgit_query_grep); | 491 | html_option("committer", "committer", cgit_query_grep); |
427 | html("</select>"); | 492 | html("</select>\n"); |
428 | html("<input class='txt' type='text' name='q' value='"); | 493 | html("<input class='txt' type='text' name='q' value='"); |
429 | html_attr(cgit_query_search); | 494 | html_attr(cgit_query_search); |
430 | html("'/><input class='btn' type='submit' value='...'/></form>"); | 495 | html("'/>\n"); |
496 | html("</form>\n"); | ||
497 | } else { | ||
498 | if (!cgit_index_info || html_include(cgit_index_info)) | ||
499 | html(default_info); | ||
431 | } | 500 | } |
432 | html("</td></tr>"); | 501 | |
433 | html("<tr><td id='content' colspan='2'>"); | 502 | html("</div>\n"); |
503 | |||
504 | html("</div>\n<table class='grid'><tr><td id='content'>\n"); | ||
434 | } | 505 | } |
435 | 506 | ||
507 | |||
436 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 508 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |