Merge conflict resolved

This commit is contained in:
Preston Doman 2019-01-30 20:35:44 -08:00
commit 635edf83b6
12 changed files with 171 additions and 240 deletions

View file

@ -1,13 +1,13 @@
import hashlib
hasher = hashlib.md5()
with open ('simple_policy.py', 'rb') as afile:
with open('simple_policy.py', 'rb') as afile:
buf = afile.read()
hasher.update(buf)
print("md5 of simple: " + hasher.hexdigest())
hasher = hashlib.md5()
with open ('moderate_policy.py', 'rb') as afile:
with open('moderate_policy.py', 'rb') as afile:
buf = afile.read()
hasher.update(buf)
print("md5 of moderate: " + hasher.hexdigest())
@ -15,13 +15,13 @@ print("md5 of moderate: " + hasher.hexdigest())
hasher = hashlib.sha1()
with open ('simple_policy.py', 'rb') as afile:
with open('simple_policy.py', 'rb') as afile:
buf = afile.read()
hasher.update(buf)
print("sha1 of simple: " + hasher.hexdigest())
hasher = hashlib.sha1()
with open ('moderate_policy.py', 'rb') as afile:
with open('moderate_policy.py', 'rb') as afile:
buf = afile.read()
hasher.update(buf)
print("sha1 of moderate: " + hasher.hexdigest())

132
back/backend/policy.py Normal file
View file

@ -0,0 +1,132 @@
# simple_policy.py
from datetime import date
from policy import Policy, Section
# - For the rules, should one refer to fields by 'section.fields.x'
# or by the section name eg. 'general_section.fields.x'?
#### General
#### Section 0
general_section = Section(
title="General Info",
html_description="",
fields={
"destination": {"label": "Destination City", "type": "string"}
}
)
general_section.add_rule(
title="Destination city check",
rule=lambda report, section: section.field.destination == "Timbuktu",
rule_break_text="What did the cowboy say about Tim, his wild horse?"
)
Policy.add_section(general_section)
#### Flight
#### Section 1
flight_section = Section(
title="Flight Info",
html_description="<p>Enter flight details here.</p>",
fields={
"international": {"label": "Is this an international flight?", "type": "boolean"},
"departure_date": {"label": "Departure date", "type": "date"},
"return_date": {"label": "Return date", "type": "date"},
"fare": {"label": "Fare", "type": "decimal"},
}
)
flight_section.add_rule(
title="Airline fare pre-approval check",
rule=lambda report, section: section.fields.fare < 500,
rule_break_text="Fares cannot be more than $500"
)
Policy.add_section(flight_section)
#### Lodging
#### Section 2
lodging_section = Section(
title="Hotel Info",
html_description="<p>Enter hotel info here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>",
fields={
"check-in_date": {"label": "Check-in date", "type": "date"},
"check-out_date": {"label": "Check-out date", "type": "date"},
"rate": {"label": "Per diem nightly rate", "type": "decimal"},
"cost": {"label": "Total Cost", "type": "decimal"}
}
)
def nightly_rate_check(report, section):
checkin_date = date(section.fields.checkin_date)
checkout_date = date(section.fields.checkout_date)
duration = checkout_date - checkin_date
return section.fields.cost <= duration * section.fields.rate
section.add_rule(
title="",
rule=nightly_rate_check,
rule_break_text="The average nightly rate cannot be more than the USGSA rate."
)
Policy.add_section(lodging_section)
#### Local Transportation
#### Section 3
transport_section = Section(
title="Local Transportation",
html_description="<p>How much did you spend on local transportation, in total?</p>",
fields={
"duration": {"label": "How many days was your trip?", "type": "decimal"},
"cost": {"label": "Total cost", "type": "decimal"}
}
)
transport_section.add_rule(
title="Total cost check",
rule=lambda report, section: section.fields.cost <= section.fields.duration * 10,
rule_break_text="Local transportation costs must be less than $10 per day, on average."
)
Policy.add_section(transport_section)
#### Per Diem
#### Section 4
per_diem_section = Section(
title="Per Diem",
html_description="<p>Enter info about meals and incidentals here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>",
fields={
"duration": {"label": "How many days was your trip?", "type": "decimal"},
"rate": {"label": "What is the per diem rate for your destination?", "type": "decimal"},
"cost": {"label": "Total Cost for meals and incidentals", "type": "decimal"}
}
)
per_diem_section.add_rule(
title="Per Diem Cost Check",
rule=lambda report, section: section.fields.cost <= section.fields.duration * section.fields.rate,
rule_break_text="The average cost per day for per diem expenses cannot be more than the rate specified by the USGSA."
)
Policy.add_section(per_diem_section)
'''
Section(
title="",
html_description="<p></p>",
fields={
"": {"label": "", "type": ""}
}
)
section.add_rule(
title="",
rule=lambda report, section: boolean_statement,
rule_break_text=""
)
#// or, for a rule which doesnt apply to a specific section...
#//
#// add_general_rule(...)
'''

