Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample code for table associations #3

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6d5317c
Configured express to serve the static files in /public
Shivppatel Mar 14, 2021
f52a09f
Created initial files nedded for the site
Shivppatel Mar 14, 2021
a012ef6
added auto incerment for dining post endpoint for hall_id
Shivppatel Mar 17, 2021
8e6929b
js to make bulma nav responsive
Shivppatel Mar 17, 2021
d235fca
created endpoint for the fetching of macros via custom SQL
Shivppatel Mar 17, 2021
7eee259
created endpoint for the fetching of macros via custom SQL
Shivppatel Mar 17, 2021
5ebc6b2
eevert "created endpoint for the fetching of macros via custom SQL"
Shivppatel Mar 17, 2021
690ee65
created endpoint for the fetching of macros via custom SQL
Shivppatel Mar 17, 2021
5a0b6f0
set up initial homepage layout
Shivppatel Mar 17, 2021
247a0ed
Created functions to populate both the nearby dinning halls and macro…
Shivppatel Mar 17, 2021
d90357b
created about and documentation pages
Shivppatel Mar 17, 2021
a03d5ce
fixed naming conflict resulting in the wrong endpoint being hit
Shivppatel Mar 19, 2021
a9139cc
Changed scheme to include the newly added lat and long columns
Shivppatel Mar 19, 2021
4d48646
added meal map to navbar and also linked hero buttons
Shivppatel Mar 19, 2021
61d1d6b
created initial about page
Shivppatel Mar 19, 2021
b0fb114
created initial documentation page
Shivppatel Mar 19, 2021
793c3f4
Fixed broken reference to hall_location
Shivppatel Mar 19, 2021
c0be0c9
updated Dining Hall post to include the new columns also created an e…
Shivppatel Mar 19, 2021
dbb0d60
Created model for Meals Locations table
Shivppatel Mar 19, 2021
44164df
Added code from lab 5 to create a map and allow for searching of meals
Shivppatel Mar 19, 2021
f1cadb8
centered map
Shivppatel Mar 19, 2021
6b1b0df
changed height to min-height
Shivppatel Mar 19, 2021
515b92a
made table scrollable
Shivppatel Mar 19, 2021
f8183b6
Changed address and city to be on different lines
Shivppatel Mar 19, 2021
8db48d0
centered map and tweaked styling
Shivppatel Mar 19, 2021
b505261
added popups for the markers to show the dining hall name
Shivppatel Mar 19, 2021
8b59393
configured map and wrapper size
Shivppatel Mar 19, 2021
fb5bfa0
removed unused file
Shivppatel Mar 19, 2021
05bad20
Completed demo layout
Shivppatel Mar 19, 2021
ee15c3d
Completed demo layout
Shivppatel Mar 19, 2021
058cf04
prettier formating
Shivppatel Mar 19, 2021
d1b2562
moved meal map to homepage
Shivppatel Mar 19, 2021
5620b09
Added tab for the map on homepage
Shivppatel Mar 19, 2021
62e8ae0
Fixed map centering
Shivppatel Mar 19, 2021
283b790
fixed map breaking on mobile
Shivppatel Mar 19, 2021
78228f0
linked stylesheet
Shivppatel Mar 20, 2021
ba3dbad
made navbar sticky
Shivppatel Mar 20, 2021
4af0375
Linked logo on nav to go back to hero section
Shivppatel Mar 20, 2021
07cf678
made ESLint happy
Shivppatel Mar 22, 2021
e3516ad
Allow CORS on server
aleitch1 Apr 21, 2021
71689b1
How To Associate Tables
aleitch1 Apr 21, 2021
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
1 change: 0 additions & 1 deletion database/initializeDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ if (config.use_env_variable) {
}

