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

home work #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
42 changes: 42 additions & 0 deletions models/missions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// DATA - put into marsMissions.js file inside of a models folder, for module.exports
// remember to require it in the server

const marsMissions = [
{
name: "Curiosity",
launchDate: "26 Nov 2011",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Opportunity",
launchDate: "8 Jul 2003",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Spirit",
launchDate: "10 Jun 2003",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Sojourner",
launchDate: "4 Dec 1996",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Rosetta",
launchDate: "2 Mar 2004",
operator: "ESA",
missionType: "Gravity Assist",
img: ""
}
];

module.exports = marsMissions;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"chai": "^4.2.0",
"cheerio": "^1.0.0-rc.2",
"ejs": "^2.6.1",
"express": "^4.16.3",
"mocha": "^5.2.0",
"supertest": "^3.3.0"
Expand Down
77 changes: 15 additions & 62 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,28 @@
const express = require('express');
const app = express();

// run `npm install` to install dependencies in package.json
const MarsMissions = require('./models/missions');

// * Your mission is to complete the app
// * The app will need routes for index and show
// * The app will need views for index and show
//
// * MAIN GOAL:
// * User should be able to click on a mission’s name on the index page, and be taken to that mission’s show page
//
// * Bonus/Hungry for More: add images to the data and have them display (google how)
// * Bonus/Hungry for More: add static css to style the pages (google how)

// NOTES:
// ejs has not been installed
// views folder has not been created
// views/missions folder has not been created
//INDEX
app.get('/missions', (req, res) => {
res.render('../views/index.ejs', {
marsMissions: MarsMissions
})
});

// PORT
const port = 3000;

// DATA - put into marsMissions.js file inside of a models folder, for module.exports
// remember to require it in the server
const marsMissions = [
{
name: "Curiosity",
launchDate: "26 Nov 2011",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Opportunity",
launchDate: "8 Jul 2003",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Spirit",
launchDate: "10 Jun 2003",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Sojourner",
launchDate: "4 Dec 1996",
operator: "NASA",
missionType: "Rover",
img: ""
},
{
name: "Rosetta",
launchDate: "2 Mar 2004",
operator: "ESA",
missionType: "Gravity Assist",
img: ""
}
];
//SHOW
app.get('/missions/:id', (req, res) => {
res.render('../views/show.ejs', {
marsMissions: MarsMissions[req.param.id]
})
});

// INDEX Route
// send data to 'missions/index.ejs' view
// the view should display just the names of each mission
// display the mission names as <li> in a <ul> with the class name "missions"

// SHOW Route
// send data to 'missions/show.ejs' view
// the view should display all the data for a single mission

// PORT
const port = 3000;


// LISTENER
Expand Down
20 changes: 20 additions & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Mars Mission Control</title>

<h1>Mars Missions</h1>
<ul>
<% for(let i = 0; i < marsMissions.length; i++) {%>
<li>
<a href='/missions/<%=i%>'><%= marsMissions[i].name %></a>
</li>
<% }%>

</ul>

</head>
<body>

</body>
</html>
14 changes: 14 additions & 0 deletions views/show.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Mars Missions</title>
<h1>Mission show page</h1>
The <%= marsMissions.name %> launched <%= marsMissions.launcDate%>

<h3>The mission Operator is <%=marsMissions.operator %> and the mission type is a <%=marsMissions.missionType%></h3>

</head>
<body>

</body>
</html>