View file

@ -1,144 +0,0 @@
# simple_policy.py
from datetime import date
#TODO:
# - For the rules, should one refer to fields by 'section.fields.x' or by the section name eg. 'general_section.fields.x'?
#### General
#### Section 0
general_section = Section(
title = "General Info",
html_description = "",
fields = {
"destination": {"label": "Destination City", "type": "string"}
}
)
general_section.add_rule(
title = "Destination city check",
rule = lambda report, section:
if section.fields.destination == "Timbuktu":
return True
else:
return False
,
rule_break_text = "What did the cowboy say about Tim, his wild horse?"
)
#### Flight
#### Section 1
flight_section = Section(
title = "Flight Info",
html_description = "<p>Enter flight details here.</p>",
fields = {
"international": {"label": "Is this an international flight?", "type": "boolean"},
"departure_date": {"label": "Departure date", "type": "date"},
"return_date": {"label": "Return date", "type": "date"},
"fare": {"label": "Fare", "type": "decimal"},
}
)
flight_section.add_rule(
title = "Airline fare pre-approval check",
rule = lambda report, section:
return section.fields.fare < 500
,
rule_break_text = "Fares cannot be more than $500"
)
#### Lodging
#### Section 2
lodging_section = Section(
title = "Hotel Info",
html_description = "<p>Enter hotel info here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>",
fields = {
"check-in_date": {"label": "Check-in date", "type": "date"},
"check-out_date": {"label": "Check-out date", "type": "date"},
"rate": {"label": "Per diem nightly rate", "type": "decimal"},
"cost": {"label": "Total Cost", "type": "decimal"}
}
)
section.add_rule(
title = "",
rule = lambda report, section:
check-in_date = date(section.fields.check-in_date)
check-out_date = date(section.fields.check-out_date)
duration = check-out_date - check-in_date
return section.fields.cost <= duration * section.fields.rate
,
rule_break_text = "The average nightly rate cannot be more than the USGSA rate."
)
#### Local Transportation
#### Section 3
transport_section = Section(
title = "Local Transportation",
html_description = "<p>How much did you spend on local transportation, in total?</p>",
fields = {
"duration": {"label": "How many days was your trip?", "type": "decimal"},
"cost": {"label": "Total cost", "type": "decimal"}
}
)
transport_section.add_rule(
title = "Total cost check",
rule = lambda report, section:
return section.fields.cost <= section.fields.duration * 10
,
rule_break_text = "Local transportation costs must be less than $10 per day, on average."
)
#### Per Diem
#### Section 4
per_diem_section = Section(
title = "Per Diem",
html_description = "<p>Enter info about meals and incidentals here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>",
fields = {
"duration": {"label": "How many days was your trip?", "type": "decimal"},
"rate": {"label": "What is the per diem rate for your destination?", "type": "decimal"},
"cost": {"label": "Total Cost for meals and incidentals", "type": "decimal"}
}
)
per_diem_section.add_rule(
title = "Per Diem Cost Check",
rule = lambda report, section:
return section.fields.cost <= section.fields.duration * section.fields.rate
,
rule_break_text = "The average cost per day for per diem expenses cannot be more than the rate specified by the USGSA."
)
'''
Section(
title = "",
html_description = "<p></p>",
fields = {
"": {"label": "", "type": ""}
}
)
section.add_rule(
title = "",
rule = lambda report, section: return boolean_statement,
rule_break_text = ""
)
#// or, for a rule which doesnt apply to a specific section...
#//
#// add_general_rule(...)
'''

View file

@ -12,14 +12,14 @@
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<div class="navbar-brand">Reimbursinator</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-dashboard-navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsing-dashboard-navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="dashboard.html">Dashboard</a>
<a class="nav-link" href="home.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="new_report.html">New Report</a>
@ -27,9 +27,6 @@
<li class="nav-item">
<a class="nav-link active" href="edit_report.html">Edit Report</a>
</li>
<li class="nav-item">
<a class="nav-link" href="view_history.html">View History</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
@ -38,10 +35,20 @@
</ul>
</div>
</nav>
<div class="container">
<p>Edit an existing report</p>
<div class="container pt-5">
<div class="row">
<div class="col-sm-8 mx-auto">
<div class="card bg-light text-dark">
<div class="card-header text-center">
<h3>Your Report History</h3>
</div>
<div class="card-body">
</div>
</div>
</div>
</div>
</div>
<script src="js/logout.js"></script>
<script src="js/viewHistory.js"></script>
</body>
</html>

