Skip to content

Commit

Permalink
style(code): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jan 21, 2019
1 parent 613d763 commit d15bd11
Show file tree
Hide file tree
Showing 46 changed files with 1,732 additions and 1,462 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/public/js/plugins/*
/src/public/js/vendor/*
/mobile/*
/public/*
35 changes: 15 additions & 20 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
{
"plugins": ["node"],
"extends": ["standard", "plugin:node/recommended"],
"plugins": ["import", "prettier", "standard"],
"extends": ["standard", "prettier", "prettier/standard"],
"root": true,
"parserOptions": {
"ecmaVersion": 5
},
"env": {
"browser": true,
"node": true
"node": true,
"mocha": true
},
"rules": {
"standard/no-callback-literal": 0, // enable after error handing refactor
"node/exports-style": ["error", "module.exports"],
"new-cap": 0,
"no-console": "off",
// "new-cap": "error",
"quotes": ["error", "single"],
"curly": ["error", "multi-or-nest"],
"complexity": ["error", 20],
"wrap-iife": ["error", "outside"],
"semi": ["error", "always"],
"no-extra-semi": "error",
"no-func-assign": "error",
"no-redeclare": "error"
"complexity": ["error", 20]
},
"globals": {
"angular": 1,
"define": 1,
"requirejs": 1,
"MG": 1,
"Snackbar": 1,
"ROLES": 1,
"io": 1,
"d3": 1
"angular": true,
"define": true,
"requirejs": true,
"MG": true,
"Snackbar": true,
"ROLES": true,
"io": true,
"d3": true
}
}
2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (grunt) {

express: {
options: {
//Override Defaults
// Override Defaults
},
web: {
options: {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@
"css-loader": "2.1.0",
"eslint": "5.12.1",
"eslint-config-angular": "0.5.0",
"eslint-config-prettier": "3.6.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-angular": "4.0.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-node": "8.0.1",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-promise": "4.0.1",
"eslint-plugin-react": "7.12.4",
"eslint-plugin-standard": "4.0.0",
"exports-loader": "0.7.0",
Expand Down
2 changes: 2 additions & 0 deletions src/cache/quickStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var init = function (tickets, callback) {
function (done) {
if (tickets) {
ticketSchema.populate(tickets, { path: 'owner comments.owner assignee' }, function (err, _tickets) {
if (err) return done(err)

$tickets = _tickets

return done()
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/api/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ apiGroups.get = function (req, res) {

if (hasPublic) {
GroupSchema.getAllPublicGroups(function (err, grps) {
if (err) return res.status(400).json({ success: false, error: err })

groups = groups.concat(grps)

return res.json({ success: true, groups: groups })
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/api/v1/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ apiReports.generate.ticketsByPriority = function (req, res) {
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)
return done(null, grps)
})
} else {
Expand Down Expand Up @@ -199,6 +200,8 @@ apiReports.generate.ticketsByStatus = function (req, res) {
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
Expand Down Expand Up @@ -278,6 +281,8 @@ apiReports.generate.ticketsByTags = function (req, res) {
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
Expand Down Expand Up @@ -356,6 +361,8 @@ apiReports.generate.ticketsByType = function (req, res) {
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
Expand Down Expand Up @@ -434,6 +441,8 @@ apiReports.generate.ticketsByUser = function (req, res) {
function (done) {
if (_.includes(postData.groups, '-1')) {
groupSchema.getAllGroupsNoPopulate(function (err, grps) {
if (err) return done(err)

return done(null, grps)
})
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/api/v1/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ apiTickets.update = function (req, res) {
if (!_.isUndefined(reqTicket.assignee) && !_.isNull(reqTicket.assignee)) {
ticket.assignee = reqTicket.assignee
ticket.populate('assignee', function (err, t) {
if (err) return cb(err)

var HistoryItem = {
action: 'ticket:set:assignee',
description: t.assignee.fullname + ' was set as assignee',
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,17 @@ debugController.populatedatabase = function (req, res) {
},
function (done) {
userSchema.findAll(function (err, users) {
if (err) return done(err)

groupSchema.getAllGroups(function (err, groups) {
if (err) return done(err)

ticketTypeSchema.getTypes(function (err, types) {
if (err) return done(err)

tagSchema.getTags(function (err, tags) {
if (err) return done(err)

var loremIpsum = require('lorem-ipsum')
for (var i = 0; i < 100001; i++) {
var user = users[Math.floor(Math.random() * users.length)]
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ mainController.about = function (req, res) {
var marked = require('marked')
var settings = require('../models/setting')
settings.getSettingByName('legal:privacypolicy', function (err, privacyPolicy) {
if (err)
return res.render('error', {
layout: false,
error: err,
message: err.message
})

var content = {}
content.title = 'About'
content.nav = 'about'
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ reportsController.generate = function (req, res) {

var prioritySchema = require('../models/ticketpriority')
prioritySchema.getPriorities(function (err, priorities) {
if (err) {
return res.render('error', {
layout: false,
error: err,
message: err.message
})
}

content.data.priorities = priorities

return res.render('subviews/reports/generate', content)
Expand Down
4 changes: 0 additions & 4 deletions src/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
* Copyright (c) 2014-2019. All rights reserved.
*/

