srctree

Gregory Mullen parent d9cb8ac5 5d1feeb6
html skel to pull diff from upstream

src/endpoints/repos/diffs.zig added: 76, removed: 18, total 58
@@ -30,8 +30,8 @@ const UriIter = Route.UriIter;
 
pub const routes = [_]Route.Match{
ROUTE("", list),
GET("new", new),
POST("new", newPost),
ROUTE("new", new),
POST("create", newPost),
POST("add-comment", newComment),
};
 
@@ -53,9 +53,49 @@ pub fn router(ctx: *Context) Error!Route.Callable {
return Route.router(ctx, &routes);
}
 
const DiffNewHtml = Template.PageData("diff-new.html");
 
const DiffCreateChangeReq = struct {
from_network: ?bool = null,
patch_uri: []const u8,
title: []const u8,
desc: []const u8,
};
 
fn new(ctx: *Context) Error!void {
var tmpl = comptime Template.find("diff-new.html");
try ctx.sendTemplate(&tmpl);
var network: ?S.Network = null;
var patchuri: ?S.PatchUri = .{};
if (ctx.reqdata.post) |post| {
const udata = post.validate(DiffCreateChangeReq) catch return error.BadData;
 
if (udata.from_network) |_| {
network = .{
.remotes = &.{
.{ .value = "upstream", .name = "upstream network thingy" },
},
.branches = &.{
.{ .value = "main", .name = "main" },
.{ .value = "develop", .name = "develop" },
.{ .value = "master", .name = "master" },
},
};
}
patchuri = null;
}
 
var page = DiffNewHtml.init(.{
.meta_head = .{
.open_graph = .{},
},
.body_header = .{ .nav = .{
.nav_buttons = &try Repo.navButtons(ctx),
.nav_auth = undefined,
} },
.network = network,
.patch_uri = patchuri,
});
 
try ctx.sendPage(&page);
}
 
fn inNetwork(str: []const u8) bool {
@@ -64,7 +104,7 @@ fn inNetwork(str: []const u8) bool {
return true;
}
 
const IssueCreateReq = struct {
const DiffCreateReq = struct {
patch_uri: []const u8,
title: []const u8,
desc: []const u8,
@@ -77,7 +117,9 @@ const IssueCreateReq = struct {
fn newPost(ctx: *Context) Error!void {
const rd = Repo.RouteData.make(&ctx.uri) orelse return error.Unrouteable;
if (ctx.reqdata.post) |post| {
const udata = post.validate(IssueCreateReq) catch return error.BadData;
const udata = post.validate(DiffCreateReq) catch return error.BadData;
 
if (udata.title.len == 0) return error.BadData;
 
var delta = Delta.new(rd.name) catch unreachable;
//delta.src = src;
 
src/routes.zig added: 76, removed: 18, total 58
@@ -83,7 +83,7 @@ pub fn ROUTE(comptime name: []const u8, comptime match: anytype) Match {
"]"),
},
 
.methods = .{ .GET = true },
.methods = .{ .GET = true, .POST = true },
};
}
 
 
static/main.css added: 76, removed: 18, total 58
@@ -511,18 +511,20 @@ form.pretty {
height: 35px;
padding: 4px 0 4px 12px;
}
input, textarea {
input, textarea, select {
margin: 0 0.5em;
display: block;
flex-grow: 1;
background: #333;
display: inline-block;
border: 1px solid gray;
border-radius: 0;
font-size: 130%;
padding: 4px;
}
input, textarea {
border-bottom: 0px solid gray;
&:last-of-type {
border-bottom: 1px solid gray;
margin-bottom: 0.5em;
}
}
button {
 
templates/diff-new.html added: 76, removed: 18, total 58
@@ -7,11 +7,25 @@
<body>
<_body_header.html>
<content>
<form class="pretty" action="new" method="POST">
<form class="pretty" action="create" method="POST">
<context>Suggest New Diff</context>
<input name="patch_uri" placeholder="Patch URL" />
<input name="title" placeholder="Diff Title" />
<textarea name="desc" placeholder="Additional information about this patch suggestion"></textarea>
<input name="title" placeholder="Diff Title" value="<Title ORNULL>" />
<With Network>
<div style="display:flex">
<select name="network">
<For Remotes>
<option value="<Value>"><Name></option>
</For>
</select><span style="font-size: 130%;margin: auto;">/</span>
<select name="branch">
<For Branches>
<option value="<Value>"><Name></option>
</For>
</select>
</div>
</With>
<With PatchUri><div style="display:flex"><input name="patch_uri" placeholder="Patch URL" /><button name="from_network" value="true" formaction="new">Use Network</button></div></With>
<textarea name="desc" placeholder="Additional information about this patch suggestion"><Desc ORNULL></textarea>
<buttons>
<button name="submit">Submit</button>
<button name="preview">Preview</button>