Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
path('visitor-chart9/', views.visitor_chart9, name="visitor-chart9"),
path('visitor-chart10/', views.visitor_chart10, name="visitor-chart10"),
path('pid-to-name/', views.pid_to_name, name="pid-to-name"),
path('name-to-pid/', views.name_to_pid, name="name-to-pid"),
path('checked-in/', views.checked_in, name="checked-in")
]

]
11 changes: 11 additions & 0 deletions backend/checkin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from datetime import datetime, date, timedelta
from functools import reduce
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.csrf import csrf_exempt
from django.forms.models import model_to_dict
import json

Expand Down Expand Up @@ -694,6 +695,16 @@ def pid_to_name(request):
returnData = {"name": None}
return JsonResponse(data=returnData)

def name_to_pid(request):
data = json.loads(request.body)
name = data['name']
result = Checkin.objects.filter(name__iexact=name.lower()).values("PID").first()
if (result):
returnData = {"pid": result["PID"]}
else:
returnData = {"pid": None}
return JsonResponse(data=returnData)

def checked_in(request):
data = json.loads(request.body)
result = Checkin.objects.filter(PID=data['pid'], checkedIn=True)
Expand Down
41 changes: 38 additions & 3 deletions src/Screens/CheckIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class CheckIn extends React.Component {
}

handleKeyPress = (e) => {
if (!(e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA")) {
if (!(e.target.nodeName === "INPUT" || e.target.nodeName === "TEXTAREA")) {
const pidArray = this.state.keypresses.slice(1, 9);
pidArray.push(String.fromCharCode(e.keyCode));
if (pidArray.every(x => !isNaN(parseInt(x)))) {
Expand All @@ -216,9 +216,9 @@ export default class CheckIn extends React.Component {
});
}
} else {
if (!(String.fromCharCode(e.keyCode) === '\b')) {
if ((!(String.fromCharCode(e.keyCode) === '\b') && (!(String.fromCharCode(e.keyCode) === '\x10')) && (!(String.fromCharCode(e.keyCode) === '\r'))) && (!(String.fromCharCode(e.keyCode) === '\t')) && (!(String.fromCharCode(e.keyCode) === '\x14'))) {
this.state.keysPidBox.push(String.fromCharCode(e.keyCode))
} else {
} else if (String.fromCharCode(e.keyCode) === '\b'){
this.state.keysPidBox.pop()
}

Expand All @@ -232,11 +232,46 @@ export default class CheckIn extends React.Component {
this.setState({
keypresses: pidArray
});
}
} else if (this.state.keysPidBox.some(x => isNaN(parseInt(x)))){
const nameArray = this.state.keysPidBox;
console.log(nameArray);
if (String.fromCharCode(e.keyCode) === '\r' || String.fromCharCode(e.keyCode) === '\t') {
const newName = nameArray.join("");
console.log(newName);
console.log(e.target);
this.checkForHistoryName(newName);
}
}
}
}

checkForHistoryName = (name) => {

axios({
method: "POST",
url: "/name-to-pid/",
headers: { 'X-CSRFToken': csrfToken },
data: {
name: name
}
}).then((response => {
if (response.data.pid) {
if (this.state.pid.trim() === "") {
this.setState({
pid: response.data.pid,
});
}
this.reasonRef.current.focus();
} else {
this.pidRef.current.focus()
this.setState({
firstTime: true
});
}
}));
}

pidChange = (event) => {
this.setState({
pid: event.target.value
Expand Down
2 changes: 1 addition & 1 deletion src/Screens/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Home = () => {
}

const handleKeyPress = (e) => {
if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA")
if (e.target.nodeName === "INPUT" || e.target.nodeName === "TEXTAREA")
return;
if (e.target.isContentEditable) return;

Expand Down