'edit' ui, no functionality tough
authorChristian Thaeter <ct@pipapo.org>
Sun, 10 Feb 2008 02:40:19 +0000 (03:40 +0100)
committerChristian Thaeter <ct@pipapo.org>
Sun, 10 Feb 2008 02:40:19 +0000 (03:40 +0100)
Makefile.am
src/actions.c
src/edit.c [new file with mode: 0644]
src/edit.h [new file with mode: 0644]
src/object_blob.c
src/object_tree.c
src/webgit.c
src/webgit.h

index 0bb10e7..1b094ff 100644 (file)
@@ -54,6 +54,7 @@ webgit_SOURCES =                              \
        $(webgit_srcdir)/log.c                  \
        $(webgit_srcdir)/login.c                \
        $(webgit_srcdir)/account.c              \
+       $(webgit_srcdir)/edit.c                 \
        $(webgit_srcdir)/rxpd_client.c
 
 noinst_HEADERS =                               \
@@ -70,6 +71,7 @@ noinst_HEADERS =                              \
        $(webgit_srcdir)/log.h                  \
        $(webgit_srcdir)/login.h                \
        $(webgit_srcdir)/account.h              \
+       $(webgit_srcdir)/edit.h                 \
        $(webgit_srcdir)/rxpd_client.h
 
 webgit_DEPENDENCIES = $(abs_top_builddir)/git/libgit.a $(abs_top_builddir)/git/xdiff/lib.a
index 068ddcb..83eefe1 100644 (file)
@@ -28,6 +28,7 @@
 #include "branch.h"
 #include "tag.h"
 #include "account.h"
+#include "edit.h"
 
 #include "llist.h"
 #include <cwa.h>
@@ -576,8 +577,26 @@ webgit_account_action (struct webgit_query* query)
 static Html
 webgit_edit_action (struct webgit_query* query)
 {
-  (void) query;
-  return html("edit");
+  struct webgit_repo_info* repo = webgit_repo_enter (query);
+  webgit_object_deduce (query);
+
+  unsigned char sha1[20];
+  if (get_sha1 (query->object, sha1))
+    return html("error: unknown object");
+
+  switch (sha1_object_info(sha1, NULL))
+    {
+    case OBJ_BLOB:
+      return webgit_edit_blob_action (repo, sha1);
+      //case OBJ_COMMIT:
+      //case OBJ_TREE:
+      //case OBJ_TAG:
+
+      break;
+    default:
+      return html ("error: unknown object type");
+      break;
+    }
 }
 
 
