Skip to content

Commit

Permalink
Merge pull request #64 from DemocraciaEnRed/dev_clear-proyectistas
Browse files Browse the repository at this point in the history
Dev clear proyectistas
  • Loading branch information
xtian7489 authored Jul 4, 2023
2 parents 1feb095 + dfcc8c1 commit 204b080
Show file tree
Hide file tree
Showing 16 changed files with 746 additions and 12 deletions.
97 changes: 97 additions & 0 deletions ext/lib/api-v2/topics/xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,103 @@ app.get('/export/topics/xlsx',
}
})

app.get('/export/old-topics',
middlewares.users.restrict,
middlewares.forums.findFromQuery,
middlewares.topics.findDeletedFromForum,
middlewares.forums.privileges.canChangeTopics,
function getAllUserMails(req, res, next) {
api.user.all(function (err, users) {
let usersMail = {}
if (err) {
log('error serving users from DB:', err)
return res.status(500).end()
}
users.forEach(u => usersMail[u._id] = u.email)
req.usersMail = usersMail
next()
})
},
(req, res, next) => Promise.all(
// populamos owners (parecido a populateOwners)
req.topics.map(topic =>
api.user.getFullUserById(topic.owner, true).then(user => {
topic.owner = user
return topic
})
)
).then((topics) => Promise.all(
// populamos votos
topics.map(topic =>
api.vote.getVotesByTopic(topic._id).then(votes => {
topic.action.results = votes.map(v => req.usersMail[v.author])
return topic
})
)
)).then((topics) => {
req.topics = topics
next()
}),
(req, res, next) =>
api.user.populateProyectistas(req.topics).then(() => next())
,
function getXlsx(req, res, next) {
let infoTopics = []
const attrsNames = req.forum.topicsAttrs
.map((attr) => attr.name)

let listTopics= req.topics
if(req.query.sort==='voted'){
listTopics.sort(function(a, b){return b.votesLength-a.votesLength})
}else if(req.query.sort==='newest'){
listTopics.sort(function(a, b){return new Date(b.createdAt) - new Date(a.createdAt)})
}else if(req.query.sort==='latest'){
listTopics.sort(function(a, b){return new Date(a.createdAt) - new Date(b.createdAt)})
}

if(req.query.years){
let listYears = req.query.years.split(',').map(Number)
listTopics = listTopics.filter(topic => listYears.includes(topic.createdAt.getFullYear()))
}

req.topics.forEach((topic) => {
if (topic.attrs === undefined) {
topic.attrs = {}
}
console.log(topic)
let theTopic = {
'Idea ID': topic.id,
'Idea Fecha': `${escapeTxt(moment(topic.createdAt, '', req.locale).format('LL LT'))}`,
'Idea Título': `${escapeTxt(topic.mediaTitle)}`,
// 'Idea Temas': `${escapeTxt(topic.tags.join(', '))}`,
'Idea Tema': `${topic.tag ? escapeTxt(topic.tag.name) : '-'}`,
'Idea Facultad': `${escapeTxt(topic.owner.facultad && topic.owner.facultad.abreviacion)}`,
'Idea Texto': `${escapeTxt(topic.attrs['problema'])}`,
'Autor/a nombre': `${escapeTxt(topic.owner.firstName)}`,
'Autor/a apellido': `${escapeTxt(topic.owner.lastName)}`,
'Autor/a email': `${escapeTxt(topic.owner.email)}`,
'Autor/a claustro': `${escapeTxt(topic.owner.claustro && topic.owner.claustro.nombre)}`,
'Autor/a género': `${escapeTxt(topic.attrs['genero'])}`,
'Seguidores cantidad': `${escapeTxt(topic.action.count)}`,
'Seguidores emails': `${escapeTxt(topic.action.results.join(', '))}`,
'Proyectistas cantidad': `${escapeTxt(topic.proyectistas && topic.proyectistas.length)}`,
'Proyectistas emails': `${escapeTxt(topic.proyectistas && topic.proyectistas.map(p=>p.email).join(','))}`
}

/*attrsNames.map((name) => {
theTopic[name] = `${escapeTxt(topic.attrs[name])}` || ''
});*/
infoTopics.push(theTopic);
});
try {
res.xls(`ideas-facultades.xlsx`, infoTopics);
} catch (err) {
log('get csv: array to csv error', err)
return res.status(500).end()
}
})