const db = Object.keys(modelList).reduce((collection, modelName) => {

if (!collection[modelName]) {
// eslint-disable-next-line no-param-reassign
collection[modelName] = modelList[modelName](sequelizeDB, DataTypes);
Expand Down
8 changes: 4 additions & 4 deletions models/DietaryRestrictions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export default (sequelize, DataTypes) => {
const DietaryRestrictions = sequelize.define(
"Dietary_Restrictions",
'Dietary_Restrictions',
{
restriction_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
primaryKey: true
},
restriction_type: {
type: DataTypes.STRING,
},
type: DataTypes.STRING
}
},
{ freezeTableName: true, timestamps: false }
);
Expand Down
16 changes: 11 additions & 5 deletions models/DiningHall.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
export default (database, DataTypes) => {
const DiningHall = database.define(
"Dining_Hall",
'Dining_Hall',
{
hall_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
primaryKey: true
},
hall_name: {
type: DataTypes.STRING,
type: DataTypes.STRING
},
hall_location: {
type: DataTypes.STRING,
hall_address: {
type: DataTypes.STRING
},
hall_lat: {
type: DataTypes.DECIMAL
},
hall_long: {
type: DataTypes.DECIMAL
}
},
{ freezeTableName: true, timestamps: false }
);
Expand Down
5 changes: 5 additions & 0 deletions models/Macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ export default (sequelize, DataTypes) => {
},
{ freezeTableName: true, timestamps: false }
);
Macros.associate = (models) => {
Macros.belongsTo(models.Meals, {
foreignKey: 'meal_id'
});
};
return Macros;
};
7 changes: 7 additions & 0 deletions models/Meals.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ export default (sequelize, DataTypes) => {
},
{ freezeTableName: true, timestamps: false }
);
Meals.associate = (models) => {
Meals.hasOne(models.Macros, {
foreignKey: 'meal_id'
});
};
return Meals;
};

// TODO: associate meals and macros
17 changes: 17 additions & 0 deletions models/MealsLocations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default (sequelize, DataTypes) => {
const Meals = sequelize.define(
"Meals_Locations",
{
hall_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
meal_id: {
type: DataTypes.INTEGER,
allowNull: false,
},
},
{ freezeTableName: true, timestamps: false }
);
return Meals;
};
2 changes: 1 addition & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
DiningHall,
Macros,
Meals
};
};
23 changes: 23 additions & 0 deletions public/bulmaNav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
document.addEventListener("DOMContentLoaded", () => {
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(
document.querySelectorAll(".navbar-burger"),
0
);

// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach((el) => {
el.addEventListener("click", () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);

// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle("is-active");
$target.classList.toggle("is-active");
});
});
}
});
266 changes: 266 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
<!DOCTYPE html>
<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.0" />
<title>UMD Dining Hall</title>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""
/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script
src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"
/>
<script
src="https://kit.fontawesome.com/978cb43e08.js"
crossorigin="anonymous"
></script>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<section class="hero is-link is-fullheight" id="home">
<div class="hero-head">
<nav class="navbar">
<div class="container">
<div class="navbar-brand">
<a href="#home" class="navbar-item">
<p class="subtitle">Dining Hall Tracker</p>
</a>
<span class="navbar-burger" data-target="navbarMenuHeroB">
<span></span>
<span></span>
<span></span>
</span>
</div>
<div id="navbarMenuHeroB" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item is-active"> Home </a>
<a href="./pages/about.html" class="navbar-item"> About </a>
<a href="./pages/documentation.html" class="navbar-item">
Documentation
</a>
<span class="navbar-item">
<a href="https://github.com/Shivppatel/sequelize" target="_blank" class="button is-info is-inverted">
<span class="icon">
<i class="fab fa-github"></i>
</span>
<span>Source Code</span>
</a>
</span>
</div>
</div>
</div>
</nav>
</div>

<div class="hero-body">
<div class="container has-text-centered">
<p class="title">UMD Dining Information</p>
<p class="subtitle">INST377 Example</p>
</div>
</div>
<nav class="level pb-6">
<div class="level-item has-text-centered">
<div>
<p class="heading">Dining Halls</p>
<p class="title">3</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Meals</p>
<p class="title">46</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Macro Points</p>
<p class="title">322</p>
</div>
</div>
</nav>
</div>

