Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
f8e8885
Initial changes for sprint 2 employee edit functionality, incomplete.
snowcycle Jan 8, 2020
5c11414
Updates to the product details route controller for sprint 2 function…
snowcycle Jan 8, 2020
4a2830d
Load string resources at app startup.
snowcycle Jan 24, 2020
2c624f3
Merge branch 'master' of github.com:snowcycle/RegisterApp-NodeJS into…
snowcycle Jan 24, 2020
d44adeb
updated signIn.ejs for sprint 2 task 2
robertjohnsonark Feb 20, 2020
63a05f5
Merge branch 'master' of https://github.com/software-squirrels/Regist…
Feb 20, 2020
a49c284
Merge branch 'Sprint2Employee'
Willard21 Feb 20, 2020
5adb814
Routing for sign in page
Feb 20, 2020
7faa323
Updated sign in view
Feb 20, 2020
f2dc9ee
Task 3: Sign In - Client-side functionality
EmrLan Feb 20, 2020
2d30ee0
Add files via upload
benguthrie44 Feb 21, 2020
1171190
Implement EmployeeQuery methods
Willard21 Feb 21, 2020
48d299d
ssl
Feb 21, 2020
559f627
worked on task 10
robertjohnsonark Feb 27, 2020
5664310
Sign in controller routing
Feb 28, 2020
958e47a
Add files via upload
benguthrie44 Feb 28, 2020
f94b1b2
Completed main menu and added routing
LilySeokJin Feb 28, 2020
966e62a
Connected functionality
Feb 29, 2020
1ee8baf
-Added MainMenu check for elevated users from EmployeeHelper
LilySeokJin Mar 2, 2020
49bf970
Bugs
Mar 3, 2020
09425b1
Task 2-5
Mar 3, 2020
3998a52
Employee detail routing
Mar 3, 2020
e09225e
Employee detail initial route
Mar 3, 2020
2af7a5c
Merged employee commands from Sprint2SignIn
Mar 3, 2020
ab7e31a
Added a return false statement to master.js, changed mainMenu to impl…
LilySeokJin Mar 3, 2020
4868c86
Merged sign in view from Sprint2SignIn
Mar 3, 2020
15b3941
Added ViewNameLookup.SignIn
Mar 3, 2020
322a9c2
Merge branch 'Sprint2SignIn' into mainMenuTest
LilySeokJin Mar 3, 2020
1c8ed69
Added view functionality to product details for elevated users. Way t…
LilySeokJin Mar 3, 2020
1f4afb3
Update employeeDetail.js
robertjohnsonark Mar 4, 2020
466d6f6
GET request controllers
Mar 4, 2020
1d407ee
Merge branch 'Sprint2Employee' of https://github.com/software-squirre…
Mar 4, 2020
57762ea
Finished route controller
Mar 4, 2020
b8ec87a
Merged Sprint2SignIn into Sprint2Employee
Mar 4, 2020
0bb5f79
Bugs
Mar 4, 2020
53ac83c
isElevatedUser helper function
Mar 4, 2020
583d6e8
Implement employeeCreateCommand and employeeUpdateCommand
Willard21 Mar 4, 2020
6ac68fc
Merge branch 'Sprint2Employee'
Willard21 Mar 4, 2020
c59162f
bug
Mar 4, 2020
20ac290
bug
Mar 4, 2020
b017d75
Remove unused imports
Willard21 Mar 4, 2020
ffd1eb4
bugs
Mar 4, 2020
4753fea
Merge branch 'Sprint2Employee'
Willard21 Mar 4, 2020
4e6237f
Merge branch 'Sprint2Employee' of https://github.com/software-squirre…
Mar 4, 2020
cccb50e
bug
Mar 4, 2020
f90bd59
Merge branch 'Sprint2Employee'
Willard21 Mar 4, 2020
ece406e
bugs
Mar 4, 2020
77a2548
Merge branch 'master' of https://github.com/software-squirrels/Regist…
Mar 4, 2020
02fc5f7
Merge branch 'master'
Willard21 Mar 4, 2020
f9e9b80
Merge branch 'master'
Willard21 Mar 4, 2020
73edafa
Merge branch 'master'
Willard21 Mar 4, 2020
38e7458
Added isElevatedUser functionality to product listing and product det…
LilySeokJin Mar 4, 2020
92e8097
Merge branch 'mainMenuTest' of https://github.com/software-squirrels/…
LilySeokJin Mar 4, 2020
cfc8c49
Finished task 10 I think?
robertjohnsonark Mar 5, 2020
ebe9be2
fixed one mistake - sorry
robertjohnsonark Mar 5, 2020
1d75e1c
bugs
Mar 5, 2020
e48a98e
Merge branch 'Sprint2Employee' of https://github.com/software-squirre…
Mar 5, 2020
d6a93a2
Fixed SignIn and Employee Detail routing + functionality
Mar 5, 2020
e8e1f7c
Merge branch 'master' of https://github.com/software-squirrels/Regist…
Mar 5, 2020
dd66441
Merge branch 'Sprint2SignIn' of https://github.com/software-squirrels…
Mar 5, 2020
8a196e9
Merge branch 'Sprint2Product' of https://github.com/software-squirrel…
Mar 5, 2020
ea24160
Merge branch 'Sprint2Starter' of https://github.com/software-squirrel…
Mar 5, 2020
3ff41a0
bugs
Mar 5, 2020
8e885ca
Check if employee exists
Mar 5, 2020
6722984
Fix employeeSignInCommand
Willard21 Mar 5, 2020
a95b332
Fix clearActiveUser controller
Mar 5, 2020
74d4eaa
Added whitespace to view, fixed bugs to make it compile, made sure th…
LilySeokJin Mar 5, 2020
1f3f39e
Fix signin
Willard21 Mar 5, 2020
bd1dfce
Merge branch 'Sprint2Starter' of https://github.com/software-squirrel…
Willard21 Mar 5, 2020
adb3230
Fix missing semicolon
Willard21 Mar 5, 2020
fccc972
Fixed invisible buttons
LilySeokJin Mar 5, 2020
dd7ecc9
Fix manager perms
Willard21 Mar 5, 2020
c599b33
Merge branch 'master'
Willard21 Mar 6, 2020
96c7db1
Merge branch 'mainMenuTest' of https://github.com/software-squirrels/…
Willard21 Mar 6, 2020
c90aa5c
Ok if this doesn't work...
LilySeokJin Mar 6, 2020
af6bc86
Merge branch 'mainMenuTest' of https://github.com/software-squirrels/…
LilySeokJin Mar 6, 2020
f19d181
TRIAL 2
LilySeokJin Mar 6, 2020
cd266aa
Everything should work for invisbility. The only thing to check is th…
LilySeokJin Mar 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions public/scripts/employeeDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
let hideEmployeeSavedAlertTimer = undefined;

