Skip to content

Commit

Permalink
Added order model to current orders page, modified styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed May 13, 2022
1 parent 570b274 commit f37e547
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 60 deletions.
29 changes: 14 additions & 15 deletions build/menu-staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ <h1>List of items:</h1>
<th></th>
</tr>
</table>
<div class="cover" id="cover">
<div class="create-edit", id="creatediv">
<h3 id="subject">Create new item:</h3>
<label for="dishName">Name of item</label>
<input type="text" id="dishName" name="dishName"> <br>
<label for="dishDescription">Description:</label>
<textarea id="dishDescription" name="dishDescription" rows="4" maxlength="250" inputmode="latin" ></textarea> <br>
<label for="imageURL">Image link:</label>
<input type="url" id="imageURL" name="imageURL"> <br>
<label for="price">Price:</label>
<input type="text" id="price" name="price"> <br>
<div id="buttons">
<button onclick="addElementtoTable()", id="editorcreate">Add</button>
<button onclick="closeDiag('cover')">Cancel</button>
</div>
<div class="cover" id="cover" onclick="closeDiag('creatediv')"></div>
<div class="create-edit", id="creatediv">
<h1 id="subject">Create new item:</h3>
<label for="dishName">Name of item</label>
<input type="text" id="dishName" name="dishName" placeholder="Milk Tea"> <br>
<label for="dishDescription">Description:</label>
<textarea id="dishDescription" name="dishDescription" rows="4" maxlength="250" inputmode="latin" placeholder="Traditional milk tea."></textarea> <br>
<label for="imageURL">Image link:</label>
<input type="url" id="imageURL" name="imageURL" placeholder="https://img.buzzfeed.com/thumbnailer-prod-us-east-1/8f1e6c865e5b4ef0a1f8d15b3f676202/BFV69042_HowToMakeBobaFromScratch_JP_Final_YT.jpg?resize=1200:*&output-format=jpg&output-quality=auto"> <br>
<label for="price">Price:</label>
<input type="text" id="price" name="price" placeholder="9.99"> <br>
<div id="buttons">
<button onclick="addElementtoTable()", id="editorcreate">Add</button>
<button onclick="closeDiag('creatediv')">Cancel</button>
</div>
</div>
<script src="/scripts/menu-staff.js"></script>
Expand Down
57 changes: 36 additions & 21 deletions build/orders-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,48 @@
{% block head %}
<title>Active Orders</title>
<link href="/styles/order-page.css" rel="stylesheet" type="text/css"/>
<link href="/styles/order-page-orders.css" rel="stylesheet" type="text/css"/>
{% endblock %}

{% block body %}
<h1>Active orders:</h1>
<div class="whitebox">
<div class="header">
<h2>Current time:</h2>
<h2 id="currentTime"></h2>
<h1 class="h1">Active orders:</h1>
<div class="whitebox">
<div class="header">
<h2 class="h2">Current time:</h2>
<h2 class="h2" id="currentTime"></h2>
</div>
<div class="tablecont">
<table class="ptable", id="ptable">
<tr>
<th>OrderID</th>
<th>Items</th>
<th>CustomerID</th>
<th>Address</th>
<th>Total Price</th>
<th>Time Placed</th>
<th>Delivery Person</th>
<th>Delivery Method</th>
<th>Order Status</th>
<th></th>
</tr>
</table>
</div>
</div>
<div class="tablecont">
<table class="ptable", id="ptable">
<tr>
<th>OrderID</th>
<th>Items</th>
<th>CustomerID</th>
<th>Address</th>
<th>Total Price</th>
<th>Time Placed</th>
<th>Delivery Person</th>
<th>Delivery Method</th>
<th>Order Status</th>
<th></th>
</tr>
</table>
<div class="displayblock" id="displayblock" onclick="closeModel()">
</div>
<div class="ordermodel" id="ordermodel" onclick="">
<div class="order-container">
<h1 class="order-id"></h1>
<div class="order-items" id="order-items"></div>
<div class="order-cost" id="order-cost"></div>
<div class="order-status" id="order-status"></div>
</div>
<div>
<button onclick="closeModel()">Close</button>
</div>
</div>
<script src="/scripts/order-page.js"></script>
<script src="/scripts/order-page-bidpicking.js"></script>
</div>
<script src="/scripts/order-page-orders.js"></script>
{% endblock %}

31 changes: 17 additions & 14 deletions build/scripts/menu-staff.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function addElementtoTable() { // Function adds an element to the item bar. Uses createElement() function.
let data = parseIntoDict()
console.log(data)
addtoDB(data)
closeDiag("cover")
let data = parseIntoDict();
console.log(data);
addtoDB(data);
closeDiag("cover");
}

