-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nightly (hopefully) See merge request jaguililla/hexagonal_spring!15
- Loading branch information
Showing
10 changed files
with
929 additions
and
6 deletions.
There are no files selected for viewing
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
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
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,57 @@ | ||
<!DOCTYPE html> | ||
|
||
<head> | ||
<meta lang="en"> | ||
<meta charset="UTF-8"> | ||
|
||
<title>Appointments</title> | ||
|
||
<link rel="stylesheet" href="simple.css"> | ||
<style> | ||
:root { | ||
--body-font-size: 1rem; | ||
--body-line-height: 1.2; | ||
} | ||
</style> | ||
</head> | ||
|
||
<header> | ||
<h1>Appointments</h1> | ||
<p>Example task application</p> | ||
|
||
<nav> | ||
<a href="/" class="current">Appointments</a> | ||
<a href="/">Users</a> | ||
</nav> | ||
</header> | ||
|
||
<h3>Open</h3> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Title</th> | ||
<th>Order</th> | ||
</tr> | ||
</thead> | ||
<tbody id="appointments"></tbody> | ||
</table> | ||
|
||
<h3>New</h3> | ||
<form> | ||
<label for="title">Title</label> | ||
<input id="title" type="text"> | ||
<label for="order">Order</label> | ||
<input id="order" type="number"> | ||
</form> | ||
<button onclick="add()">Add</button> | ||
|
||
<template id="appointmentRow"> | ||
<tr> | ||
<td>title</td> | ||
<td>0</td> | ||
<td><input type="checkbox" checked></td> | ||
</tr> | ||
</template> | ||
|
||
<script src="main.js"></script> |
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,62 @@ | ||
|
||
const http = new XMLHttpRequest(); | ||
|
||
const tbody = document.querySelector("tbody#appointments"); | ||
const template = document.querySelector("#appointmentRow"); | ||
const titleInput = document.querySelector("#title"); | ||
const orderInput = document.querySelector("#order"); | ||
|
||
function httpSend(method, url, body, callback) { | ||
http.open(method, url); | ||
http.setRequestHeader('Content-type', 'application/json'); | ||
http.send(JSON.stringify(body)); | ||
http.onload = callback; | ||
} | ||
|
||
function httpGet(url, body, callback) { | ||
httpSend('GET', url, body, callback); | ||
} | ||
|
||
function httpPost(url, body, callback) { | ||
httpSend('POST', url, body, callback); | ||
} | ||
|
||
function addTask(task) { | ||
const clone = template.content.cloneNode(true); | ||
const td = clone.querySelectorAll("td"); | ||
const input = clone.querySelectorAll("input"); | ||
td[0].textContent = task.title; | ||
td[1].textContent = task.order; | ||
input.checked = task.completed; | ||
tbody.appendChild(clone); | ||
} | ||
|
||
function add() { | ||
const body = { | ||
title: titleInput.value, | ||
order: orderInput.valueAsNumber | ||
}; | ||
|
||
httpPost('/appointments', body, () => { | ||
titleInput.value = ""; | ||
orderInput.value = 0; | ||
|
||
addTask(JSON.parse(http.responseText)); | ||
}); | ||
} | ||
|
||
function main() { | ||
|
||
httpGet('/appointments', null, () => { | ||
for (const tr of tbody.children) | ||
tr.remove(); | ||
|
||
const response = JSON.parse(http.responseText); | ||
for (const task of response) | ||
addTask(task); | ||
|
||
console.log(http.responseText); | ||
}); | ||
} | ||
|
||
document.body.onload = main; |
Oops, something went wrong.