Skip to content

Commit

Permalink
chore(reports): added Teams
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Apr 28, 2019
1 parent 556a2d1 commit 0666f8e
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"archiver": "3.0.0",
"async": "2.6.1",
"axios": "0.18.0",
"bcrypt": "3.0.3",
"bcrypt": "3.0.6",
"body-parser": "1.18.3",
"busboy": "0.2.14",
"chance": "1.0.18",
Expand Down
34 changes: 34 additions & 0 deletions src/controllers/api/v1/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,40 @@ apiReports.generate.ticketsByGroup = function (req, res) {
)
}

apiReports.generate.ticketsByTeam = function (req, res) {
var postData = req.body
if (!postData || !postData.startDate || !postData.endDate)
return res.status(400).json({ success: false, error: 'Invalid Post Data' })

var departmentSchema = require('../../../models/department')
departmentSchema.getDepartmentsByTeam(postData.teams, function (err, departments) {
if (err) return res.status(500).json({ success: false, error: err.message })

ticketSchema.getTicketsByDepartments(
departments,
{
limit: -1,
page: 0,
filter: {
date: {
start: postData.startDate,
end: postData.endDate
}
}
},
function (err, tickets) {
if (err) return res.status(500).json({ success: false, error: err.message })

var input = processReportData(tickets)

tickets = null

return processResponse(res, input)
}
)
})
}

