Skip to content

Commit

Permalink
Merge pull request #14 from lobophf/database
Browse files Browse the repository at this point in the history
Database
  • Loading branch information
lobophf authored Oct 21, 2020
2 parents 6c9a94e + e536c3c commit caac524
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 111 deletions.
17 changes: 15 additions & 2 deletions public/css/page-orphanage.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#page-orphanage {
display: flex;
min-height: 100vh;
min-height: 100vh;
}

main {
Expand Down Expand Up @@ -42,7 +42,7 @@ main {
transition: opacity 0.2s;
}

.images button:hover,
.images button:hover,
.images button.active {
opacity: 1.0;
}
Expand Down Expand Up @@ -90,6 +90,7 @@ main {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 2rem;
line-height: 1.5;
}

.open-details div {
Expand All @@ -116,3 +117,15 @@ main {
border-radius: 20px;
color: #37C77F;
}

.open-on-weekends.open {
background: linear-gradient(154.16deg, #EDFFF6 7.85%, #FFFFFF 91.03%);
border: 1px solid #A1E9C5;
color: #37C77F;
}

.open-on-weekends.closed {
background: linear-gradient(154.16deg, #FCF0F4 7.85%, #FFFFFF 91.03%);
border: 1px solid #FFBCD4;
color: #FF669D;
}
10 changes: 5 additions & 5 deletions public/css/page-orphanages.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ aside {

aside h2 {
margin-top: 2.4rem;
font: 800 clamp(2rem, 5vw, 3.6)/1.1 'Nunito', sans-serif;
font: 800 clamp(2rem, 5vw, 3.6rem)/1.1 'Nunito', sans-serif;
}

aside p {
margin-top: 2.4rem;
font: 400 1.6rem/1.5 'Nunito', sans-serif;
}

aside footer p{
aside footer p {
margin-top: 0.8rem;
}

Expand Down Expand Up @@ -55,7 +55,7 @@ a.create-orphanage:hover {

.leaflet-popup-content-wrapper {
background: rgba(255, 255, 255, 0.8);
border-radius: 20px;
border-radius: 20px;
}

.leaflet-popup-content {
Expand All @@ -66,7 +66,7 @@ a.create-orphanage:hover {
justify-content: space-between;
}

.leaflet-popup-content a{
.leaflet-popup-content a {
width: 4rem;
height: 4rem;
background: #15C3D6;
Expand All @@ -79,7 +79,7 @@ a.create-orphanage:hover {
}


.leaflet-popup-content a:hover{
.leaflet-popup-content a:hover {
background: #17D6EB;
}

Expand Down
8 changes: 5 additions & 3 deletions public/scripts/page-orphanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const options = {
zoomControl: false
}

const map = L.map('mapid', options).setView([-27.222633, -49.6455874], 15);
const lat = document.querySelector('span[data-lat]').dataset.lat;
const lng = document.querySelector('span[data-lng]').dataset.lng;

const map = L.map('mapid', options).setView([lat, lng], 15);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',).addTo(map);

Expand All @@ -17,8 +20,7 @@ const icon = L.icon({
popupAnchor: [170, 2]
});

L.marker([-27.222633, -49.6455874], {icon })
.addTo(map)
L.marker([lat, lng], { icon }).addTo(map)

function selectImage(event) {
const button = event.currentTarget
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/page-orphanages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function addMarker({id, name, lat, lng}){
className: 'map-popup',
minWidth: 240,
minHeight: 240
}).setContent(`${name} <a href="orphanage.html?id=${id}"><img src="/images/arrow-white.svg"></a>`);
}).setContent(`${name} <a href="orphanage?id=${id}"><img src="/images/arrow-white.svg"></a>`);

L.marker([lat, lng], { icon })
.addTo(map)
Expand Down
7 changes: 3 additions & 4 deletions src/database/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const saveOrphanage = require('./saveOrphanage');
Database.then(async db => {
await saveOrphanage(db, {
lat: "-27.222633",
lng: "-49.6455874",
name: "Lar das meninas",
lng: "-49.6555874",
name: "Lar dos Meninos",
about: "Presta assistência a crianças de 06 a 15 anos que se encontrem em situação de risco e/ou vulnerabilidade social.",
whatsapp: "31 9999 9999",
images: [
Expand All @@ -18,9 +18,8 @@ Database.then(async db => {
].toString(),
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"
open_on_weekends: "0"
}
);
const orphanage = await db.all('SELECT * FROM orphanages WHERE id = "1"');
console.log(orphanage);
})
83 changes: 71 additions & 12 deletions src/pages.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,76 @@
const orphanages = require('./database/fakedata.js');
const Database = require("./database/db");
const saveOrphanage = require("./database/saveOrphanage");

module.exports = {

index(req, res){
return res.render('index')
index(req, res) {
return res.render("index");
},
async orphanage(req, res) {
const id = req.query.id;

try {
const db = await Database;
const results = await db.all(
`SELECT * FROM orphanages WHERE id = "${id}"`
);

const orphanage = results[0];

orphanage.images = orphanage.images.split(",");
orphanage.firstImage = orphanage.images[0];

if (orphanage.open_on_weekends == "0") {
orphanage.open_on_weekends = false;
} else {
orphanage.open_on_weekends = true;
}

return res.render("orphanage", { orphanage });
} catch (error) {
console.log(error);
return res.send("Erro no banco de dados");
}
},

async orphanages(req, res) {
try {
const db = await Database;
const orphanages = await db.all("SELECT * FROM orphanages");
return res.render("orphanages", { orphanages });
} catch (error) {
console.log(error);
return res.send("Erro no banco de dados");
}
},
orphanage(req, res){
return res.render('orphanage')

createOrphanage(req, res) {
return res.render("create-orphanage");
},
orphanages(req, res){
return res.render('orphanages', { orphanages })

async saveOrphanage(req, res) {
const fields = req.body;

if (Object.values(fields).includes("")) {
return res.send("Todos os campos devem ser preenchidos");
}

try {
const db = await Database;
await saveOrphanage(db, {
lat: fields.lat,
lng: fields.lng,
name: fields.name,
about: fields.about,
whatsapp: fields.whatsapp,
images: fields.images.toString(),
instructions: fields.instructions,
opening_hours: fields.opening_hours,
open_on_weekends: fields.open_on_weekends,
});
return res.redirect("/orphanages");
} catch (error) {
console.log(error);
return res.send("Erro no banco de dados");
}
},
createOrphanage(req, res){
return res.render('create-orphanage')
}
}
};
2 changes: 2 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const pages = require('./pages.js');
const server = express();

server
.use(express.urlencoded({ extended: true }))
.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)
.post('/save-orphanage', pages.saveOrphanage)

server.listen(5500)
2 changes: 1 addition & 1 deletion src/views/create-orphanage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</footer>
</aside>
<main class="animate-appear with-sidebar">
<form action="">
<form action="save-orphanage" method="post">
<fieldset>
<legend>Dados</legend>
<div class="map-container">
Expand Down
Loading

0 comments on commit caac524

Please sign in to comment.