Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Abjiri/TP_DAW2020
Browse files Browse the repository at this point in the history
  • Loading branch information
Abjiri committed Feb 6, 2021
2 parents 208488c + 8937da9 commit 5655f12
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 135 deletions.
6 changes: 6 additions & 0 deletions api-server/controllers/recurso.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ module.exports.editarRecurso = (id, novos) => {
{useFindAndModify: false, new: true})
}

module.exports.consultarTitulo = id => {
return Recurso
.findOne({_id: id}, {titulo: 1, _id: 0})
.exec()
}

module.exports.incrementarDownloads = dir => {
return Recurso.findOneAndUpdate(
{ diretoria: dir },
Expand Down
7 changes: 6 additions & 1 deletion api-server/models/publicacao.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ const mongoose = require('mongoose')
var comentarioSchema = new mongoose.Schema({
corpo: {type: String, required: true},
id_autor: {type: String, required: true},
nome_autor: {type: String, required: true},
foto: {type: String, required: true},
dataCriacao: {type: String, required: true, default: new Date().toISOString().substr(0,19)}
});

var publicacaoSchema = new mongoose.Schema({
titulo: {type: String, required: true},
corpo: {type: String, required: true},
recurso: {type: String, required: true},
id_recurso: {type: String, required: true},
titulo_recurso: {type: String, required: true},
id_autor: {type: String, required: true},
nome_autor: {type: String, required: true},
foto: {type: String, required: true},
dataCriacao: {type: String, required: true, default: new Date().toISOString().substr(0,19)},
comments: {type: [comentarioSchema], default: []}
});
Expand Down
6 changes: 6 additions & 0 deletions api-server/routes/recurso.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ router.post('/pesquisar', function(req, res) {
}
})

router.get('/titulo/:id', function(req, res) {
Recurso.consultarTitulo(req.params.id)
.then(dados => res.status(200).jsonp(dados))
.catch(e => res.status(500).jsonp({error: e}))
});

// Consultar um recurso
router.get('/:id', function(req, res) {
Recurso.consultar(req.params.id)
Expand Down
5 changes: 0 additions & 5 deletions app-server/public/javascripts/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ $(document).ready(function()
document.getElementById('new_resource_modal').style.display='block';
});

$("#new_post").click(function(event) {
event.preventDefault();
document.getElementById('new_post_modal').style.display='block';
});

$("#close_new_resource").click(function(event) {
event.preventDefault();
document.getElementById('new_resource_modal').style.display='none';
Expand Down
16 changes: 6 additions & 10 deletions app-server/public/javascripts/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function showPostForm(id) {
<div class="login_container">
<div class="login_container">
<input type="text" name="recurso" value=${id} hidden/>
<input type="text" name="id_recurso" value=${id} hidden/>
<div class="w3-col s3">
<label class="w3-text-teal"><b>Título: </b></label>
Expand Down Expand Up @@ -35,13 +35,9 @@ function showPostForm(id) {

$('#new_post_modal').append(html)
document.getElementById('new_post_modal').style.display = 'block';
}

$(document).ready(function()
{
$("#close_new_post").click(function(event) {
event.preventDefault();
document.getElementById('new_post_modal').style.display = 'none';
});
}
)
$("#close_new_post").click(function(event) {
event.preventDefault();
document.getElementById('new_post_modal').style.display = 'none';
});
}
139 changes: 79 additions & 60 deletions app-server/public/javascripts/showedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,103 @@ var loadFile = function(event){
}
};

function showEdit(){
var ficheiro = `<img src='https://bootdey.com/img/Content/avatar/avatar3.png' />`

$('#display').empty()
$('#display').append(ficheiro)
$('#display').modal()
}

function pictureForm(id){
var form = `
<form class="w3-container my-modal-content" action="/perfil/${id}/editar/imagem/" method="POST" style="border: 0; width: 100%" enctype='multipart/form-data'>
<div class="login_img">
<span class="picture_close" title="Fechar" onclick="fechar()"> &times;</span>
</div>
<div "w3-row w3-margin-bottom">
<div class="w3-col s3">
$('#edit_pic_modal').empty()
var html = `
<form class="my-modal-content" action="/perfil/${id}/editar/imagem/" method="POST" enctype='multipart/form-data'>
<h2 style="margin: 10px 20px 20px 20px">Mudar Foto</h2>
<div class="login_container">
<div class="login_container">
<div class="w3-col s3">
<label class="w3-text-teal"><b>Selecionar Imagem: </b></label>
</div>
<div class="w3-col s9 w3-border">
</div>
<div class="w3-col s9 w3-border">
<input class="w3-input w3-border w3-light-grey" onchange="loadFile(event)" type="file" name="foto" accept="image/*" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
</div>
</div>
<img class="w3-margin-top w3-margin-bottom" id="output" style="width:100%"/>
</div>
<input class="w3-btn w3-light-blue" type="submit" value="Confirmar" style="width: 100%"/>
</form>
`
$('#display').empty()
$('#display').append(form)
$('#display').modal()
<div class="login_container">
<img class="w3-margin-top w3-margin-bottom" id="output" style="width:100%"/>
<div class="w3-row login_container w3-margin-bottom">
<input class="w3-btn w3-blue-grey w3-margin-top" style="float:right" type="submit" value="Submeter"/>
<input class="w3-btn w3-blue-grey w3-margin-top" id="close_edit_picture" style="float:right; margin-right: 10px" type="button" value="Cancelar"/>
</div>
</div>
</form>`

$('#edit_pic_modal').append(html)
document.getElementById('edit_pic_modal').style.display = 'block';

$("#close_edit_picture").click(function(event) {
event.preventDefault();
document.getElementById('edit_pic_modal').style.display='none';
})
}

function equalSelect(f1,f2){
return f1 == f2
}

function editForm(user){
$('#edit_profile_modal').empty()
var json = JSON.parse(user.replace(/\\/g, "/"))
var form = `
<form class="w3-container" action="/perfil/${json._id}/editar/" method="POST">
<div class="w3-row w3-margin-bottom">
<div class="w3-col s3">
<label class="w3-text-teal"><b>Nome:</b></label>
</div>
<div class="w3-col s9 w3-border">
var html = `
<form class="my-modal-content" action="/perfil/${json._id}/editar/" method="POST">
<h2 style="margin: 10px 20px 20px 20px">Editar Perfil</h2>
<div class="login_container">
<div class="login_container">
<div class="w3-col s3">
<label class="w3-text-teal"><b>Nome: </b></label>
</div>
<div class="w3-col s9 w3-border">
<input class="w3-input w3-border w3-light-grey" type="text" name="nome" value="${json.nome}">
</div>
</div>
</div>
<div "w3-row w3-margin-bottom">
<div class="w3-col s3">
<label class="w3-text-teal"><b>Descrição:</b></label>
</div>
<div class="w3-col s9 w3-border">
<div class="login_container">
<div class="w3-col s3">
<label class="w3-text-teal"><b>Descrição: </b></label>
</div>
<div class="w3-col s9 w3-border">
<input class="w3-input w3-border w3-light-grey" type="text" name="descricao" value="${json.descricao}">
</div>
</div>
</div>
<div "w3-row w3-margin-bottom">
<div class="w3-col s3 w3-margin-top">
<label class="w3-text-teal"><b>Estatuto:</b></label>
</div>
<div class="w3-col s9 w3-border w3-margin-top">
<select name="estatuto" id="estatuto" style="width:100%">
<option value="estudante" ` + (json.estatuto.tipo == "estudante" ? `selected` : ``) + `>Estudante</option>
<option value="docente" ` + (json.estatuto.tipo == "docente" ? `selected` : ``) + `>Docente</option>
<option value="trabalhador" ` + (json.estatuto.tipo == "trabalhador" ? `selected` : ``) + `>Trabalhador</option>
</select>
</div>
</div>
<div "w3-row w3-margin-bottom">
<div class="login_container">
<div class="w3-col s3 w3-margin-top">
<label class="w3-text-teal"><b>Estatuto: </b></label>
</div>
<div class="w3-col s9 w3-margin-top">
<select name="estatuto" id="estatuto" style="width:100%">
<option value="estudante" ` + (json.estatuto.tipo == "estudante" ? `selected` : ``) + `>Estudante</option>
<option value="docente" ` + (json.estatuto.tipo == "docente" ? `selected` : ``) + `>Docente</option>
<option value="trabalhador" ` + (json.estatuto.tipo == "trabalhador" ? `selected` : ``) + `>Trabalhador</option>
</select>
</div>
</div>
<div class="login_container">
<div class="w3-col s3 w3-margin-top">
<label class="w3-text-teal"><b>Filiação:</b></label>
<label class="w3-text-teal"><b>Filiação: </b></label>
</div>
<div class="w3-col s9 ">
<input class="w3-input w3-margin-top w3-light-grey w3-margin-top w3-border" type="text" name="filiacao" value="${json.estatuto.filiacao}">
</div>
<div class="w3-col s9">
<input class="w3-input w3-margin-top w3-border w3-light-grey" type="text" name="filiacao" value="${json.estatuto.filiacao}">
</div>
<div class="w3-row login_container w3-margin-bottom">
<input class="w3-btn w3-blue-grey w3-margin-top" style="float:right" type="submit" value="Submeter"/>
<input class="w3-btn w3-blue-grey w3-margin-top" id="close_edit_profile" style="float:right; margin-right: 10px" type="button" value="Cancelar"/>
</div>
</div>
<input class="w3-margin-top w3-btn w3-light-blue" type="submit" value="Confirmar" style="width: 100%"/>
</div>
</form>`
$('#display2').empty()
$('#display2').append(form)
$('#display2').modal()

$('#edit_profile_modal').append(html)
document.getElementById('edit_profile_modal').style.display = 'block';

$("#close_edit_profile").click(function(event) {
event.preventDefault();
document.getElementById('edit_profile_modal').style.display='none';
})

}
9 changes: 4 additions & 5 deletions app-server/public/stylesheets/perfil.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ body{
}

.profile-header .profile-header-cover {
background-image: url(https://venngage-wordpress.s3.amazonaws.com/uploads/2018/09/Colorful-Circle-Simple-Background-Image-1.jpg);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
Expand All @@ -22,11 +21,11 @@ body{
.profile-header .profile-header-cover:before {
content: '';
position: absolute;
background: lightskyblue;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, .75) 100%)
}

.profile-header .profile-header-content {
Expand All @@ -41,14 +40,14 @@ body{
overflow: hidden;
position: relative;
z-index: 10;
margin: 0 0 -20px;
padding: 3px;
border-radius: 4px;
background: #7FDBFF
margin-top: 40px;
}

.profile-header-img img {
display: block;
border:2px solid #2196F3;
border-radius: 10px;
margin-left: auto;
margin-right: auto;
width: 100%;
Expand Down
65 changes: 31 additions & 34 deletions app-server/routes/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,14 @@ router.get('/:id', function(req,res) {

axios.get('http://localhost:8001/publicacoes/' + req.params.id + '?token=' + req.cookies.token)
.then(dados => {
let visitante
aux.sortComments(dados.data)

let users = {}
let promises = []
let visitante, autor

dados.data.comments.forEach(c => {
promises.push(
axios.get('http://localhost:8001/users/' + c.id_autor + '?token=' + req.cookies.token)
.then(userData => {
let user = userData.data
if (!(user._id in users)) users[user._id] = user
})
.catch(error => res.render('error', {error}))
)
})

promises.push(
axios.get('http://localhost:8001/users/' + token._id + '?token=' + req.cookies.token)
.then(visitanteData => visitante = visitanteData.data)
.catch(error => res.render('error', {error}))
)

promises.push(
axios.get('http://localhost:8001/users/' + dados.data.id_autor + '?token=' + req.cookies.token)
.then(autorData => autor = autorData.data)
axios.get('http://localhost:8001/users/' + token._id + '?token=' + req.cookies.token)
.then(visitanteData => {
visitante = visitanteData.data
res.render('publicacao', {publicacao: dados.data, nivel: token.nivel, visitante})
})
.catch(error => res.render('error', {error}))
)
Promise.all(promises).then(() => res.render('publicacao', {publicacao: dados.data, nivel: token.nivel, users, visitante, autor}));
})
.catch(error => res.render('error', {error}))
}
Expand All @@ -54,10 +33,23 @@ router.post('/', function(req, res) {
if (token.nivel == 'produtor' || token.nivel == 'admin') {
req.body["id_autor"] = token._id
req.body["dataCriacao"] = new Date().toISOString().substr(0,19)
axios.get('http://localhost:8001/users/imagem/' + token._id + '?token=' + req.cookies.token)
.then(fotoData => {
req.body["nome_autor"] = token.nome
req.body["foto"] = fotoData.data.foto

axios.post('http://localhost:8001/publicacoes?token=' + req.cookies.token, req.body)
.then(dados => res.redirect("/publicacoes/" + dados.data._id))
.catch(error => res.render('error', {error}))
axios.get('http://localhost:8001/recursos/titulo/' + req.body.id_recurso + '?token=' + req.cookies.token)
.then(tituloData => {
console.log(tituloData.data)
req.body["titulo_recurso"] = tituloData.data.titulo

axios.post('http://localhost:8001/publicacoes?token=' + req.cookies.token, req.body)
.then(dados => res.redirect("/publicacoes/" + dados.data._id))
.catch(error => res.render('error', {error}))
})
.catch(error => res.render('error', {error}))
})
.catch(error => res.render('error', {error}))
}
}
})
Expand All @@ -70,10 +62,15 @@ router.post('/comentar/:id', function(req, res) {
if (token.nivel == 'produtor' || token.nivel == 'admin') {
req.body["id_autor"] = token._id
req.body["dataCriacao"] = new Date().toISOString().substr(0,19)

axios.post('http://localhost:8001/publicacoes/comentar/' + req.params.id + '?token=' + req.cookies.token, req.body)
.then(dados => res.redirect("/publicacoes/"+dados.data._id))
.catch(error => res.render('error', {error}))
axios.get('http://localhost:8001/users/imagem/' + token._id + '?token=' + req.cookies.token)
.then(fotoData => {
req.body["nome_autor"] = token.nome
req.body["foto"] = fotoData.data.foto
axios.post('http://localhost:8001/publicacoes/comentar/' + req.params.id + '?token=' + req.cookies.token, req.body)
.then(dados => res.redirect("/publicacoes/"+dados.data._id))
.catch(error => res.render('error', {error}))
})
.catch(error => res.render('error', {error}))
}
}
})
Expand Down
Loading

0 comments on commit 5655f12

Please sign in to comment.