var async = require('async')
var _ = require('lodash')
var jsStringEscape = require('js-string-escape')
var settingSchema = require('../models/setting')
var ticketTypeSchema = require('../models/tickettype')
var permissions = require('../permissions')
var settingsUtil = require('../settings/settingsUtil')

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ticketsController.getByStatus = function (req, res, next) {
status: []
}

var pathname = url.parse(req.url).pathname
var pathname = url.URL(req.url).pathname
var arr = pathname.split('/')
var tType = 'new'
var s = 0
Expand Down
8 changes: 7 additions & 1 deletion src/emitter/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ var notifications = require('../notifications') // Load Push Events
var hostname = data.hostname

ticketSchema.getTicketById(ticketObj._id, function (err, ticket) {
if (err) return true
if (err) return false

settingsSchema.getSettingsByName(['tps:enable', 'tps:username', 'tps:apikey'], function (err, tpsSettings) {
if (err) return false

var tpsEnabled = _.head(_.filter(tpsSettings, ['name', 'tps:enable']))
var tpsUsername = _.head(_.filter(tpsSettings, ['name', 'tps:username']))
var tpsApiKey = _.head(_.filter(tpsSettings), ['name', 'tps:apikey'])
Expand Down Expand Up @@ -302,6 +304,8 @@ var notifications = require('../notifications') // Load Push Events
io.sockets.emit('updateComments', ticket)

settingsSchema.getSettingsByName(['tps:enable', 'tps:username', 'tps:apikey'], function (err, tpsSettings) {
if (err) return false

var tpsEnabled = _.head(_.filter(tpsSettings, ['name', 'tps:enable']))
var tpsUsername = _.head(_.filter(tpsSettings, ['name', 'tps:username']))
var tpsApiKey = _.head(_.filter(tpsSettings), ['name', 'tps:apikey'])
Expand Down Expand Up @@ -441,6 +445,8 @@ var notifications = require('../notifications') // Load Push Events

emitter.on('ticket:setAssignee', function (data) {
settingsSchema.getSettingsByName(['tps:enable', 'tps:username', 'tps:apikey'], function (err, tpsSettings) {
if (err) return false

var tpsEnabled = _.head(_.filter(tpsSettings, ['name', 'tps:enable']))
var tpsUsername = _.head(_.filter(tpsSettings, ['name', 'tps:username']))
var tpsApiKey = _.head(_.filter(tpsSettings), ['name', 'tps:apikey'])
Expand Down
1 change: 1 addition & 0 deletions src/helpers/hbs/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ var helpers = {
return l >= r
},
typeof: function (l, r) {
// eslint-disable-next-line
return typeof l === r
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/viewdata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,26 @@ viewController.getData = function (request, cb) {
},
function (callback) {
viewController.getShowTourSetting(request, function (err, data) {
if (err) return callback(err)

viewdata.showTour = data

return callback()
})
},
function (callback) {
viewController.getOverdueSetting(request, function (err, data) {
if (err) return callback(err)

viewdata.showOverdue = data

return callback()
})
},
function (callback) {
viewController.getPluginsInfo(request, function (err, data) {
if (err) return callback(err)

viewdata.plugins = data

return callback()
Expand Down Expand Up @@ -589,6 +595,8 @@ viewController.getShowTourSetting = function (request, callback) {

var userSchema = require('../../models/user')
userSchema.getUser(request.user._id, function (err, user) {
if (err) return callback(err)

var hasTourCompleted = false

if (user.preferences.tourCompleted) {
Expand Down
20 changes: 1 addition & 19 deletions src/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,19 @@
* Copyright (c) 2014-2019. All rights reserved.
*/

var _ = require('lodash')

var path = require('path')

var async = require('async')

var express = require('express')

var mongoose = require('mongoose')

var HandleBars = require('handlebars').create()

var hbs = require('express-hbs')

var hbsHelpers = require('../helpers/hbs/helpers')

var winston = require('winston')

var flash = require('connect-flash')

var bodyParser = require('body-parser')

var cookieParser = require('cookie-parser')

var favicon = require('serve-favicon')

var session = require('express-session')

var MongoStore = require('connect-mongo')(session)

var passportConfig = require('../passport')()

var middleware = {}
Expand All @@ -57,13 +40,12 @@ module.exports = function (app, db, callback) {
hbs.express4({
handlebars: HandleBars,
defaultLayout: path.join(__dirname, '../views/layout/main.hbs'),
partialsDir: [path.join(__dirname + '/../views/partials/'), path.join(__dirname + '/../views/subviews/reports')]
partialsDir: [path.join(__dirname, '../views/partials/'), path.join(__dirname, '../views/subviews/reports')]
})
)
app.set('view engine', 'hbs')
hbsHelpers.register(hbs.handlebars)

// app.use(favicon(nconf.get('base_dir') + '/public/img/favicon.ico'));
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cookieParser())
Expand Down
Loading

0 comments on commit d15bd11

Please sign in to comment.