Skip to content

Commit

Permalink
chore(tickets): due dates #141
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Mar 27, 2019
1 parent ce376b4 commit c9ce050
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/helpers/hbs/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ var helpers = {
},

formatDate: function (date, format) {
if (!date) return ''
return moment
.utc(date)
.tz(global.timezone)
Expand Down
16 changes: 16 additions & 0 deletions src/models/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var ticketSchema = mongoose.Schema({
subject: { type: String, required: true },
issue: { type: String, required: true },
closedDate: { type: Date },
dueDate: { type: Date },
comments: [commentSchema],
notes: [noteSchema],
attachments: [attachmentSchema],
Expand Down Expand Up @@ -350,6 +351,21 @@ ticketSchema.methods.setTicketGroup = function (ownerId, groupId, callback) {
})
}

ticketSchema.methods.setTicketDueDate = function (ownerId, dueDate, callback) {
var self = this
self.dueDate = dueDate

var historyItem = {
action: 'ticket:set:duedate',
description: 'Ticket Due Date set to: ' + self.dueDate,
owner: ownerId
}

self.history.push(historyItem)

callback(null, self)
}

/**
* Sets this ticket's issue text
* @instance
Expand Down
26 changes: 26 additions & 0 deletions src/public/js/angularjs/controllers/singleTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define([
.module('trudesk.controllers.singleTicket', ['trudesk.services.session'])
.controller('singleTicket', function (SessionService, $window, $rootScope, $scope, $http, $timeout, $q, $log) {
$scope.loggedInAccount = SessionService.getUser()
onSocketUpdateTicketDueDate()

var mdeToolbarItems = [
{
Expand Down Expand Up @@ -479,6 +480,31 @@ define([
}
}

$scope.updateTicketDueDate = function () {
var id = $('#__ticketId').html()
if (id.length > 0) {
socket.ui.setTicketDueDate(id, $scope.dueDate)
}
}

function onSocketUpdateTicketDueDate () {
socket.socket.removeAllListeners('updateTicketDueDate')
socket.socket.on('updateTicketDueDate', function (data) {
$timeout(function () {
if ($scope.ticketId === data._id)
$scope.dueDate = helpers.formatDate(data.dueDate, helpers.getShortDateFormat())
}, 0)
// var dueDateInput = $('input#tDueDate[data-ticketId="' + data._id + '"]')
// if (dueDateInput.length > 0) {
// $scope.dueDate = helpers.formatDate(data.duedate, helpers.getShortDateFormat())
// } else {
// dueDateInput = $('div#tDueDate[data-ticketId="' + data._id + '"]')
// if (dueDateInput.length > 0)
// dueDateInput.html(helpers.formatDate(data.duedate, helpers.getShortDateFormat()))
// }
})
}

$scope.updateTicketIssue = function () {
var id = $('#__ticketId').html()
if (id.length > 0) {
Expand Down
18 changes: 18 additions & 0 deletions src/public/js/modules/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ define('modules/ui', [
var ticketTypeSelect = $('select#tType')
var ticketPriority = $('select#tPriority')
var ticketGroup = $('select#tGroup')
var ticketDueDate = $('input#tDueDate')
var ticketTags = $('div#editTags')

var addAttachments = $('form#attachmentForm > div.add-attachment')
Expand Down Expand Up @@ -222,6 +223,10 @@ define('modules/ui', [
ticketGroup.prop('disabled', true)
}

if (ticketDueDate.length > 0) {
ticketDueDate.prop('disabled', true)
}

if (ticketTags.length > 0) {
ticketTags.addClass('hide')
}
Expand Down Expand Up @@ -255,6 +260,10 @@ define('modules/ui', [
ticketGroup.prop('disabled', false)
}

if (ticketDueDate.length > 0) {
ticketDueDate.prop('disabled', false)
}

if (ticketTags.length > 0) {
ticketTags.removeClass('hide')
}
Expand Down Expand Up @@ -473,6 +482,15 @@ define('modules/ui', [
})
}

socketUi.setTicketDueDate = function (ticketId, dueDate) {
var payload = {
ticketId: ticketId,
dueDate: dueDate
}

socket.emit('setTicketDueDate', payload)
}

socketUi.setTicketIssue = function (ticketId, issue, subject) {
var payload = {
ticketId: ticketId,
Expand Down
20 changes: 3 additions & 17 deletions src/public/js/pages/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ define('pages/tickets', [
'datatables',
'dt_responsive',
'dt_grouping',
// 'dt_foundation',
'dt_scroller',
'history'
], function ($, helpers, velocity) {
], function ($, helpers) {
var ticketsPage = {}

ticketsPage.init = function (callback) {
Expand All @@ -37,9 +36,9 @@ define('pages/tickets', [
scrollY: '100%',
columnDefs: [
{ width: '50px', targets: 0 },
{ width: '100px', targets: 1 },
{ width: '50px', targets: 1 },
{ width: '65px', targets: 2 },
{ width: '25%', targets: 3 },
{ width: '20%', targets: 3 },
{ width: '110px', targets: 4 }
],
order: [[2, 'desc']],
Expand All @@ -62,19 +61,6 @@ define('pages/tickets', [
History.pushState(null, 'Ticket - ' + i, '/tickets/' + i)
})

// Overdue Tickets
// var hexDigits = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];

// Function to convert hex format to a rgb color
// function rgb2hex(rgb) {
// rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
// return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]).toLowerCase();
// }

// function hex(x) {
// return isNaN(x) ? '00' : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
// }

$('tr.overdue td').velocity(
{ backgroundColor: '#b71c1c', color: '#ffffff' },
{
Expand Down
7 changes: 7 additions & 0 deletions src/sass/partials/common.sass
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
.marginright30,
.mr-30
margin-right: 30px !important
.ml-0
margin-left: 0 !important
.marginleft5,
.ml-5
margin-left: 5px !important
Expand All @@ -109,6 +111,8 @@
margin-bottom: 15px !important
.mb-25
margin-bottom: 25px !important
.mb-50
margin-bottom: 50px !important
.mr-10
margin-right: 10px !important
.mr-15
Expand Down Expand Up @@ -210,6 +214,9 @@
.font-light,
.text-light
font-weight: 300 !important
.font-size-12,
.small-font
font-size: 12px !important
.font-size-40
font-size: 40px !important

Expand Down
35 changes: 27 additions & 8 deletions src/sass/partials/tickets.sass
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,55 @@ div#accountsTable_wrapper

.ticket-status span
display: block
width: 65px
width: 25px
line-height: 25px
height: 25px
text-align: center
font-size: 12px
font-weight: 300
font-weight: 600
font-family: "Roboto", sans-serif
color: white
background: $ticket_status_closed
//color: white
//background: $ticket_status_closed
//border: 2px solid $ticket_status_closed
+borderRadius(3px)

.ticket-status.ticket-open span,
.ticket-status-open
background: $ticket_status_open !important
color: white !important
.ticket-status.ticket-new span,
.ticket-status-new
background: $ticket_status_new !important
color: white !important
.ticket-status.ticket-pending span,
.ticket-status-pending
background: $ticket_status_pending !important
color: white !important
.ticket-status.ticket-closed span,
.ticket-status-closed
background: $ticket_status_closed !important
color: white !important

.floating-ticket-status
.ticket-status,
.ticket-status span
width: 65px !important
.ticket-status
&.ticket-new span
background: $ticket_status_new !important
color: white !important
&.ticket-open span
background: $ticket_status_open !important
color: white !important
&.ticket-pending span
background: $ticket_status_pending !important
color: white !important
&.ticket-closed span
background: $ticket_status_closed !important
color: white !important

.ticket-priority
border-left: 10px solid transparent
&.ticket-priority-2
border-color: #8e24aa
&.ticket-priority-3
border-color: #e65100

.floating-ticket-status
position: absolute
Expand Down
26 changes: 26 additions & 0 deletions src/socketio/ticketSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function register (socket) {
events.onSetTicketType(socket)
events.onSetTicketPriority(socket)
events.onSetTicketGroup(socket)
events.onSetTicketDueDate(socket)
events.onSetTicketIssue(socket)
events.onSetCommentText(socket)
events.onRemoveComment(socket)
Expand Down Expand Up @@ -262,6 +263,31 @@ events.onSetTicketGroup = function (socket) {
})
}

events.onSetTicketDueDate = function (socket) {
socket.on('setTicketDueDate', function (data) {
var ticketId = data.ticketId
var dueDate = data.dueDate
var ownerId = socket.request.user._id

if (_.isUndefined(ticketId) || _.isUndefined(dueDate)) return true

ticketSchema.getTicketById(ticketId, function (err, ticket) {
if (err) return true

ticket.setTicketDueDate(ownerId, dueDate, function (err, t) {
if (err) return true

t.save(function (err, tt) {
if (err) return true

emitter.emit('ticket:updated', ticketId)
utils.sendToAllConnectedClients(io, 'updateTicketDueDate', tt)
})
})
})
})
}

events.onSetTicketIssue = function (socket) {
socket.on('setTicketIssue', function (data) {
var ticketId = data.ticketId
Expand Down
4 changes: 2 additions & 2 deletions src/socketserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var socketServer = function (ws) {
'use strict'

var socketConfig = {
pingTimeout: nconf.get('socket:pingTimeout') ? nconf.get('socket:pingTimeout') : 5000,
pingInterval: nconf.get('socket:pingInterval') ? nconf.get('socket:pingInterval') : 25000
pingTimeout: nconf.get('socket:pingTimeout') ? nconf.get('socket:pingTimeout') : 15000,
pingInterval: nconf.get('socket:pingInterval') ? nconf.get('socket:pingInterval') : 30000
}

var io = require('socket.io')(ws.server, {
Expand Down
22 changes: 22 additions & 0 deletions src/views/subviews/singleticket.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div ng-init="
ticketId='{{data.ticket._id}}';
ticketType='{{data.ticket.type._id}}';
ticketPriority='{{data.ticket.priority._id}}';
ticketGroup='{{data.ticket.group._id}}';
dueDate='{{formatDate data.ticket.dueDate data.common.shortDateFormat}}';
subscribed={{isSubscribed data.ticket.subscribers data.common.loggedInAccount._id}};
user='{{data.common.loggedInAccount._id}}';">

Expand Down Expand Up @@ -180,6 +182,26 @@
<div id="tGroup" class="input-box" data-ticketId="{{data.ticket._id}}">{{data.ticket.group.name}}</div>
{{/hasPermOverRole}}
</div>
<div class="uk-width-1-1 p-0">
<span>Due Date</span>
{{#hasPermOverRole data.ticket.owner.role data.common.loggedInAccount.role "tickets:update"}}
<input
id="tDueDate"
type="text"
readonly
class="md-input small-font p-0"
data-ticketId="{{data.ticket._id}}"
data-uk-datepicker="{format:'{{data.common.shortDateFormat}}'}"
data-validation="shortDate"
style="width: 97%"
ng-model="dueDate"
ng-change="updateTicketDueDate($event)"
{{#compare data.ticket.status '==' 3}}disabled{{/compare}}
/>
{{else}}
<div id="tDueDate" class="input-box" ng-bind="dueDate"></div>
{{/hasPermOverRole}}
</div>
<div class="uk-width-1-1 nopadding">
<span>Tags
{{#hasPermOverRole data.ticket.owner.role data.common.loggedInAccount.role "tickets:update"}}
Expand Down
Loading

0 comments on commit c9ce050

Please sign in to comment.