document.addEventListener("DOMContentLoaded", () => {
// TODO: Things that need doing when the view is loaded
getSaveActionElement().addEventListener("click", saveActionClick);
});

// Save
function saveActionClick(event) {
// TODO: Actually save the employee via an AJAX call
if (!validateSave()) {
return;
}

const saveActionElement = event.target;
saveActionElement.disabled = true;

const employeeId = getEmployeeId();
const employeeIdIsDefined = ((employeeId != null) && (employeeId.trim() !== ""));
const saveActionUrl = ("/api/employeeDetail/"
+ (employeeIdIsDefined ? employeeId : ""));
const saveEmployeeRequest = {
id: employeeId,
firstName: getEmployeeFirstName(),
lastName: getEmployeeLastName(),
password: getEmployeePassword(),
type: getEmployeeType()
};

if (employeeIdIsDefined) {
ajaxPatch(saveActionUrl, saveEmployeeRequest, (callbackResponse) => {
saveActionElement.disabled = false;

if (isSuccessResponse(callbackResponse)) {
displayEmployeeSavedAlertModal();
}
});
} else {
ajaxPost(saveActionUrl, saveEmployeeRequest, (callbackResponse) => {
saveActionElement.disabled = false;

if (isSuccessResponse(callbackResponse)) {
displayEmployeeSavedAlertModal();

if ((callbackResponse.data != null)
&& (callbackResponse.data.employee != null)
&& (callbackResponse.data.employee.id.trim() !== "")) {

document.getElementById("employeeID").classList.remove("hidden");

setEmployeeId(callbackResponse.data.employee.id.trim());
}
}
});
}
};



