Skip to content

Commit

Permalink
chore(tickets): ticket status display order
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jun 21, 2023
1 parent 65ede4b commit 073a308
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 11 deletions.
4 changes: 2 additions & 2 deletions public/js/5.js

Large diffs are not rendered by default.

Binary file modified public/js/5.js.gz
Binary file not shown.
9 changes: 6 additions & 3 deletions src/client/containers/Settings/Tickets/ticketStatusBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { observer } from 'mobx-react'
import Input from 'components/Input'
import { makeObservable, observable } from 'mobx'
import { fetchSettings } from 'actions/settings'
import ColorSelector from 'components/ColorSelector'
import Button from 'components/Button'
import EnableSwitch from 'components/Settings/EnableSwitch'
Expand Down Expand Up @@ -59,8 +61,8 @@ class TicketStatusBody extends React.Component {
api.tickets
.updateStatus({ id, name, htmlColor, isResolved, slatimer })
.then(res => {
console.log(res)
helpers.UI.showSnackbar('Status updated')
this.props.fetchSettings()
})
.catch(e => {
console.log(e)
Expand Down Expand Up @@ -147,7 +149,8 @@ class TicketStatusBody extends React.Component {
}

TicketStatusBody.propTypes = {
status: PropTypes.object.isRequired
status: PropTypes.object.isRequired,
fetchSettings: PropTypes.func.isRequired
}

export default TicketStatusBody
export default connect(null, { fetchSettings })(TicketStatusBody)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TicketStatusContainer extends React.Component {
for (let i = 0; i < children.length; i++) arr.push($(children[i]).attr('data-key'))

axios
.put('/api/v2/tickets/status/order', { order: arr })
.put('/api/v1/tickets/status/order', { order: arr })
.then(res => {
console.log(res)
})
Expand Down
1 change: 1 addition & 0 deletions src/controllers/api/v1/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = function (middleware, router, controllers) {

router.post('/api/v1/tickets/status/create', apiv1, isAdmin, apiCtrl.tickets.createStatus)
router.get('/api/v1/tickets/status', apiv1, apiCtrl.tickets.getStatus)
router.put('/api/v1/tickets/status/order', apiv1, isAdmin, apiCtrl.tickets.updateStatusOrder)
router.put('/api/v1/tickets/status/:id', apiv1, isAdmin, apiCtrl.tickets.updateStatus)
router.post('/api/v1/tickets/status/:id/delete', apiv1, isAdmin, apiCtrl.tickets.deleteStatus)

Expand Down
32 changes: 30 additions & 2 deletions src/controllers/api/v1/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ apiTickets.getStatus = function (req, res) {
ticketStatusSchema.find({}, function (err, status) {
if (err) return res.status(400).json({ success: false, error: err.message })

status = _.sortBy(status, ['uid'])
status = _.sortBy(status, 'order')

return res.json({ success: true, status: status })
})
Expand All @@ -1414,12 +1414,40 @@ apiTickets.updateStatus = function (req, res) {

status.save(function (err, p) {
if (err) return res.status(400).json({ success: false, error: err.message })
console.log(p)

return res.json({ success: true, status: p })
})
})
}

apiTickets.updateStatusOrder = function (req, res) {
var data = req.body
if (!data || !data.order) return res.status(400).json({ success: false, error: 'Invalid Post Data' })

var order = data.order
var ticketStatusSchema = require('../../../models/ticketStatus')
ticketStatusSchema.find({}, function (err, statuses) {
if (err) return res.status(400).json({ success: false, error: err })

async.eachSeries(
statuses,
function (item, done) {
var idx = _.findIndex(order, id => item._id.toString() === id)
item.order = idx
item.save(done)
},
function (err) {
if (err) {
winston.debug(err)
return res.status(500).json({ success: false, error: err })
}

return res.status(200).json({ success: true })
}
)
})
}

apiTickets.deleteStatus = function (req, res) {
var id = req.params.id

Expand Down
4 changes: 4 additions & 0 deletions src/migration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ function createTicketStatus (callback) {
name: 'New',
htmlColor: '#29b955',
uid: 0,
order: 1,
isResolved: false,
slatimer: true,
isLocked: true
Expand All @@ -221,6 +222,7 @@ function createTicketStatus (callback) {
name: 'Open',
htmlColor: '#d32f2f',
uid: 1,
order: 2,
isResolved: false,
slatimer: true,
isLocked: true
Expand All @@ -229,6 +231,7 @@ function createTicketStatus (callback) {
name: 'Pending',
htmlColor: '#2196F3',
uid: 2,
order: 3,
isResolved: false,
slatimer: false,
isLocked: true
Expand All @@ -237,6 +240,7 @@ function createTicketStatus (callback) {
name: 'Closed',
htmlColor: '#CCCCCC',
uid: 3,
order: 4,
isResolved: true,
slatimer: false,
isLocked: true
Expand Down
3 changes: 2 additions & 1 deletion src/models/ticketStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var statusSchema = mongoose.Schema(
name: { type: String, required: true, unique: true },
htmlColor: { type: String, default: '#29b955' },
uid: { type: Number, unique: true, index: true },
order: { type: Number, unique: true, index: true },
order: { type: Number, index: true },
slatimer: { type: Boolean, default: true },
isResolved: { type: Boolean, default: false },
isLocked: { type: Boolean, default: false }
Expand Down Expand Up @@ -70,6 +70,7 @@ statusSchema.statics.getStatus = function (_id, callback) {
statusSchema.statics.getStatus = function (callback) {
return this.model(COLLECTION)
.find({})
.sort({ order: 1 })
.exec(callback)
}

Expand Down
4 changes: 2 additions & 2 deletions src/settings/settingsUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ util.getSettings = async callback => {
content.data.priorities = _.sortBy(priorities, ['migrationNum', 'name'])

const status = await statusSchema.getStatus()
content.data.status = _.sortBy(status,'_id')
content.data.status = _.sortBy(status, 'order')

const templateSchema = require('../models/template')
const templates = await templateSchema.find({})
content.data.mailTemplates = _.sortBy(templates, 'name')
Expand Down

0 comments on commit 073a308

Please sign in to comment.