let summary headers link to to the respective subpages
[webgit] / src / actions.c
index 8aaa31c..4242ecb 100644 (file)
@@ -2,23 +2,23 @@
     cehtehs git web frontend
 
   Copyright (C)
-    2007,               Christian Thaeter <ct@pipapo.org>
+    2007, 2008,         Christian Thaeter <ct@pipapo.org>
 
-  This program is free software; you can redistribute it and/or
-  modify it under the terms of the GNU General Public License as
-  published by the Free Software Foundation; either version 2 of the
-  License, or (at your option) any later version.
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+  GNU Affero General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "webgit.h"
 #include "actions.h"
 #include "summary.h"
 #include "object.h"
 static Html
 webgit_main_menu_action (struct webgit_query* query)
 {
-  (void) query;
-  return html ("TODO: main menu");
-}
-
-static Html
-webgit_header_action (struct webgit_query* query)
-{
-  (void) query;
-  return html (
-                          "webgit header action"
-                          );
+  return html (html_tag ("div"),
+               html (
+                     html_tag ("img",
+                               html_attr ("src", webgit_webskinpath (query, "icons/webgit_logo.png")),
+                               html_attr ("alt", "Webgit-Logo")
+                               )
+                     ), "<br />",
+               html_include (webgit_skinpath (query, "inc/site.inc")), "<br />",
+               // TODO: webgit_user_config_link (query), "<br />",
+               html (
+                     html_tag ("a",
+                               html_attr ("href", webgit_webskinpath (query, "inc/about.html"))
+                               ),
+                     "Powered by webgit"
+                     )
+               );
 }
 
 static Html
@@ -78,69 +83,75 @@ webgit_main_content_action (struct webgit_query* query)
                           )
               );
 
+  int row = 0;
+
   LLIST_FOREACH (&query->repos, node)
     {
       struct webgit_repo_info* n = (struct webgit_repo_info*)node;
 
       webgit_repoinfo_find_last (n);
 
-      html_list_append (table, html (
-                                     html_tag ("tr"),
-                                     html(html_tag ("td"),
-                                          webgit_summary_link (query, n, html (n->name))),
-                                     html(html_tag ("td"), n->url ?
-                                          html (
-                                                html_tag ("a", html_attr ("href", n->url)),
-                                                n->url)
-                                          : html("N/A")
-                                          ),
-                                     html(html_tag ("td"), n->description),
-                                     html(html_tag ("td"), n->owner),
-                                     html(html_tag ("td"),
-                                          webgit_object_link (query,
-                                                              n->name, strlen(n->name),
-                                                              n->last_commit, 40,
-                                                              NULL,
-                                                              NULL,
-                                                              webgit_pretty_age (n->age))
-                                          ),
-                                     html(html_tag ("td"),
-                                          webgit_email_link (
-                                                             html (n->last_author_name),
-                                                             html (n->last_author_email)
-                                                             )
-                                          ),
-                                     html(html_tag ("td"),
-                                          webgit_email_link (
-                                                             html (n->last_committer_name),
-                                                             html (n->last_committer_email)
-                                                             )
-                                          ),
-                                     html(html_tag ("td"),
-                                          html(
-                                               webgit_log_link (query,
-                                                                n->name,
-                                                                n->last_head,
-                                                                NULL, 0,
-                                                                query->count,
-                                                                html("Log")
-                                                                ),
-                                               " ",
-
-                                               "Diff ",
-                                               //webgit_diff_link (query, n, n->last_head, html("Diff")),
-                                               //" ",
-                                               webgit_object_link (query,
-                                                                   n->name, strlen(n->name),
-                                                                   n->last_tree, 40,
-                                                                   NULL,
-                                                                   NULL,
-                                                                   html("Tree"))
-                                               )
-                                          )
-                                     ),
-                        html_nl()
-                        );
+      if (n->age < n->maxage)
+        {
+          html_list_append (table, html (
+                                         html_tag ("tr",
+                                                   html_attr ("class", (++row & 1) ? "odd" : "even")
+                                                   ),
+                                         html(html_tag ("td"),
+                                              webgit_summary_link (query, n, html (n->name))),
+                                         html(html_tag ("td"), n->url ?
+                                              html (
+                                                    html_tag ("a", html_attr ("href", n->url)),
+                                                    n->url)
+                                              : html("N/A")
+                                              ),
+                                         html(html_tag ("td"), n->description),
+                                         html(html_tag ("td"), n->owner),
+                                         html(html_tag ("td"),
+                                              webgit_object_link (query,
+                                                                  n->name, strlen(n->name),
+                                                                  n->last_commit, 40,
+                                                                  NULL,
+                                                                  NULL,
+                                                                  webgit_pretty_age (n->age))
+                                              ),
+                                         html(html_tag ("td"),
+                                              webgit_email_link (
+                                                                 html (n->last_author_name),
+                                                                 html (n->last_author_email)
+                                                                 )
+                                              ),
+                                         html(html_tag ("td"),
+                                              webgit_email_link (
+                                                                 html (n->last_committer_name),
+                                                                 html (n->last_committer_email)
+                                                                 )
+                                              ),
+                                         html(html_tag ("td"),
+                                              html(
+                                                   webgit_log_link (query,
+                                                                    n->name,
+                                                                    n->last_head,
+                                                                    NULL, 0,
+                                                                    query->count,
+                                                                    html("Log")
+                                                                    ),
+                                                   " ",
+                                                   "Diff ",
+                                                   //webgit_diff_link (query, n, n->last_head, html("Diff")),
+                                                   //" ",
+                                                   webgit_object_link (query,
+                                                                       n->name, strlen(n->name),
+                                                                       n->last_tree, 40,
+                                                                       NULL,
+                                                                       NULL,
+                                                                       html("Tree"))
+                                                   )
+                                              )
+                                         ),
+                            html_nl()
+                            );
+        }
     }
 
   return html (html_tag ("table", html_attr ("id", "summary")), table);
