Browse Source

userpex: improve error and fix test databases

pull/59/head
Arthur POULET 11 months ago
parent
commit
f6a951f704
Signed by: Sceptique GPG Key ID: C108A668349EE601
  1. 2
      .env.sample
  2. 15
      README.md
  3. 2
      public/js/ajax.js
  4. 11
      public/js/error.js
  5. 2
      public/js/index.js
  6. 7
      src/app.rb
  7. 3
      src/views/layout.slim

2
.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=

15
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).

2
public/js/ajax.js

@ -27,7 +27,7 @@ async function ajax({
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;

11
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} <button class=\"btn-close\" type=\"button\" data-bs-dismiss=\"alert\" aria-label=\"Close\" />`;
const flash = document.querySelectorAll('.flash')[0].appendChild(new_flash_error);
}

2
public/js/index.js

@ -73,7 +73,7 @@ function userpexValidation(event) {
event.target.parentNode.parentNode.childNodes[2].childNodes[0].hidden = should_hide_decrease_button;
},
on_failure: (body, req) => {
// console.log("KO", event);
flashError("Error JS#0001 while validating...");
},
});
}

7
src/app.rb

@ -18,8 +18,12 @@ require "active_support"
require "active_support/core_ext"
require "pry" # debug
module LifePex
APP_ENV = ENV.fetch("LIFEPEX_ENV") { "development" }
end
require "dotenv"
Dotenv.load(".env.local", ".env")
Dotenv.load(".env.#{LifePex::APP_ENV}.local", ".env.local", ".env")
require_relative "./utils/url.rb"
require_relative "./utils/boot_framework"
@ -42,7 +46,6 @@ module LifePex
SECRET = ENV["LIFEPEX_SECRET"]
CODE_VERSION = DB[:meta].first[:code_version]
CODE_DATE = DB[:meta].first[:code_date]
APP_ENV = ENV.fetch("LIFEPEX_ENV") { "development" }
include LifePex::Utils::Url

3
src/views/layout.slim

@ -56,7 +56,7 @@ html lang="en"
a.btn.btn-lg.btn-dark href="/about" About lifepex
.flash
#flash.flash
- if defined? flash
- flash.each do |flash_name, flash_message|
.alert.alert-dismissible.fade.show role="alert" class="alert-#{flash_name}"
@ -72,4 +72,5 @@ html lang="en"
/ script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"
script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"
script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"
script src="/js/error.js"
script src="/js/ajax.js"

Loading…
Cancel
Save