completing the links for the repo listing page
[webgit] / src / actions.c
1 /*
2     cehtehs git web frontend
3
4   Copyright (C)
5     2007,               Christian Thaeter <ct@pipapo.org>
6
7   This program is free software; you can redistribute it and/or
8   modify it under the terms of the GNU General Public License as
9   published by the Free Software Foundation; either version 2 of the
10   License, or (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program; if not, write to the Free Software
19   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "actions.h"
23 #include "summary.h"
24 #include "object.h"
25 #include "log.h"
26 #include "repo.h"
27
28 #include "cwa.h"
29
30 #include <stdio.h>
31
32
33 static Html
34 ctgit_main_menu_action (struct ctgit_query* query)
35 {
36   return html ("TODO: main menu sidebar");
37 }
38
39 static Html
40 ctgit_main_content_action (struct ctgit_query* query)
41 {
42   Html table = html_list ();
43
44   html_list_append (table, html(
45                           html(html_tag ("tr"),
46                                html(html_tag ("th"),"Name"),
47                                html(html_tag ("th"),"Description"),
48                                html(html_tag ("th"),"Owner"),
49                                html(html_tag ("th"),"Last Change"),
50                                html(html_tag ("th"),"Action")
51                                ),
52                           html_nl()
53                           )
54               );
55
56   LLIST_FOREACH (&query->repos, node)
57     {
58       struct ctgit_repo_info* n = (struct ctgit_repo_info*)node;
59       html_list_append (table, html (
60                                      html_tag ("tr"),
61                                      html(html_tag ("td"), ctgit_summary_link (query, n, html (n->name))),
62                                      html(html_tag ("td"), n->description),
63                                      html(html_tag ("td"), n->owner),
64                                      html(html_tag ("td"),
65                                           ctgit_object_link (query, n, n->last_commit, ctgit_pretty_age (n->age))
66                                           ),
67                                      html(html_tag ("td"),
68                                           html(
69                                                ctgit_log_link (query, n, n->last_head, html("Log")),
70                                                " ",
71                                                ctgit_object_link (query, n, n->last_tree, html("Tree"))
72                                                )
73                                           )
74                                      ),
75                         html_nl()
76                         );
77     }
78
79   return html (html_tag ("table", html_attr ("border", "1")), table);
80 }
81
82 static Html
83 ctgit_main_action (struct ctgit_query* query)
84 {
85   return html(
86               html(html_tag("div"), ctgit_main_menu_action (query)), html_nl (),
87               html(html_tag("div"), ctgit_main_content_action (query)), html_nl ()
88               );
89 }
90
91 static Html
92 ctgit_summary_action (struct ctgit_query* query)
93 {
94   return html("summary");
95 }
96
97 static Html
98 ctgit_log_action (struct ctgit_query* query)
99 {
100   return html("log");
101 }
102
103 static Html
104 ctgit_diff_action (struct ctgit_query* query)
105 {
106   return html("diff");
107 }
108
109 static Html
110 ctgit_object_action (struct ctgit_query* query)
111 {
112   return html("object");
113 }
114
115 static Html
116 ctgit_raw_action (struct ctgit_query* query)
117 {
118   return html("raw");
119 }
120
121 static Html
122 ctgit_tag_action (struct ctgit_query* query)
123 {
124   return html("tag");
125 }
126
127 static Html
128 ctgit_edit_action (struct ctgit_query* query)
129 {
130   return html("edit");
131 }
132
133 static Html
134 ctgit_commit_action (struct ctgit_query* query)
135 {
136   return html("commit");
137 }
138
139
140 Html
141 ctgit_action_dispatch (struct ctgit_query* query)
142 {
143 #define CTGIT_ACTION(name, _)                   \
144 {                                               \
145  #name,                                         \
146  ctgit_##name##_action,                         \
147 },
148   struct action_table{
149     char* name;
150     Html (*cb)(struct ctgit_query* query);
151   } cmds[] = {CTGIT_ACTIONS {"", NULL}};
152 #undef CTGIT_ACTION
153
154   for (struct action_table* j = cmds; j->cb; ++j)
155     {
156       if (!strcmp (j->name, query->action))
157         return j->cb (query);
158     }
159   return html("error, no such action");
160 }
161
162