function validateSave() {
const employeeFirstName = getEmployeeFirstName();
if ((employeeFirstName == null) || (employeeFirstName.trim() === "")) {
displayError("Please provide your first name.");
employeeFirstName.focus();
employeeFirstName.select();
return false;
}

const employeeLastName = getEmployeeLastName();
if ((employeeLastName == null) || (employeeLastName.trim() === "")) {
displayError("Please provide your last name.");
employeeLastName.focus();
employeeLastName.select();
return false;
}

const employeePassword = getEmployeePassword();
if ((employeePassword == null) || (employeePassword.trim() === "") || (employeePassword != getEmployeeConfirmPassword())) {
displayError("The password you entered is not correct.");
employeePassword.focus();
employeePassword.select();
return false;
}

const employeeType = getEmployeeType();
if ((employeeType == null) || (employeeType.trim() === "")) {
displayError("Please provide a valid employee type.");
employeeType.focus();
employeeType.select();
return false;
}

return true;
}

function displayEmployeeSavedAlertModal() {
if (hideEmployeeSavedAlertTimer) {
clearTimeout(hideEmployeeSavedAlertTimer);
}

const savedAlertModalElement = getSavedAlertModalElement();
savedAlertModalElement.style.display = "none";
savedAlertModalElement.style.display = "block";

hideEmployeeSavedAlertTimer = setTimeout(hideEmployeeSavedAlertModal, 1200);
}

function hideEmployeeSavedAlertModal() {
if (hideEmployeeSavedAlertTimer) {
clearTimeout(hideEmployeeSavedAlertTimer);
}

getSavedAlertModalElement().style.display = "none";
}

function ajaxPost(resourceRelativeUri, data, callback) {
return ajax(resourceRelativeUri, "POST", data, callback);
}

function ajaxPatch(resourceRelativeUri, data, callback) {
return ajax(resourceRelativeUri, "PATCH", data, callback);
}

function ajax(resourceRelativeUri, verb, data, callback) {
const httpRequest = new XMLHttpRequest();

if (httpRequest == null) {
return httpRequest;
}

httpRequest.onreadystatechange = () => {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if ((httpRequest.status >= 200) && (httpRequest.status < 300)) {
handleSuccessResponse(httpRequest, callback);
} else {
handleFailureResponse(httpRequest, callback);
}
}
};

httpRequest.open(verb, resourceRelativeUri, true);
if (data != null) {
httpRequest.setRequestHeader('Content-Type', 'application/json');
httpRequest.send(JSON.stringify(data));
} else {
httpRequest.send();
}

return httpRequest;
}
// End save

// Getters and setters

function getSaveActionElement() {
return document.getElementById("saveButton");
}

function getSavedAlertModalElement() {
return document.getElementById("employeeSavedAlertModal");
}

function getEmployeeFirstName() {
return getEmployeeFirstNameElement().value;
}

function getEmployeeFirstNameElement() {
return document.getElementById("employeeFirstName");
}

function getEmployeeLastName() {
return getEmployeeLastNameElement().value;
}

function getEmployeeLastNameElement() {
return document.getElementById("employeeLastName");
}

function getEmployeePassword() {
return getEmployeePasswordElement().value;
}

function getEmployeePasswordElement() {
return document.getElementById("employeePassword");
}

function getEmployeeConfirmPassword() {
return getEmployeeConfirmPasswordElement().value;
}

function getEmployeeConfirmPasswordElement() {
return document.getElementById("employeeConfirmPassword");
}

function getEmployeeType() {
return getEmployeeTypeElement().value;
}

function getEmployeeTypeElement() {
return document.getElementById("employeeType");
}

function getEmployeeId() {
return getEmployeeIdElement().value;
}
function setEmployeeId(employeeId) {
getEmployeeIdElement().value = employeeId;
}
function getEmployeeIdElement() {
return document.getElementById("employeeId");
}

