Skip to content

Commit

Permalink
Added in admin panel new query for "state" which can be "Idea" or "Pr…
Browse files Browse the repository at this point in the history
…oyecto".
  • Loading branch information
guillecro committed Aug 24, 2023
1 parent 204b080 commit d9c2dd6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ext/lib/api/topics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ app.get('/topics',
state: {
type: 'string',
format: 'states',
default: 'pendiente,factible,no-factible,integrado'
default: 'idea,proyecto'
},
sort: {
type: 'string',
Expand Down
4 changes: 3 additions & 1 deletion lib/admin/admin-topics/styles.styl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
.row-filtros
margin-top: 10px;
.input-group
margin: 0 auto;
// margin: 0 auto;
width: 100%;
select
display: block;
width: 100%;

#topic-list
.placa
Expand Down
14 changes: 11 additions & 3 deletions lib/admin/admin-topics/template.jade
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,29 @@
button.btn.btn-primary.sort.por-nombre(data-sort='topic-title')
span='A - Z'
.row.row-filtros
.col-md-3.col-xs-12
.col-md-6.col-xs-12
.input-group.input-group-md
='Facultad: '
select(name='facultad')
option(value="") Todos
- each obj in uniqAttrs.facultades
option(value="#{obj.value}") #{obj.name}
.col-md-4.col-xs-12
.col-md-6.col-xs-12
.input-group.input-group-md
='Claustro: '
select(name='claustro')
option(value="") Todos
- each obj in uniqAttrs.claustros
option(value="#{obj.value}") #{obj.name}
.col-md-5.col-xs-12
.row.row-filtros
.col-md-6.col-xs-12.text-left
.input-group.input-group-md
='Tipo: '
select(name='state')
option(value="") Todos
option(value="pendiente") Idea
option(value="proyecto") Proyecto
.col-md-6.col-xs-12
.input-group.input-group-md
='Temas: '
select(name='tema')
Expand Down
8 changes: 6 additions & 2 deletions lib/admin/admin-topics/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ export default class TopicsListView extends View {
let facultadSelect = this.el[0].querySelector('select[name=facultad]')
if (facultadSelect.value) query.facultad = facultadSelect.value

// let temaSelect = this.el[0].querySelector('select[name=tema]')
// if (temaSelect.value) query.tema = temaSelect.value
let stateSelect = this.el[0].querySelector('select[name=state]')
if (stateSelect.value) query.state = stateSelect.value

let temaSelect = this.el[0].querySelector('select[name=tema]')
if (temaSelect.value) query.tag = temaSelect.value

Expand All @@ -205,6 +206,9 @@ export default class TopicsListView extends View {

let tag = getQueryVariable('tag')
if (tag) this.el[0].querySelector('select[name=tema]').value = decodeURIComponent(tag)

let state = getQueryVariable('state')
if (state) this.el[0].querySelector('select[name=state]').value = decodeURIComponent(state)
// let tema = getQueryVariable('tema')
// if (tema) this.el[0].querySelector('select[name=tema]').value = decodeURIComponent(tema)
}
Expand Down
4 changes: 4 additions & 0 deletions lib/api-v2/db-api/topics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ exports.list = function list (opts) {

if (opts.tag) query.tag = { $in: [opts.tag] }

if (opts.state) query["attrs.state"] = opts.state

if (!opts.draft) query.publishedAt = { $ne: null }

if (opts.search) query.mediaTitle = { $regex : createMediaTitleRegex(opts.search), $options : 'i' }
Expand Down Expand Up @@ -149,6 +151,8 @@ exports.listCount = function listCount (opts) {

if (opts.tema) query.tags = { $in: [opts.tema] }

if (opts.state) query["attrs.state"] = opts.state

if (opts.search) query.mediaTitle = { $regex : createMediaTitleRegex(opts.search), $options : 'i' }

if (owners && owners.length > 0) query.owner = { $in: owners }
Expand Down
34 changes: 21 additions & 13 deletions lib/api-v2/topics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ validate({
tema: {
type: 'string',
format: 'tema'
},
state: {
type: 'string',
default: ''
}
})
}),
Expand All @@ -75,26 +79,30 @@ function (req, res, next) {
}
},
function getTopics (req, res, next) {
let dbQuery = {
user: req.user,
forum: req.forum,
limit: req.query.limit,
page: req.query.page,
tag: req.query.tag,
sort: req.query.sort,
draft: !!req.query.draft,
search: decodeURI(req.query.search),
facultad: req.query.facultad,
claustro: req.query.claustro,
tema: decodeURI(req.query.tema),
state: req.query.state
}
console.log(dbQuery)
Promise.all([
api.topics.list({
user: req.user,
forum: req.forum,
limit: req.query.limit,
page: req.query.page,
tag: req.query.tag,
sort: req.query.sort,
draft: !!req.query.draft,
search: decodeURI(req.query.search),
facultad: req.query.facultad,
claustro: req.query.claustro,
tema: decodeURI(req.query.tema)
}).then(topics => apiV1.user.populateOwners(topics)),
api.topics.list(dbQuery).then(topics => apiV1.user.populateOwners(topics)),
req.query.limit,
api.topics.listCount({
forum: req.forum,
search: decodeURI(req.query.search),
facultad: req.query.facultad,
claustro: req.query.claustro,
state: req.query.state,
tema: decodeURI(req.query.tema)
})
]).then((results) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/middlewares/topic-middlewares/topic-middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function findPrivateTopics (ctx, next) {
if (!ctx.forum) {
throw new Error('First you must fetch the current forum.')
}

let query = {
draft: true,
forum: ctx.forum.id,
Expand All @@ -31,7 +30,8 @@ export function findPrivateTopics (ctx, next) {
facultad: getQueryVariable('facultad') || '',
claustro: getQueryVariable('claustro') || '',
tema: getQueryVariable('tema') || '',
tag: getQueryVariable('tag') || ''
tag: getQueryVariable('tag') || '',
state: getQueryVariable('state') || '',
}
topicStore.findAll(query).then(([topics, pagination]) => {
ctx.topics = topics
Expand Down

0 comments on commit d9c2dd6

Please sign in to comment.