app.get('/export/topics/export-resultados',
middlewares.users.restrict,
middlewares.forums.findByName,
Expand Down
72 changes: 69 additions & 3 deletions lib/admin/admin-proyectistas/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import t from 't-component'
import 'whatwg-fetch'
import urlBuilder from 'lib/url-builder'
import { limit } from '../../api-v2/validate/schemas/pagination'
import NanoModal from 'nanomodal'

let modalRef = null

export default class AdminProyectistas extends Component {
constructor (props) {
Expand All @@ -27,6 +30,7 @@ export default class AdminProyectistas extends Component {

componentDidMount () {
this.getProyectistas()
this.createModal()
}

getProyectistas = () => {
Expand Down Expand Up @@ -176,6 +180,66 @@ export default class AdminProyectistas extends Component {
limit: this.state.limit+50
})
}

onButtonPressed() {
window.fetch('/api/proyectistas/delete', {
method: 'DELETE',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}).then(res => res.json())
.then(res => {
let modalRefDelete = NanoModal(`se eliminaron ${res.result.nModified} proyectistas`, {
classes: 'modalContent',
buttons: [{
text: "cerrar",
handler: (modal) => {
// do something...
this.setState({proyectistas:[]})
modal.hide();
},
classes: 'btn btn-primary end',
}]})
modalRefDelete.customShow = function (defaultShow, modalAPI) {
modalAPI.overlay.el.style.position = 'fixed'
modalAPI.overlay.el.style.display = 'block';
modalAPI.modal.el.style.display = 'block';
};
modalRefDelete.customShow(modalRefDelete.show, modalRefDelete);
})
}

createModal() {
modalRef = NanoModal("¿Seguro desea de eliminar proyectistas?", {
classes: 'modalContent',
overlayClose: true, // Can't close the modal by clicking on the overlay.
buttons: [{
text: "SI",
handler: (modal) => {
// do something...
this.onButtonPressed()
modal.hide();
},
classes: 'btn btn-primary',
}, {
text: "NO",
classes: 'btn btn-danger',
handler: "hide"
}],
});
modalRef.customShow = function (defaultShow, modalAPI) {
modalAPI.overlay.el.style.position = 'fixed'
modalAPI.overlay.el.style.display = 'block';
modalAPI.modal.el.style.display = 'block';
};
}


clearProyectistas() {
modalRef.customShow(modalRef.show, modalRef);
}

render () {
// const { forum } = this.props
Expand All @@ -186,16 +250,18 @@ export default class AdminProyectistas extends Component {
<hr/>
<p className='h3'>Descargar listado</p>
<div className="clearfix">
<div className="pull-left">
<div className="container-flex justify-content-between">
<p>Descarge el listado de proyectistas en una planilla</p>
</div>
<div className="pull-right">

<a href='/api/v2/proyectistas/all/csv'
download
className='btn btn-primary'>
Descargar CSV
</a>
</div>
{proyectistas.length > 0 &&<div className='text-right'>
<button className='btn btn-danger' onClick={this.clearProyectistas}>Borrar proyectistas ({proyectistas.length} )</button>
</div>}
</div>
<hr/>
<p className='h3'>Agregar nuevo proyectista</p>
Expand Down
24 changes: 24 additions & 0 deletions lib/admin/admin-proyectistas/styles.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.modalContent
position: fixed
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
padding:0;
width: 40%;
text-align: center;
margin: 0
border-radius: 0
@media(max-width: 788px)
width: 95%

.nanoModalContent
margin: 32px 56px;


.nanoModalButtons
display: flex!important;
margin: 0 16px;
justify-content: flex-end;

.end
margin-left:auto
1 change: 0 additions & 1 deletion lib/admin/admin-settings-stage/template.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.password-settings
.heading
h2= 'Configuraciones'
//button.btn.btn-primary#borrar-proyectistas='borrar proyectistas'
form.form(action=form.action, method='post', role='form', autovalidate, autosubmit)
ul.form-messages
.container-fluid
Expand Down
Loading

0 comments on commit 204b080

Please sign in to comment.