diff --git a/src/edit.c b/src/edit.c
new file mode 100644 (file)
index 0000000..420ca4b
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+    cehtehs git web frontend
+
+  Copyright (C)
+    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 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 Affero General Public License for more details.
+
+  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 "edit.h"
+#include "repo.h"
+#include "actions.h"
+#include "object.h"
+#include "summary.h"
+
+/*
+  Edit menu
+*/
+
+static Html
+webgit_edit_blob_menu_action (struct webgit_repo_info* repo, unsigned char* sha1, void* buf, unsigned long size)
+{
+  (void) sha1;
+  (void) buf;
+  (void) size;
+
+  struct webgit_query* query = repo->query;
+
+  return html (html_tag ("div"),
+               webgit_repo_logo (repo), "<br />",
+               webgit_object_tree_parent_link (query, "<<%s"),
+               webgit_summary_link (query, repo, html("Summary")), "<br />",
+               webgit_main_link (query, html ("Main"))
+               );
+}
+
+static Html
+webgit_edit_blob_content_action (struct webgit_repo_info* repo, unsigned char* sha1, void* buf, unsigned long size)
+{
+  (void) sha1;
+
+  return html (
+               html (html_tag ("form",
+                               html_attr ("name", "blob-edit"),
+                               html_attr ("enctype", "multipart/form-data"),
+                               html_attr ("method", "post"),
+                               html_attr ("action", repo->query->request->script_name)
+                               ),
+                     html (html_tag ("p"), "File: (change this for renaming or copying)",
+                           html_hidden ("repo", repo->name),
+                           html_hidden ("action", "edit"),
+                           html (html_tag ("input",
+                                           html_attr ("name", "path"),
+                                           html_attr ("type", "text"),
+                                           html_attr ("maxlen", html_fmt ("%d", PATH_MAX)),
+                                           html_attr ("size", "80"),
+                                           html_attr ("value", repo->query->path)
+                                           )
+                                 ),
+                           html (html_tag ("input",
+                                           html_attr ("name", "mode"),
+                                           html_attr ("type", "radio"),
+                                           html_attr ("value", "rename"),
+                                           html_attr ("checked", "checked")
+                                           )
+                                 ),
+                           "rename",
+                           html (html_tag ("input",
+                                           html_attr ("name", "mode"),
+                                           html_attr ("type", "radio"),
+                                           html_attr ("value", "copy")
+                                           )
+                                 ),
+                           "copy",
+                           !memchr(buf, 0, size>8192 ? 8192 : size) ?
+                           html (
+#ifndef ENABLE_CODEPRESS
+                                 html (html_tag ("input",
+                                                 html_attr ("type", "reset"),
+                                                 html_attr ("value", "Undo all changes")
+                                                 )
+                                       ),
+#endif
+                                 html (html_tag ("textarea",
+                                                 html_attr ("id", "blob"),
+                                                 html_attr ("name", "blob"),
+                                                 html_attr ("class", "codepress generic"),
+                                                 html_attr ("wrap", "off"),
+                                                 html_attr ("style", "width:100%;height:600px")
+                                                 ),
+                                       html_strndup (buf, size)
+                                       )
+                                 ) : html ()
+                           ),
+                           html (html_tag ("p"), "Please add a brief summary of the changes you have made:",
+                           html (html_tag ("input",
+                                           html_attr ("name", "comment"),
+                                           html_attr ("type", "text"),
+                                           html_attr ("value", ""),
+                                           html_attr ("maxlen", "512"),
+                                           html_attr ("size", "80")
+                                           )
+                                 )
+                           ),
+                     html (html_tag ("p"),
+                           html (html_tag ("input",
+                                           html_attr ("name", "cancel"),
+                                           html_attr ("type", "submit"),
+                                           html_attr ("value", "Cancel")
+                                           )
+                                 ),
+                           html (html_tag ("input",
+                                           html_attr ("name", "stage"),
+                                           html_attr ("type", "submit"),
+                                           html_attr ("value", "Stage for commit")
+                                           )
+                                 ),
+                           html (html_tag ("input",
+                                           html_attr ("name", "commit"),
+                                           html_attr ("type", "submit"),
+                                           html_attr ("value", "Commit ...")
+                                           )
+                                 )
+                           ),
+                     html (html_tag ("p"), "Or"),
+                     html ( html_tag ("dl"),
+                            html ( html_tag ("dt"), "Upload File:"),
+                            html ( html_tag ("dt"),
+                                   html (html_tag ("input",
+                                                   html_attr ("name", "file"),
+                                                   html_attr ("size", "50"),
+                                                   html_attr ("maxlen", html_fmt ("%d", PATH_MAX)),
+                                                   html_attr ("value", ""),
+                                                   html_attr ("type", "file")
+                                                   )
+                                         ),
+                                   html (html_tag ("input",
+                                                   html_attr ("name", "upload"),
+                                                   html_attr ("value", "Upload"),
+                                                   html_attr ("type", "submit")
+                                                   )
+                                         )
+                                   )
+                            )
+                     )
+               );
+}
+
+
+
+Html
+webgit_edit_blob_action (struct webgit_repo_info* repo, unsigned char* sha1)
+{
+  void* buf;
+  unsigned long size;
+
+  buf = read_object_with_reference (sha1, "blob", &size, NULL);
+
+  return html(
+              html(html_tag("div", html_attr("id", "sub-menu")),
+                   webgit_edit_blob_menu_action (repo, sha1, buf, size)), html_nl (),
+              html(html_tag("div", html_attr("id", "content")),
+                   webgit_edit_blob_content_action (repo, sha1, buf, size)), html_nl ()
+              );
+}
+
+/*
+//      Local Variables:
+//      mode: C
+//      c-file-style: "gnu"
+//      indent-tabs-mode: nil
+//      End:
+*/
diff --git a/src/edit.h b/src/edit.h
new file mode 100644 (file)
index 0000000..565d03d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+    cehtehs git web frontend
+
+  Copyright (C)
+    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 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 Affero General Public License for more details.
+
+  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/>.
+*/
+#ifndef WEBGIT_EDIT_H
+#define WEBGIT_EDIT_H
+
+#include "webgit.h"
+
+#define SHA1_HEADER <openssl/sha.h>
+#include "git/cache.h"
+#include "git/object.h"
+#include "git/commit.h"
+
+
+Html
+webgit_edit_blob_action (struct webgit_repo_info* repo, unsigned char* sha1);
+
+#endif
+
+/*
+//      Local Variables:
+//      mode: C
+//      c-file-style: "gnu"
+//      indent-tabs-mode: nil
+//      End:
+*/
index 07d8815..3e14e57 100644 (file)
@@ -33,6 +33,8 @@ webgit_object_blob_menu_action (struct webgit_repo_info* repo, unsigned char* sh
   (void) buf;
   (void) size;
 
+  struct webgit_query* query = repo->query;
+
   return html (html_tag ("div"),
                webgit_repo_logo (repo), "<br />",
                // TODO: "diff against.. <br />",
@@ -40,11 +42,16 @@ webgit_object_blob_menu_action (struct webgit_repo_info* repo, unsigned char* sh
                // TODO: "history <br />",
                // TODO: "blame <br />",
                // TODO: "Back to tree <br />",
-               // TODO: "Edit <br />",
-               // TODO: "Parent <br />",
-               webgit_object_tree_parent_link (repo->query, "<<%s"),
-               webgit_summary_link (repo->query, repo, html("Summary")), "<br />",
-               webgit_main_link (repo->query, html ("Main"))
+               // TODO: ,
+               webgit_object_link (query, html ("Edit <br />"),
+                                   "repo", query->repo,
+                                   "ref", query->head,
+                                   "commit", query->commit,
+                                   "path", query->path,
+                                   "action", "edit"),
+               webgit_object_tree_parent_link (query, "<<%s"),
+               webgit_summary_link (query, repo, html("Summary")), "<br />",
+               webgit_main_link (query, html ("Main"))
                );
 }
 
@@ -108,8 +115,12 @@ webgit_object_blob_action (struct webgit_repo_info* repo, unsigned char* sha1)
   buf = read_object_with_reference (sha1, "blob", &size, NULL);
 
   return html(
-              html(html_tag("div", html_attr("id", "sub-menu")), webgit_object_blob_menu_action (repo, sha1, buf, size)), html_nl (),
-              html(html_tag("div", html_attr("id", "content")), webgit_object_blob_content_action (repo, sha1, buf, size)), html_nl ()
+              html(html_tag("div",
+                            html_attr("id", "sub-menu")),
+                   webgit_object_blob_menu_action (repo, sha1, buf, size)), html_nl (),
+              html(html_tag("div",
+                            html_attr("id", "content")),
+                   webgit_object_blob_content_action (repo, sha1, buf, size)), html_nl ()
               );
 }
 