function createRow(item) {
Expand Down Expand Up @@ -55,15 +55,17 @@ async function getfromDBInd(id) {
}

function openDiag(motive, buttonText, id = false) {
let actbutton = document.getElementById("editorcreate")
actbutton.innerHTML = buttonText
let actbutton = document.getElementById("editorcreate");
actbutton.innerHTML = buttonText;

document.getElementById("subject").innerHTML = motive
document.getElementById("subject").innerHTML = motive;

let diag = document.getElementById('cover')
if (id) { actbutton.onclick = function () { editItem(id) } }
else { actbutton.onclick = addElementtoTable }
diag.style.display = 'block'
let cover = document.getElementById('cover');
let diag = document.getElementById('creatediv');
if (id) { actbutton.onclick = function () { editItem(id); } }
else { actbutton.onclick = addElementtoTable; }
cover.style.display = 'block';
diag.style.display = 'flex';

// let
}
Expand All @@ -72,9 +74,10 @@ function closeDiag(name) {
['dishName', 'dishDescription', 'price', 'imageURL'].forEach(field => {
document.getElementById(field).value = '';
})

let diag = document.getElementById(name)
diag.style.display = 'none'
let cover = document.getElementById('cover');
let diag = document.getElementById(name);
diag.style.display = 'none';
cover.style.display = 'none';
}

async function displayItems() {
Expand Down
117 changes: 117 additions & 0 deletions build/scripts/order-page-orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
async function getOrder(id) {
const response = await fetch(`/api/order/${id}`);
if (response.headers.get("content-type") === 'application/json') {
const data = await response.json();
const order = data['response'];
return order
}
return undefined
}



async function loadOrder(id) {
const order = await getOrder(id);
// console.log(order)
if (order) {
// set order id
document.getElementsByClassName('order-id')[0].textContent = `Order ID: ${order['orderID']}`
// display order items
loadOrderItems(order['dishes'])
// display order costs
loadCosts(order['dishes'], order['deliveryMethod'] === 'delivery');
// display order status
loadStatus(order['status'])
}
else {
orderContainer = document.getElementsByClassName('order-container')[0];
notFound = createElement('p', { text: 'Order not found' })
orderContainer.appendChild(notFound);
}
openModel();
}

function loadOrderItems(items) {
const orderItems = document.getElementsByClassName('order-items')[0];
let h2 = createElement('h2', { text: 'Items' });
let itemdiv = createElement('div', {class:'order-items-div'})
orderItems.appendChild(h2);
items.forEach(item => {
orderItem = createOrderItem(item);
itemdiv.appendChild(orderItem);
})
orderItems.appendChild(itemdiv);
}

function createOrderItem(item) {
const orderItem = createElement('div', { class: 'order-item' });
const image = createElement('img', { class: 'order-img', src: item['imageURL'] });
const dishName = createElement('h3', { text: item['dishName'] });
const quantity = createElement('p', { text: `Quantity: ${item['quantity']}` });
appendChildren(orderItem, [image, dishName, quantity])
return orderItem
}

function loadCosts(items, isDelivery) {
const prices = calculateCartPrice(items, isDelivery);
const orderCosts = document.getElementsByClassName('order-cost')[0]
const h2 = createElement('h2', { text: 'Costs' });
orderCosts.appendChild(h2);
const priceElementArray = Object.keys(prices).map(priceType => {
return createElement('p', { text: `${priceType}: ${prices[priceType].toFixed(2)}` });
})
appendChildren(orderCosts, priceElementArray);

}
// cur
function calculateCartPrice(items, isDelivery) {
let subtotal = 0;
let taxes = 0;
let deliveryFee = 0;
let total = 0;
items.forEach(item => { subtotal = item.price * item.quantity; })
taxes = subtotal * 0.08875;
isDelivery && (deliveryFee = 7.99);
total = subtotal + taxes + deliveryFee;
return { subtotal, taxes, deliveryFee, total };
}

function loadStatus(status) {
const orderStatus = document.getElementsByClassName('order-status')[0];
const h2 = createElement('h2', { text: 'Status' });
const p = createElement('p', { text: status });
appendChildren(orderStatus, [h2, p]);
}

function openModel() { // Opens a selected modal.
const back = document.getElementById('displayblock');
back.onclick = function() {closeModel();};
back.style.display = "block";
console.log(back);
const model = document.getElementById('ordermodel');
model.style.display = "block";
}

function closeModel() { // Closes a selected modal.
document.getElementById('displayblock').style.display = "none";
const model = document.getElementById('ordermodel');
model.style.display = "none";
cleanModel();
}

function cleanModel(){
document.getElementsByClassName('order-id')[0].textContent = "";

let orderitems = document.getElementById("order-items").children;
Array.from(orderitems).forEach(element => {
element.remove();
});
let ordercost = document.getElementById("order-cost").children;
Array.from(ordercost).forEach(element => {
element.remove();
});
let orderstatus = document.getElementById("order-status").children;
Array.from(orderstatus).forEach(element => {
element.remove();
});
}
2 changes: 1 addition & 1 deletion build/scripts/order-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function filltable(data) {
break;
case 'orderID':
column = createElement('td');
let anchor = createElement('a', { href: `/orders/${order[key]}`, text: order[key] })
let anchor = createElement('a', { onclick:`loadOrder(${order[key]})`/*href: `/orders/${order[key]}`*/, text: order[key] })
column.appendChild(anchor)
break;
default:
Expand Down
1 change: 1 addition & 0 deletions build/styles/dashboard-layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ button{
margin: 5px;
padding: 10px;
border: none;
/* background-color: rgb(245, 245, 245); */
transition: hover 1s;
}

Expand Down
18 changes: 12 additions & 6 deletions build/styles/menu-staff.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ tr {
width: 350px;
top: 50%;
left: 50%;
display: flex;
display: none;
transform: translate(-50%, -50%);
background-color: rgb(255, 230, 244);
flex-direction: column;
justify-content: left;
justify-content: center;
/* align-items: left; */
text-align: left;
text-align: center;
padding: 20px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}

input {
Expand Down Expand Up @@ -90,8 +91,13 @@ textarea {
}

.cover {
/* width: 100%;
position: fixed;
top: 0px; left:0px; bottom: 0px; right: 0px;
width: 100%;
height: 100%;
color: rgb(58, 44, 47, 40%); */
background-color: rgba(5, 4, 5, 0.3);
display: none;
}
}
/* #subject{
font-size: 30px;
} */
2 changes: 1 addition & 1 deletion build/styles/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
margin: 10px 10px;
width: 250px;
display: flex;
flex-direction: row;
flex-direction: column;
align-items: center;
justify-content: center;
transition: hover 0.7s;
Expand Down
Loading

0 comments on commit f37e547

Please sign in to comment.