<div class="hero-foot">
<div class="tabs is-centered">

<ul>
<li class="">
<a href="#map">
<span class="icon is-small"><i class="fas fa-search-location" aria-hidden="true"></i></span>
<span>Locate Meals</span>
</a>
</li>
<li>
<a href="#macros">
<span class="icon is-small"><i class="fas fa-weight" aria-hidden="true"></i></span>
<span>Macros</span>
</a>
</li>
<li class="">
<a href="#halls">
<span class="icon is-small"><i class="fas fa-utensils" aria-hidden="true"></i></span>
<span>Dining Halls</span>
</a>
</li>
<li>
<a href="#form">
<span class="icon is-small"><i class="fas fa-map-marker-alt" aria-hidden="true"></i></span>
<span>Add Location</span>
</a>
</li>
</ul>
</div>
</div>
<i class="fas fa-chevron-down has-text-centered pb-3"></i>
</section>


<section class="section has-background-info-light" id="map">
<div class="column">
<div class="box container" id="wrapper">
<h1 class="title has-text-centered">Meal Locator</h1>
<div class="subtitle has-text-centered">
Food Search by Hall name or Dish
</div>

<div class="container columns">
<div class="column info">
<div class="block">
<form id="search-form" action="" class="block form">
<div class="field">
<label class="subtitle has-text-dark" for="search"
>Search</label
>
<div class="control">
<input
class="input"
type="text"
name="search"
id="search"
placeholder="Enter a dish or hall name (e.g. eggs)"
/>
</div>
</div>
</form>
<div class="reply-box block">
<div class="reply-message"></div>
<ul class="target-list"></ul>
</div>
</div>
</div>
<div class="column is-align-self-center">
<div class="box" id="mapid">Map</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="section has-background-info-light" id="macros">
<div class="box">
<p class="title has-text-centered">Meal Macro Information</p>
<div class="table-container">
<table class="table is-bordered is-hoverable is-fullwidth is-striped">
<thead>
<tr>
<th>Meal Id</th>
<th>Name</th>
<th>Calories</th>
<th>Carbs</th>
<th>Sodium</th>
<th>Protein</th>
<th>Fat</th>
<th>Cholesterol</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</section>
<section class="section has-text-centered has-background-info-light" id="halls">
<div class="box">
<p class="title">Nearby Places</p>
<p class="subtitle">
Places that are near campus to get food.
</p>
<div class="tile is-ancestor is-justify-content-center"></div>
</div>
</div>
</section>
<section class="section has-background-info-light" id="form">
<div class="box">
<p class="title">Add Restaurant</p>
<p class="subtitle">
Do you know a place <strong>near</strong> campus? Add it to our
database!
</p>
<form class="box has-text-centered is-half" action="/api/dining" method="post">
<div class="field">
<p class="control has-icons-left">
<input class="input" type="text" name="hall_name" placeholder="Restaurant Name" required/>
<span class="icon is-small is-left">
<i class="fas fa-utensils"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" name="hall_address" type="text" placeholder="Address" required/>
<span class="icon is-small is-left">
<i class="fas fa-map-pin"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" name="hall_lat" type="number" min="38" max="39" step="0.0001" placeholder="Latitude" required/>
<span class="icon is-small is-left">
<i class="fas fa-compass"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" name="hall_long" type="number" min="-77" max="-76" step="0.0001"placeholder="Longitude" required/>
<span class="icon is-small is-left">
<i class="fas fa-compass"></i>
</span>
</p>
</div>
<div class="field">
<p class="control">
<button class="button is-link" type="submit">Submit</button>
</p>
</div>
</form>
</div>
</section>

<footer class="footer has-background-info-light">
<div class="content has-text-centered">
<p>
<strong>UMD Dining Information</strong> by
<a href="https://github.com/Shivppatel" target="_blank">Shiv Patel</a>. The source code is licensed _____. The
website content is licensed
by _____.
</p>
</div>
</footer>
<script src="script.js"></script>
<script src="bulmaNav.js"></script>
</body>

</html>
Loading