index b55307c..7dccffd 100644 (file)
@@ -174,7 +174,14 @@ webgit_html_tree (const unsigned char *sha1, const char *base, int baselen,
                                                               "commit", query_in_flight->commit,
                                                               "path", pathname,
                                                               "action", "raw"),
-                                          " edit")
+                                          " ",
+                                          webgit_object_link (query_in_flight, html ("Edit <br />"),
+                                                              "repo", query_in_flight->repo,
+                                                              "ref", query_in_flight->head,
+                                                              "commit", query_in_flight->commit,
+                                                              "path", pathname,
+                                                              "action", "edit")
+                                          )
                                     ),
                               html_nl()
                               )
index 3dd4c99..b4c8901 100644 (file)
 
 #include "webgit.h"
 
-#define ENABLE_CODEPRESS 1
-#define ENABLE_SORTTABLE 0
-
-#define WEBGIT_CONFIG "./webgit.conf"
-
-#ifndef WEBGIT_CONFIG
-#define WEBGIT_CONFIG "/etc/webgit.conf"
-#endif
-
 #include "login.h"
 #include "actions.h"
 #include "query.h"
index d8f5ee4..562c05b 100644 (file)
 
 #include "llist.h"
 
+#define ENABLE_CODEPRESS 1
+//#define ENABLE_SORTTABLE 1
+
+#define WEBGIT_CONFIG "./webgit.conf" /* TODO fix via configure --with-webgit-config=... */
+
+#ifndef WEBGIT_CONFIG
+#define WEBGIT_CONFIG "/etc/webgit.conf"
+#endif
+
 #ifndef WEBGIT_SKINDIR_DEFAULT
 #define WEBGIT_SKINDIR_DEFAULT "/usr/share/webgit/skins"
 #endif