summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2008-05-03 08:54:39 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-05-03 08:54:39 (UTC)
commitc6078b8b006bcb0671a3c1bc21dd1a2c01035a2e (patch) (side-by-side diff)
tree0ca48d3ac455a7aecd30590ed71703ba5b34c4f1
parent141f1c3eb657470e81bbf998f44f9723f9009def (diff)
downloadcgit-c6078b8b006bcb0671a3c1bc21dd1a2c01035a2e.zip
cgit-c6078b8b006bcb0671a3c1bc21dd1a2c01035a2e.tar.gz
cgit-c6078b8b006bcb0671a3c1bc21dd1a2c01035a2e.tar.bz2
Add a pager on the repolist
This enables a pager on the repolist which restricts the number of entries displayed per page, controlled by the new option `max-repo-count` (default value 50). Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.css10
-rw-r--r--cgit.h1
-rw-r--r--ui-repolist.c19
4 files changed, 32 insertions, 1 deletions
diff --git a/cgit.c b/cgit.c
index ccd61f4..2036ceb 100644
--- a/cgit.c
+++ b/cgit.c
@@ -56,24 +56,26 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "cache-root-ttl"))
ctx.cfg.cache_root_ttl = atoi(value);
else if (!strcmp(name, "cache-repo-ttl"))
ctx.cfg.cache_repo_ttl = atoi(value);
else if (!strcmp(name, "cache-static-ttl"))
ctx.cfg.cache_static_ttl = atoi(value);
else if (!strcmp(name, "cache-dynamic-ttl"))
ctx.cfg.cache_dynamic_ttl = atoi(value);
else if (!strcmp(name, "max-message-length"))
ctx.cfg.max_msg_len = atoi(value);
else if (!strcmp(name, "max-repodesc-length"))
ctx.cfg.max_repodesc_len = atoi(value);
+ else if (!strcmp(name, "max-repo-count"))
+ ctx.cfg.max_repo_count = atoi(value);
else if (!strcmp(name, "max-commit-count"))
ctx.cfg.max_commit_count = atoi(value);
else if (!strcmp(name, "summary-log"))
ctx.cfg.summary_log = atoi(value);
else if (!strcmp(name, "summary-branches"))
ctx.cfg.summary_branches = atoi(value);
else if (!strcmp(name, "summary-tags"))
ctx.cfg.summary_tags = atoi(value);
else if (!strcmp(name, "agefile"))
ctx.cfg.agefile = xstrdup(value);
else if (!strcmp(name, "renamelimit"))
ctx.cfg.renamelimit = atoi(value);
@@ -150,24 +152,25 @@ static void prepare_context(struct cgit_context *ctx)
memset(ctx, 0, sizeof(ctx));
ctx->cfg.agefile = "info/web/last-modified";
ctx->cfg.nocache = 0;
ctx->cfg.cache_size = 0;
ctx->cfg.cache_dynamic_ttl = 5;
ctx->cfg.cache_max_create_time = 5;
ctx->cfg.cache_repo_ttl = 5;
ctx->cfg.cache_root = CGIT_CACHE_ROOT;
ctx->cfg.cache_root_ttl = 5;
ctx->cfg.cache_static_ttl = -1;
ctx->cfg.css = "/cgit.css";
ctx->cfg.logo = "/git-logo.png";
+ ctx->cfg.max_repo_count = 50;
ctx->cfg.max_commit_count = 50;
ctx->cfg.max_lock_attempts = 5;
ctx->cfg.max_msg_len = 60;
ctx->cfg.max_repodesc_len = 60;
ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
ctx->cfg.renamelimit = -1;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
ctx->page.mimetype = "text/html";
ctx->page.charset = PAGE_ENCODING;
diff --git a/cgit.css b/cgit.css
index 30cb8e6..d57722c 100644
--- a/cgit.css
+++ b/cgit.css
@@ -404,24 +404,34 @@ a.primary {
a.secondary {
font-size: 90%;
}
td.toplevel-repo {
}
table.list td.sublevel-repo {
padding-left: 1.5em;
}
+div.pager {
+ text-align: center;
+ margin: 1em 0em 0em 0em;
+}
+
+div.pager a {
+ color: #777;
+ margin: 0em 0.5em;
+}
+
span.age-mins {
font-weight: bold;
color: #080;
}
span.age-hours {
color: #080;
}
span.age-days {
color: #040;
}
diff --git a/cgit.h b/cgit.h
index bbb404e..4fa5cf2 100644
--- a/cgit.h
+++ b/cgit.h
@@ -136,24 +136,25 @@ struct cgit_config {
char *root_readme;
char *script_name;
char *virtual_root;
int cache_size;
int cache_dynamic_ttl;
int cache_max_create_time;
int cache_repo_ttl;
int cache_root_ttl;
int cache_static_ttl;
int enable_index_links;
int enable_log_filecount;
int enable_log_linecount;
+ int max_repo_count;
int max_commit_count;
int max_lock_attempts;
int max_msg_len;
int max_repodesc_len;
int nocache;
int renamelimit;
int snapshots;
int summary_branches;
int summary_log;
int summary_tags;
};
diff --git a/ui-repolist.c b/ui-repolist.c
index 3f78e28..ee4facb 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -62,48 +62,63 @@ int is_match(struct cgit_repo *repo)
void print_header(int columns)
{
html("<tr class='nohover'>"
"<th class='left'>Name</th>"
"<th class='left'>Description</th>"
"<th class='left'>Owner</th>"
"<th class='left'>Idle</th>");
if (ctx.cfg.enable_index_links)
html("<th class='left'>Links</th>");
html("</tr>\n");
}
+
+void print_pager(int items, int pagelen, char *search)
+{
+ int i;
+ html("<div class='pager'>");
+ for(i = 0; i * pagelen < items; i++)
+ cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL,
+ search, i * pagelen);
+ html("</div>");
+}
+
void cgit_print_repolist()
{
int i, columns = 4, hits = 0, header = 0;
char *last_group = NULL;
if (ctx.cfg.enable_index_links)
columns++;
ctx.page.title = ctx.cfg.root_title;
cgit_print_http_headers(&ctx);
cgit_print_docstart(&ctx);
cgit_print_pageheader(&ctx);
if (ctx.cfg.index_header)
html_include(ctx.cfg.index_header);
html("<table summary='repository list' class='list nowrap'>");
for (i=0; i<cgit_repolist.count; i++) {
ctx.repo = &cgit_repolist.repos[i];
if (!is_match(ctx.repo))
continue;
+ hits++;
+ if (hits <= ctx.qry.ofs)
+ continue;
+ if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
+ continue;
if (!header++)
print_header(columns);
- hits++;
if ((last_group == NULL && ctx.repo->group != NULL) ||
(last_group != NULL && ctx.repo->group == NULL) ||
(last_group != NULL && ctx.repo->group != NULL &&
strcmp(ctx.repo->group, last_group))) {
htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
columns);
html_txt(ctx.repo->group);
html("</td></tr>");
last_group = ctx.repo->group;
}
htmlf("<tr><td class='%s'>",
ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
@@ -125,20 +140,22 @@ void cgit_print_repolist()
NULL, "button");
html("summary</a>");
cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
0, NULL, NULL);
cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
html("</td>");
}
html("</tr>\n");
}
html("</table>");
if (!hits)
cgit_print_error("No repositories found");
+ else if (hits > ctx.cfg.max_repo_count)
+ print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search);
cgit_print_docend();
}
void cgit_print_site_readme()
{
if (ctx.cfg.root_readme)
html_include(ctx.cfg.root_readme);
}