Add delete button to drive page
This commit is contained in:
parent
6dc8447343
commit
d4703a2127
3 changed files with 56 additions and 1 deletions
|
@ -280,6 +280,7 @@ const drive = struct {
|
||||||
|
|
||||||
const Action = enum {
|
const Action = enum {
|
||||||
mkdir,
|
mkdir,
|
||||||
|
delete,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const body_tag_from_query_param = "action";
|
pub const body_tag_from_query_param = "action";
|
||||||
|
@ -287,6 +288,7 @@ const drive = struct {
|
||||||
mkdir: struct {
|
mkdir: struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
},
|
},
|
||||||
|
delete: struct {},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
||||||
|
@ -297,6 +299,19 @@ const drive = struct {
|
||||||
|
|
||||||
try servePage(req, res, srv);
|
try servePage(req, res, srv);
|
||||||
},
|
},
|
||||||
|
.delete => {
|
||||||
|
const trimmed_path = std.mem.trim(u8, req.args.path, "/");
|
||||||
|
_ = try srv.driveDelete(trimmed_path);
|
||||||
|
|
||||||
|
const dir = trimmed_path[0 .. std.mem.lastIndexOfScalar(u8, trimmed_path, '/') orelse trimmed_path.len];
|
||||||
|
const url = try std.fmt.allocPrint(srv.allocator, "{s}/drive/{s}", .{
|
||||||
|
req.mount_path,
|
||||||
|
dir,
|
||||||
|
});
|
||||||
|
defer srv.allocator.free(url);
|
||||||
|
try res.headers.put("Location", url);
|
||||||
|
return res.status(.see_other);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,25 @@
|
||||||
{$dir.name.?}
|
{$dir.name.?}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
<td />
|
||||||
|
<td />
|
||||||
|
<td />
|
||||||
|
<td class="actions">
|
||||||
|
<div class="popup" id="delete-{$dir.name.?}">
|
||||||
|
<a href="#delete-{$dir.name.?}">
|
||||||
|
<i class="fa-solid fa-trash"></i>
|
||||||
|
</a>
|
||||||
|
<form class="popup-dialog" action="
|
||||||
|
{= .mount_path}/{.base_drive_path}
|
||||||
|
{= #for @slice(.breadcrumbs, 0, .breadcrumbs.len) |$c|}/{$c}{/for =}/{$dir.name.? =}
|
||||||
|
?action=delete" method="post"
|
||||||
|
>
|
||||||
|
<div>Are you sure you want to delete this directory?</div>
|
||||||
|
<button type="submit">Yes, Delete</button>
|
||||||
|
<a href="#">No, Cancel</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
{#case file |$file|}
|
{#case file |$file|}
|
||||||
<td class="icons">
|
<td class="icons">
|
||||||
{#if %user |$u|}
|
{#if %user |$u|}
|
||||||
|
@ -71,6 +90,23 @@
|
||||||
<td class="content-type">{#if $file.meta.content_type |$t|}{$t}{/if}</td>
|
<td class="content-type">{#if $file.meta.content_type |$t|}{$t}{/if}</td>
|
||||||
<td class="size">{$file.meta.size}</td>
|
<td class="size">{$file.meta.size}</td>
|
||||||
<td class="created-at">{$file.meta.created_at}</td>
|
<td class="created-at">{$file.meta.created_at}</td>
|
||||||
|
<td class="actions">
|
||||||
|
<div class="popup" id="delete-{$file.name.?}">
|
||||||
|
<a href="#delete-{$file.name.?}">
|
||||||
|
<i class="fa-solid fa-trash"></i>
|
||||||
|
</a>
|
||||||
|
<form class="popup-dialog" action="
|
||||||
|
{= .mount_path}/{.base_drive_path}
|
||||||
|
{= #for @slice(.breadcrumbs, 0, .breadcrumbs.len) |$c|}/{$c}{/for =}/{$file.name.? =}
|
||||||
|
?action=delete" method="post"
|
||||||
|
>
|
||||||
|
<div>Are you sure you want to delete this file?</div>
|
||||||
|
<input type="hidden" name="action" value="delete" />
|
||||||
|
<button type="submit">Yes, Delete</button>
|
||||||
|
<a href="#">No, Cancel</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
{/switch =}
|
{/switch =}
|
||||||
</tr>
|
</tr>
|
||||||
{/for=}
|
{/for=}
|
||||||
|
|
|
@ -266,7 +266,11 @@ pub fn DeserializerContext(comptime Result: type, comptime From: type, comptime
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish(self: *@This(), allocator: std.mem.Allocator) !Result {
|
pub fn finish(self: *@This(), allocator: std.mem.Allocator) !Result {
|
||||||
return (try self.deserialize(allocator, Result, self.data, &.{})) orelse error.MissingField;
|
return (try self.deserialize(allocator, Result, self.data, &.{})) orelse
|
||||||
|
if (std.meta.fields(Result).len == 0)
|
||||||
|
return .{}
|
||||||
|
else
|
||||||
|
return error.MissingField;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getSerializedField(self: *@This(), comptime field_ref: FieldRef) ?From {
|
fn getSerializedField(self: *@This(), comptime field_ref: FieldRef) ?From {
|
||||||
|
|
Loading…
Reference in a new issue