cleanup and cosmetics
[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_diff_link (query, n, n->last_head, html("Diff")),
72                                                //" ",
73                                                ctgit_object_link (query, n, n->last_tree, html("Tree"))
74                                                )
75                                           )
76                                      ),
77                         html_nl()
78                         );
79     }
80
81   return html (html_tag ("table", html_attr ("border", "1")), table);
82 }
83
84 static Html
85 ctgit_main_action (struct ctgit_query* query)
86 {
87   return html(
88               html(html_tag("div"), ctgit_main_menu_action (query)), html_nl (),
89               html(html_tag("div"), ctgit_main_content_action (query)), html_nl ()
90               );
91 }
92
93 static Html
94 ctgit_summary_action (struct ctgit_query* query)
95 {
96   return html("summary");
97 }
98
99 static Html
100 ctgit_log_action (struct ctgit_query* query)
101 {
102   return html("log");
103 }
104
105 static Html
106 ctgit_diff_action (struct ctgit_query* query)
107 {
108   return html("diff");
109 }
110
111 static Html
112 ctgit_object_action (struct ctgit_query* query)
113 {
114   return html("object");
115 }
116
117 static Html
118 ctgit_raw_action (struct ctgit_query* query)
119 {
120   return html("raw");
121 }
122
123 static Html
124 ctgit_tag_action (struct ctgit_query* query)
125 {
126   return html("tag");
127 }
128
129 static Html
130 ctgit_edit_action (struct ctgit_query* query)
131 {
132   return html("edit");
133 }
134
135 static Html
136 ctgit_commit_action (struct ctgit_query* query)
137 {
138   return html("commit");
139 }
140
141
142 Html
143 ctgit_action_dispatch (struct ctgit_query* query)
144 {
145 #define CTGIT_ACTION(name, _)                   \
146 {                                               \
147  #name,                                         \
148  ctgit_##name##_action,                         \
149 },
150   struct action_table{
151     char* name;
152     Html (*cb)(struct ctgit_query* query);
153   } cmds[] = {CTGIT_ACTIONS {"", NULL}};
154 #undef CTGIT_ACTION
155
156   for (struct action_table* j = cmds; j->cb; ++j)
157     {
158       if (!strcmp (j->name, query->action))
159         return j->cb (query);
160     }
161   return html("error, no such action");
162 }
163
164