-rw-r--r-- | ui-repolist.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index 7c7aa9b..3ef2e99 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -133,12 +133,24 @@ static int cmp(const char *s1, const char *s2) | |||
133 | return -1; | 133 | return -1; |
134 | if (s2 && !s1) | 134 | if (s2 && !s1) |
135 | return 1; | 135 | return 1; |
136 | return 0; | 136 | return 0; |
137 | } | 137 | } |
138 | 138 | ||
139 | static int sort_section(const void *a, const void *b) | ||
140 | { | ||
141 | const struct cgit_repo *r1 = a; | ||
142 | const struct cgit_repo *r2 = b; | ||
143 | int result; | ||
144 | |||
145 | result = cmp(r1->section, r2->section); | ||
146 | if (!result) | ||
147 | result = cmp(r1->name, r2->name); | ||
148 | return result; | ||
149 | } | ||
150 | |||
139 | static int sort_name(const void *a, const void *b) | 151 | static int sort_name(const void *a, const void *b) |
140 | { | 152 | { |
141 | const struct cgit_repo *r1 = a; | 153 | const struct cgit_repo *r1 = a; |
142 | const struct cgit_repo *r2 = b; | 154 | const struct cgit_repo *r2 = b; |
143 | 155 | ||
144 | return cmp(r1->name, r2->name); | 156 | return cmp(r1->name, r2->name); |
@@ -175,12 +187,13 @@ static int sort_idle(const void *a, const void *b) | |||
175 | struct sortcolumn { | 187 | struct sortcolumn { |
176 | const char *name; | 188 | const char *name; |
177 | int (*fn)(const void *a, const void *b); | 189 | int (*fn)(const void *a, const void *b); |
178 | }; | 190 | }; |
179 | 191 | ||
180 | struct sortcolumn sortcolumn[] = { | 192 | struct sortcolumn sortcolumn[] = { |
193 | {"section", sort_section}, | ||
181 | {"name", sort_name}, | 194 | {"name", sort_name}, |
182 | {"desc", sort_desc}, | 195 | {"desc", sort_desc}, |
183 | {"owner", sort_owner}, | 196 | {"owner", sort_owner}, |
184 | {"idle", sort_idle}, | 197 | {"idle", sort_idle}, |
185 | {NULL, NULL} | 198 | {NULL, NULL} |
186 | }; | 199 | }; |
@@ -200,13 +213,14 @@ int sort_repolist(char *field) | |||
200 | } | 213 | } |
201 | 214 | ||
202 | 215 | ||
203 | void cgit_print_repolist() | 216 | void cgit_print_repolist() |
204 | { | 217 | { |
205 | int i, columns = 4, hits = 0, header = 0; | 218 | int i, columns = 4, hits = 0, header = 0; |
206 | char *last_group = NULL; | 219 | char *last_section = NULL; |
220 | char *section; | ||
207 | int sorted = 0; | 221 | int sorted = 0; |
208 | 222 | ||
209 | if (ctx.cfg.enable_index_links) | 223 | if (ctx.cfg.enable_index_links) |
210 | columns++; | 224 | columns++; |
211 | 225 | ||
212 | ctx.page.title = ctx.cfg.root_title; | 226 | ctx.page.title = ctx.cfg.root_title; |
@@ -216,12 +230,14 @@ void cgit_print_repolist() | |||
216 | 230 | ||
217 | if (ctx.cfg.index_header) | 231 | if (ctx.cfg.index_header) |
218 | html_include(ctx.cfg.index_header); | 232 | html_include(ctx.cfg.index_header); |
219 | 233 | ||
220 | if(ctx.qry.sort) | 234 | if(ctx.qry.sort) |
221 | sorted = sort_repolist(ctx.qry.sort); | 235 | sorted = sort_repolist(ctx.qry.sort); |
236 | else | ||
237 | sort_repolist("section"); | ||
222 | 238 | ||
223 | html("<table summary='repository list' class='list nowrap'>"); | 239 | html("<table summary='repository list' class='list nowrap'>"); |
224 | for (i=0; i<cgit_repolist.count; i++) { | 240 | for (i=0; i<cgit_repolist.count; i++) { |
225 | ctx.repo = &cgit_repolist.repos[i]; | 241 | ctx.repo = &cgit_repolist.repos[i]; |
226 | if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) | 242 | if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) |
227 | continue; | 243 | continue; |
@@ -229,25 +245,28 @@ void cgit_print_repolist() | |||
229 | if (hits <= ctx.qry.ofs) | 245 | if (hits <= ctx.qry.ofs) |
230 | continue; | 246 | continue; |
231 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) | 247 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) |
232 | continue; | 248 | continue; |
233 | if (!header++) | 249 | if (!header++) |
234 | print_header(columns); | 250 | print_header(columns); |
251 | section = ctx.repo->section; | ||
252 | if (section && !strcmp(section, "")) | ||
253 | section = NULL; | ||
235 | if (!sorted && | 254 | if (!sorted && |
236 | ((last_group == NULL && ctx.repo->group != NULL) || | 255 | ((last_section == NULL && section != NULL) || |
237 | (last_group != NULL && ctx.repo->group == NULL) || | 256 | (last_section != NULL && section == NULL) || |
238 | (last_group != NULL && ctx.repo->group != NULL && | 257 | (last_section != NULL && section != NULL && |
239 | strcmp(ctx.repo->group, last_group)))) { | 258 | strcmp(section, last_section)))) { |
240 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 259 | htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>", |
241 | columns); | 260 | columns); |
242 | html_txt(ctx.repo->group); | 261 | html_txt(section); |
243 | html("</td></tr>"); | 262 | html("</td></tr>"); |
244 | last_group = ctx.repo->group; | 263 | last_section = section; |
245 | } | 264 | } |
246 | htmlf("<tr><td class='%s'>", | 265 | htmlf("<tr><td class='%s'>", |
247 | !sorted && ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); | 266 | !sorted && section ? "sublevel-repo" : "toplevel-repo"); |
248 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); | 267 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); |
249 | html("</td><td>"); | 268 | html("</td><td>"); |
250 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); | 269 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); |
251 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); | 270 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); |
252 | html_link_close(); | 271 | html_link_close(); |
253 | html("</td><td>"); | 272 | html("</td><td>"); |