@@ -150,9 +161,8 @@ static Html
 webgit_main_action (struct webgit_query* query)
 {
   return html(
-              html(html_tag("div", html_attr("id", "header")), webgit_header_action (query)) , html_nl (),
-              html(html_tag("div", html_attr("id", "main-menu")), webgit_main_menu_action (query)), html_nl (),
-              html(html_tag("div"), webgit_main_content_action (query)), html_nl ()
+              html(html_tag("div", html_attr("id", "sub-menu")), webgit_main_menu_action (query)), html_nl (),
+              html(html_tag("div", html_attr("id", "content")), webgit_main_content_action (query)), html_nl ()
               );
 }
 
@@ -163,8 +173,41 @@ webgit_main_action (struct webgit_query* query)
 static Html
 webgit_summary_menu_action (struct webgit_repo_info* repo)
 {
-  (void) repo;
-  return html ("TODO: summary");
+  return html (html_tag ("div"),
+               repo->logo ?
+               html (
+                     html_tag ("a",
+                               html_attr ("href", repo->logolink ? repo->logolink : "/")),
+                     html (
+                           html_tag ("img",
+                                     html_attr ("src", repo->logo),
+                                     html_attr ("alt", html (repo->name,"-logo"))
+                                     )
+                           )
+                     )
+               : html (
+                       html_tag ("img",
+                                 html_attr ("src", webgit_webskinpath (repo->query, "icons/webgit_logo.png")),
+                                 html_attr ("alt", "Webgit-Logo")
+                                 )
+                       ), "<br />",
+               repo->readme ? html_include (repo->readme) : html (), "<br />",
+               html (
+                     html_tag ("a",
+                               html_attr ("href", html_fmt ("%s?repo=%s&action=config",
+                                                            repo->query->request->script_name,
+                                                            repo->name)
+                                          )
+                               ),
+                     "Configure"
+                     ),"<br />",
+               html (
+                     html_tag ("a",
+                               html_attr ("href", repo->query->request->script_name)
+                               ),
+                     "Main Page"
+                     ),"<br />"
+               );
 }
 
 
@@ -221,7 +264,12 @@ webgit_summary_content_action (struct webgit_repo_info* repo)
   /* log */
   html_list_append (content,
                     html (
-                          html (html_tag ("h2"), "Log of branch '", repo->last_head, "'"),
+                          html (html_tag ("h2"),
+                                webgit_log_link (repo->query, repo->name, repo->last_head,
+                                                 NULL, 0, repo->query->count,
+                                                 html ("Log of branch '", repo->last_head, "'")
+                                                 )
+                                ),
                           webgit_log_table (repo->query, repo->last_head, 5 /*TODO: config this*/, 0))
                     );
 
@@ -229,7 +277,11 @@ webgit_summary_content_action (struct webgit_repo_info* repo)
   /* branches */
   html_list_append (content,
                     html (
-                          html (html_tag ("h2"), "Branches"),
+                          html (html_tag ("h2"),
+                                webgit_branch_link (repo, NULL, repo->query->count,
+                                                    html ("Branches")
+                                                    )
+                                ),
                           webgit_branch_table (repo, NULL, 5 /*TODO: config this*/)
                           )
                     );
@@ -237,7 +289,11 @@ webgit_summary_content_action (struct webgit_repo_info* repo)
   /* tags */
   html_list_append (content,
                     html (
-                          html (html_tag ("h2"), "Tags"),
+                          html (html_tag ("h2"),
+                                webgit_tag_link (repo, NULL, repo->query->count,
+                                                 html ("Tags")
+                                                 )
+                                ),
                           webgit_tag_table (repo, NULL, 5 /*TODO: config this*/)
                           )
                     );
