diff --git a/.env.sample b/.env.sample index f5a8c70..bd4f0e7 100644 --- a/.env.sample +++ b/.env.sample @@ -2,4 +2,4 @@ LIFEPEX_DB=sqlite://sqlite.db LIFEPEX_BIND=127.0.0.1 LIFEPEX_BASE_URL= LIFEPEX_SECRET= -LIFEPEX_ENV= +PORT= \ No newline at end of file diff --git a/README.md b/README.md index ec59c93..407d316 100644 --- a/README.md +++ b/README.md @@ -81,4 +81,17 @@ xdg-open ./public/doc/index.html ### Testing -If you want to run the test, simply type `rake test` (you will need the startup env variable to be set first). +Generate first a specific configuration file + +``` +cp .env.local .env.test.local +editor .env.test.local # don't forget to set a new database !!! +``` + +Then init the database + +``` +LIFEPEX_ENV=test ./init/database.rb +``` + +Then if you want to run the test, simply type `rake test` (you will need the startup env variable to be set first). diff --git a/public/js/ajax.js b/public/js/ajax.js new file mode 100644 index 0000000..9e9fc31 --- /dev/null +++ b/public/js/ajax.js @@ -0,0 +1,34 @@ +async function ajax({ + method = "GET", + url = ".", + body = undefined, + headers = {}, + on_success = () => {}, + on_failure = () => {}, +}) { + const xhttp = new XMLHttpRequest(); + const return_on_sent = new Promise((resolve, reject) => { + try { + xhttp.onreadystatechange = () => { + if (xhttp.readyState == 4) { + const response_status = String(xhttp.status); + if (/2\d\d/.test(response_status)) { + resolve(on_success(xhttp.responseText, xhttp)); + } else { + resolve(on_failure(xhttp.responseText, xhttp)); + } + } + }; + } catch (err) { + reject(err); + } + }); + + xhttp.open(method, url, true); + Object.keys(headers).forEach((header_key) => { + xhttp.setRequestHeader(header_key, headers[header_key]); + }); + xhttp.send(body); + + return return_on_sent; +} diff --git a/public/js/error.js b/public/js/error.js new file mode 100644 index 0000000..aaea054 --- /dev/null +++ b/public/js/error.js @@ -0,0 +1,11 @@ +function flashError(message) { + const new_flash_error = document.createElement('p'); + new_flash_error.classList.add("alert"); + new_flash_error.classList.add("alert-danger"); + new_flash_error.classList.add("alert-dismissible"); + new_flash_error.classList.add("fade"); + new_flash_error.classList.add("show"); + new_flash_error.setAttribute("role", "alert"); + new_flash_error.innerHTML = `${message}