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

Detailpagina #6

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
5cbea87
Update README.md
YoussraElmortai Apr 17, 2023
faa0c32
Merge branch 'fdnd-task:main' into main
YoussraElmortai Apr 19, 2023
0ae1161
copy
YoussraElmortai Apr 19, 2023
1f316ec
ejs erin gezet
YoussraElmortai Apr 19, 2023
dfea651
update
TobiasVr23 Apr 19, 2023
7d84fa4
Update style.css
YoussraElmortai Apr 21, 2023
b77515d
pages
YoussraElmortai Apr 21, 2023
3455842
server side
YoussraElmortai Apr 21, 2023
3de6fbb
index.ejs link gefixt
YoussraElmortai Apr 21, 2023
9985392
Merge pull request #10 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 21, 2023
0a6b9c4
style link gefixt
YoussraElmortai Apr 21, 2023
1c0604c
Create placeholder.png
YoussraElmortai Apr 21, 2023
df7deff
method kaarten erin
YoussraElmortai Apr 21, 2023
17cf82d
Update style.css
YoussraElmortai Apr 21, 2023
46ed924
responsieve
YoussraElmortai Apr 23, 2023
3031044
icons in assets
YoussraElmortai Apr 23, 2023
5b0ccc6
Merge pull request #11 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 24, 2023
ac8bda4
Refactored comments
Robin1224 Apr 24, 2023
00fc067
styling plus variable gefixt
YoussraElmortai Apr 24, 2023
8dd8173
Merge pull request #14 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 24, 2023
9060e7c
Merge pull request #13 from zombie0youssra/index.js-refactoring
YoussraElmortai Apr 24, 2023
12cb16b
extra styling en missende head elementen
YoussraElmortai Apr 24, 2023
15eab8c
Merge pull request #15 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 24, 2023
4dd64fd
Update head.ejs
YoussraElmortai Apr 24, 2023
e69e1ce
var in gezet
YoussraElmortai Apr 24, 2023
efc0f7d
Update style.css
YoussraElmortai Apr 24, 2023
8e0e6d7
Merge pull request #16 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 24, 2023
5ef0169
foutje gefixt
YoussraElmortai Apr 24, 2023
c213e4d
Merge pull request #17 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 24, 2023
5e560b0
categories erin gezet
YoussraElmortai Apr 24, 2023
6266c74
method title erin gezet
YoussraElmortai Apr 25, 2023
3cc19f2
Update style.css
YoussraElmortai Apr 25, 2023
ac0af04
main class geven
YoussraElmortai Apr 25, 2023
e66b354
Merge pull request #18 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 25, 2023
71c66e6
drop shadow en flex gefixt
YoussraElmortai Apr 25, 2023
79c5f36
Merge pull request #19 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 25, 2023
c906d50
js bestand aangemaakt
YoussraElmortai Apr 25, 2023
46223ec
Merge pull request #20 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 25, 2023
0af3158
overviewpage head aangemaakt
YoussraElmortai Apr 25, 2023
b8d04bb
Merge pull request #21 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 25, 2023
0c90e1c
styling head en form
YoussraElmortai Apr 25, 2023
480c8ab
Merge pull request #22 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 25, 2023
4c7f787
update
TobiasVr23 Apr 25, 2023
9a8ac1c
Merge branch 'main' into detailpagina
YoussraElmortai Apr 25, 2023
b34bfea
Merge pull request #23 from zombie0youssra/detailpagina
YoussraElmortai Apr 25, 2023
544969a
Update head-overviewpage.ejs
YoussraElmortai Apr 26, 2023
a0bf280
Update overviewpage.ejs
YoussraElmortai Apr 26, 2023
5159e26
Merge pull request #25 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 26, 2023
4b383fc
filter container en searchbar
YoussraElmortai Apr 26, 2023
574ba13
Update overviewpage.ejs
YoussraElmortai Apr 26, 2023
f9316a9
Merge pull request #26 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 26, 2023
5247543
Create pen-potlood.png
YoussraElmortai Apr 26, 2023
eee3c88
methode toevoegen tekst
YoussraElmortai Apr 26, 2023
e05b496
Merge pull request #27 from zombie0youssra/overzichtspagina
YoussraElmortai Apr 26, 2023
cc2fa00
update index.ejs
Robin1224 May 2, 2023
03837ab
progress on index.ejs
Robin1224 May 2, 2023
81febfc
Update README.md
YoussraElmortai May 8, 2023
e16cf18
footer erin gezet
YoussraElmortai May 8, 2023
de6c6fb
style plus form update
YoussraElmortai May 9, 2023
a6f5b7c
Merge pull request #30 from zombie0youssra/overzichtspagina
YoussraElmortai May 9, 2023
dab142c
update
TobiasVr23 May 10, 2023
629b249
fixed styling head
YoussraElmortai May 10, 2023
091eaf7
styling update
YoussraElmortai May 10, 2023
03380aa
Merge pull request #31 from zombie0youssra/overzichtspagina
YoussraElmortai May 10, 2023
e1af3f4
Update style.css
YoussraElmortai May 10, 2023
f4ff149
Merge pull request #32 from zombie0youssra/overzichtspagina
YoussraElmortai May 10, 2023
1d97655
Merge branch 'main' into index-ejs-html
Robin1224 May 10, 2023
fe0c1aa
Merge pull request #33 from zombie0youssra/index-ejs-html
Robin1224 May 10, 2023
c4345ce
Small fix from merge
Robin1224 May 10, 2023
f24c2b3
fix in overviewpage
YoussraElmortai May 10, 2023
2f3a58e
Merge branch 'main' into detailpagina
YoussraElmortai May 10, 2023
0de05d1
Merge pull request #34 from zombie0youssra/detailpagina
YoussraElmortai May 10, 2023
1c84e48
merge conflict
YoussraElmortai May 10, 2023
acd683d
yeaaaahhh it worksss
YoussraElmortai May 10, 2023
7fcc71b
Merge pull request #35 from zombie0youssra/overzichtspagina
YoussraElmortai May 10, 2023
fa74e6d
footer styling
YoussraElmortai May 10, 2023
b81c144
update
TobiasVr23 May 10, 2023
8ce4879
Merge branch 'detailpagina' of https://github.com/zombie0youssra/perf…
TobiasVr23 May 10, 2023
00386e2
Update style.css
YoussraElmortai May 10, 2023
c4d8bae
Merge pull request #36 from zombie0youssra/overzichtspagina
YoussraElmortai May 10, 2023
142e169
Merge branch 'main' into detailpagina
YoussraElmortai May 10, 2023
a4a0c3d
Update client-side.js
YoussraElmortai May 10, 2023
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
logs
*.logs
npm-debug.log*
node_modules
.npm
.env
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
views/
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
> _Fork_ deze leertaak en ga aan de slag. Onderstaande outline ga je gedurende deze taak in jouw eigen GitHub omgeving uitwerken. De instructie vind je in: [docs/INSTRUCTIONS.md](docs/INSTRUCTIONS.md)