@@ -254,8 +310,8 @@ webgit_summary_action (struct webgit_query* query)
   webgit_repoinfo_find_last (repo);
 
   return html(
-              html(html_tag("div"), webgit_summary_menu_action (repo)), html_nl (),
-              html(html_tag("div"), webgit_summary_content_action (repo)), html_nl ()
+              html(html_tag("div", html_attr("id", "sub-menu")), webgit_summary_menu_action (repo)), html_nl (),
+              html(html_tag("div", html_attr("id", "content")), webgit_summary_content_action (repo)), html_nl ()
               );
 }
 
@@ -270,7 +326,7 @@ webgit_log_action (struct webgit_query* query)
 
   return html(
               html(html_tag("div"), webgit_log_menu_action (query)), html_nl (),
-              html(html_tag("div"), webgit_log_content_action (query)), html_nl ()
+              html(html_tag("div", html_attr("id", "content")), webgit_log_content_action (query)), html_nl ()
               );
 }
 
@@ -282,6 +338,14 @@ static Html
 webgit_diff_action (struct webgit_query* query)
 {
   (void) query;
+#if 0
+  return html (html_tag ("div"),
+               "Webgit logo<br />",
+               "Readme.html <br />",
+               "User (cookie) config <br />",
+               "About webgit (info/admin) <br />"
+               );
+#endif
   return html("diff");
 }
 
@@ -361,7 +425,14 @@ static Html
 webgit_branch_menu_action (struct webgit_repo_info* repo)
 {
   (void) repo;
-  return html ("TODO: branch sidebar");
+  return html (html_tag ("div"),
+               "Project or webgit logo<br />",
+               "switch-branch-dropdown <br />",
+               "push/fetch/merge <br />",
+               "branch administation <br />",
+               "link to project summary <br />",
+               "link to main page <br />"
+               );
 }
 
 
@@ -372,13 +443,13 @@ webgit_branch_action (struct webgit_query* query)
   webgit_repoinfo_find_last (repo);
 
   return html(
-                         html(html_tag("div", html_attr("id", "header")), webgit_header_action (query)) , html_nl (),
-              html(html_tag("div"), webgit_branch_menu_action (repo)), html_nl (),
-              html(html_tag("div"), webgit_branch_table (repo, query->head, query->count), html_nl ())
+              html(html_tag("div", html_attr("id", "sub-menu")), webgit_branch_menu_action (repo)), html_nl (),
+              html(html_tag("div", html_attr("id", "content")), webgit_branch_table (repo, query->head, query->count), html_nl ())
               );
 }
 
 
+
 /*
   show tag
 */
@@ -397,12 +468,20 @@ static Html
 webgit_config_menu_action (struct webgit_repo_info* repo)
 {
   (void) repo;
-  return html ("TODO: config menu");
+  return html (html_tag ("div"),
+               "Project or webgit logo<br />",
+               "manage remotes? <br />",
+               "manage subprojects? <br />",
+               "link to project summary <br />",
+               "link to main page <br />"
+               );
 }
 
 static Html
 webgit_config_content_action (struct webgit_repo_info* repo)
 {
+  int readonly = !!access (git_path("config"), W_OK);
+
   return html (
                html_tag ("form",
                          html_attr ("name", "config-change"),
@@ -421,16 +500,18 @@ webgit_config_content_action (struct webgit_repo_info* repo)
                      html_tag ("textarea",
                                html_attr ("name", "blob"),
                                html_attr ("rows", "40"),
-                               html_attr ("cols", "80")
-                               )//,
-                     //html_include_escaped (git_path("config"))
+                               html_attr ("cols", "80"),
+                               readonly ? "readonly" : ""
+                               ),
+                     html_include_escaped (git_path("config"))
                      ),
-               html (
-                     html_tag ("input",
-                               html_attr ("type", "submit"),
-                               html_attr ("value", "Save")
-                               )
-                     )
+               readonly ? html ()
+               : html (
+                       html_tag ("input",
+                                 html_attr ("type", "submit"),
+                                 html_attr ("value", "Save")
+                                 )
+                       )
                );
 }
 
@@ -443,7 +524,7 @@ webgit_config_action (struct webgit_query* query)
   if (query->blob)
     {
       FILE* cfg = fopen (git_path ("config"), "w");
+
       /*TODO rxpd check */
       if (!cfg)
         webgit_warn ("could not open %s for writing", git_path("config"));
@@ -457,7 +538,7 @@ webgit_config_action (struct webgit_query* query)
 
   return html(
               html (html_tag ("div"), webgit_config_menu_action (repo)), html_nl (),
-              html (html_tag ("div"), webgit_config_content_action (repo)), html_nl ()
+              html (html_tag ("div", html_attr("id", "content")), webgit_config_content_action (repo)), html_nl ()
               );
 }
 
@@ -506,3 +587,11 @@ webgit_action_dispatch (struct webgit_query* query)
 }
 
 
+
+/*
+//      Local Variables:
+//      mode: C
+//      c-file-style: "gnu"
+//      indent-tabs-mode: nil
+//      End:
+*/