// End getters and setters
8 changes: 4 additions & 4 deletions public/scripts/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function clearError() {

function displayError(errorMessage) {
if ((errorMessage == null) || (errorMessage === "")) {
return;
return false; //Just to prevent invalid URL redirects, returns false
}

const errorMessageDisplayElement = getErrorMessageDisplayElement();
Expand All @@ -154,7 +154,7 @@ function displayError(errorMessage) {
if ((errorMessageContainerElement == null)
|| (errorMessageDisplayElement == null)) {

return;
return false; //Just to prevent invalid URL redirects, returns false
}

errorMessageDisplayElement.innerHTML = errorMessage;
Expand Down Expand Up @@ -185,9 +185,9 @@ function signOutActionClickHandler() {
&& (callbackResponse.data.redirectUrl != null)
&& (callbackResponse.data.redirectUrl !== "")) {

window.location.replace(callbackResponse.data.redirectUrl);
window.location.replace(callbackResponse.data.redirectUrl); //This sends it back to redirect URL
} else {
window.location.replace("/");
window.location.replace("/"); //This sends it back to app main view if there isn't a redirect URL
}
});
}
Expand Down
19 changes: 16 additions & 3 deletions public/scripts/signIn.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
document.addEventListener("DOMContentLoaded", () => {
// TODO: Anything you want to do when the page is loaded?
});

function validateForm() {
// TODO: Validate the user input
var employeeID = document.getElementById("employeeID").value;
var pass = document.getElementById("password").value;

if((isNaN(employeeID)) || (employeeID == ""))
{
alert("Enter a valid ID number")
return false;
}

if(pass == "")
{
alert("Enter a password")
return false;
}

return true;
}
};
3 changes: 3 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as fileSystem from "fs";
import bodyParser from "body-parser";
import compression from "compression";
import session from "express-session";
import { Resources } from "./resourceLookup";

// Load environment variables from .env file, where API keys and passwords are configured
dotenv.config({ path: ".env" });
Expand Down Expand Up @@ -46,4 +47,6 @@ fileSystem.readdirSync(__dirname + "/routes").forEach(function (routeConfig: str
}
});

Resources.loadStrings();

export default app;
21 changes: 21 additions & 0 deletions src/controllers/commands/employees/activeEmployeeExistsQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EmployeeModel } from "../models/employeeModel";
import { Resources, ResourceKey } from "../../../resourceLookup";
import * as EmployeeRepository from "../models/employeeModel";
import { CommandResponse, Employee } from "../../typeDefinitions";
import * as EmployeeHelper from "./helpers/employeeHelper";

export const execute = async (): Promise<CommandResponse<Employee>> => {
return EmployeeRepository.queryActiveExists()
.then((queriedActiveUser: (EmployeeModel | null)): Promise<CommandResponse<Employee>> => {
if (queriedActiveUser) {
return Promise.resolve(<CommandResponse<Employee>>{
status: 200,
data: EmployeeHelper.mapEmployeeData(queriedActiveUser)});
}

return Promise.reject(<CommandResponse<Employee>>{
status: 404,
message: Resources.getString(ResourceKey.EMPLOYEES_UNABLE_TO_QUERY)
});
});
};
20 changes: 20 additions & 0 deletions src/controllers/commands/employees/clearActiveUserCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ActiveUserModel } from "../models/activeUserModel";
import { Resources, ResourceKey } from "../../../resourceLookup";
import * as ActiveUserRepository from "../models/activeUserModel";
import { CommandResponse, ActiveUser } from "../../typeDefinitions";
import * as DatabaseConnection from "../models/databaseConnection";

export const execute = async (sessionKey: string): Promise<CommandResponse<ActiveUser>> => {
return ActiveUserRepository.queryBySessionKey(sessionKey, await DatabaseConnection.createTransaction())
.then((activeUser: (ActiveUserModel | null)): Promise<CommandResponse<ActiveUser>> => {
if (activeUser) {
return Promise.resolve(<CommandResponse<ActiveUser>>{
status: 200
});
}
return Promise.reject(<CommandResponse<ActiveUser>>{
status: 404,
message: Resources.getString(ResourceKey.USER_SESSION_NOT_FOUND)
});
});
};
Loading