diff --git a/.gitignore b/.gitignore index 3d41ed7..b62ab71 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ built package-lock.json ### MAC ## -.DS_Store \ No newline at end of file +.DS_Store + +### VSCODE ### +.vscode diff --git a/src/main/java/ca/mcgill/ecse428/potatopeeps/config/DatabaseLoader.java b/src/main/java/ca/mcgill/ecse428/potatopeeps/config/DatabaseLoader.java index bdb044c..53c846f 100644 --- a/src/main/java/ca/mcgill/ecse428/potatopeeps/config/DatabaseLoader.java +++ b/src/main/java/ca/mcgill/ecse428/potatopeeps/config/DatabaseLoader.java @@ -4,6 +4,7 @@ import ca.mcgill.ecse428.potatopeeps.diningsession.DiningSessionRepository; import ca.mcgill.ecse428.potatopeeps.menuitem.MenuItem; import ca.mcgill.ecse428.potatopeeps.menuitem.MenuItemRepository; +import ca.mcgill.ecse428.potatopeeps.order.Order; import ca.mcgill.ecse428.potatopeeps.order.OrderRepository; import ca.mcgill.ecse428.potatopeeps.tag.Tag; import ca.mcgill.ecse428.potatopeeps.tag.TagRepository; @@ -95,6 +96,25 @@ public void run(String... strings) { menuItemRepository.save(menuItem); } } + + // FILL ORDER TABLE + Order[] orders = new Order[10]; + orders[0] = new Order(menuItems[0].getPrice(), 1, menuItems[0], diningSessions[0]); + orders[1] = new Order(menuItems[3].getPrice(), 2, menuItems[3], diningSessions[0]); + orders[2] = new Order(menuItems[7].getPrice(), 1, menuItems[7], diningSessions[0]); + orders[3] = new Order(menuItems[13].getPrice(), 4, menuItems[13], diningSessions[0]); + orders[4] = new Order(menuItems[25].getPrice(), 1, menuItems[25], diningSessions[1]); + orders[5] = new Order(menuItems[19].getPrice(), 1, menuItems[19], diningSessions[1]); + orders[6] = new Order(menuItems[2].getPrice(), 1, menuItems[2], diningSessions[2]); + orders[7] = new Order(menuItems[15].getPrice(), 1, menuItems[15], diningSessions[3]); + orders[8] = new Order(menuItems[11].getPrice(), 1, menuItems[11], diningSessions[4]); + orders[9] = new Order(menuItems[9].getPrice(), 1, menuItems[9], diningSessions[4]); + for (Order order : orders) { + orderRepository.save(order); +// if(!orderRepository.existsById(order.getId())){ +// orderRepository.save(order); +// } + } } } diff --git a/src/main/js/components/App.js b/src/main/js/components/App.js index ba5caab..87a767e 100644 --- a/src/main/js/components/App.js +++ b/src/main/js/components/App.js @@ -11,6 +11,7 @@ import {Login, SelectTask} from "./Login"; import {Staff, StaffOrders, StaffRequests} from "./Staff"; import {Manager} from "./Manager"; import {Customer, CustomerMenu, CustomerLandingPage} from "./Customer"; +import {DiningSessionOrders} from "./subcomponents/Order" /** ----- TUTORIAL API IMPORTS -----**/ import follow from "../follow"; @@ -572,6 +573,27 @@ export class App extends React.Component { selectedView={'Customer'} filterMenuItemList={this.filterMenuItemList} {...props}/>)}/> + {/* */} + + ()}/> diff --git a/src/main/js/components/Staff.js b/src/main/js/components/Staff.js index 3b234d0..22d1d36 100755 --- a/src/main/js/components/Staff.js +++ b/src/main/js/components/Staff.js @@ -3,6 +3,7 @@ import React from "react"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; /** ----- COMPONENT IMPORTS -----**/ +import {CustomerDiningSessionSelect, StaffDiningSessionPage, StaffDiningSession} from "./subcomponents/DiningSession"; /** ----- CSS/STYLING IMPORTS -----**/ import "../../resources/static/css/staff.css"; @@ -15,17 +16,33 @@ import "../../resources/static/css/staff.css"; */ export class Staff extends React.Component { + + constructor(props){ + super(props); + this.state = {pageSize: 30, selectedView: 'Staff'}; + } render() { return (
- + +
) } + + componentDidMount() { + this.props.loadResourceFromServer('diningSessions', this.state.pageSize); + } } class StaffLanding extends React.Component { @@ -66,6 +83,7 @@ class StaffLanding extends React.Component {
/* Deleted the sample list of menu items as we do not need to see the menu items from staff*/ +
Sushi
@@ -73,8 +91,10 @@ class StaffLanding extends React.Component {
+ +
  • @@ -82,6 +102,7 @@ class StaffLanding extends React.Component {
+ ) } diff --git a/src/main/js/components/subcomponents/DiningSession.js b/src/main/js/components/subcomponents/DiningSession.js index b101dc8..8ca2a77 100644 --- a/src/main/js/components/subcomponents/DiningSession.js +++ b/src/main/js/components/subcomponents/DiningSession.js @@ -2,8 +2,20 @@ /** ----- NPM PACKAGE IMPORTS -----**/ import React from "react"; +import ReactDOM from "react-dom"; +import Select from "react-select"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import { + faTrash, faEdit, faAngleDoubleLeft, + faAngleDoubleRight, faAngleLeft, faAngleRight, + faPlus +} from "@fortawesome/free-solid-svg-icons"; - +/** ----- CSS/STYLING IMPORTS -----**/ +import "../../../resources/static/css/staff.css" +//TODO filter for active export class CustomerDiningSessionSelect extends React.Component { constructor(props) { super(props); @@ -23,4 +35,109 @@ export class CustomerDiningSessionSelect extends React.Component { ); } +} + +export class StaffDiningSessionPage extends React.Component{ + + constructor(props) { + super(props); + this.state = { + show : false, + orders : [] + } + } + + render(){ + const sessions = this.props.diningSessions.map(session => + ) + + //TODO review how to get number of diningSessions. Test whether this.props.diningSessions.size returns a number or undefined + return ( +
+ All Orders + {sessions} + +
+ ) + } + + handleClose(){ + //load orders + // const orders; + } + +} + +export class StaffDiningSession extends React.Component{ + + constructor(props){ + super(props); + this.handleListOrders = this.handleListOrders.bind(this); + } + + requestOrders(){ + fetch(this.props.diningSession.entity._links.orders.href, {method: 'GET', headers: {'Content-Type': 'application/json'}}) + .then( + response => { + if (!response.ok) { + console.log('Looks like there was a problem. Status Code: ' + + response.status); + return; + } + + // Examine the text in the response + response.json().then((data) => { + console.log(data._embedded.orders); + this.setState( + { + orders : data._embedded.orders + } + ); + }); + } + ) + .catch(function(err) { + console.log('Fetch Error :-S', err); + }); + } + render(){ + // console.log("Individual session:"); + // console.log(this.props.diningSession); + return ( +
+ +
+
Table {this.props.diningSession.entity.tableNumber}
+
{this.props.diningSession.entity.price}
+
+ +
+ +
+
+ ) + } + + handleListOrders(){ + this.props.history.push + ( + { + pathname: ('/orders/'), + state: {diningSession : this.props.diningSession}, + diningSession : this.props.diningSession + } + ); + + } } \ No newline at end of file diff --git a/src/main/js/components/subcomponents/Order.js b/src/main/js/components/subcomponents/Order.js index 9e76310..ad95c75 100644 --- a/src/main/js/components/subcomponents/Order.js +++ b/src/main/js/components/subcomponents/Order.js @@ -2,4 +2,256 @@ /** ----- NPM PACKAGE IMPORTS -----**/ import React from "react"; -import ReactDOM from "react-dom"; \ No newline at end of file +import ReactDOM from "react-dom"; +import Select from "react-select"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +/**Custom Class imports */ +import { StaffOrders } from "../Staff"; +/** Styling Imports */ +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import { + faTrash, faEdit, faAngleDoubleLeft, + faAngleDoubleRight, faAngleLeft, faAngleRight, + faPlus +} from "@fortawesome/free-solid-svg-icons"; +import "../../../resources/static/css/staff.css" + +//******************* IMPORTANT***** +//Due to an unknown caveat of React.js, the unmounting of this component does not occur for multiple seconds +//This will therefore cause the end-user to load stale information if the user does not wait long enough in between + //selecting a diningSession's orders to view. +//It is recommended that the end user, and testers wait 20 seconds after navigating backwards from a diningSessionOrders page before selecting another +//******/ +//The DiningSessionOrders class is routed to from a list of all diningSession. +//This component corresponds to a list of Orders associated with a diningSession +//The hierarchy of Order expression goes as: StaffDiningSession -routes-> DiningSessionOrders -contains-> StaffOrderList -contains-> StaffOrder +export class DiningSessionOrders extends React.Component{ + constructor(props){ + super(props); //assume the following props are passed in: diningSession + this.state = { + orders : [], + } + this.requestOrders = this.requestOrders.bind(this); + this.handleBackClick = this.handleBackClick.bind(this); + } + + render(){ + return ( +
+
+
+
+ +
+

