support for last_committer and last_author when scanning repos
[webgit] / src / actions.c
index 9a482bac1d5886dfecc1e52979534355e0d5e02e..cb2a1ba6d75f5c14cec1410076f751eb62249860 100644 (file)
 */
 
 #include "actions.h"
+#include "summary.h"
+#include "object.h"
+#include "log.h"
+#include "repo.h"
 
 #include "cwa.h"
 
+/* todo configure this */
+#define SHA1_HEADER <openssl/sha.h>
+#include "git/cache.h"
+
+#include <stdio.h>
+
+
+static Html
+webgit_main_menu_action (struct webgit_query* query)
+{
+  return html ("TODO: main menu sidebar");
+}
+
+static Html
+webgit_main_content_action (struct webgit_query* query)
+{
+  Html table = html_list ();
+
+  html_list_append (table, html(
+                          html(html_tag ("tr"),
+                               html(html_tag ("th"),"Name"),
+                               html(html_tag ("th"),"Description"),
+                               html(html_tag ("th"),"Owner"),
+                               html(html_tag ("th"),"Last Change"),
+                               html(html_tag ("th"),"Author"),
+                               html(html_tag ("th"),"Committer"),
+                               html(html_tag ("th"),"Action")
+                               ),
+                          html_nl()
+                          )
+              );
+
+  LLIST_FOREACH (&query->repos, node)
+    {
+      struct webgit_repo_info* n = (struct webgit_repo_info*)node;
+      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->description),
+                                     html(html_tag ("td"), n->owner),
+                                     html(html_tag ("td"),
+                                          webgit_object_link (query,
+                                                              n->name, strlen(n->name),
+                                                              n->last_commit, 40,
+                                                              webgit_pretty_age (n->age))
+                                          ),
+                                     html(html_tag ("td"),
+                                          webgit_email_link (n->last_author_name, n->last_author_email)
+                                          ),
+                                     html(html_tag ("td"),
+                                          webgit_email_link (n->last_committer_name, n->last_committer_email)
+                                          ),
+                                     html(html_tag ("td"),
+                                          html(
+                                               webgit_log_link (query, n, n->last_head, html("Log")),
+                                               " ",
+                                               //webgit_diff_link (query, n, n->last_head, html("Diff")),
+                                               //" ",
+                                               webgit_object_link (query,
+                                                                  n->name, strlen(n->name),
+                                                                  n->last_tree, 40,
+                                                                  html("Tree"))
+                                               )
+                                          )
+                                     ),
+                        html_nl()
+                        );
+    }
+
+  return html (html_tag ("table", html_attr ("border", "1")), table);
+}
 
 static Html
-ctgit_main_action (struct ctgit_query* query)
+webgit_main_action (struct webgit_query* query)
 {
-  return html("main");
+  return html(
+              html(html_tag("div"), webgit_main_menu_action (query)), html_nl (),
+              html(html_tag("div"), webgit_main_content_action (query)), html_nl ()
+              );
 }
 
 static Html
-ctgit_summary_action (struct ctgit_query* query)
+webgit_summary_action (struct webgit_query* query)
 {
   return html("summary");
 }
 
 static Html
-ctgit_log_action (struct ctgit_query* query)
+webgit_log_action (struct webgit_query* query)
 {
   return html("log");
 }
 
 static Html
-ctgit_diff_action (struct ctgit_query* query)
+webgit_diff_action (struct webgit_query* query)
 {
   return html("diff");
 }
 
 static Html
-ctgit_object_action (struct ctgit_query* query)
+webgit_object_action (struct webgit_query* query)
 {
-  return html("object");
+  LLIST_FOREACH (&query->repos, node)
+    {
+      struct webgit_repo_info* ri = (struct webgit_repo_info*) node;
+      if (!strcmp (ri->name, query->repo))
+        {
+          chdir (ri->path);
+          break;
+        }
+    }
+
+  setup_git_directory ();
+
+  unsigned char sha1[20];
+  if (get_sha1(query->object, sha1))
+    return html("error: unknown object");
+
+  switch (sha1_object_info(sha1, NULL))
+    {
+    case OBJ_COMMIT:
+      return webgit_object_commit_action (query, sha1);
+    case OBJ_TREE:
+      return webgit_object_tree_action (query, sha1);
+    case OBJ_BLOB:
+      return webgit_object_blob_action (query, sha1);
+    case OBJ_TAG:
+      return html ("its a tag");
+
+      break;
+    default:
+      return html ("error: unknown object type");
+      break;
+    }
 }
 
 static Html
-ctgit_raw_action (struct ctgit_query* query)
+webgit_raw_action (struct webgit_query* query)
 {
   return html("raw");
 }
 
 static Html
-ctgit_tag_action (struct ctgit_query* query)
+webgit_tag_action (struct webgit_query* query)
 {
   return html("tag");
 }
 
 static Html
-ctgit_edit_action (struct ctgit_query* query)
+webgit_edit_action (struct webgit_query* query)
 {
   return html("edit");
 }
 
 static Html
-ctgit_commit_action (struct ctgit_query* query)
+webgit_commit_action (struct webgit_query* query)
 {
   return html("commit");
 }
 
 
 Html
-ctgit_action_dispatch (struct ctgit_query* query)
+webgit_action_dispatch (struct webgit_query* query)
 {
-#define CTGIT_ACTION(name) {#name, ctgit_##name##_action},
+#define WEBGIT_ACTION(name, _)                   \
+{                                               \
+ #name,                                         \
+ webgit_##name##_action,                         \
+},
   struct action_table{
     char* name;
-    Html (*cb)(struct ctgit_query* query);
-  } cmds[] = {CTGIT_ACTIONS {"", NULL}};
-#undef CTGIT_ACTION
+    Html (*cb)(struct webgit_query* query);
+  } cmds[] = {WEBGIT_ACTIONS {"", NULL}};
+#undef WEBGIT_ACTION
 
   for (struct action_table* j = cmds; j->cb; ++j)
     {