diff --git a/docker-compose.yml b/docker-compose.yml index fedb5fd..c21c363 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,4 +29,4 @@ services: - "33060:3306" environment: TZ: "America/New York" - MYSQL_ROOT_PASSWORD: "root" \ No newline at end of file + MYSQL_ROOT_PASSWORD: "root" diff --git a/package-lock.json b/package-lock.json index 50cdd8e..c2ca669 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "headsup", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3530577..7b1ad0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "headsup", - "version": "1.1.1", + "version": "1.1.2", "description": "RPIA's digital whiteboard system", "main": "server.js", "scripts": { diff --git a/public/admin.html b/public/admin.html index 75e995b..d728f43 100644 --- a/public/admin.html +++ b/public/admin.html @@ -92,6 +92,7 @@ + diff --git a/public/js/admin.js b/public/js/admin.js index daedcc7..5c0eafc 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -1,5 +1,6 @@ async function getNotes() { const response = await fetch('/notes'); + checkResult(response); const notes = (await response.json()).data; let html = ''; if (notes.length !== 0) { @@ -25,35 +26,23 @@ async function getNotes() { } // eslint-disable-next-line -function createNote() { +async function createNote() { const note = document.querySelector('#add-a-note').value; - fetch('/note/create', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - redirect: 'follow', - body: JSON.stringify({ note }) - }); - window.location.reload(); + if (note === '') return; + await postToServer('/note/create', {note: note}); + document.querySelector('#add-a-note').value = ''; + await getNotes(); } // eslint-disable-next-line async function deleteNote(note_id) { - await fetch('/note/delete', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - redirect: 'follow', - body: JSON.stringify({ note: note_id }) - }); - document.querySelector('#notes').innerHTML = ''; - getNotes(); + await postToServer('/note/delete', {note: note_id}); + await getNotes(); } async function generateCategoryDropdown() { const response = await fetch('/public/js/call-categories.json'); + checkResult(response); const categories = await response.json(); for (const category of categories) { const option = document.createElement('option'); @@ -71,15 +60,30 @@ async function addCall() { const category = document.querySelector('#category').value; const response = document.querySelector('#response').value; const call_data = { prid, cc, driver, category, response }; - fetch('/call/create', { + await postToServer('/call/create',call_data); + document.querySelector('#prid').value = ''; + document.querySelector('#tic').value = ''; + document.querySelector('#driver').value = ''; + document.querySelector('#category').value = ''; + document.querySelector('#response').value = ''; +} + +async function postToServer(endpoint, body) { + const response = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, redirect: 'follow', - body: JSON.stringify(call_data) + body: JSON.stringify(body) }); - window.location.reload(); + checkResult(response); +} + +function checkResult(response) { + if (!response.ok) { + throw response.statusText; + } } getNotes();