Skip to content

Commit

Permalink
chore(code): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jan 15, 2019
1 parent a0d767b commit 46c7169
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 442 deletions.
2 changes: 1 addition & 1 deletion public/css/plugins.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/plugins.min.css

Large diffs are not rendered by default.

Binary file added public/sounds/click.ogg
Binary file not shown.
Binary file added public/sounds/ding.ogg
Binary file not shown.
Binary file added public/sounds/error.ogg
Binary file not shown.
Binary file added public/sounds/messagereceived.ogg
Binary file not shown.
Binary file added public/sounds/messagesent.ogg
Binary file not shown.
Binary file added public/sounds/success.ogg
Binary file not shown.
2 changes: 1 addition & 1 deletion src/backup/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function createZip(callback) {
if (err.code === 'ENOENT')
winston.warn(err);
else {
winston.error(err);
winston.error(err) ;
return callback(err);
}
});
Expand Down
21 changes: 9 additions & 12 deletions src/backup/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,19 @@ function runRestore(file, callback) {
var FILE = process.env.FILE;
if (!FILE) return process.send({success: false, error: 'Invalid File'});

if (!fs.existsSync(path.join(__dirname, '../../backups', FILE))) {
process.send({success: false, error: 'FILE NOT FOUND'});
return;
}
if (!fs.existsSync(path.join(__dirname, '../../backups', FILE)))
return process.send({success: false, error: 'FILE NOT FOUND'});


var options = { keepAlive: 0, auto_reconnect: false, connectTimeoutMS: 5000, useNewUrlParser: true };
database.init(function(e, db) {
if (e) {
process.send({success: false, error: e});
return;
}
if (e)
return process.send({success: false, error: e});


if (!db) {
process.send({success: false, error: {message: 'Unable to open database'}});
return;
}
if (!db)
return process.send({success: false, error: {message: 'Unable to open database'}});


databaseName = database.db.connection.db.databaseName;

Expand Down
73 changes: 0 additions & 73 deletions src/controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,79 +246,6 @@ apiController.logout = function(req, res) {
});
};

/**
* @name apiController.devices
* @description Stores all device related functions
* @namespace
*/
apiController.devices = {};

/**
* Sets the device token for a given account via access token.
*
* @param {object} req Express Request
* @param {object} res Express Response
* @return {JSON} Json object with token
* @example
* //Return
* {
* success: {boolean},
* error: {string},
* token: {string}
* }
*/
apiController.devices.setDeviceToken = function(req, res) {
var accessToken = req.headers.accesstoken;
var token = req.body.token;

if (_.isUndefined(accessToken) || _.isNull(accessToken)) return res.status(401).json({error: 'Invalid Access Token'});
if (_.isUndefined(token) || _.isNull(token)) return res.status(400).json({error: 'Invalid Device Token'});

userSchema.getUserByAccessToken(accessToken, function(err, user) {
if (err) return res.status(401).json({error: err.message});
if (!user) return res.status(401).json({error: 'Unknown User'});

user.addDeviceToken(token, 1, function(err) {
if (err) return res.status(400).json({error: err.message});

res.json({success: true, token: token});
});
});
};

apiController.devices.testApn = function(req, res) {
var notification = {};
notification.title = 'Test Push Notification [trudesk]';

var userModel = require('../models/user');
var ticketModel = require('../models/ticket');
userModel.getUser('5472dbcd925a4d04c80089ee', function(err, user) {
if (err) {
winston.warn(err);
return true;
}

notification.owner = user;

ticketModel.getTicketByUid(1777, function(err, ticket) {
if (err) {
winston.warn(err);
return true;
}

notification.data = {};
notification.data.ticket = ticket;

var apn = require('../notifications');
apn.pushNotification(notification);
});

});

return res.send('Sent!');

};

/**
* @name apiController.roles
* @description Stores all role/permission related static functions
Expand Down
17 changes: 8 additions & 9 deletions src/controllers/backuprestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ var _ = require('lodash');
var fs = require('fs-extra');
var path = require('path');
var async = require('async');
var winston = require('winston');
var moment = require('moment');

var backup_restore = {};
var backupRestore = {};

function formatBytes(bytes, fixed) {
if (!fixed) fixed = 2;
Expand All @@ -30,7 +29,7 @@ function formatBytes(bytes, fixed) {
return (bytes / 1073741824).toFixed(fixed) + ' GB';
}

backup_restore.getBackups = function(req, res) {
backupRestore.getBackups = function(req, res) {
fs.readdir(path.join(__dirname, '../../backups'), function(err, files) {
if (err) return res.status(400).json({error: err});

Expand Down Expand Up @@ -61,7 +60,7 @@ backup_restore.getBackups = function(req, res) {
});
};

backup_restore.runBackup = function(req, res) {
backupRestore.runBackup = function(req, res) {
var database = require('../database');
var child = require('child_process').fork(path.join(__dirname, '../../src/backup/backup'), { env: { FORK: 1, NODE_ENV: global.env, MONGOURI: database.connectionuri } });
global.forks.push({name: 'backup', fork: child});
Expand Down Expand Up @@ -92,7 +91,7 @@ backup_restore.runBackup = function(req, res) {
});
};

backup_restore.deleteBackup = function(req, res) {
backupRestore.deleteBackup = function(req, res) {
var filename = req.params.backup;
if (_.isUndefined(filename) || !fs.existsSync(path.join(__dirname, '../../backups/', filename)))
return res.status(400).json({success: false, error: 'Invalid Filename'});
Expand All @@ -104,7 +103,7 @@ backup_restore.deleteBackup = function(req, res) {
});
};

backup_restore.restoreBackup = function(req, res) {
backupRestore.restoreBackup = function(req, res) {
var database = require('../database');

var file = req.body.file;
Expand Down Expand Up @@ -156,7 +155,7 @@ backup_restore.restoreBackup = function(req, res) {
});
};

backup_restore.hasBackupTools = function(req, res) {
backupRestore.hasBackupTools = function(req, res) {
if (require('os').platform() === 'win32')
return res.json({success: true});

Expand All @@ -167,7 +166,7 @@ backup_restore.hasBackupTools = function(req, res) {
});
};

backup_restore.uploadBackup = function(req, res) {
backupRestore.uploadBackup = function(req, res) {
var Busboy = require('busboy');
var busboy = new Busboy({
headers: req.headers,
Expand Down Expand Up @@ -218,4 +217,4 @@ backup_restore.uploadBackup = function(req, res) {
req.pipe(busboy);
};

module.exports = backup_restore;
module.exports = backupRestore;
65 changes: 32 additions & 33 deletions src/public/js/angularjs/controllers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,38 @@ define(['angular', 'underscore', 'jquery', 'modules/socket', 'uikit', 'modules/t
var form = $('#createTagForm');
if (!form.isValid(null, null, false))
return true;
else {
var tagName = form.find('input[name="tagName"]').val();
if (!tagName || tagName.length < 2) return true;

$http.post('/api/v1/tags/create', {
tag: tagName
}, {
headers: {
'Content-Type': 'application/json'
}
}).then(function successCallback(response) {
var data = response.data;
helpers.UI.showSnackbar('Tag: ' + tagName + ' created successfully', false);
if (page === 'settings') {
var time = new Date().getTime();
History.pushState(null, null, '/settings/tickets/?refresh=' + time);
} else if (page === 'singleticket') {
var tagModal = $('#createTagModal');
var tagFormField = $('select#tags');
tagFormField.append('<option id="TAG__' + data.tag._id + '" value="' + data.tag._id + '">' + data.tag.name + '</option>');
tagFormField.find('option#TAG__' + data.tag._id).prop('selected', true);
tagFormField.trigger('chosen:updated');
form.find('#tag').val('');
if (tagModal.length > 0) UI.modal(tagModal).hide();
$timeout(function() {
$scope.showTags($event);
}, 250);
}
}, function errorCallback(err) {
helpers.UI.showSnackbar('Unable to create tag. Check console', true);
$log.error(err);
});
}

var tagName = form.find('input[name="tagName"]').val();
if (!tagName || tagName.length < 2) return true;

$http.post('/api/v1/tags/create', {
tag: tagName
}, {
headers: {
'Content-Type': 'application/json'
}
}).then(function successCallback(response) {
var data = response.data;
helpers.UI.showSnackbar('Tag: ' + tagName + ' created successfully', false);
if (page === 'settings') {
var time = new Date().getTime();
History.pushState(null, null, '/settings/tickets/?refresh=' + time);
} else if (page === 'singleticket') {
var tagModal = $('#createTagModal');
var tagFormField = $('select#tags');
tagFormField.append('<option id="TAG__' + data.tag._id + '" value="' + data.tag._id + '">' + data.tag.name + '</option>');
tagFormField.find('option#TAG__' + data.tag._id).prop('selected', true);
tagFormField.trigger('chosen:updated');
form.find('#tag').val('');
if (tagModal.length > 0) UI.modal(tagModal).hide();
$timeout(function() {
$scope.showTags($event);
}, 250);
}
}, function errorCallback(err) {
helpers.UI.showSnackbar('Unable to create tag. Check console', true);
$log.error(err);
});
};

//NG Init function
Expand Down
9 changes: 7 additions & 2 deletions src/public/js/angularjs/controllers/settings-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ define([
$uploadButton.removeClass('hide');
$scope.getBackups();
$backupUploadSelect.val(null);
helpers.UI.playSound('success');
}, 1500);
}
};
Expand All @@ -85,7 +86,7 @@ define([
$http.get('/api/v1/backup/hastools')
.then(function success(res) {
$scope.hasTools = (res.data && res.data.success);
}, function error(err) {
}, function error() {
$scope.hasTools = false;
}).then(function() {
$scope.loadingTools = false;
Expand All @@ -99,7 +100,7 @@ define([
if (res.data && res.data.success === true)
$scope.backupFiles = res.data.files;
}, function error(err) {
console.log(err);
$log.error(err);
});
};

Expand All @@ -112,8 +113,12 @@ define([
$log.log(res);
$button.parent().find('.uk-progress').addClass('hide');
$button.show();
helpers.UI.showSnackbar('Backup completed successfully.', false);
helpers.UI.playSound('success');
$scope.getBackups();
}, function error(err) {
helpers.UI.playSound('error');
helpers.UI.showSnackbar('Error: ' + err, true);
$log.error(err);
});
};
Expand Down
33 changes: 16 additions & 17 deletions src/public/js/angularjs/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1041,26 +1041,25 @@ define([
var form = $('#createTicketTypeForm');
if (!form.isValid(null, null, false))
return true;
else {
var typeName = form.find('input[name="typeName"]').val();
if (!typeName || typeName.length < 3) return true;

$http.post('/api/v1/tickets/types/create', {
name: typeName
}, {
headers: {
'Content-Type': 'application/json'
}
}).then(function successCallback() {
helpers.UI.showSnackbar('Type: ' + typeName + ' created successfully', false);
var typeName = form.find('input[name="typeName"]').val();
if (!typeName || typeName.length < 3) return true;

History.pushState(null, null, '/settings/tickets/?refresh=true');
$http.post('/api/v1/tickets/types/create', {
name: typeName
}, {
headers: {
'Content-Type': 'application/json'
}
}).then(function successCallback() {
helpers.UI.showSnackbar('Type: ' + typeName + ' created successfully', false);

}, function errorCallback(err) {
helpers.UI.showSnackbar('Unable to create ticket type. Check console', true);
$log.error(err);
});
}
History.pushState(null, null, '/settings/tickets/?refresh=true');

}, function errorCallback(err) {
helpers.UI.showSnackbar('Unable to create ticket type. Check console', true);
$log.error(err);
});
};

$scope.editTicketType = function($event) {
Expand Down
2 changes: 1 addition & 1 deletion src/public/js/angularjs/controllers/singleTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ define(['angular', 'underscore', 'jquery', 'uikit', 'modules/socket', 'modules/n
element: $commentReply[0],
forceSync: true,
minHeight: '220px', //Slighty smaller to adjust the scroll
toolbar: mdeToolbarItems,
toolbar: mdeToolbarItems
});

commentMDE.codemirror.setOption('extraKeys', {
Expand Down
Loading

0 comments on commit 46c7169

Please sign in to comment.