Skip to content

Commit

Permalink
Merge branch 'master' into bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Apr 21, 2017
2 parents d937b87 + 64ae85a commit 260aad7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
41 changes: 34 additions & 7 deletions WebContent/html/webpages/profileSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="components/navbar.jsp"%>
</nav>
<%
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
%>
<!-- Sidebar -->
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
Expand Down Expand Up @@ -125,10 +128,12 @@
<!-- Notification Settings -->
<div class = "notificationContainer" style = "visibility: hidden;">
<!-- Where main user information is edited -->
<form action = "redirect/notificationSettingsRedirect.jsp" class = "infobar">
<form name="notificationForm" onsubmit="return applyNotifiationChanges()" action = "redirect/notificationSettingsRedirect.jsp" class = "infobar" method="post">
<h2>Email Notification Settings</h2>
<br>
<h4>Send me a messege when...</h4>
<input name="prefferedNotificationInteger" style="display: none;">
<input name="user" style="display: none;" value='<%=self.getID()%>'>
<div style="float: left; margin-right: 10px;"><h5>Tickets are generated</h5></div>
<div style="float: right;">
<label class="switch">
Expand All @@ -148,15 +153,13 @@
<div class="slider round"></div>
</label></div><br><br><br>
<div style="text-align: center;">
<button name = "notification" type="submit" class="btn btn-primary" id = "applyNotifications">Apply Changes</button>
<button name = "notification" type="submit" class="btn btn-primary">Apply Changes</button>
<button name="leaveMeAlone" class="btn btn-primary" style="background-color: red">Please just leave me alone</button>
</div>
</form>
</div>

<%
User self = EmployeeQueries.getEmployeeByID(Integer.parseInt(navsso));
%>

<script>
var iconSelect;
Expand Down Expand Up @@ -195,8 +198,8 @@
document.getElementById('inputSSO').addEventListener('keyup',checkEmpty);
document.getElementById('closeBttn').addEventListener('click',function(){document.getElementById('missingcontent').style.display = "none";});
// Listeners for notification settings
document.getElementById('applyNotifications').addEventListener('click',applyNotifiationChanges);
document.getElementsByName('leaveMeAlone')[0].addEventListener('click',disableAllNotifications);
var typeTimer;
var doneTypingInterval = 2000 //ms
Expand Down Expand Up @@ -237,16 +240,40 @@
$('#missingcontent').css('display','block');
}
function applyNotifiationChanges(){
// Here is how the notification preferences integer works:
// Begin by converting to binary.
// First (least significant) bit: Ticket generation/order received email
// Second bit: Ticket approved email
// Third bit: Ticket rejected email
// If more email situations come up they can correspond to the fourth bit, fifth bit, etc.
// 1 means send email; 0 means do not send email
// This means determining what to set the new preference integer to is simply a matter of binary addition.
var bit1 = document.getElementById('notificationSlider1').checked ? 1 : 0;
var bit2 = document.getElementById('notificationSlider2').checked ? 1 : 0;
var bit3 = document.getElementById('notificationSlider3').checked ? 1 : 0;
var newNotificationPreferenceInteger = 1*bit1 + 2*bit2 + 4*bit3;
document.notificationForm.prefferedNotificationInteger.value=newNotificationPreferenceInteger;
return true;
}
//populates form fields if info exists in db already
function populate(){
//get values from database
// Populationg profile settings
$('#inputName').val('<%=navname%>');
$('#inputSSO').val('<%=self.getID()%>');
$('#inputTelephone').val('<%=self.getPhone()%>');
$('#inputEmail').val('<%=self.getEmail()%>');
// -----------------Populating notification settings------------
// The notificationPreferences integer is explained in the applyNotifiationChanges() function above ^
var NotificationPreferenceInteger='<%=self.getNotificationPreferences()%>';
var bit1 = (NotificationPreferenceInteger/1)%2!=0;
var bit2 = (NotificationPreferenceInteger/2)%2!=0;
var bit3 = (NotificationPreferenceInteger/4)%2!=0;
document.getElementById("notificationSlider1").checked = (bit1==1);
document.getElementById("notificationSlider2").checked = (bit2==1);
document.getElementById("notificationSlider3").checked = (bit3==1);
}
function checkEmpty(){
Expand Down
33 changes: 33 additions & 0 deletions WebContent/html/webpages/redirect/notificationSettingsRedirect.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%@ page import = "database.*,entities.Device" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>Synchrony Financial</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel = "stylesheet" type = "text/css" href = "../../css/stylesheet.css">
<link rel = "shortcut icon" href = "../../imgs/synchrony-financial-logo-dlpx_1.ico">
</head>
<%
int user = Integer.parseInt(request.getParameter("prefferedNotificationInteger"));
int prefs = Integer.parseInt(request.getParameter("user"));
EmployeeQueries.updateNotificationPreferences(prefs,user);
%>
<script>
window.location.replace("../profileSettings.jsp");
</script>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="../components/navbar.jsp"%>
</nav>
</body>
</html>
17 changes: 15 additions & 2 deletions src/database/EmployeeQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLExc
resultSet.getString("Name"),
resultSet.getString("Phone_Number"),
resultSet.getString("Email"),
resultSet.getInt("Img_Index")
resultSet.getInt("Img_Index"),
resultSet.getInt("Notification_Preference")
);
resultSet = stmt.executeQuery("SELECT Address FROM location WHERE Location_ID = "+employee.getLocation());
resultSet.next();
Expand Down Expand Up @@ -225,12 +226,24 @@ public static User[] getAllUsers() throws SQLException, ClassNotFoundException,

//iterate result set
while(resultSet.next()){
users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number"),resultSet.getString("Email"),resultSet.getInt("Img_Index"));
users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number"),resultSet.getString("Email"),resultSet.getInt("Img_Index"),resultSet.getInt("Notification_Preference"));
counter++;
}

stmt.close();
connection.close();
return users;
}

public static void updateNotificationPreferences(int client, int preferences) throws SQLException, ClassNotFoundException{
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database, user, password);
Statement statement = connect.createStatement();
String query = "UPDATE employee SET Notification_Preference = "+preferences+" WHERE Employee_ID = "+client+";";
System.out.println("Executing query: "+query);
statement.executeUpdate(query);
statement.close();
connect.close();
}
}
4 changes: 2 additions & 2 deletions src/entities/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class Admin extends User {
private int password_flag;
private int finger_flag;

public Admin(int id, int location, String name, String phone, String email, int icon, int pass, int finger) {
super(id, location, name, phone, email, icon);
public Admin(int id, int location, String name, String phone, String email, int icon, int pass, int finger, int notificationPreferences) {
super(id, location, name, phone, email, icon, notificationPreferences);
password_flag = pass;
finger_flag = finger;
}
Expand Down
4 changes: 2 additions & 2 deletions src/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public User(){
//empty
}

public User(int id, int location, String name, String phone, String email, int icon){
public User(int id, int location, String name, String phone, String email, int icon, int notificationPreferences){
this.id = id;
this.location = location;
this.name = name; //later will do table lookup to determine by id
this.phone = phone;
this.email = email;
this.icon = icon;
this.notificationPreferences = 1+2+4;
this.notificationPreferences = notificationPreferences;
}

public int getIcon(){
Expand Down

0 comments on commit 260aad7

Please sign in to comment.