# Titel
# Visual Thinking in het HBO
<!-- Geef je project een titel en schrijf in één zin wat het is -->

## Inhoudsopgave
Expand All @@ -23,9 +23,31 @@
## Kenmerken
<!-- Bij Kenmerken staat welke technieken zijn gebruikt en hoe. Wat is de HTML structuur? Wat zijn de belangrijkste dingen in CSS? Wat is er met JS gedaan en hoe? Misschien heb je iets met NodeJS gedaan, of heb je een framwork of library gebruikt? -->

### tools 🍔
- figma
- goodnotes
- visuel studio code
- polyplane

### gebruikte technieken 🍟
- ejs
- javascript
- node.js
- express
- css


## Installatie
<!-- Bij Instalatie staat hoe een andere developer aan jouw repo kan werken -->

1. Om in de repository te werken en aanpassingen te maken moet je node.js downloaden versie: .
2. Clone of download deze respository.
3. Open hem in je `code-editor`.
4. open de `terminal` en type `npm install`.
5. Daarna door gerbruik van `npm start` krijg je een localhost link waar je de code live
6. gebruik `gitignore` voor de modules zodat het niet allemaal op github komt te staan.
7. Live zetten van je project kan met behulp van cyclic.

## Bronnen

## Licentie
Expand Down
144 changes: 144 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Import necesssary express and ejs modules
import { render } from "ejs";
import express, { response } from "express";

