Skip to content

Commit

Permalink
chore(departments): added view all public ticket option
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Aug 8, 2019
1 parent 1d97104 commit d849b99
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 28 deletions.
7 changes: 7 additions & 0 deletions src/client/containers/Departments/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ class DepartmentsContainer extends React.Component {
</h6>
</div>
)}
{department.get('publicGroups') === true && (
<div>
<h6 className={'text-success'} style={{ fontWeight: 'bold' }}>
All Public Groups
</h6>
</div>
)}
{department.get('allGroups') !== true &&
groups &&
groups.map(group => {
Expand Down
34 changes: 27 additions & 7 deletions src/client/containers/Modals/CreateDepartmentModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import MultiSelect from 'components/MultiSelect'
class CreateDepartmentModal extends React.Component {
@observable name = ''
@observable allGroups = false
@observable publicGroups = false
componentDidMount () {
this.props.fetchTeams()
Expand Down Expand Up @@ -60,21 +61,22 @@ class CreateDepartmentModal extends React.Component {
e.preventDefault()
const $form = $(e.target)
if (!$form.isValid(null, null, false)) return false
if(!this.allGroups && this.groupSelect.getSelected() == null){
if (!this.allGroups && !this.publicGroups && this.groupSelect.getSelected() == null) {
helpers.UI.showSnackbar('Can not create department without a group selected or all groups enabled!', true)
return false;
return false
}
if(this.teamsSelect.getSelected() == null){
if (this.teamsSelect.getSelected() == null) {
helpers.UI.showSnackbar('Can not create department without a team selected!', true)
return false;
return false
}
const payload = {
name: this.name,
teams: this.teamsSelect.getSelected(),
allGroups: this.allGroups,
publicGroups: this.publicGroups,
groups: this.allGroups ? [] : this.groupSelect.getSelected()
}
Expand Down Expand Up @@ -137,6 +139,24 @@ class CreateDepartmentModal extends React.Component {
</label>
</div>
</div>
<div className={'uk-margin-medium-bottom uk-clearfix'}>
<div className='uk-float-left'>
<h4 style={{ paddingLeft: 2 }}>Access all current and new public groups?</h4>
</div>
<div className='uk-float-right md-switch md-green' style={{ marginTop: 1 }}>
<label>
Yes
<input
type='checkbox'
checked={this.publicGroups}
onChange={e => {
this.publicGroups = e.target.checked
}}
/>
<span className={'lever'} />
</label>
</div>
</div>
<div className={'uk-margin-medium-bottom'}>
<label style={{ marginBottom: 5 }}>Customer Groups</label>
<MultiSelect
Expand Down
22 changes: 22 additions & 0 deletions src/client/containers/Modals/EditDepartmentModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ import MultiSelect from 'components/MultiSelect'
class EditDepartmentModal extends React.Component {
@observable name = ''
@observable allGroups = false
@observable publicGroups = false
componentDidMount () {
this.props.fetchTeams()
this.props.fetchGroups({ type: 'all' })
this.name = this.props.department.get('name')
this.allGroups = this.props.department.get('allGroups')
this.publicGroups = this.allGroups ? true : this.props.department.get('publicGroups')
helpers.UI.inputs()
helpers.UI.reRenderInputs()
Expand Down Expand Up @@ -70,6 +72,7 @@ class EditDepartmentModal extends React.Component {
name: this.name,
teams: this.teamsSelect.getSelected(),
allGroups: this.allGroups,
publicGroups: this.publicGroups,
groups: this.allGroups ? [] : this.groupSelect.getSelected()
}
Expand Down Expand Up @@ -132,6 +135,7 @@ class EditDepartmentModal extends React.Component {
checked={this.allGroups}
onChange={e => {
this.allGroups = e.target.checked
this.publicGroups = this.allGroups
if (this.allGroups) this.groupSelect.selectAll()
else this.groupSelect.deselectAll()
}}
Expand All @@ -140,6 +144,24 @@ class EditDepartmentModal extends React.Component {
</label>
</div>
</div>
<div className={'uk-margin-medium-bottom uk-clearfix'}>
<div className='uk-float-left'>
<h4 style={{ paddingLeft: 2 }}>Access all current and new public groups?</h4>
</div>
<div className='uk-float-right md-switch md-green' style={{ marginTop: 1 }}>
<label>
Yes
<input
type='checkbox'
checked={this.publicGroups}
onChange={e => {
this.publicGroups = e.target.checked
}}
/>
<span className={'lever'} />
</label>
</div>
</div>
<div className={'uk-margin-medium-bottom'}>
<label style={{ marginBottom: 5 }}>Customer Groups</label>
<MultiSelect
Expand Down
20 changes: 6 additions & 14 deletions src/controllers/api/v2/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,14 @@ ticketsV2.get = function (req, res) {
[
function (next) {
if (req.user.role.isAdmin || req.user.role.isAgent) {
Department.getUserDepartments(req.user._id, function (err, departments) {
Department.getDepartmentGroupsOfUser(req.user._id, function (err, dbGroups) {
if (err) return next(err)

if (_.some(departments, { allGroups: true })) {
Group.find({}, next)
} else {
var groups = _.flattenDeep(
departments.map(function (d) {
return d.groups.map(function (g) {
return g._id
})
})
)

return next(null, groups)
}
var groups = dbGroups.map(function (g) {
return g._id
})

return next(null, groups)
})
} else {
Group.getAllGroupsOfUser(req.user._id, next)
Expand Down
32 changes: 25 additions & 7 deletions src/models/department.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var departmentSchema = mongoose.Schema({
normalized: { type: String },
teams: [{ type: mongoose.Schema.Types.ObjectId, ref: 'teams', autopopulate: true }],
allGroups: { type: Boolean, default: false },
publicGroups: { type: Boolean, default: false },
groups: [{ type: mongoose.Schema.Types.ObjectId, ref: 'groups', autopopulate: true }]
})

Expand Down Expand Up @@ -72,17 +73,34 @@ departmentSchema.statics.getDepartmentGroupsOfUser = function (userId, callback)
if (err) return callback(err)

var hasAllGroups = _.some(departments, { allGroups: true })
var hasPublicGroups = _.some(departments, { publicGroups: true })
if (hasAllGroups) {
return Groups.getAllGroups(callback)
}
} else if (hasPublicGroups) {
return Groups.getAllPublicGroups(function (err, publicGroups) {
if (err) return callback(err)

var groups = _.flattenDeep(
departments.map(function (department) {
return department.groups
})
)
var mapped = departments.map(function (department) {
return department.groups
})
var merged = _.concat(publicGroups, mapped)

merged = _.flattenDeep(merged)
merged = _.uniqBy(merged, function (i) {
return i._id
})

return callback(null, groups)
return callback(null, merged)
})
} else {
var groups = _.flattenDeep(
departments.map(function (department) {
return department.groups
})
)

return callback(null, groups)
}
})
})
}
Expand Down

0 comments on commit d849b99

Please sign in to comment.