view src/admin/index.html.luan @ 0:dfc36e7ed22c

init
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 12 May 2022 13:51:59 +0400
parents
children 028e74c8889d
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local pairs = Luan.pairs or error()
local ipairs = Luan.ipairs or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.admin_header or error()
local get_user = Shared.get_user or error()
local config = Shared.config or error()


local user_repos = {}
for _, repo in pairs(config.repos) do
	for user in pairs(repo.users) do
		local repos = user_repos[user]
		if repos == nil then
			repos = {}
			user_repos[user] = repos
		end
		repos[#repos+1] = repo
	end
end

return function()
	local user = get_user()
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title>Your Mercurial Repositories</title>
		<script>
			function deleteRepo(name) {
				if( confirm('Are you sure that you want to delete repo "'+name+'"?') )
					location = "delete.html?repo="+name;
			}
		</script>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Repositories of <%=user%></h1>
<%	for _, repo in ipairs(user_repos[user] or {}) do
		local name = repo.name
%>
			<p>
				<a href="/repo/<%=name%>/"><%=name%></a>
<%		if repo.admins[user] then %>
				- <a href="edit.html?repo=<%=name%>">edit</a>
				- <a href="javascript:deleteRepo('<%=name%>')">delete</a>
<%		end %>
			</p>
<%	end %>
			<hr>
			<h2>Add Repository</h2>
			<form action="add.html">
				<p>
					<label prompt>Repo name</label>
					<input type=text name=repo required>
				</p>
				<p>
					<input type=submit value="Add Repo">
				</p>
			</form>
<%	if config.private==nil or config.private[user] then %>
			<hr>
			<p><a href="/private/">/private/</a></p>
<%	end %>
		</div>
	</body>
</html>
<%
end