/**
* @api {post} /api/v1/reports/generate/tickets_by_priority Generate Report - Priority
* @apiName generate_ticketsByPriority
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 @@ -164,6 +164,7 @@ module.exports = function (middleware, router, controllers) {
router.post(genBaseUrl + 'tickets_by_type', apiv1, canUser('reports:create'), reportsGenCtrl.ticketsByType)
router.post(genBaseUrl + 'tickets_by_user', apiv1, canUser('reports:create'), reportsGenCtrl.ticketsByUser)
router.post(genBaseUrl + 'tickets_by_assignee', apiv1, canUser('reports:create'), reportsGenCtrl.ticketsByAssignee)
router.post(genBaseUrl + 'tickets_by_team', apiv1, canUser('reports:create'), reportsGenCtrl.ticketsByTeam)

// Settings
router.get('/api/v1/settings', apiv1, apiCtrl.settings.getSettings)
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/viewdata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ viewController.getData = function (request, cb) {
return callback()
})
},
function (callback) {
viewController.getTeams(request, function (err, teams) {
if (err) return callback(null, null)

viewdata.teams = teams
return callback()
})
},
function (callback) {
viewController.getGroups(request, function (err, data) {
if (err) return callback(null, null)
Expand Down Expand Up @@ -522,6 +530,11 @@ viewController.loggedInAccount = function (request, callback) {
})
}

viewController.getTeams = function (request, callback) {
var Team = require('../../models/team')
return Team.getTeams(callback)
}

viewController.getGroups = function (request, callback) {
var groupSchema = require('../../models/group')
var Department = require('../../models/department')
Expand Down
6 changes: 6 additions & 0 deletions src/models/department.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ departmentSchema.pre('save', function (next) {
return next()
})

departmentSchema.statics.getDepartmentsByTeam = function (teamIds, callback) {
return this.model(COLLECTION)
.find({ teams: { $in: teamIds } })
.exec(callback)
}

departmentSchema.statics.getUserDepartments = function (userId, callback) {
var self = this

Expand Down
28 changes: 28 additions & 0 deletions src/public/js/angularjs/controllers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ define(['angular', 'underscore', 'jquery', 'moment', 'modules/helpers', 'formval
case 'tickets_by_assignees':
changeView('#report_tickets_by_assignees')
break
case 'tickets_by_teams':
changeView('#report_tickets_by_teams')
break
default:
break
}
Expand Down Expand Up @@ -304,6 +307,31 @@ define(['angular', 'underscore', 'jquery', 'moment', 'modules/helpers', 'formval
hideLoader()
})
break
case 'team':
showLoader()
var teams = form.find('select#teams').val()
$http({
method: 'POST',
url: '/api/v1/reports/generate/tickets_by_team',
data: {
startDate: startDate,
endDate: endDate,
teams: teams
},
headers: { 'Content-Type': 'application/json' }
})
.then(
function successCallback (response) {
downloadReport(response, 'report_tickets_by_teams__' + data['filterDate_Start'])
},
function errorCallback (response) {
$log.log(response.statusText)
}
)
.then(function () {
hideLoader()
})
break
default:
break
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/subviews/reports/generate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<li style="margin-bottom: 5px;"><a href="#" class="no-ajaxy" ng-click="selectReport($event, 'tickets_by_types');">Tickets by Types</a></li>
<li style="margin-bottom: 5px;"><a href="#" class="no-ajaxy" ng-click="selectReport($event, 'tickets_by_users');">Tickets by Users</a></li>
<li style="margin-bottom: 5px;"><a href="#" class="no-ajaxy" ng-click="selectReport($event, 'tickets_by_assignees');">Tickets by Assignees</a></li>
<li style="margin-bottom: 5px;"><a href="#" class="no-ajaxy" ng-click="selectReport($event, 'tickets_by_teams');">Tickets by Teams</a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -52,6 +53,9 @@
<div id="report_tickets_by_assignees" class="hide">
{{> generate_partials/report_TicketsByAssignees }}
</div>
<div id="report_tickets_by_teams" class="hide">
{{> generate_partials/report_TicketsByTeams }}
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<div id="report_ticketsByTeams" class="hide1">
<div class="tru-card full-height" data-offset="25">
<h6 style="display: inline-block; padding: 15px; margin: 0; font-size: 14px;">Tickets by Teams</h6>
<div class="uk-float-right">
<!--<button class="btn md-btn-flat-success md-btn-small md-btn md-btn-flat md-btn-wave md-btn-wave-light"-->
<!--style="margin: 10px 15px 0 0; font-size: 14px !important;">-->
<!--Generate-->
<!--</button>-->
<!--<button class="btn md-btn-flat-primary md-btn-small md-btn md-btn-flat md-btn-wave md-btn-wave-light"-->
<!--style="margin: 10px 15px 0 0; font-size: 14px !important;">-->
<!--Need Help?-->
<!--</button>-->
</div>
<hr class="nomargin">
<div class="tru-card-content">
<p class="uk-text-muted" style="margin-bottom: 10px;">
Please select the start and end dates for the report and which teams to include in the report.
</p>
<hr class="uk-margin-large-bottom" />
<form action="#" class="uk-form-stacked sel_report_tickets" id="report_ticketsByGroup_form">
<div class="uk-grid uk-grid-collapse uk-margin-medium-bottom">
<div class="uk-width-1-2" style="padding: 0 15px 0 0;">
<label for="filterDate_Start" class="uk-form-label nopadding nomargin">Date Start</label>
<input id="filterDate_Start" class="filterDate_Start md-input label-fixed" name="filterDate_Start" type="text" data-uk-datepicker="{format:'{{data.common.shortDateFormat}}'}"
data-validation="shortDate"
/>
</div>
<div class="uk-width-1-2" style="padding: 0 0 0 15px;">
<label for="filterDate_End" class="uk-form-label nopadding nomargin">Date End</label>
<input id="filterDate_End" class="filterDate_End md-input label-fixed" name="filterDate_End" type="text" data-uk-datepicker="{format:'{{data.common.shortDateFormat}}'}" value="{{formatDate now data.common.shortDateFormat}}"
data-validation="shortDate"
/>
</div>
</div>
<div class="uk-margin-medium-bottom">
<label for="groups" class="uk-form-label">Teams</label>
<select name="teams" id="teams" class="selectize" multiple data-md-selectize-inline data-md-selectize-bottom="true"
data-validation="length"
data-validation-length="min1"
>
{{#each data.common.teams}}
<option value="{{{_id}}}">{{name}}</option>
{{/each}}
</select>
</div>
<div class="uk-margin-medium-bottom">
<div class="uk-float-right">
<button class="md-btn md-btn-success md-btn-wave" type="submit" ng-click="submitGenerateReport($event, 'team');">Generate</button>
</div>
</div>
</form>
</div>
</div>
</div>
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1919,12 +1919,12 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"

[email protected].3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-3.0.3.tgz#7d1e9e5d533c5ea060e6ac8834942c004dbffe9c"
integrity sha512-4EuzUo6K790QC3uq/ogzy9w2Hc7XDIBoEndU5y7l7YaEAwQF8vyFqv6tC30+gOBZvyxk3F632xzKBQoLNz2pjg==
[email protected].6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-3.0.6.tgz#f607846df62d27e60d5e795612c4f67d70206eb2"
integrity sha512-taA5bCTfXe7FUjKroKky9EXpdhkVvhE5owfxfLYodbrAR1Ul3juLmIQmIQBK4L9a5BuUcE6cqmwT+Da20lF9tg==
dependencies:
nan "2.12.1"
nan "2.13.2"
node-pre-gyp "0.12.0"

before-after-hook@^1.2.0:
Expand Down Expand Up @@ -8590,7 +8590,12 @@ mv@~2:
ncp "~2.0.0"
rimraf "~2.4.0"

[email protected], nan@^2.10.0, nan@^2.9.2:
[email protected]:
version "2.13.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7"
integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==

nan@^2.10.0, nan@^2.9.2:
version "2.12.1"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==
Expand Down

0 comments on commit 0666f8e

Please sign in to comment.