From aa933229404d76ed3bfc28733de07ea2259922ba Mon Sep 17 00:00:00 2001 From: "LT \"syreal\" Jones" Date: Tue, 10 Mar 2020 18:05:34 -0400 Subject: [PATCH 1/4] Give user feedback with delete form WIP: minor things left --- .../assets/js/api-request-delete-record.js | 27 +++ .../assets/js/api-request-get-record.js | 27 +++ .../assets/js/requestDestroyRecord-func.js | 18 -- atlas-web-app/config/routes.js | 2 +- atlas-web-app/views/layouts/layout.ejs | 3 +- .../views/pages/delete-record-form.ejs | 177 ++++++++++++++++++ .../views/pages/destroy-record-form.ejs | 19 -- atlas-web-app/views/pages/manage.ejs | 4 +- .../views/pages/update-record-form.ejs | 13 +- 9 files changed, 247 insertions(+), 43 deletions(-) create mode 100644 atlas-web-app/assets/js/api-request-delete-record.js create mode 100644 atlas-web-app/assets/js/api-request-get-record.js delete mode 100644 atlas-web-app/assets/js/requestDestroyRecord-func.js create mode 100644 atlas-web-app/views/pages/delete-record-form.ejs delete mode 100644 atlas-web-app/views/pages/destroy-record-form.ejs diff --git a/atlas-web-app/assets/js/api-request-delete-record.js b/atlas-web-app/assets/js/api-request-delete-record.js new file mode 100644 index 0000000..e39b0fb --- /dev/null +++ b/atlas-web-app/assets/js/api-request-delete-record.js @@ -0,0 +1,27 @@ +/** + * Request deletion of record on client's behalf. + * @param id - id of the record to delete. + * @returns {Array} Tuple of [server_success, JSON_server_response]. + */ +function requestDeleteRecord(id) { + var server_success; + + var xhr = new XMLHttpRequest(); + + xhr.open('DELETE', '/record/'+ id); + + xhr.onload = function () { + var responseJSON = JSON.parse(xhr.responseText); + + // eslint-disable-next-line eqeqeq + if (xhr.readyState == 4 && xhr.status == '200') { + server_success = true; + return [server_success, responseJSON]; + } else { + server_success = false; + return [server_success, responseJSON]; + } + }; + + xhr.send(null); +} diff --git a/atlas-web-app/assets/js/api-request-get-record.js b/atlas-web-app/assets/js/api-request-get-record.js new file mode 100644 index 0000000..9bd6a7a --- /dev/null +++ b/atlas-web-app/assets/js/api-request-get-record.js @@ -0,0 +1,27 @@ +/** + * Request record on client's behalf. + * @param id - id of the record to get. + * @returns {Array} Tuple of [server_success, JSON_server_response]. + */ +function requestGetRecord(id) { + var server_success; + + var xhr = new XMLHttpRequest(); + + xhr.open('GET', '/record/'+ id); + + xhr.onload = function () { + var responseJSON = JSON.parse(xhr.responseText); + + // eslint-disable-next-line eqeqeq + if (xhr.readyState == 4 && xhr.status == '200') { + server_success = true; + return [server_success, responseJSON]; + } else { + server_success = false; + return [server_success, responseJSON]; + } + }; + + xhr.send(null); +} diff --git a/atlas-web-app/assets/js/requestDestroyRecord-func.js b/atlas-web-app/assets/js/requestDestroyRecord-func.js deleted file mode 100644 index 31f4449..0000000 --- a/atlas-web-app/assets/js/requestDestroyRecord-func.js +++ /dev/null @@ -1,18 +0,0 @@ -// TODO: consider inlining in update-record-form.ejs as that is the only page that will use this func? - -function requestDestroyRecord(id) { - var xhr = new XMLHttpRequest(); - xhr.open('DELETE', '/record/'+id); - xhr.onload = function () { - var records = JSON.parse(xhr.responseText); - - // TODO : upgrade "==" to "===" but do test that it doesn't break Destroy - // --ltj - if (xhr.readyState == 4 && xhr.status == '200') { - console.table(records); - } else { - console.error(records); - } - }; - xhr.send(null); -} diff --git a/atlas-web-app/config/routes.js b/atlas-web-app/config/routes.js index 97c188c..9fcb8f1 100644 --- a/atlas-web-app/config/routes.js +++ b/atlas-web-app/config/routes.js @@ -27,7 +27,7 @@ module.exports.routes = { '/create-record-form': { view: 'pages/create-record-form' }, '/search-records-form': { view: 'pages/search-records-form' }, '/update-record-form': { view: 'pages/update-record-form'}, - '/destroy-record-form': { view: 'pages/destroy-record-form' }, + '/delete-record-form': { view: 'pages/delete-record-form' }, '/landing-geo-loc-near': { view: 'pages/landing-geo-loc-near' }, 'GET /redirect/:id': { action: 'record/redirect-id' }, diff --git a/atlas-web-app/views/layouts/layout.ejs b/atlas-web-app/views/layouts/layout.ejs index f72a387..9d17873 100644 --- a/atlas-web-app/views/layouts/layout.ejs +++ b/atlas-web-app/views/layouts/layout.ejs @@ -110,7 +110,8 @@ - + + diff --git a/atlas-web-app/views/pages/delete-record-form.ejs b/atlas-web-app/views/pages/delete-record-form.ejs new file mode 100644 index 0000000..4c78ab9 --- /dev/null +++ b/atlas-web-app/views/pages/delete-record-form.ejs @@ -0,0 +1,177 @@ + + + + + + + +ATLAS Home / ATLAS Management / Delete Record Form > + +

+ Delete ATLAS Record +

+ +

+ Delete which ATLAS record? +

+ + +
+
+ ID: +
+ + +
+
+ + + + + + diff --git a/atlas-web-app/views/pages/destroy-record-form.ejs b/atlas-web-app/views/pages/destroy-record-form.ejs deleted file mode 100644 index daa6e32..0000000 --- a/atlas-web-app/views/pages/destroy-record-form.ejs +++ /dev/null @@ -1,19 +0,0 @@ -ATLAS Home / ATLAS Management / Destroy Record Form > - -

- Destroy ATLAS Record -

- -

- Please fill out this form and submit: -

- -
- ID: -
- - - - -
diff --git a/atlas-web-app/views/pages/manage.ejs b/atlas-web-app/views/pages/manage.ejs index 91cf3af..ba5c632 100644 --- a/atlas-web-app/views/pages/manage.ejs +++ b/atlas-web-app/views/pages/manage.ejs @@ -25,7 +25,7 @@
  • Create Record (Form)
  • Show All Records (JSON dump)
  • Advanced Search Records (Waterline QL)
  • -
  • Update Record (Form)
  • -
  • Destroy Record by ID (Form)
  • +
  • Update Record by ID (Form)
  • +
  • Delete Record by ID (Form)
  • diff --git a/atlas-web-app/views/pages/update-record-form.ejs b/atlas-web-app/views/pages/update-record-form.ejs index 206fffc..be1ad29 100644 --- a/atlas-web-app/views/pages/update-record-form.ejs +++ b/atlas-web-app/views/pages/update-record-form.ejs @@ -1,4 +1,8 @@ + + + + + +
    + ATLAS Home +
    +
    + + <%- body %> @@ -107,11 +118,11 @@ --> - - - - - + + + + + diff --git a/atlas-web-app/views/pages/about.ejs b/atlas-web-app/views/pages/about.ejs index 4235408..3c92586 100644 --- a/atlas-web-app/views/pages/about.ejs +++ b/atlas-web-app/views/pages/about.ejs @@ -1,6 +1,4 @@ -ATLAS Home / About ATLAS > -

    About Development diff --git a/atlas-web-app/views/pages/create-record-form.ejs b/atlas-web-app/views/pages/create-record-form.ejs index 3c0832b..e9ab47b 100644 --- a/atlas-web-app/views/pages/create-record-form.ejs +++ b/atlas-web-app/views/pages/create-record-form.ejs @@ -3,7 +3,7 @@ Periodically revisit validation needs for this form. See: https://github.com/conix-center/ATLAS/issues/1 --> -ATLAS Home / ATLAS Management / Create Record Form > +

    Create New ATLAS Record diff --git a/atlas-web-app/views/pages/delete-record-form.ejs b/atlas-web-app/views/pages/delete-record-form.ejs index 4c78ab9..0aec3bf 100644 --- a/atlas-web-app/views/pages/delete-record-form.ejs +++ b/atlas-web-app/views/pages/delete-record-form.ejs @@ -126,7 +126,8 @@ -ATLAS Home / ATLAS Management / Delete Record Form > + +

    Delete ATLAS Record diff --git a/atlas-web-app/views/pages/homepage.ejs b/atlas-web-app/views/pages/homepage.ejs index bba39a5..d89054c 100644 --- a/atlas-web-app/views/pages/homepage.ejs +++ b/atlas-web-app/views/pages/homepage.ejs @@ -1,9 +1,12 @@ -ATLAS Home > - +
    + +
    diff --git a/atlas-web-app/views/pages/landing-geo-loc-near.ejs b/atlas-web-app/views/pages/landing-geo-loc-near.ejs index ec894f6..ac5d81f 100644 --- a/atlas-web-app/views/pages/landing-geo-loc-near.ejs +++ b/atlas-web-app/views/pages/landing-geo-loc-near.ejs @@ -8,8 +8,8 @@ window.onload = function() { }; -ATLAS Home / GEOLOC Landing Pad (Near Scenes Only) > +

    Auto-geolocate near scenes ...