View file

@ -12,14 +12,14 @@
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<div class="navbar-brand">Reimbursinator</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-dashboard-navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsing-dashboard-navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="dashboard.html">Dashboard</a>
<a class="nav-link active" href="home.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="new_report.html">New Report</a>
@ -27,9 +27,6 @@
<li class="nav-item">
<a class="nav-link" href="edit_report.html">Edit Report</a>
</li>
<li class="nav-item">
<a class="nav-link" href="view_history.html">View History</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
@ -39,7 +36,7 @@
</div>
</nav>
<div class="container">
<p>Welcome, you are logged in</p>
<p>Welcome to Reimbursinator</p>
</div>
<script src="js/logout.js"></script>
</body>

View file

@ -12,7 +12,7 @@
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<div class="navbar-brand">Reimbursinator</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-index-navbar">
<span class="navbar-toggler-icon"></span>
</button>

View file

@ -24,11 +24,11 @@ function postToLoginEndpoint(event) {
console.log(`Server response:\n${this.response}`);
token = JSON.parse(this.response).token;
localStorage.setItem("token", token);
window.location.replace("dashboard.html");
window.location.replace("home.html");
} else {
console.log("LOGIN FAILURE!");
console.log(`Server status: ${this.status}`);
console.log(`Server response:\n${this.response}`);
console.error("LOGIN FAILURE!");
console.error(`Server status: ${this.status}`);
console.error(`Server response:\n${this.response}`);
displayErrorMessage(this.response);
}
}

View file

@ -76,10 +76,11 @@ function createEditReportForm(parsedData) {
console.log(`Section title: ${sections[section].title}`);
console.log(`Section html description: ${sections[section].html_description}`);
let sectionTitle = document.createElement("p").innerHTML = sections[section].title;
form.appendChild(title);
let sectionDescription = sections[section].html_description;
form.appendChild(sectionDescription);
let sectionTitle = document.createElement("p");
sectionTitle.innerHTML = sections[section].title;
form.appendChild(sectionTitle);
let sectionDescription = sections[section].html_description; // html_description should be updated to a standard string
form.insertAdjacentHTML("beforeend", sectionDescription);
for (let field in sections[section].fields) {
console.log(`Field label: ${sections[section].fields[field].label}`);
@ -194,5 +195,3 @@ function openEditReportForm(event) {
document.addEventListener("DOMContentLoaded", getReportHistory);

View file

@ -8,11 +8,11 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="img/favicon.ico">
<title>Log in</title>
<title>Log In</title>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="index.html">Reimbursinator</a>
<div class="navbar-brand">Reimbursinator</div>
</nav>
<div class="container pt-5">
<div class="row">

View file

@ -12,14 +12,14 @@
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<div class="navbar-brand">Reimbursinator</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-dashboard-navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsing-dashboard-navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="dashboard.html">Dashboard</a>
<a class="nav-link" href="home.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="new_report.html">New Report</a>
@ -27,9 +27,6 @@
<li class="nav-item">
<a class="nav-link" href="edit_report.html">Edit Report</a>
</li>
<li class="nav-item">
<a class="nav-link" href="view_history.html">View History</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">

View file

@ -8,11 +8,11 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="img/favicon.ico">
<title>Sign up</title>
<title>Sign Up</title>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="index.html">Reimbursinator</a>
<div class="navbar-brand">Reimbursinator</div>
</nav>
<div class="container pt-5">
<div class="row">

View file

@ -1,57 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="img/favicon.ico">
<title>Reimbursinator</title>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-dashboard-navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsing-dashboard-navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="dashboard.html">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="new_report.html">New Report</a>
</li>
<li class="nav-item">
<a class="nav-link" href="edit_report.html">Edit Report</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="view_history.html">View History</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link log-out-link" href="#"><i class="fas fa-sign-out-alt"></i> Log Out </a>
</li>
</ul>
</div>
</nav>
<div class="container pt-5">
<div class="row">
<div class="col-sm-8 mx-auto">
<div class="card bg-light text-dark">
<div class="card-header text-center">
<h3>Your Report History</h3>
</div>
<div class="card-body">
</div>
</div>
</div>
</div>
</div>
<script src="js/logout.js"></script>
<script src="js/viewHistory.js"></script>
</body>
</html>