// Create a new express instance
const app = express();

// Assign URL of API to variable
const url = "https://api.visualthinking.fdnd.nl/api/v1";

// Make EJS the selected view engine for our express app, and assign the views directory
app.set("view engine", "ejs");
app.set("views", "./views");

// Let express know we want to use JSON and URL-encoded request bodies
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Use map "public" to serve static files
app.use(express.static("public"));

// --- Rendering the index page: ---
app.get("/", (request, response) => {
response.render("index");
});

// --- Rendering the overview page: ---
// Define an HTTP GET route for the path '/overviewpage'
app.get("/overviewpage", (request, response) => {
// Log the value of the 'methods' parameter from the request's query string
console.log(request.query.methods);

// Define the URL to fetch the data from
const methodsUrl = url + "/methods?first=100";

// Use the fetchJson function to retrieve data from the specified URL
// Once the data is retrieved, render the 'overviewpage' view with the data
fetchJson(methodsUrl).then((data) => {
response.render("overviewpage", data);
});
});

// --- Rendering the detail page: ---
// Define an HTTP GET route for the path '/detailpage/:slug', where ':slug' is a URL parameter
app.get("/detailpage/:slug", (request, response) => {
// Construct the URL to fetch the detail page data from based on the URL parameter ':slug'
let detailPageUrl = url + "/method/" + request.params.slug;
// Construct the URL to fetch the comments page data from based on the query parameter 'id'
let commentsPageUrl = url + "/comments/?id=" + request.query.id;

// Log the constructed URL for the comments page
// console.log(commentsPageUrl);

const id = request.query.id;

// Use the fetchJson function to retrieve the data for the detail page
fetchJson(detailPageUrl).then((data) => {
// Use the fetchJson function to retrieve the data for the comments page
fetchJson(commentsPageUrl).then((data2) => {
// Combine the data from both responses into a single object
const combinedData = {
method: data.method, // Data from the detail page
comments: data2.comments, // Data from the comments page
};

// Log the combined data
// console.log(combinedData);

// Render the 'detailpage' view with the combined data
response.render("detailpage", combinedData);
});
});
});

// --- Handling post requests for the comments: ---
// Define an HTTP POST route for the path '/detailpagina/:slug', where ':slug' is a URL parameter
app.post("/detailpage/:slug", (request, response) => {
// Define the URLS we will use to post the comment data to
const baseurl = "https://api.visualthinking.fdnd.nl/api/v1/";
const url = `${baseurl}comments`;
// Construct the URL to fetch the comments page data from based on the query parameter 'id'
const commentUrl = `${baseurl}comments` + "?id=" + request.query.id;

// Log the request body (the data submitted by the user)
console.log("verstuurd:");
console.log(request.body);

// Use the postJson function to post the comment data to the specified URL
postJson(url, request.body).then((data) => {
// Create a copy of the request body
let newComment = { ...request.body };

// Log the response data from the API
console.log("ontvangen:");
console.log(data);

// Check if the comment was successfully posted
if (data.success) {
// If the comment was successfully posted, redirect to the detail page with a success message
response.redirect(
"/detailpage/" + request.params.slug + "?methodPosted=true"
);
} else {
// If the comment was not successfully posted, redirect to the detail page with an error message
response.redirect(
"/detailpage/" + request.params.slug + "?methodPosted=false"
);
}
});
});

// Stel het poortnummer in waar express op gaat luisteren
app.set("port", process.env.PORT || 8000);

// Start express op, haal het ingestelde poortnummer op
app.listen(app.get("port"), function () {
// Toon een bericht in de console en geef het poortnummer door
console.log(`Application started on http://localhost:${app.get("port")}`);
});

/**
* Wraps the fetch api and returns the response body parsed through json
* @param {*} url the api endpoint to address
* @returns the json response from the api endpoint
*/

async function fetchJson(url) {
return await fetch(url)
.then((response) => response.json())
.catch((error) => error);
}

// post json

export async function postJson(url, body) {
return await fetch(url, {
method: "post",
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" },
})
.then((response) => response.json())
.catch((error) => error);
}

Loading