Commit a832b41b authored by Vytor Calixto's avatar Vytor Calixto 👾
Browse files

Parte administrativa dos professores

parent a5650948
<!DOCTYPE html>
<html>
<% include ../partials/head %>
<body>
<% include ../partials/admin-header %>
<% if (message.length > 0) { %>
<div class="card margin"><%= message %></div>
<% } %>
<section class="page-wrap margin card">
<h1><%= professor.nome %></h1>
<form method="post">
<label for="nome">Nome: </label>
<input type="text" name="nome" value="<%= professor.nome %>">
<br>
<input type="submit" name="submit" value="Enviar" class="button normal">
<a href="/admin/professores" class="button red">Cancelar</a>
</form>
</section>
<% include ../partials/footer %>
</body>
</html>
<!DOCTYPE html>
<html>
<% include ../partials/head %>
<body>
<% include ../partials/admin-header %>
<section class="page-wrap">
<% if (message.length > 0) { %>
<div class="card margin"><%= message %></div>
<% } %>
<div class="card card-list margin">
<ul class="list">
<h2 class="list-title">Professores</h2>
<input type="search" name="filter" class="search-bar margin-vertical two-thirds" placeholder="Busca" />
<li class="list-item text-left">
<span>Novo professor:</span>
<form method="post">
<input type="text" name="nome" ng-model="nome" placeholder="Nome" required/>
<button type="submit" class="button dark hover-shadow float-right">
<i class="fa fa-plus fa-fw"></i>
</button>
</form>
</li>
<% for(var i=0; i < professores.length; i++) { %>
<li class="list-item text-left">
<%= professores[i].nome %>
<div class="float-right">
<a href="/admin/professores/<%= professores[i]._id %>" class="button normal hover-shadow">
<i class="fa fa-edit fa-fw"></i>
</a>
<a href="/admin/professores/delete/<%= professores[i]._id %>" class="button red hover-shadow">
<i class="fa fa-close fa-fw"></i>
</a>
</div>
</li>
<% } %>
<% if (professores.length == 0) { %>
<li class="list-item">Não há matérias cadastradas.</li>
<% } %>
</ul>
</div>
</section>
<% include ../partials/footer %>
</body>
</html>
......@@ -19,6 +19,7 @@ var oauth2 = require('./auth/oauth2')
var rotas = require('./routes/routes')
var admin = require('./routes/admin/admin')
var materias = require('./routes/admin/materias')
var professores = require('./routes/admin/professores')
var api = require('./routes/api/api')
var usuariosRest = require('./routes/api/usuarios')
......@@ -48,6 +49,7 @@ app.use(flash())
app.use('/', rotas)
app.use('/admin', admin)
app.use('/admin/materias', materias)
app.use('/admin/professores', professores)
// Pasta pública onde ficam os uploads
app.use('/uploads', express.static('uploads'))
......
var express = require('express')
var passport = require('passport')
var router = express.Router()
var libs = process.cwd() + '/libs/'
var role = require(libs + 'role')
var Usuario = require(libs + 'model/usuario')
var Arquivo = require(libs + 'model/arquivo')
var Materia = require(libs + 'model/materia')
router.use(role.isLoggedIn())
router.get('/', function(req, res) {
Arquivo.count({}, function(err, count) {
if(err) {
console.log(err.message)
} else {
res.render('admin', {user: req.user, pendentes: count})
}
})
})
router.get('/uploads', function(req, res) {
Arquivo.find({status: 'pendente'})
.populate('materia')
.populate('professor')
.populate('usuario')
.exec(function(err, arquivos) {
if(!err) {
return res.render('uploads', {user: req.user , uploads: arquivos})
} else {
// TODO: redirecionar para página de erro
}
})
})
module.exports = router
......@@ -11,7 +11,7 @@ router.use(role.isLoggedIn())
router.get('/', function(req, res) {
Materia.find()
.sort([['nome', 'ascending']])
.sort([['codigo', 'ascending']])
.exec(function(err, materias) {
if(!err) {
return res.render('admin/materias', {user: req.user, materias: materias, message: req.flash('materiasMessage')})
......
var express = require('express')
var passport = require('passport')
var router = express.Router()
var libs = process.cwd() + '/libs/'
var role = require(libs + 'role')
var Professor = require(libs + 'model/professor')
router.use(role.isLoggedIn())
router.get('/', function(req, res) {
Professor.find()
.sort([['nome', 'ascending']])
.exec(function(err, professores) {
if(!err) {
return res.render('admin/professores', {user: req.user, professores: professores, message: req.flash('professoresMessage')})
}
})
})
router.post('/', function(req, res) {
var professor = new Professor()
professor.codigo = req.body.codigo
professor.nome = req.body.nome
professor.save(function(err) {
if(!err) {
res.redirect('/admin/professores')
} else {
req.flash('professoresMessage', 'Erro ao salvar a matéria')
res.redirect('/admin/professores')
}
})
})
router.get('/:id', function(req, res) {
Professor.findById(req.params.id, function(err, professor) {
if(!professor) {
// TODO: redirecionar para 404
res.redirect('/')
}
if(!err) {
res.render('admin/professorDetails', {user: req.user, professor: professor, message: req.flash('professorDetailsMessage')})
} else {
// TODO: redirecionar para 500
res.redirect('/')
}
})
})
router.post('/:id', function(req, res) {
Professor.findById(req.params.id, function(err, professor) {
if(!professor) {
// TODO: redirecionar para 404
res.redirect('/admin/professor/'+req.params.id)
}
professor.codigo = req.body.codigo
professor.nome = req.body.nome
professor.save(function(err) {
if(!err) {
req.flash('professoresMessage', 'Professor salvo com sucesso')
res.redirect('/admin/professores')
} else {
// TODO: redirecionar para 500
res.redirect('/')
}
})
})
})
router.get('/delete/:id', function(req, res) {
Professor.findByIdAndRemove(req.params.id, function(err, professor) {
if(!professor) {
// TODO: redirecionar para 500
res.redirect('/')
}
req.flash('professoresMessage', 'Professor removido com sucesso')
res.redirect('/admin/professores')
})
})
module.exports = router
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment