-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Event Creator | Bondscape</title> | ||
|
||
<!-- Note: The ?v= query parameter is used to solve a caching issue that exists with Cloudfare --> | ||
<link rel="stylesheet" href="styles.css?v=1.1.0"> | ||
|
||
<link rel="manifest" href="assets/manifest.json"> | ||
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon/favicon-16x16.png"> | ||
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon/favicon-32x32.png"> | ||
|
||
<!-- Add the Tailwind CSS CDN link below --> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
|
||
<!-- Add the QR code generator library --> | ||
<script src="https://cdn.jsdelivr.net/npm/qrcode-generator/qrcode.js"></script> | ||
|
||
<script src="scripts/creator.js"></script> | ||
</head> | ||
|
||
<body class="bg-[#FFFFFF] text-[#3B3B3B] "> | ||
<div class="container mx-auto p-4 w-full lg:w-1/2"> | ||
<h1 class="text-[#8358f9] text-4xl font-bold mb-4">Bondscape Event Creator</h1> | ||
<p class="mt-8">Welcome to the Bondscape event creator! </p> | ||
<p>With this tool you can create a new Bondscape event. All you have to do is:</p> | ||
<ol class="pl-6 my-8 list list-decimal"> | ||
<li>Fill all the fields you want (those with a * are required).</li> | ||
<li>Tap on "Create Event".</li> | ||
</ol> | ||
<p class="mb-8 text-sm"> | ||
<span class="font-bold">Note</span>: This tool can only be used by people possessing an admin key. | ||
</p> | ||
|
||
<form id="eventCreationForm" action=""> | ||
<div class="mb-4"> | ||
<label for="name" class="block font-bold mb-2">Name <span class="text-[#8358f9]">*</span></label> | ||
<input type="text" id="name" name="name" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300" | ||
required> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="description" class="block font-bold mb-2">Description</label> | ||
<textarea id="description" name="description" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</textarea> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="coverPicture" class="block font-bold mb-2">Cover Picture</label> | ||
<input type="file" id="coverPicture" name="coverPicture" autocomplete="off" | ||
class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="website" class="block font-bold mb-2">Website</label> | ||
<input type="url" id="website" name="website" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="startDate" class="block font-bold mb-2">Start Date</label> | ||
<input type="datetime-local" id="startDate" name="startDate" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="endDate" class="block font-bold mb-2">End Date</label> | ||
<input type="datetime-local" id="endDate" name="endDate" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="place" class="block font-bold mb-2">Place</label> | ||
<input type="text" id="place" name="place" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="tags" class="block font-bold mb-2"> | ||
Tags<br/><span class="text-xs">(Comma separated)</span> | ||
</label> | ||
<input type="text" id="tags" name="tags" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="organizers" class="block font-bold mb-2"> | ||
Organizers addresses<br/><span class="text-xs">(Comma separated)</span> | ||
</label> | ||
<input type="text" id="organizers" name="organizers" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label for="adminKey" class="block font-bold mb-2">Admin key <span class="text-[#8358f9]">*</span></label> | ||
<input type="text" id="adminKey" name="adminKey" autocomplete="off" | ||
class="text-[#5C5C5C] w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300" | ||
required> | ||
</div> | ||
|
||
<button type="submit" class="w-full bg-[#8358f9] hover:bg-[#5C3EAE] text-white font-bold py-2 px-4 rounded"> | ||
Create Event | ||
</button> | ||
|
||
<div class="mt-4"> | ||
|
||
<!-- Loading text --> | ||
<div id="loadingIndicator" class="hidden flex flex-row items-center"> | ||
<svg aria-hidden="true" class="inline w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" | ||
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" | ||
fill="currentColor"/> | ||
<path | ||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" | ||
fill="currentFill"/> | ||
</svg> | ||
<span id="loadingText">Creating event...</span> | ||
</div> | ||
|
||
<!-- Success text --> | ||
<div id="successIndicator" | ||
class="hidden p-4 text-sm text-green-800 rounded-lg bg-green-50 dark:bg-gray-800 dark:text-green-400" | ||
role="alert"> | ||
|
||
<p class="font-medium">Event created!</p> | ||
|
||
<p class="mt-2">ID: <span id="eventID"></span></p> | ||
|
||
<p class="mt-2">QR Code to view the event details:</p> | ||
<div id="detailsQRCode"></div> | ||
|
||
<p class="mt-2">QR Code to join the event:</p> | ||
<div id="joinQRCode"></div> | ||
</div> | ||
|
||
<!-- Error text --> | ||
<div id="errorIndicator" | ||
class="hidden p-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400" role="alert"> | ||
<span class="font-medium">Error!</span> | ||
<span id="errorMessage">Change a few things up and try submitting again.</span> | ||
</div> | ||
|
||
</div> | ||
|
||
|
||
</form> | ||
</div> | ||
|
||
|
||
<script async defer | ||
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCywSKgHWVQZaxi8Klt9pv4PTgVVJwd3kM&libraries=places&callback=initAutocomplete"></script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
// const apiBase = "https://api-bondscape.testnet.desmos.network"; | ||
const apiBase = "http://localhost:3000"; | ||
|
||
const values = { | ||
place_id: "", | ||
}; | ||
|
||
// Initialize the Google Places Autocomplete service for the specific input field | ||
function initAutocomplete() { | ||
const input = document.getElementById("place"); | ||
const options = { | ||
types: ["geocode"], // Restrict results to geocoding (place name or address) | ||
}; | ||
const autocomplete = new google.maps.places.Autocomplete(input, options); | ||
|
||
// Listen for the "place_changed" event to get the selected place details | ||
autocomplete.addListener("place_changed", function () { | ||
const place = autocomplete.getPlace(); | ||
if (place && place.place_id) { | ||
values.place_id = place.place_id; | ||
console.log("Selected Place ID:", values.place_id); | ||
// You can use the placeId variable to perform further actions with the selected place. | ||
} | ||
}); | ||
} | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
// --- Utils | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
// Split a string into an array of items | ||
function splitItems(value) { | ||
return value.split(",").map((item) => item.trim()); | ||
} | ||
|
||
// Format a date value to ISO 8601 format | ||
function formatDate(value) { | ||
const dateValue = new Date(value); | ||
if (!isNaN(dateValue)) { | ||
return dateValue.toISOString(); | ||
} | ||
return null; | ||
} | ||
|
||
function createQRCode(text) { | ||
const qr = qrcode(0, "M"); | ||
qr.addData(text); | ||
qr.make(); | ||
|
||
// Create an image tag for the QR code | ||
return qr.createImgTag(6, 16); | ||
} | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
// --- Messages | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
function showLoadingIndicator() { | ||
hideSuccessMessage(); | ||
hideErrorMessage() | ||
document.getElementById("loadingIndicator").classList.remove("hidden"); | ||
} | ||
|
||
function hideLoadingIndicator() { | ||
document.getElementById("loadingIndicator").classList.add("hidden"); | ||
} | ||
|
||
function setLoadingText(text) { | ||
document.getElementById("loadingText").innerText = text; | ||
} | ||
|
||
function setEventID(text) { | ||
hideLoadingIndicator(); | ||
document.getElementById("eventID").innerText = text; | ||
document.getElementById("successIndicator").classList.remove("hidden"); | ||
} | ||
|
||
function setDetailsQRCode(qrCode) { | ||
document.getElementById("detailsQRCode").innerHTML = qrCode; | ||
} | ||
|
||
function setJoinQRCode(qrCode) { | ||
document.getElementById("joinQRCode").innerHTML = qrCode; | ||
} | ||
|
||
function hideSuccessMessage() { | ||
document.getElementById("successIndicator").classList.add("hidden"); | ||
} | ||
|
||
function setErrorMessage(text) { | ||
hideLoadingIndicator(); | ||
document.getElementById("errorMessage").innerText = text; | ||
document.getElementById("errorIndicator").classList.remove("hidden"); | ||
} | ||
|
||
function hideErrorMessage() { | ||
document.getElementById("errorIndicator").classList.add("hidden"); | ||
} | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
// --- Form submission | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
// Upload a picture to the API | ||
async function uploadPicture(elementID, adminKey) { | ||
const fileInput = document.getElementById(elementID); | ||
const files = fileInput.files; | ||
|
||
// Check if any files were selected | ||
if (files.length === 0) { | ||
return ""; | ||
} | ||
|
||
// Create a FormData object and append the file data to it | ||
const formData = new FormData(); | ||
formData.append("file", files[0]); | ||
|
||
// Set up the headers with the "Authorization" Bearer token | ||
const headers = new Headers(); | ||
headers.append("Authorization", `Bearer ${adminKey}`); | ||
|
||
// Send the form data to your API endpoint using fetch API with await | ||
const response = await fetch(`${apiBase}/media`, { | ||
method: "POST", body: formData, headers: headers, | ||
}); | ||
|
||
if (response.ok) { | ||
const returnedData = await response.json(); | ||
return returnedData.url; | ||
} else { | ||
console.error("Upload failed:", response.statusText); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
// Handle the form submission | ||
async function handleFormSubmission(event) { | ||
// Get form input values | ||
const name = document.getElementById("name").value; | ||
const description = document.getElementById("description").value; | ||
const website = document.getElementById("website").value; | ||
const startDate = document.getElementById("startDate").value; | ||
const endDate = document.getElementById("endDate").value; | ||
const placeID = values.place_id; | ||
const tags = document.getElementById("tags").value; | ||
const organizers = document.getElementById("organizers").value; | ||
const adminKey = document.getElementById("adminKey").value; | ||
|
||
// Upload the picture | ||
setLoadingText("Uploading cover picture..."); | ||
const pictureUrl = await uploadPicture("coverPicture", adminKey) | ||
|
||
// Build the data to be sent | ||
const data = { | ||
name: name, | ||
description: description, | ||
cover_picture_url: pictureUrl, | ||
website: website, | ||
start_date: formatDate(startDate), | ||
end_date: formatDate(endDate), | ||
place_id: placeID, | ||
tags: splitItems(tags), | ||
organizers: splitItems(organizers), | ||
} | ||
|
||
try { | ||
// Set up the headers with the "Authorization" Bearer token | ||
const headers = new Headers(); | ||
headers.append("Authorization", `Bearer ${adminKey}`); | ||
headers.append("Content-Type", "application/json"); | ||
|
||
// Perform the API call | ||
setLoadingText("Uploading data..."); | ||
const response = await fetch(`${apiBase}/events`, { | ||
method: "POST", headers: headers, body: JSON.stringify(data), | ||
}); | ||
|
||
if (response.ok) { | ||
const responseData = await response.json(); | ||
|
||
|
||
setLoadingText("Generating QR codes..."); | ||
|
||
const detailsQRCode = createQRCode(responseData.event_details_link); | ||
setDetailsQRCode(detailsQRCode); | ||
|
||
const joinQRCode = createQRCode(responseData.event_join_link); | ||
setJoinQRCode(joinQRCode); | ||
|
||
setEventID(responseData.event_id); | ||
} else { | ||
const responseData = await response.text(); | ||
setErrorMessage(`Error while creating event: ${responseData}`); | ||
} | ||
} catch (error) { | ||
setErrorMessage(`Error while creating event: ${error}`); | ||
} | ||
} | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
// --- Page setup | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
window.addEventListener("DOMContentLoaded", (event) => { | ||
document.getElementById("eventCreationForm").addEventListener("submit", function (event) { | ||
event.preventDefault(); | ||
|
||
showLoadingIndicator(); | ||
|
||
setTimeout(handleFormSubmission, 2000); | ||
}); | ||
}); |