This commit is contained in:
Christoph Hagen 2022-02-10 16:19:11 +01:00
commit 896a9f79d1
4 changed files with 30 additions and 8 deletions

View File

@ -17,3 +17,17 @@ function loadList(name, source) {
txtFile.open("GET", list, true);
txtFile.send(null);
}
function loadCount() {
var txtFile = new XMLHttpRequest();
var allText = "";
txtFile.onreadystatechange = function () {
if (txtFile.readyState === XMLHttpRequest.DONE && txtFile.status == 200) {
allText = txtFile.responseText;
}
document.getElementById("left-button").innerHTML = "Registered (" + allText + ")";
}
var list = '/festival/api/count' + name;
txtFile.open("GET", list, true);
txtFile.send(null);
}

View File

@ -19,7 +19,7 @@
<link rel="stylesheet" type="text/css" href="assets/festival.css">
<link rel="stylesheet" type="text/css" href="assets/festival-info.css">
<script src="assets/festival.js?v=9"></script>
<script src="assets/festival-info.js?v=0"></script>
<script src="assets/festival-info.js?v=1"></script>
</head>
<body>
<div class="wrapper">
@ -49,6 +49,7 @@
</div>
<div class="member-list" id="remote-content">Liste nicht geladen</div>
<script>loadList('registered.txt', document.getElementById('left-button'))</script>
<script>loadCount()</script>
</div>
</body>
</html>

View File

@ -16,6 +16,16 @@ private let df: DateFormatter = {
return df
}()
func guestCount() -> Int {
registeredGuests
.reduce([]) { $0 + $1.components(separatedBy: "+") }
.reduce([]) { $0 + $1.components(separatedBy: "-") }
.reduce([]) { $0 + $1.components(separatedBy: "und ") }
.reduce([]) { $0 + $1.components(separatedBy: "&") }
//.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.count
}
func add(guest: String) -> String {
registeredGuests.insert(guest)

View File

@ -12,16 +12,13 @@ private func register(_ req: Request, isAttending: Bool) -> String {
}
func routes(_ app: Application) throws {
app.get { req in
app.get("festival", "api", "ping") { req in
return "It works!"
}
app.get("festival", "api", "hello") { req in
return "It works!"
}
app.get("hello") { req in
return "It works!"
app.get("festival", "api", "count") { req in
return "\(guestCount())"
}
app.post("festival", "api", "register") { req -> String in