-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
a1449b2
commit 88a0a69
Showing
27 changed files
with
703 additions
and
269 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
modalOverlay = document.querySelector('.modal-overlay'); | ||
cards = document.querySelectorAll('.card'); | ||
courseCards = document.querySelector ('.course-card') | ||
|
||
|
||
for (let card of cards) { | ||
card.addEventListener ('click', ()=> { | ||
let page = card.getAttribute('id'); | ||
window.location.href = `/courses/${page}`; | ||
}) | ||
} | ||
|
||
|
||
const currentPage = location.pathname | ||
const menuItems = document.querySelectorAll("header .links a") | ||
|
||
console.log(currentPage); | ||
console.log(menuItems); | ||
|
||
|
||
for (item of menuItems) { | ||
if (currentPage.includes(item.getAttribute("href"))){ | ||
item.classList.add("active") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
const { simpleDate, age, graduation, grade } = require('../../lib/utils.js'); | ||
const Intl = require('intl'); | ||
|
||
|
||
|
||
module.exports = { | ||
index(req, res) { | ||
let students = new Object(data.students); | ||
|
||
for (student of students){ | ||
student.level = grade(student.level) | ||
} | ||
|
||
return | ||
}, | ||
create(req, res) { | ||
return | ||
}, | ||
post(req, res) { | ||
const keys = Object.keys(req.body); | ||
|
||
for (key of keys){ | ||
if (req.body[key] == '') { | ||
return res.send ("Please, fill all forms"); | ||
} | ||
} | ||
|
||
|
||
const birth = Date.parse(req.body.birth) | ||
|
||
let id = 1; | ||
|
||
if (data.students.length >= 1) { | ||
id = data.students.length + 1 | ||
} | ||
|
||
data.students.push({ | ||
id, | ||
...req.body, | ||
birth | ||
}) | ||
|
||
return | ||
}, | ||
show(req, res) { | ||
// const { id } = req.params; | ||
|
||
// if (id > data.students.length){ | ||
// return res.send("Usuario inválido"); | ||
// } | ||
|
||
|
||
// const foundStudent = data.students.find(function(student){ | ||
// return student.id == id; | ||
// }) | ||
|
||
|
||
// const student = { | ||
// ...foundStudent, | ||
// age: age(foundStudent.birth) | ||
// } | ||
|
||
return | ||
|
||
}, | ||
edit(req, res){ | ||
const { id } = req.params; | ||
|
||
if (id > data.students.length){ | ||
return res.send("Usuario inválido"); | ||
} | ||
|
||
const foundUser = data.students.find(function (student){ | ||
return id == student.id; | ||
}) | ||
|
||
const student = { | ||
...foundUser, | ||
date: simpleDate(foundUser.birth) | ||
} | ||
|
||
return res.render('students/edit', { student }) | ||
}, | ||
put(req, res) { | ||
let { id } = req.body; | ||
|
||
id = Number(id); | ||
|
||
let index = 0; | ||
|
||
const foundStudent = data.students.find(function(student, foundIndex){ | ||
if (student.id == id) { | ||
index = foundIndex; | ||
return true; | ||
} | ||
}) | ||
|
||
const student = { | ||
...foundStudent, | ||
...req.body, | ||
birth: Date.parse(req.body.birth), | ||
id: Number(req.body.id) | ||
} | ||
|
||
data.students[index] = student; | ||
|
||
return | ||
}, | ||
delete(req, res) { | ||
let { id } = req.body | ||
|
||
id = Number(id); | ||
|
||
const filteredStudents = data.students.filter(function(student){ | ||
return (student.id != id) | ||
}) | ||
|
||
data.students = filteredStudents | ||
|
||
return | ||
}, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { simpleDate, age, graduation, grade } = require('../../lib/utils.js'); | ||
const Intl = require('intl'); | ||
const Teacher = require('../models/Teacher.js') | ||
|
||
|
||
|
||
module.exports = { | ||
index(req, res) { | ||
Teacher.all(function(results){ | ||
for (let i=0 ; i < results.length ; i++){ | ||
results[i].subjects_taught = results[i].subjects_taught.split(',') | ||
} | ||
return res.render('teachers/index', {teachers: results}) | ||
}) | ||
}, | ||
|
||
create(req, res) { | ||
return res.render("teachers/create") | ||
}, | ||
|
||
post(req, res) { | ||
const keys = Object.keys(req.body); | ||
|
||
for (key of keys){ | ||
if (req.body[key] == '') { | ||
return res.send ("Please, fill all forms"); | ||
} | ||
} | ||
|
||
|
||
Teacher.create(req.body, function(teacher){ | ||
return res.redirect(`teachers/${teacher.id}`) | ||
}) | ||
}, | ||
show(req, res){ | ||
const {id} = req.params | ||
|
||
Teacher.find(id, function(teacher){ | ||
if (!teacher) return res.send("Teacher not found") | ||
|
||
teacher.age = age(teacher.birth_date) | ||
teacher.education_level = graduation(teacher.education_level) | ||
teacher.subjects_taught = teacher.subjects_taught.split(',') | ||
teacher.created_at = simpleDate(teacher.created_at).format | ||
|
||
return res.render('teachers/show', {teacher}) | ||
}) | ||
|
||
}, | ||
|
||
edit(req, res){ | ||
return | ||
}, | ||
put(req, res){ | ||
return | ||
}, | ||
delete(req, res){ | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const { simpleDate, age, graduation, grade } = require('../../lib/utils.js'); | ||
const db = require('../../config/db.js') | ||
|
||
module.exports = { | ||
|
||
all(callback){ | ||
db.query('SELECT * FROM teachers', function(err, results){ | ||
if (err) throw `Database error! ${err}` | ||
|
||
callback(results.rows) | ||
}) | ||
}, | ||
|
||
create(data, callback){ | ||
const query = ` | ||
INSERT INTO teachers ( | ||
avatar_url, | ||
name, | ||
birth_date, | ||
education_level, | ||
class_type, | ||
subjects_taught, | ||
created_at | ||
) VALUES ($1, $2, $3, $4, $5, $6, $7) | ||
RETURNING id | ||
` | ||
|
||
const values = [ | ||
data.avatar_url, | ||
data.name, | ||
simpleDate(data.birth_date).iso, | ||
data.education_level, | ||
data.class_type, | ||
data.subjects_taught, | ||
simpleDate(Date.now()).iso | ||
] | ||
|
||
|
||
db.query(query, values, function(err, results){ | ||
if (err) throw `Database Error ${err}` | ||
|
||
callback(results.rows[0]) | ||
}) | ||
}, | ||
|
||
find(id, callback) { | ||
|
||
db.query(` | ||
SELECT * | ||
FROM teachers | ||
WHERE id = $1`, [id], function(err, results){ | ||
console.log('Executando db query...'); | ||
if (err) throw `Database Error! ${err}` | ||
callback(results.rows[0]) | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
const deleteButton = document.querySelector("#delete-form button") | ||
deleteButton.addEventListener("click", (event)=> { | ||
const confirmation = confirm("Deseja realmente deletar?") | ||
if (!confirmation){ | ||
event.preventDefault() | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends "layout.njk" %} | ||
|
||
{% block content %} | ||
|
||
<form class="card" method="POST" action="/students"> | ||
<section class="avatar" style="background: url('https://source.unsplash.com/collection/8874679/600x800') no-repeat center center / cover"></section> | ||
<section class="info"> | ||
<h3>CADASTRO DE ESTUDANTE</h3> | ||
|
||
{% include 'students/fields.njk' %} | ||
|
||
</section> | ||
|
||
</div> | ||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "layout.njk" %} | ||
|
||
{% block content %} | ||
|
||
<div class="card"> | ||
<section class="avatar" style="background: url({{student.avatar_url}}) no-repeat center center / cover"></section> | ||
<section class="info"> | ||
<form method="POST" action="/students?_method=PUT"> | ||
<h3>EDITAR PROFESSOR</h3> | ||
|
||
{% include 'students/fields.njk' %} | ||
|
||
<input type="hidden" name="id" value="{{ student.id }}"> | ||
</form> | ||
|
||
<form id="delete-form" method="POST" action="/students?_method=DELETE" > | ||
<input type="hidden" name="id" value="{{ student.id }}"> | ||
<button type="submit">Deletar</button> | ||
</form> | ||
|
||
</section> | ||
|
||
</div> | ||
|
||
{% include 'students/confirm-delete.njk' %} | ||
|
||
|
||
|
||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
<div class="item"> | ||
<div>URL do Avatar</div> | ||
<input type="url" name="avatar_url" placeholder="https://" value="{{student.avatar_url}}"> | ||
</div> | ||
<div class="item"> | ||
<div>Nome</div> | ||
<input type="text" name="name" placeholder="Digite o seu nome completo" value="{{student.name}}"> | ||
</div> | ||
<div class="item"> | ||
<div>Data de Nascimento</div> | ||
<input type="date" name="birth" value="{{student.date}}"> | ||
</div> | ||
<div class="item"> | ||
<div>E-mail</div> | ||
<input type="email" name="email" value="{{student.email}}"> | ||
</div> | ||
<div class="item"> | ||
<div>Ano escolar</div> | ||
<select name="level"> | ||
<option value="" selected disabled>Selecione o seu ano escolar</option> | ||
<option value="5f" {% if student.level == '5f' %} selected {% endif %}>5º ano do Ensino Fundamental</option> | ||
<option value="6f" {% if student.level == '6f' %} selected {% endif %}>6º ano do Ensino Fundamental</option> | ||
<option value="7f" {% if student.level == '7f' %} selected {% endif %}>7º ano do Ensino Fundamental</option> | ||
<option value="8f" {% if student.level == '8f' %} selected {% endif %}>8º ano do Ensino Fundamental</option> | ||
<option value="9f" {% if student.level == '9f' %} selected {% endif %}>9º ano do Ensino Fundamental</option> | ||
<option value="1a" {% if student.level == '1a' %} selected {% endif %}>1º ano do Ensino Médio</option> | ||
<option value="2a" {% if student.level == '2a' %} selected {% endif %}>2º ano do Ensino Médio</option> | ||
<option value="3a" {% if student.level == '3a' %} selected {% endif %}>3º ano do Ensino Médio</option> | ||
</select> | ||
</div> | ||
|
||
<div class="item"> | ||
<div>Carga Horária Semanal</div> | ||
<input type="number" name="charge" placeholder="Quantidade de horas por semana" value='{{ student.charge }}'> | ||
</div> | ||
|
||
<button type="submit">Enviar</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% extends "layout.njk" %} | ||
|
||
{% block content %} | ||
<div class="card table-teachers"> | ||
|
||
<a id="new-button" href="/students/create"><span>+</span>NOVO</a> | ||
|
||
<table> | ||
|
||
<thead> | ||
<tr> | ||
<th>Estudante</th> | ||
<th>Email</th> | ||
<th>Ano Escolar</th> | ||
<th>Ação</th> | ||
<tr> | ||
|
||
</thead> | ||
|
||
|
||
|
||
<tbody> | ||
|
||
{% for student in students %} | ||
<tr> | ||
<td> | ||
<span style="background-image: url('{{student.avatar_url}}')"></span> | ||
{{ student.name }} | ||
</td> | ||
<td> | ||
{{ student.email }} | ||
</td> | ||
<td> | ||
{{ student.level }} | ||
</td> | ||
<td><a href="/students/{{student.id}}">VER</a> | ||
</tr> | ||
{% endfor %} | ||
|
||
</tbody> | ||
|
||
</table> | ||
</div> | ||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{% extends "layout.njk" %} | ||
|
||
{% block content %} | ||
|
||
<div class="card"> | ||
<section class="avatar" style="background: url('{{ student.avatar_url }}') no-repeat center center / cover"></section> | ||
<section class="info"> | ||
<h3>ESTUDANTE</h3> | ||
<div class="item"> | ||
<div>Nome</div> | ||
<div>{{ student.name }}</div> | ||
</div> | ||
<div class="item"> | ||
<div>Idade</div> | ||
<div>{{ student.age }}</div> | ||
</div> | ||
<div class="item"> | ||
<div>E-mail</div> | ||
<div>{{ student.email }}</div> | ||
</div> | ||
<div class="item"> | ||
<div>Ano Escolar</div> | ||
<div> | ||
{% if student.level == '5f' %}5º ano do Ensino Fundamental{% endif %} | ||
{% if student.level == '6f' %}6º ano do Ensino Fundamental{% endif %} | ||
{% if student.level == '7f' %}7º ano do Ensino Fundamental{% endif %} | ||
{% if student.level == '8f' %}8º ano do Ensino Fundamental{% endif %} | ||
{% if student.level == '9f' %}9º ano do Ensino Fundamental{% endif %} | ||
{% if student.level == '1a' %}1º ano do Ensino Médio{% endif %} | ||
{% if student.level == '2a' %}2º ano do Ensino Médio{% endif %} | ||
{% if student.level == '3a' %}3º ano do Ensino Médio{% endif %} | ||
</div> | ||
</div> | ||
<div class="item"> | ||
<div>Carga horária</div> | ||
<div>{{ student.charge }}</div> | ||
</div> | ||
|
||
|
||
|
||
<a href='/students/{{ student.id }}/edit'>Editar</a> | ||
|
||
</section> | ||
|
||
</div> | ||
|
||
{% endblock content %} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
<div class="item"> | ||
<div>URL do Avatar</div> | ||
<input type="url" name="avatar_url" placeholder="https://" value="{{teacher.avatar_url}}"> | ||
</div> | ||
<div class="item"> | ||
<div>Nome</div> | ||
<input type="text" name="name" placeholder="Digite o seu nome completo" value="{{teacher.name}}"> | ||
</div> | ||
<div class="item"> | ||
<div>Data de Nascimento</div> | ||
<input type="date" name="birth_date" value="{{teacher.date}}"> | ||
</div> | ||
<div class="item"> | ||
<div>Grau de Escolaridade</div> | ||
<select name="education_level"> | ||
<option value="" selected disabled>Selecione o seu grau de escolaridade</option> | ||
<option value="medio" {% if teacher.education_level == 'medio' %} selected {% endif %}>Ensino Médio Completo</option> | ||
<option value="superior" {% if teacher.education_level == 'superior' %} selected {% endif %}>Ensino Superior Completo</option> | ||
<option value="mestrado" {% if teacher.education_level == 'mestrado' %} selected {% endif %}>Mestrado</option> | ||
<option value="doutorado" {% if teacher.education_level == 'doutorado' %} selected {% endif %}>Doutorado</option> | ||
</select> | ||
</div> | ||
<div class="item"> | ||
<div>Tipo de Aula</div> | ||
<span><input type="radio" name="class_type" value="Presencial" {% if teacher.class_type == 'Presencial' %} checked {% endif %}>Presencial</span> | ||
<span><input type="radio" name="class_type" value="À distância" {% if teacher.class_type == 'À distância' %} checked {% endif %}>À distância</span> | ||
</div> | ||
<div class="item"> | ||
<div>Área de Atuação</div> | ||
<input type="text" name="subjects_taught" placeholder="Quais matérias você leciona? Separe por vírgulas" value='{{ teacher.subjects_taught }}'> | ||
</div> | ||
|
||
<button type="submit">Enviar</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { Pool } = require('pg') | ||
|
||
module.exports = new Pool({ | ||
user: 'postgres', | ||
password: 'postgres', | ||
host: 'localhost', | ||
port: '5432', | ||
database: 'my_teacher' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const express = require('express'); | ||
const routes = express.Router(); | ||
const teachers = require('./app/controllers/teachers') | ||
const students = require('./app/controllers/students') | ||
|
||
routes.get('/', function(req,res){ | ||
return res.redirect("/teachers"); | ||
}) | ||
|
||
routes.get('/teachers', teachers.index) | ||
routes.post('/teachers', teachers.post) | ||
routes.get('/teachers/create', teachers.create) | ||
routes.get('/teachers/:id', teachers.show) | ||
routes.get('/teachers/:id/edit', teachers.edit) | ||
routes.put('/teachers', teachers.put); | ||
routes.delete('/teachers', teachers.delete); | ||
|
||
routes.get('/students', students.index) | ||
routes.post('/students', students.post) | ||
routes.get('/students/create', students.create) | ||
routes.get('/students/:id', students.show) | ||
routes.get('/students/:id/edit', students.edit) | ||
routes.put('/students', students.put); | ||
routes.delete('/students', students.delete); | ||
|
||
|
||
module.exports = routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.