diff --git a/back_end/sources/api.js b/back_end/sources/api.js index c7d7f12..f708275 100644 --- a/back_end/sources/api.js +++ b/back_end/sources/api.js @@ -4,7 +4,7 @@ * @author Obrymec - obrymecsprinces@gmail.com * @file controller.js * @created 2022-02-03 -* @updated 2023-12-16 +* @updated 2023-12-22 * @supported DESKTOP * @version 0.0.2 */ @@ -50,7 +50,8 @@ module.exports.get_expired_contracts = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable to + get expired contracts. Try Again ! ` }); @@ -87,7 +88,8 @@ module.exports.get_running_contracts = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable to + get running contracts. Try Again ! ` }); @@ -176,8 +178,9 @@ module.exports.get_bad_employees = ( result ({ status: 500, message: ` - Request failed. - Try Again !" + Request failed. Unable to + get offending employees. + Try Again ! ` }); // Otherwise. @@ -252,7 +255,8 @@ module.exports.get_employee_mistakes = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable to + get employee's misconducts Try Again ! ` }); @@ -380,8 +384,8 @@ module.exports.stop_contract = ( result ({ status: 500, message: ` - Request failed. - Try Again ! + No employee has + been chosen. ` }); // Otherwise. @@ -403,7 +407,8 @@ module.exports.stop_contract = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable + to stop this contract. Try Again ! ` }); @@ -424,7 +429,8 @@ module.exports.stop_contract = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable + to stop this contract. Try Again ! ` }); @@ -437,7 +443,7 @@ module.exports.stop_contract = ( message: ` The contract was successfully - terminated. + stoped. ` }); } @@ -509,7 +515,8 @@ module.exports.save_mistake = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable + to save this mistake. Try Again ! ` }); @@ -521,8 +528,7 @@ module.exports.save_mistake = ( status: 200, message: ` Fault registration - completed - successfully ! + completed successfully ! ` }); } @@ -592,7 +598,7 @@ module.exports.sign_in = ( result ({ status: 500, message: ` - Request failed. + Something wrong. Try Again ! ` }); @@ -660,7 +666,7 @@ module.exports.override_contract = ( status: 500, message: ` Some field(s) - are empty." + are empty. ` }); // Otherwise. @@ -712,7 +718,8 @@ module.exports.override_contract = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable to + override this contract. Try Again ! ` }); @@ -807,7 +814,7 @@ module.exports.save_contract = ( result ({ status: 500, message: ` - Request failed. + Something wrong. Try Again ! ` }); @@ -822,7 +829,7 @@ module.exports.save_contract = ( status: 500, message: ` This employee is - already under + already under a contract. ` }); @@ -857,7 +864,8 @@ module.exports.save_contract = ( result ({ status: 500, message: ` - Request failed. + Request failed. Unable + to save this contract. Try Again ! ` }); @@ -909,7 +917,21 @@ module.exports.sign_up = ( status: 500, message: ` Some field(s) - are empty." + are empty. + ` + }); + // Whether the given + // username is invalid. + } else if ( + !/^[a-zA-Z0-9_ïèéêûÊÉÈÏÛÇçæÆŒœ\.\-]*$/ + .test (data.username) + ) { + // Sends an error message. + result ({ + status: 500, + message: ` + The given username + is invalid. ` }); // Whether the passed email @@ -928,8 +950,23 @@ module.exports.sign_up = ( is invalid. ` }); - // Whether the password is - // not valid. + // Whether the password + // length is less than + // height (08). + } else if ( + data.password.length < 8 + ) { + // Sends an error + // message. + result ({ + status: 500, + message: ` + The password must have + least (08) characters. + ` + }); + // Whether the passwords + // aren't a match. } else if ( data.password.length !== data.confirm.length @@ -968,7 +1005,7 @@ module.exports.sign_up = ( result ({ status: 500, message: ` - Request failed. + Something wrong. Try Again ! ` }); @@ -1015,8 +1052,9 @@ module.exports.sign_up = ( result ({ status: 500, message: ` - Request failed. - Try Again ! + Request failed. We have + some difficulties to + sign up you. Try Again ! ` }); // Otherwise. diff --git a/front_end/public/generic.css b/front_end/public/generic.css index dbb1d8a..182eb8b 100644 --- a/front_end/public/generic.css +++ b/front_end/public/generic.css @@ -3,7 +3,7 @@ * @fileoverview: The main stylesheet of application. * @author: Obrymec - obrymecsprinces@gmail.com * @created: 2022-02-03 -* @updated: 2023-12-17 +* @updated: 2023-12-21 * @supported: DESKTOP * @file: generic.css * @version: 0.0.3 @@ -14,8 +14,13 @@ div.active { background-color: var(--primary-color) !important; } -/* Button hover and table header */ -thead.table-header, button:hover { +/* Button hover */ +button:hover { + background-color: var(--primary-color-300); +} + +/* Table header */ +thead.table-header { background-color: var(--primary-color); } @@ -29,8 +34,8 @@ tbody.light-silver { background-color: var(--light-white); } -/* Inputs focus */ -input:focus, select:focus { +/* Input focus */ +input:focus { border-color: var(--primary-color); } @@ -70,6 +75,12 @@ div.empty-section { height: 100%; } +/* Select hover */ +select:hover { + border-color: var(--primary-color); + cursor: pointer; +} + /* Inputs placeholder */ textarea::placeholder, input::placeholder { diff --git a/front_end/sources/utils/generic.js b/front_end/sources/utils/generic.js index 4a3c1ec..36eb6be 100644 --- a/front_end/sources/utils/generic.js +++ b/front_end/sources/utils/generic.js @@ -3,7 +3,7 @@ * @fileoverview The base controller for all others controllers. * @author Obrymec - obrymecsprinces@gmail.com * @created 2022-02-03 -* @updated 2023-12-21 +* @updated 2023-12-22 * @supported DESKTOP * @file generic.js * @version 0.0.3 @@ -76,7 +76,7 @@ function sweetAlert ( confirm = () => {}, showConfirm = true, title = "Server Message", - outsideClick = true + outsideClick = false ) { // Displays the target // message text inside @@ -140,6 +140,43 @@ function generate_employee_table_data ( `); } +/** + * @description Checks whether the + * browser is online or not. + * @function checkNetwork + * @public + * @returns {boolean} boolean + */ +function checkNetwork () { + // Whether the browser + // is online. + const isOnLine = ( + window.navigator.onLine + ); + // Whether the browser + // is offline. + if (!isOnLine) { + // Shows an error message + // about no internet + // connection. + sweetAlert ( + `The browser isn't connected + to internet. Check your + network and retry.`, + "error", () => {}, true, + "Network Error" + ); + // Otherwise. + } else { + // Closes the active + // modal box. + Swal.close (); + } + // Sends the network + // state. + return isOnLine; +} + /** * @description Checks screen active * resolution. @@ -151,9 +188,7 @@ function checkScreenResolution () { // Whether the current // window size is less // than 1024. - if ( - window.innerWidth < 1024 - ) { + if (window.innerWidth < 1024) { // Whether the screen size // wasn't low. if (!is_low) { @@ -168,7 +203,7 @@ function checkScreenResolution () { bigger than or equal to (1024 x 768) pixels.`, "info", () => {}, false, - "Information", false + "Information" ); } // Otherwise. @@ -195,45 +230,49 @@ function checkScreenResolution () { * @returns {void} void */ function get_request (data) { - // Downloads data from - // server with the - // passed front-end - // data. - ajax_request_nodejs ( - `/${data.operation_link}`, - "GET", {}, response => { - // Whether the server - // status is `500`. - if (response.status === 500) { + // Whether the browser + // is really online. + if (checkNetwork ()) { + // Downloads data from + // server with the + // passed front-end + // data. + ajax_request_nodejs ( + `/${data.operation_link}`, + "GET", {}, response => { + // Whether the server + // status is `500`. + if (response.status === 500) { + // Makes a warn. + sweetAlert ( + response.message, + "error", () => ( + window.location.reload () + ) + ); + // Otherwise. + } else { + // Generating the associated + // html code from server's + // data. + response.data.forEach ( + item => data.callback ( + item + ) + ); + } + // Request failed. + }, () => { // Makes a warn. sweetAlert ( - response.message, + "Request failed. Try Again !", "error", () => ( window.location.reload () ) ); - // Otherwise. - } else { - // Generating the associated - // html code from server's - // data. - response.data.forEach ( - item => data.callback ( - item - ) - ); } - // Request failed. - }, () => { - // Makes a warn. - sweetAlert ( - "Request failed. Try Again !", - "error", () => ( - window.location.reload () - ) - ); - } - ); + ); + } } /** @@ -410,155 +449,159 @@ function date_difference () { * @returns {void} void */ function post_request (data, is_sign) { - // Whether the user is - // already connected. - if (is_sign) { - // Whether the user - // isn't connected. - if ( + // Whether the browser + // is really online. + if (checkNetwork ()) { + // Whether the user is + // already connected. + if (is_sign) { + // Whether the user + // isn't connected. + if ( + String ( + get_cookie ("user") + ) !== "undefined" + ) { + // Disables the main + // button. + is_pressed = true; + // Redirecting to + // stop contract + // web page. + window.location.href = ( + `${HOST_NAME}/stop-contract` + ); + } + // Otherwise. + } else if ( String ( get_cookie ("user") - ) !== "undefined" + ) === "undefined" ) { // Disables the main // button. is_pressed = true; // Redirecting to - // stop contract - // web page. + // sign web page. window.location.href = ( - `${HOST_NAME}/stop-contract` + HOST_NAME ); } - // Otherwise. - } else if ( - String ( - get_cookie ("user") - ) === "undefined" - ) { - // Disables the main - // button. - is_pressed = true; - // Redirecting to - // sign web page. - window.location.href = ( - HOST_NAME - ); - } - // Whether the button - // is not pressed. - if (!is_pressed) { - // Disables it. - is_pressed = true; - // Gets his old - // text value. - let old_button_text = ( - $ (data.button_id).text () - ); - // Changes button - // text message. - $ (data.button_id).text ( - data.button_text - ); - // Sends the given data - // to server with ajax - // method. - ajax_request_nodejs ( - `/${data.operation_link}`, - "POST", data.server_data, - response => { - // Whether the server - // status is `500`. - if ( - response.status === 500 - ) { - // Enables button. - is_pressed = false; - // Makes a warn. - sweetAlert ( - response.message, - "error", () => ( - $ (data.button_id) - .text ( - old_button_text - ) - ) - ); - // Otherwise. - } else { - // Enables button. - is_pressed = false; - // Changes button - // apprearance. - $ (data.button_id).text ( - old_button_text - ); - // Whether no message key - // is found. + // Whether the button + // is not pressed. + if (!is_pressed) { + // Disables it. + is_pressed = true; + // Gets his old + // text value. + let old_button_text = ( + $ (data.button_id).text () + ); + // Changes button + // text message. + $ (data.button_id).text ( + data.button_text + ); + // Sends the given data + // to server with ajax + // method. + ajax_request_nodejs ( + `/${data.operation_link}`, + "POST", data.server_data, + response => { + // Whether the server + // status is `500`. if ( - response.hasOwnProperty ( - "data" - ) + response.status === 500 ) { - // Calls the passed - // method callback. - response.data.forEach ( - item => data.callback ( - item + // Enables button. + is_pressed = false; + // Makes a warn. + sweetAlert ( + response.message, + "error", () => ( + $ (data.button_id) + .text ( + old_button_text + ) ) ); // Otherwise. } else { - // Warns the user and calls - // `loaded` method when - // this request is done. - sweetAlert ( - response.message, - "success", () => { - // Whether `loaded` event - // is listening. - if ( - typeof data.loaded - === "function" - ) { - // Calls it. - data.loaded (response); - } - // Whether the request - // link is defined. - if ( - data.hasOwnProperty ( - "page_link" - ) && - data.page_link.length > 0 - ) { - // Go to a web page - // whether needed. - window.location.href = ( - `${HOST_NAME}/${ - data.page_link - }` - ); - } - } - ); - } - } - // Request failed. - }, () => { - // Enables the button. - is_pressed = false; - // Makes a warn. - sweetAlert ( - "Request failed. Try Again !", - "error", () => ( + // Enables button. + is_pressed = false; + // Changes button + // apprearance. $ (data.button_id).text ( old_button_text + ); + // Whether no message key + // is found. + if ( + response.hasOwnProperty ( + "data" + ) + ) { + // Calls the passed + // method callback. + response.data.forEach ( + item => data.callback ( + item + ) + ); + // Otherwise. + } else { + // Warns the user and calls + // `loaded` method when + // this request is done. + sweetAlert ( + response.message, + "success", () => { + // Whether `loaded` event + // is listening. + if ( + typeof data.loaded + === "function" + ) { + // Calls it. + data.loaded (response); + } + // Whether the request + // link is defined. + if ( + data.hasOwnProperty ( + "page_link" + ) && + data.page_link.length > 0 + ) { + // Go to a web page + // whether needed. + window.location.href = ( + `${HOST_NAME}/${ + data.page_link + }` + ); + } + } + ); + } + } + // Request failed. + }, () => { + // Enables the button. + is_pressed = false; + // Makes a warn. + sweetAlert ( + "Request failed. Try Again !", + "error", () => ( + $ (data.button_id).text ( + old_button_text + ) ) - ) - ); - } - ); + ); + } + ); + } } } @@ -571,6 +614,16 @@ $ (() => { window.addEventListener ( "resize", checkScreenResolution ); + // Listens browser `offline` + // event. + window.addEventListener ( + "offline", checkNetwork + ); + // Listens browser `online` + // event. + window.addEventListener ( + "online", checkNetwork + ); // Listens `click` event // on all detected // refresh buttons.