Order Details for {this.props.location.state.diningSession.table}

+
+
+ +
+ +
+
+ + + Cart Totals: + {this.props.location.state.diningSession.price} +
+
+
+
Sushi
+
PotatoPeeps
+
+
+
+ +
+ ); + } + + // this method dynamically loads the orders associated with the given + // diningSession and converts them into renderable components, namely StaffOrderList and StaffOrder + requestOrders(){ + fetch(this.props.location.diningSession.entity._links.orders.href, {method: 'GET', headers: {'Content-Type': 'application/json'}}) + .then( + response => { + if (!response.ok) { + console.log('Looks like there was a problem. Status Code: ' + + response.status); + return; + } + + // Examine the text in the response + response.json().then((data) => { + console.log(data._embedded.orders); + this.setState( + { + orders : data._embedded.orders + } + ); + console.log("In the render of Orders"); + console.log(this.state); + console.log(this.state.orders); + console.log("in render"); + }); + } + ) + .catch(function(err) { + console.log('Fetch Error :-S', err); + }); + } + + + componentDidMount(){ + this.requestOrders(); + } + + componentWillUnmount(){ + console.log("UNMOUNTING UNMOUNTING UNMOUNTING UNMOUNTING UNMOUNTING") + } + + handleBackClick(){ + // this.props.history.goBack(); + this.props.history.push + ( + { + pathname: ('/staff/'), + props: this.props + } + ); + } +} + +class StaffOrderList extends React.Component{ + constructor(props){ + super(props); + + } + + render(){ + const orders = this.props.orders.map(order => + + ) + + return ( +
+ + + + + + + + + + + + + {orders} + +
ItemPriceQuantityTotalStatus
+
+ ); + } + +} + +export class StaffOrder extends React.Component{ + constructor(props){ + super(props); + this.state = { + price : 4.99, + status: this.props.order.status, + quantity: this.props.order.quantity, + menuItem: {} + }; + this.requestMenuItem = this.requestMenuItem.bind(this); + } + + render(){ + return ( + + + + + {this.state.menuItem.name} + {this.state.menuItem.price} + +
+ > +
+ + {this.state.props} + + + + + ); + } + + handleSelectChange(event){ + //TODO Matt's update code will probably go here. + this.setState( + { + status: event.target.value, + menuItem: this.state.menuItem, + quantity: this.props.order.quantity + } + + ) + } + + requestMenuItem(){ + fetch(this.props.order._links.menuItem.href, {method: 'GET', headers: {'Content-Type': 'application/json'}}) + .then( + response => { + if (!response.ok) { + console.log('Looks like there was a problem. Status Code: ' + + response.status); + return; + } + + // Examine the text in the response + response.json().then((data) => { + console.log("Menu Item"); + console.log(data); + this.setState( + { + price : 4.99, + status: this.props.order.status, + quantity: this.props.order.quantity, + menuItem: data + } + ); + console.log("In the render of Orders"); + console.log(this.state); + console.log("in render"); + }); + } + ) + .catch(function(err) { + console.log('Fetch Error :-S', err); + }); + } + + componentDidMount(){ + this.requestMenuItem(); + } + +} \ No newline at end of file