summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2008-05-03 08:37:02 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-05-03 08:37:02 (UTC)
commit141f1c3eb657470e81bbf998f44f9723f9009def (patch) (unidiff)
treea591e720b4a532fc7f53e74d611bb63629c8c5dc /ui-shared.c
parente19683bedebc74593cb4c4518e47a334a5478e1e (diff)
downloadcgit-141f1c3eb657470e81bbf998f44f9723f9009def.zip
cgit-141f1c3eb657470e81bbf998f44f9723f9009def.tar.gz
cgit-141f1c3eb657470e81bbf998f44f9723f9009def.tar.bz2
Add cgit_index_link() function with support for offset
This function will be used to build a pager in ui-repolist. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/ui-shared.c b/ui-shared.c
index d08ede9..f366354 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -105,67 +105,78 @@ const char *cgit_repobasename(const char *reponame)
105char *cgit_currurl() 105char *cgit_currurl()
106{ 106{
107 if (!ctx.cfg.virtual_root) 107 if (!ctx.cfg.virtual_root)
108 return ctx.cfg.script_name; 108 return ctx.cfg.script_name;
109 else if (ctx.qry.page) 109 else if (ctx.qry.page)
110 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); 110 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
111 else if (ctx.qry.repo) 111 else if (ctx.qry.repo)
112 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); 112 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
113 else 113 else
114 return fmt("%s/", ctx.cfg.virtual_root); 114 return fmt("%s/", ctx.cfg.virtual_root);
115} 115}
116 116
117static void site_url(char *page, char *search) 117static void site_url(char *page, char *search, int ofs)
118{ 118{
119 char *delim = "?"; 119 char *delim = "?";
120 120
121 if (ctx.cfg.virtual_root) { 121 if (ctx.cfg.virtual_root) {
122 html_attr(ctx.cfg.virtual_root); 122 html_attr(ctx.cfg.virtual_root);
123 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') 123 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
124 html("/"); 124 html("/");
125 } else 125 } else
126 html(ctx.cfg.script_name); 126 html(ctx.cfg.script_name);
127 127
128 if (page) { 128 if (page) {
129 htmlf("?p=%s", page); 129 htmlf("?p=%s", page);
130 delim = "&"; 130 delim = "&";
131 } 131 }
132 if (search) { 132 if (search) {
133 html(delim); 133 html(delim);
134 html("q="); 134 html("q=");
135 html_attr(search); 135 html_attr(search);
136 delim = "&";
137 }
138 if (ofs) {
139 html(delim);
140 htmlf("ofs=%d", ofs);
136 } 141 }
137} 142}
138 143
139static void site_link(char *page, char *name, char *title, char *class, 144static void site_link(char *page, char *name, char *title, char *class,
140 char *search) 145 char *search, int ofs)
141{ 146{
142 html("<a"); 147 html("<a");
143 if (title) { 148 if (title) {
144 html(" title='"); 149 html(" title='");
145 html_attr(title); 150 html_attr(title);
146 html("'"); 151 html("'");
147 } 152 }
148 if (class) { 153 if (class) {
149 html(" class='"); 154 html(" class='");
150 html_attr(class); 155 html_attr(class);
151 html("'"); 156 html("'");
152 } 157 }
153 html(" href='"); 158 html(" href='");
154 site_url(page, search); 159 site_url(page, search, ofs);
155 html("'>"); 160 html("'>");
156 html_txt(name); 161 html_txt(name);
157 html("</a>"); 162 html("</a>");
158} 163}
159 164
165void cgit_index_link(char *name, char *title, char *class, char *pattern,
166 int ofs)
167{
168 site_link(NULL, name, title, class, pattern, ofs);
169}
170
160static char *repolink(char *title, char *class, char *page, char *head, 171static char *repolink(char *title, char *class, char *page, char *head,
161 char *path) 172 char *path)
162{ 173{
163 char *delim = "?"; 174 char *delim = "?";
164 175
165 html("<a"); 176 html("<a");
166 if (title) { 177 if (title) {
167 html(" title='"); 178 html(" title='");
168 html_attr(title); 179 html_attr(title);
169 html("'"); 180 html("'");
170 } 181 }
171 if (class) { 182 if (class) {
@@ -587,27 +598,28 @@ void cgit_print_pageheader(struct cgit_context *ctx)
587 add_hidden_formfields(1, 0, "log"); 598 add_hidden_formfields(1, 0, "log");
588 html("<select name='qt'>\n"); 599 html("<select name='qt'>\n");
589 html_option("grep", "log msg", ctx->qry.grep); 600 html_option("grep", "log msg", ctx->qry.grep);
590 html_option("author", "author", ctx->qry.grep); 601 html_option("author", "author", ctx->qry.grep);
591 html_option("committer", "committer", ctx->qry.grep); 602 html_option("committer", "committer", ctx->qry.grep);
592 html("</select>\n"); 603 html("</select>\n");
593 html("<input class='txt' type='text' size='10' name='q' value='"); 604 html("<input class='txt' type='text' size='10' name='q' value='");
594 html_attr(ctx->qry.search); 605 html_attr(ctx->qry.search);
595 html("'/>\n"); 606 html("'/>\n");
596 html("<input type='submit' value='search'/>\n"); 607 html("<input type='submit' value='search'/>\n");
597 html("</form>\n"); 608 html("</form>\n");
598 } else { 609 } else {
599 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL); 610 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
600 if (ctx->cfg.root_readme) 611 if (ctx->cfg.root_readme)
601 site_link("about", "about", NULL, hc(cmd, "about"), NULL); 612 site_link("about", "about", NULL, hc(cmd, "about"),
613 NULL, 0);
602 html("</td><td class='form'>"); 614 html("</td><td class='form'>");
603 html("<form method='get' action='"); 615 html("<form method='get' action='");
604 html_attr(cgit_rooturl()); 616 html_attr(cgit_rooturl());
605 html("'>\n"); 617 html("'>\n");
606 html("<input type='text' name='q' size='10' value='"); 618 html("<input type='text' name='q' size='10' value='");
607 html_attr(ctx->qry.search); 619 html_attr(ctx->qry.search);
608 html("'/>\n"); 620 html("'/>\n");
609 html("<input type='submit' value='search'/>\n"); 621 html("<input type='submit' value='search'/>\n");
610 html("</form>"); 622 html("</form>");
611 } 623 }
612 html("</td></tr></table>\n"); 624 html("</td></tr></table>\n");
613 html("<div class='content'>"); 625 html("<div class='content'>");