[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgit
Subject:    [PATCH 13/17] stats: move layout into page function
From:       John Keeping <john () keeping ! me ! uk>
Date:       2015-04-05 15:54:59
Message-ID: 3934c4712fa7b942d4915497d8d8661012fa81c0.1428248621.git.john () keeping ! me ! uk
[Download RAW message or body]

This also allows us to return proper HTTP error codes for invalid
requests.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 cmd.c      | 2 +-
 ui-stats.c | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/cmd.c b/cmd.c
index 57a8fe7..5340405 100644
--- a/cmd.c
+++ b/cmd.c
@@ -158,7 +158,7 @@ struct cgit_cmd *cgit_get_cmd(void)
 		def_cmd(refs, 1, 0, 0, 0),
 		def_cmd(repolist, 0, 0, 0, 0),
 		def_cmd(snapshot, 1, 0, 0, 0),
-		def_cmd(stats, 1, 1, 1, 0),
+		def_cmd(stats, 1, 0, 1, 0),
 		def_cmd(summary, 1, 1, 0, 0),
 		def_cmd(tag, 1, 1, 0, 0),
 		def_cmd(tree, 1, 1, 1, 0),
diff --git a/ui-stats.c b/ui-stats.c
index 9cd8247..74ce0f7 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -372,11 +372,13 @@ void cgit_show_stats(void)
 
 	i = cgit_find_stats_period(code, &period);
 	if (!i) {
-		cgit_print_error("Unknown statistics type: %c", code[0]);
+		cgit_print_error_page(404, "Not found",
+			"Unknown statistics type: %c", code[0]);
 		return;
 	}
 	if (i > ctx.repo->max_stats) {
-		cgit_print_error("Statistics type disabled: %s", period->name);
+		cgit_print_error_page(400, "Bad request",
+			"Statistics type disabled: %s", period->name);
 		return;
 	}
 	authors = collect_stats(period);
@@ -387,6 +389,7 @@ void cgit_show_stats(void)
 	if (!top)
 		top = 10;
 
+	cgit_print_layout_start();
 	html("<div class='cgit-panel'>");
 	html("<b>stat options</b>");
 	html("<form method='get' action=''>");
@@ -421,5 +424,6 @@ void cgit_show_stats(void)
 	}
 	html("</h2>");
 	print_authors(&authors, top, period);
+	cgit_print_layout_end();
 }
 
-- 
2.4.0.rc0.173.gb1cefcc

_______________________________________________
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic