Skip to content

Commit

Permalink
Merge pull request #11 from lobophf/server-config
Browse files Browse the repository at this point in the history
Server config
  • Loading branch information
lobophf authored Oct 17, 2020
2 parents a0701a2 + 69ca7fd commit e78fb78
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 17 deletions.
32 changes: 23 additions & 9 deletions public/scripts/page-orphanages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@ const icon = L.icon({
popupAnchor: [170, 2]
});

const popup = L.popup({
closeButton: false,
className: 'map-popup',
minWidth: 240,
minHeight: 240
}).setContent('Lar das meninas <a href="orphanage.html?id=1" class="choose-orphanage"><img src="/images/arrow-white.svg"></a>');
function addMarker({id, name, lat, lng}){
const popup = L.popup({
closeButton: false,
className: 'map-popup',
minWidth: 240,
minHeight: 240
}).setContent(`${name} <a href="orphanage.html?id=${id}"><img src="/images/arrow-white.svg"></a>`);

L.marker([lat, lng], { icon })
.addTo(map)
.bindPopup(popup)
}

L.marker([-27.222633, -49.6455874], {icon })
.addTo(map)
.bindPopup(popup)
const orphanagesSpan = document.querySelectorAll('.orphanages span');
console.log(orphanagesSpan)
orphanagesSpan.forEach(span => {
const orphanage = {
id: span.dataset.id,
name: span.dataset.name,
lat: span.dataset.lat,
lng: span.dataset.lng
}
addMarker(orphanage)
})
38 changes: 38 additions & 0 deletions src/database/fakedata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = [
{
id: 1,
lat: "-27.222633",
lng: "-49.6455874",
name: "Lar das meninas",
description: "Presta assistência a crianças de 06 a 15 anos que se encontrem em situação de risco e/ou vulnerabilidade social.",
images: [
"https://images.unsplash.com/photo-1592676720632-e0f4741e1f46?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/flagged/photo-1576028246561-d6e04a34adbf?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjF9",
"https://images.unsplash.com/photo-1503454537195-1dcabb73ffb9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/photo-1507036066871-b7e8032b3dea?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/photo-1562346631-89773e8cd3cb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/photo-1597695435079-8544505c3a60?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
],
instructions: "Venha se sentir a vontade e traga muito amor e atenção para dar.",
opening_hours: "Horário de visita das 6h as 18h",
open_on_weekends: "1",
},
{
id: 2,
lat: "-27.222633",
lng: "-49.6555874",
name: "Lar dos guris",
description: "Presta assistência a crianças de 06 a 15 anos que se encontrem em situação de risco e/ou vulnerabilidade social.",
images: [
"https://images.unsplash.com/photo-1592676720632-e0f4741e1f46?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/flagged/photo-1576028246561-d6e04a34adbf?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjF9",
"https://images.unsplash.com/photo-1503454537195-1dcabb73ffb9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/photo-1507036066871-b7e8032b3dea?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/photo-1562346631-89773e8cd3cb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
"https://images.unsplash.com/photo-1597695435079-8544505c3a60?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9",
],
instructions: "Venha se sentir a vontade e traga muito amor e atenção para dar.",
opening_hours: "Horário de visita das 6h as 18h",
open_on_weekends: "0",
}
]
6 changes: 4 additions & 2 deletions src/pages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const orphanages = require('./database/fakedata.js');

module.exports = {

index(req, res){
Expand All @@ -7,9 +9,9 @@ module.exports = {
return res.render('orphanage')
},
orphanages(req, res){
return res.render('orphanages')
return res.render('orphanages', { orphanages })
},
createOrphanage(req, res){
return res.render('create-orphanage')
},
}
}
8 changes: 4 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const path = require('path');
const pages = require('./pages.js');

const server = express();
console.log(pages.orphanages)

server
.use(express.static('public'))
.set('views', path.join(__dirname, "views"))
.set('view engine', 'hbs')
.get('/', pages.index)
.get('orphanage', pages.orphanage)
.get('orphanages', pages.orphanages)
.get('create-orphanage', pages.createOrphanage)
.get('/orphanage', pages.orphanage)
.get('/orphanages', pages.orphanages)
.get('/create-orphanage', pages.createOrphanage)

server.listen(5500)
16 changes: 14 additions & 2 deletions src/views/orphanages.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="pt_BR">
<head>
<meta charset="UTF-8">
Expand Down Expand Up @@ -33,7 +33,19 @@
</footer>
</aside>
<div id="mapid" class="animate-appear"></div>
<a href="create-orphanage.html" class="create-orphanage" title="Cadastre um orfanato">

<div class="orphanages">
{{#each orphanages}}
<span hidden
data-id="{{this.id}}"
data-name="{{this.name}}"
data-lat="{{this.lat}}"
data-lng="{{this.lng}}"
></span>
{{/each}}
</div>

<a href="/create-orphanage" class="create-orphanage" title="Cadastre um orfanato">
<img src="/images/plus.svg" alt="Criar orfanato">
</a>
</div>
Expand Down

0 comments on commit e78fb78

Please sign in to comment.