From 362c4f3d00b15d28cb84e7380cae7a6af688d57e Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Sat, 2 Mar 2019 02:39:04 -0500 Subject: [PATCH] perf(code): cleanup --- .gitignore | 2 + package.json | 1 + src/public/js/angularjs/controllers.js | 15 +- .../js/angularjs/controllers/accounts.js | 459 ++---------------- .../controllers/settings-permissions.js | 195 -------- src/public/js/pages/accounts.js | 314 ------------ src/public/js/pages/editaccount.js | 38 -- src/public/js/pages/pageloader.js | 21 +- src/public/js/pages/settings.js | 42 -- src/public/js/pages/settingsTicketTypes.js | 56 --- src/public/js/pages/tags.js | 56 --- yarn.lock | 70 ++- 12 files changed, 110 insertions(+), 1159 deletions(-) delete mode 100644 src/public/js/angularjs/controllers/settings-permissions.js delete mode 100644 src/public/js/pages/accounts.js delete mode 100644 src/public/js/pages/editaccount.js delete mode 100644 src/public/js/pages/settings.js delete mode 100644 src/public/js/pages/settingsTicketTypes.js delete mode 100644 src/public/js/pages/tags.js diff --git a/.gitignore b/.gitignore index 8641f1b58..f7c829d2e 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ public/uploads/assets/*.* backups/ public/uploads/assets/upload/ + +stats\.json diff --git a/package.json b/package.json index 57b65ba18..960c50b81 100644 --- a/package.json +++ b/package.json @@ -163,6 +163,7 @@ "supertest": "3.4.1", "terser-webpack-plugin": "1.2.1", "webpack": "4.29.0", + "webpack-bundle-analyzer": "3.0.4", "webpack-cli": "3.2.1" }, "release": { diff --git a/src/public/js/angularjs/controllers.js b/src/public/js/angularjs/controllers.js index 4fcbb5ca8..64a62041c 100644 --- a/src/public/js/angularjs/controllers.js +++ b/src/public/js/angularjs/controllers.js @@ -26,7 +26,6 @@ define([ 'angularjs/controllers/notices', 'angularjs/controllers/plugins', 'angularjs/controllers/reports', - 'angularjs/controllers/settings-permissions', 'angularjs/controllers/editor' ], function ($, angular, _) { return angular @@ -42,19 +41,7 @@ define([ 'trudesk.controllers.notices', 'trudesk.controllers.plugins', 'trudesk.controllers.reports', - 'trudesk.controllers.settings.permissions', 'trudesk.controllers.editor' ]) - .controller('TrudeskController', function ($rootScope, $scope) { - $scope.submitForm = function (formName, $event) { - if (_.isNull(formName) || _.isUndefined(formName)) return true - - $event.preventDefault() - - var form = $('#' + formName) - if (!_.isUndefined(form)) { - form.submit() - } - } - }) + .controller('TrudeskController', function ($rootScope, $scope) {}) }) diff --git a/src/public/js/angularjs/controllers/accounts.js b/src/public/js/angularjs/controllers/accounts.js index 6cc364834..59cc1581d 100644 --- a/src/public/js/angularjs/controllers/accounts.js +++ b/src/public/js/angularjs/controllers/accounts.js @@ -12,428 +12,39 @@ * Copyright (c) 2014-2019. All rights reserved. */ -define([ - 'angular', - 'underscore', - 'jquery', - 'modules/helpers', - 'uikit', - 'pages/accounts', - 'history', - 'selectize', - 'formvalidator', - 'multiselect' -], function (angular, _, $, helpers, UIkit, accountsPage) { - return angular - .module('trudesk.controllers.accounts', []) - .controller('accountsCtrl', function ($scope, $http, $timeout, $window, $log) { - function checkGroupValidation () { - var data = {} - var form = $('#createAccountForm') - data.aGrps = form.find('select[name="caGrps[]"]').val() - - if (!data.aGrps || data.aGrps.length < 1) { - // Validate Group - $('label[for="caGrps"]').css('color', '#d85030') - $('select[name="caGrps[]"] + .selectize-control > .selectize-input').css('border-bottom', '1px solid #d85030') - $('.aGrps-error-message') - .removeClass('hide') - .css('display', 'block') - .css('color', '#d85030') - .css('font-weight', 'bold') - return false - } - - $('label[for="caGrps"]').css('color', '#4d4d4d') - $('select[name="caGrps[]"] + .selectize-control > .selectize-input').css( - 'border-bottom', - '1px solid rgba(0,0,0,.12)' - ) - $('.aGrps-error-message').addClass('hide') - return true - } - - $scope.createAccount = function (event) { - var data = {} - var form = $('#createAccountForm') - // if (!form.isValid(null, null, false)) return true; - if (!form.isValid(null, null, false)) { - checkGroupValidation() - return false - } - - if (!checkGroupValidation()) { - event.preventDefault() - return false - } - - event.preventDefault() - form.serializeArray().map(function (x) { - data[x.name] = x.value - }) - data.aGrps = form.find('select[name="caGrps[]"]').val() - $http({ - method: 'POST', - url: '/api/v1/users/create', - data: data, - headers: { 'Content-Type': 'application/json' } - }) - .success(function (data) { - if (!data.success) { - if (data.error) { - helpers.UI.showSnackbar('Error: ' + data.error, true) - return - } - - helpers.UI.showSnackbar('Error Creating Account', true) - } - - helpers.UI.showSnackbar({ text: 'Account Created' }) - - // Refresh UserGrid - History.pushState( - null, - null, - '/accounts/?refresh=' + (Math.floor(Math.random() * (99999 - 10000 + 1)) + 10000) - ) - - UIkit.modal('#accountCreateModal').hide() - }) - .error(function (err) { - $log.log('[trudesk:accounts:createAccount]', err) - helpers.UI.showSnackbar('An error occurred while creating the account. Check Console.', true) - }) - } - - var running = false - $scope.deleteAccount = function ($event) { - if (running) { - return true - } - - $event.preventDefault() - var self = $($event.target) - var username = self.attr('data-username') - if (_.isUndefined(username)) { - return true - } - - running = true - $http - .delete('/api/v1/users/' + username) - .success(function (data) { - if (!data.success) { - helpers.UI.showSnackbar(data.error, true) - running = false - return true - } - - if (data.disabled) { - self.parents('.tru-card-head').addClass('tru-card-head-deleted') - self.addClass('hide') - self - .parents('.uk-nav') - .find('.enable-account-action') - .removeClass('hide') - - helpers.UI.showSnackbar('Account ' + username + ' Successfully Disabled', false) - } else { - self - .parents('.tru-card[data-card-username]') - .parent() - .remove() - UIkit.$html.trigger('changed.uk.dom') - - helpers.UI.showSnackbar('Account ' + username + ' Successfully Deleted', false) - } - - running = false - }) - .error(function (err) { - $log.log('[trudesk:accounts:deleteAccount] - Error: ' + err.error) - helpers.UI.showSnackbar(err.error, true) - - running = false - }) - } - - $scope.enableAccount = function ($event) { - $event.preventDefault() - var self = $($event.target) - var username = self.attr('data-username') - if (_.isUndefined(username)) { - return true - } - - $http - .get('/api/v1/users/' + username + '/enable') - .success(function (data) { - if (!data.success) { - helpers.UI.showSnackbar(data.error, true) - return - } - - self.parents('.tru-card-head').removeClass('tru-card-head-deleted') - self.addClass('hide') - self - .parents('.uk-nav') - .find('.delete-account-action') - .removeClass('hide') - - helpers.UI.showSnackbar('Account successfully enabled', false) - }) - .error(function (err) { - $log.log('[trudesk:accounts:enableAccount] - Error: ' + err.error) - helpers.UI.showSnackbar(err.error, true) - }) - } - - $scope.editAccount = function ($event) { - $event.preventDefault() - - var self = $($event.target) - var username = self.attr('data-username') - if (_.isUndefined(username)) return true - - var $menu = self.parents('.tru-card-head-menu') - if (!_.isUndefined($menu)) $menu.find('.uk-dropdown').removeClass('uk-dropdown-shown uk-dropdown-active') - - $http - .get('/api/v1/users/' + username) - .success(function (data) { - var editAccountModal = $('#editAccountModal') - var form = editAccountModal.find('form#editAccountForm') - var user = data.user - if (_.isUndefined(user) || _.isNull(user)) return true - - var loggedInAccount = $window.trudeskSessionService.getUser() - if (loggedInAccount === null) return true - - var $userHeadingContent = $('.user-heading-content') - $userHeadingContent.find('.js-username').text(user.username) - if (!user.title) $userHeadingContent.find('.js-user-title').text('') - else $userHeadingContent.find('.js-user-title').text(user.title) - - var isEditingSelf = false - if (user.username === loggedInAccount.username) isEditingSelf = true - - var canEdit = false - var hasEdit = helpers.canUser('accounts:update') - if (isEditingSelf && hasEdit) { - hasEdit = true - canEdit = true - } - - if ( - helpers.hasHierarchyEnabled(loggedInAccount.role._id) && - helpers.hasPermOverRole(user.role._id, loggedInAccount.role._id) - ) - canEdit = true - - if (!canEdit) { - // Disable editing user with higher roles. - form - .find('#aPass') - .parent() - .hide() - form - .find('#aPassConfirm') - .parent() - .hide() - form - .find('#aRole') - .parent() - .hide() - form.find('#aFullname').attr('disabled', 'disabled') - form.find('#aTitle').attr('disabled', 'disabled') - form.find('#aEmail').attr('disabled', 'disabled') - form.find('#aGrps').attr('disabled', 'disabled') - form - .find('#aSaveButton') - .addClass('disabled') - .attr('disabled', 'disabled') - } else { - form - .find('#aPass') - .parent() - .show() - form - .find('#aPassConfirm') - .parent() - .show() - form - .find('#aRole') - .parent() - .show() - form.find('#aFullname').attr('disabled', false) - form.find('#aTitle').attr('disabled', false) - form.find('#aEmail').attr('disabled', false) - form.find('#aGrps').attr('disabled', false) - form - .find('#aSaveButton') - .removeClass('disabled') - .attr('disabled', false) - } - - form.find('#aId').val(user._id) - form - .find('#aUsername') - .val(user.username) - .prop('disabled', true) - .parent() - .addClass('md-input-filled') - form - .find('#aFullname') - .val(user.fullname) - .parent() - .addClass('md-input-filled') - form - .find('#aTitle') - .val(user.title) - .parent() - .addClass('md-input-filled') - form - .find('#aEmail') - .val(user.email) - .parent() - .addClass('md-input-filled') - form.find('#aRole option[value="' + user.role._id + '"]').prop('selected', true) - if (form.find('#aRole').length > 0) { - var $selectizeRole = form.find('#aRole')[0].selectize - $selectizeRole.setValue(user.role._id, true) - - var items = _.map($selectizeRole.options, function (m) { - return m.value - }) - - var assignableRoles = helpers.parseRoleHierarchy(loggedInAccount.role._id) - - _.each(items, function (role) { - var i = _.find(assignableRoles, function (o) { - return o.toString() === role.toString() - }) - if (_.isUndefined(i)) $selectizeRole.removeOption(role) - }) - - $selectizeRole.refreshOptions(false) - } - - form.find('#aGrps').multiSelect('deselect_all') - form.find('#aGrps').multiSelect('select', data.groups) - form.find('#aGrps').multiSelect('refresh') - - // Profile Picture - var aImageUploadForm = $('form#aUploadImageForm') - var image = aImageUploadForm.find('img') - var inputId = aImageUploadForm.find('input#imageUpload_id') - var inputUsername = aImageUploadForm.find('input#imageUpload_username') - inputId.val(user._id) - inputUsername.val(user.username) - if (user.image) - image.attr( - 'src', - '/uploads/users/' + user.image + '?r=' + (Math.floor(Math.random() * (99999 - 10000 + 1)) + 10000) - ) - else - image.attr( - 'src', - '/uploads/users/defaultProfile.jpg?r=' + (Math.floor(Math.random() * (99999 - 10000 + 1)) + 10000) - ) - - var modal = UIkit.modal('#editAccountModal') - if (!modal.isActive()) modal.show() - }) - .error(function (err) { - $log.log('[trudesk:Accounts:editAccount] - Error: ' + err.error) - helpers.UI.showSnackbar(err.error, true) - }) - } - - $scope.saveAccount = function () { - var form = $('#editAccountForm') - var data = form.serializeObject() - data.aUsername = form.find('#aUsername').val() - data.aGrps = form.find('#aGrps').val() - data.saveGroups = true - data.aRole = form.find('#aRole').val().length > 0 ? form.find('#aRole').val() : undefined - data.aPass = form.find('#aPass').val().length > 0 ? form.find('#aPass').val() : undefined - data.aPassConfirm = form.find('#aPassConfirm').val().length > 0 ? form.find('#aPassConfirm').val() : undefined - - $http({ - method: 'PUT', - url: '/api/v1/users/' + data.aUsername, - data: data, - headers: { 'Content-Type': 'application/json' } - }) - .success(function (data) { - if (!data.success) { - if (data.error) { - helpers.UI.showSnackbar('Error: ' + data.error, true) - return - } - - helpers.UI.showSnackbar('Error Saving Account', true) - } - - helpers.UI.showSnackbar('Account Saved', false) - - UIkit.modal('#editAccountModal').hide() - - accountsPage.init(null, true) - }) - .error(function (err) { - $log.log('[trudesk:accounts:saveAccount] - ' + err.error.message) - helpers.UI.showSnackbar('Error: ' + err.error.message, true) - }) - } - - $scope.accountEditPic = function () { - throttledAccountPicClick() - } - - $scope.selectAccountsImport = function (event, type) { - if ($(event.currentTarget).hasClass('card-disabled')) { - return false - } - - switch (type) { - case 'csv': - $('#csv_wizard_card').removeClass('uk-hidden') - $('#json-import-selector').addClass('card-disabled') - $('#ldap-import-selector').addClass('card-disabled') - break - case 'json': - $('#json_wizard_card').removeClass('uk-hidden') - $('#csv-import-selector').addClass('card-disabled') - $('#ldap-import-selector').addClass('card-disabled') - break - case 'ldap': - $('#ldap_wizard_card').removeClass('uk-hidden') - $('#csv-import-selector').addClass('card-disabled') - $('#json-import-selector').addClass('card-disabled') - } - } - - $scope.resetWizardSelection = function () { - $('#csv_wizard_card').addClass('uk-hidden') - $('#json_wizard_card').addClass('uk-hidden') - $('#ldap_wizard_card').addClass('uk-hidden') - - $('#csv-import-selector').removeClass('card-disabled') - $('#json-import-selector').removeClass('card-disabled') - $('#ldap-import-selector').removeClass('card-disabled') - } - - function throttledAccountPicClick () { - $timeout(function () { - var $profileImageInput = $('#profileImageInput') - $profileImageInput.on('click', function (event) { - // This function is a firefox hack to stop it from spawning 100000 file dialogs - event.stopPropagation() - }) - - $profileImageInput.trigger('click') - }, 0) - } - }) +define(['angular', 'underscore', 'jquery'], function (angular, _, $) { + return angular.module('trudesk.controllers.accounts', []).controller('accountsCtrl', function ($scope) { + $scope.selectAccountsImport = function (event, type) { + if ($(event.currentTarget).hasClass('card-disabled')) { + return false + } + + switch (type) { + case 'csv': + $('#csv_wizard_card').removeClass('uk-hidden') + $('#json-import-selector').addClass('card-disabled') + $('#ldap-import-selector').addClass('card-disabled') + break + case 'json': + $('#json_wizard_card').removeClass('uk-hidden') + $('#csv-import-selector').addClass('card-disabled') + $('#ldap-import-selector').addClass('card-disabled') + break + case 'ldap': + $('#ldap_wizard_card').removeClass('uk-hidden') + $('#csv-import-selector').addClass('card-disabled') + $('#json-import-selector').addClass('card-disabled') + } + } + + $scope.resetWizardSelection = function () { + $('#csv_wizard_card').addClass('uk-hidden') + $('#json_wizard_card').addClass('uk-hidden') + $('#ldap_wizard_card').addClass('uk-hidden') + + $('#csv-import-selector').removeClass('card-disabled') + $('#json-import-selector').removeClass('card-disabled') + $('#ldap-import-selector').removeClass('card-disabled') + } + }) }) diff --git a/src/public/js/angularjs/controllers/settings-permissions.js b/src/public/js/angularjs/controllers/settings-permissions.js deleted file mode 100644 index 062a9f067..000000000 --- a/src/public/js/angularjs/controllers/settings-permissions.js +++ /dev/null @@ -1,195 +0,0 @@ -/** - . .o8 oooo - .o8 "888 `888 - .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - ======================================================================== - Created: 11/15/2018 - Author: Chris Brame - - **/ - -define(['angular', 'underscore', 'jquery', 'modules/helpers', 'uikit'], function (angular, _, $, helpers, UIkit) { - return angular - .module('trudesk.controllers.settings.permissions', ['ngSanitize']) - .controller('PermissionsCtrl', function ($scope, $http, $timeout, $log) { - $scope.init = function () { - $timeout(function () { - // Permissions Sortable - var permissionList = $('#permissionList') - if (permissionList.length > 0) { - var permissionSort = UIkit.sortable(permissionList, { - handleClass: 'drag-handle' - }) - - permissionSort.on('change.uk.sortable', function () { - var items = permissionList.children('li') - var arr = [] - for (var k = 0; k < items.length; k++) arr.push($(items[k]).attr('data-key')) - - $http - .put( - '/api/v1/settings/updateroleorder', - { - roleOrder: arr - }, - { - headers: { - 'Content-Type': 'application/json' - } - } - ) - .then( - function successCallback () {}, - function errorCallback (response) { - $log.error(response) - helpers.UI.showSnackbar('Error: ' + response.data.error, true) - } - ) - }) - } - - var $ticketsAllCheck = $('input[name="perm-tickets-all"]') - - $ticketsAllCheck.change(function (e) { - toggleAllPerm('tickets', e) - }) - - if ($ticketsAllCheck.is(':checked')) toggleAll($ticketsAllCheck.parents('form'), 'tickets', true) - - var $accountPermAllCheck = $('input[name="perm-accounts-all"]') - $accountPermAllCheck.change(function (e) { - toggleAllPerm('accounts', e, ['import']) - }) - - if ($accountPermAllCheck.is(':checked')) - toggleAll($accountPermAllCheck.parents('form'), 'accounts', true, ['import']) - - $('input[name="perm-accounts-import"]').change(function (e) { - var checked = $(e.currentTarget).prop('checked') - if (checked) $('input[name="perm-accounts-create"]').prop('checked', checked) - }) - }, 0) - } - - function toggleAllPerm (type, e, specials) { - var $currentTarget = $(e.currentTarget) - var checked = e.target.checked - var $form = $currentTarget.parents('form') - - toggleAll($form, type, checked, specials) - } - - function toggleAll ($form, type, checked, specials) { - $form - .find('input[name="perm-' + type + '-create"]') - .prop('checked', checked) - .prop('disabled', checked) - $form - .find('input[name="perm-' + type + '-view"]') - .prop('checked', checked) - .prop('disabled', checked) - $form - .find('input[name="perm-' + type + '-edit"]') - .prop('checked', checked) - .prop('disabled', checked) - $form - .find('input[name="perm-' + type + '-delete"]') - .prop('checked', checked) - .prop('disabled', checked) - - if (specials && specials.length > 0) { - for (var i = 0; i < specials.length; i++) - $form - .find('input[name="perm-' + type + '-' + specials[i] + '"]') - .prop('checked', checked) - .prop('disabled', checked) - } - } - - function handleAnyChange (type, e) { - var checked = e.target.checked - var $form = $(e.target).parents('form') - var $type = $form.find('input[name="perm-' + type + '"]') - - $type.prop('disabled', checked) - if (checked) $type.prop('checked', false) - } - - function sanitizePermissions (data) { - var obj = {} - var tObj = {} - var arr = [] - _.each(data, function (v, k) { - k = k.replace('perm', '').replace(/-/g, '') - tObj[k] = v - }) - - tObj = _.mapObject(tObj, function (v) { - return v === 'on' - }) - - // Admin - obj.admin = tObj.isadmin ? ['*'] : null - obj.setting = tObj.isadmin ? ['*'] : null - - // Agent - if (tObj.isagent) obj.agent = ['*'] - - // Tickets - if (tObj.ticketsall) obj.ticket = ['*'] - else { - if (tObj.ticketscreate) arr.push('create') - if (tObj.ticketsview) arr.push('view') - if (tObj.ticketsedit) arr.push('edit') - if (tObj.ticketsdelete) arr.push('delete') - - if (arr.length > 0) obj.ticket = arr - } - - // Accounts - if (tObj.accountsall) obj.account = ['*'] - else { - if (tObj.accountscreate) arr.push('create') - if (tObj.accountsview) arr.push('view') - if (tObj.accountsedit) arr.push('edit') - if (tObj.accountsdelete) arr.push('delete') - - // specials - if (tObj.accountsimport) arr.push('import') - - if (arr.length > 0) obj.account = arr - } - - return obj - } - - $scope.saveRolePermissions = function (roleId, $event) { - $event.preventDefault() - var $form = $($event.currentTarget) - if ($form.length < 1) { - helpers.showSnackbar('Invalid Form. Check Console.', true) - $log.log($form) - return false - } - - var data = $form.serializeObject() - var hierarchy = data['perm-enable-hierarchy'] === 'on' - data = sanitizePermissions(data) - data._id = roleId - data.hierarchy = hierarchy - - $http - .put('/api/v1/roles', data) - .success(function () { - helpers.UI.showSnackbar('Role Permissions Saved', false) - }) - .error(function (err) { - $log.error(err) - }) - } - }) -}) diff --git a/src/public/js/pages/accounts.js b/src/public/js/pages/accounts.js deleted file mode 100644 index cecae6267..000000000 --- a/src/public/js/pages/accounts.js +++ /dev/null @@ -1,314 +0,0 @@ -/* - * . .o8 oooo - * .o8 "888 `888 - * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - * ======================================================================== - * Author: Chris Brame - * Updated: 1/20/19 4:43 PM - * Copyright (c) 2014-2019. All rights reserved. - */ - -define('pages/accounts', [ - 'underscore', - 'jquery', - 'angular', - 'modules/helpers', - 'uikit', - 'modules/socket', - 'isinview', - 'datatables', - 'dt_responsive', - 'dt_grouping', - // 'dt_foundation', - 'dt_scroller', - 'history' -], function (_, $, angular, helpers, UIkit, socket) { - 'use strict' - var accountsPage = {} - - function capitalizeFirstLetter (str) { - return str.charAt(0).toUpperCase() + str.slice(1) - } - - accountsPage.init = function (callback, reset) { - $(document).ready(function () { - var $accountList = $('#account_list') - var $scroller = $accountList.parents('.scrollable') - var $scrollspy = $('#scrollspy') - var $spinner = $scrollspy.find('i') - var $filterAll = $('.filter-all') - var $nextPage = 1 - var $enabled = true - var $loading = false - - if (reset) { - $nextPage = 0 - getAccounts() - } - - UIkit.grid($accountList, { - controls: '#account_list_filter', - gutter: 20 - }) - - $scroller.scroll(function () { - if ($scrollspy.isInView($scroller)) { - var run = _.throttle(getAccounts, 500) - run() - } - }) - - $('#account_list_filter li a').on('click', function () { - $('#account_list_search').val('') - $('.tru-card[data-search-result]').remove() - setTimeout(function () { - helpers.resizeAll() - }, 280) - }) - - $('#account_list_search').keyup(function (e) { - e.preventDefault() - var key = e.keyCode || e.which - - var sValue = $(this) - .val() - .toLowerCase() - - if (key === 13) { - if (sValue.length < 3) { - $('#account_list_filter li.uk-active a').trigger('click') - return true - } - - $.ajax({ - url: '/api/v1/users?search=' + sValue, - success: function (data) { - $accountList.children().css('display', 'none') - var users = data.users - var html = '' - _.each(users, function (u) { - html += buildUserHTML(u, true) - }) - - var $injector = angular.injector(['ng', 'trudesk']) - $injector.invoke([ - '$compile', - '$rootScope', - function ($compile, $rootScope) { - var $scope = $accountList.append(html).scope() - $compile($accountList)($scope || $rootScope) - $rootScope.$digest() - } - ]) - - $('.s-ajaxify').on('click', function (e) { - e.preventDefault() - var href = $(e.target).attr('href') - - History.pushState(null, null, href) - }) - - UIkit.$html.trigger('changed.uk.dom') - helpers.resizeAll() - - socket.ui.updateUsers() - }, - error: function (error) { - console.log('[trudesk:accountsPage:setupGrid] - Error: ' + error.error) - } - }) - } - - return false - }) - - function getAccounts () { - if (!$enabled || $loading) { - return false - } - - if (!$filterAll.hasClass('uk-active')) return true - - $loading = true - $spinner.removeClass('uk-hidden') - - $.ajax({ - url: '/api/v1/users?limit=20&page=' + $nextPage - }) - .done(function (data) { - $spinner.addClass('uk-hidden') - var users = data.users - if (_.size(users) < 1) { - $enabled = false - $loading = false - return false - } - - var html = '' - - _.each(users, function (u) { - var h = null - if (reset) { - $accountList.html('') - h = buildUserHTML(u, true) - reset = false - } else { - h = buildUserHTML(u, false) - } - - if (h.length > 0) html += h - }) - - var $injector = angular.injector(['ng', 'trudesk']) - $injector.invoke([ - '$compile', - '$rootScope', - function ($compile, $rootScope) { - var $scope = $accountList.append(html).scope() - $compile($accountList)($scope || $rootScope) - $rootScope.$digest() - } - ]) - - UIkit.$html.trigger('changed.uk.dom') - helpers.resizeAll() - - $('.s-ajaxify').on('click', function (e) { - e.preventDefault() - var href = $(e.target).attr('href') - - History.pushState(null, null, href) - }) - - $nextPage = $nextPage + 1 - $loading = false - - socket.ui.updateUsers() - }) - .fail(function (err) { - console.log('[trudesk:accountsPage:setupGrid] - Error: ' + err.error) - $loading = false - }) - } - - if (typeof callback === 'function') { - return callback() - } - }) - } - - function buildUserHTML (user, addRemove) { - if (!addRemove) { - var $card = $('[data-card-username="' + user.username + '"]') - if ($card.length > 0) return '' - } - - var html = '
' - if (addRemove) { - html += '
' - } else { - html += '
' - } - - if (user.role.isAdmin) { - html += '
' - } else { - html += '
' - } - - html += '
' - html += '' - html += '
' - html += '' - html += '
' - html += '
' - html += '
' - html += '' - - html += '
' - html += '

' - html += user.fullname - html += - '' + - (_.isUndefined(user.title) ? '' : capitalizeFirstLetter(user.title)) + - '' - html += '

' - html += '
' - html += '
' - html += '
    ' - html += '
  • ' - html += '
    ' - html += 'Role' - html += '' + capitalizeFirstLetter(user.role.name) + '' - html += '
    ' - html += '
  • ' - html += '
  • ' - html += '
    ' - html += 'Email' - html += - '' + - user.email + - '' - html += '
    ' - html += '
  • ' - html += '
  • ' - html += '
    ' - html += 'Groups' - html += '' - _.each(user.groups, function (g) { - html += g - if (_.size(user.groups) > 1) { - if (_.last(user.groups) !== g) { - html += ', ' - } - } - }) - html += '' - html += '
    ' - html += '
  • ' - html += '
' - html += '
' - html += '
' - html += '
' - - return html - } - - return accountsPage -}) diff --git a/src/public/js/pages/editaccount.js b/src/public/js/pages/editaccount.js deleted file mode 100644 index 3bdc505df..000000000 --- a/src/public/js/pages/editaccount.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * . .o8 oooo - * .o8 "888 `888 - * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - * ======================================================================== - * Author: Chris Brame - * Updated: 1/20/19 4:43 PM - * Copyright (c) 2014-2019. All rights reserved. - */ - -define('pages/editaccount', ['jquery', 'history'], function ($) { - var editaccount = {} - - editaccount.init = function () { - $(document).ready(function () { - var $hoverAction = $('.hoverAction') - $hoverAction.parent().off('hover') - $hoverAction.parent().hover( - function () { - var self = $(this) - var hoverAction = self.find('.hoverAction') - hoverAction.stop().animate({ bottom: 0 }, 300) - }, - function () { - var self = $(this) - var hoverAction = self.find('.hoverAction') - hoverAction.stop().animate({ bottom: '-256px' }, 300) - } - ) - }) - } - - return editaccount -}) diff --git a/src/public/js/pages/pageloader.js b/src/public/js/pages/pageloader.js index 5cafa199f..9f682a0c7 100644 --- a/src/public/js/pages/pageloader.js +++ b/src/public/js/pages/pageloader.js @@ -46,14 +46,11 @@ define('pages/pageloader', ['async', 'jquery'], function (async, $) { 'pages/notices', 'pages/createNotice', 'pages/plugins', - 'pages/settings', 'pages/logs', - 'pages/tags', - 'pages/settingsTicketTypes', 'modules/ajaximgupload', 'modules/attachmentUpload' - ], function (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) { + ], function (a, b, c, d, e, f, g, h, i, j, k, l, m, n) { async.parallel( [ function (done) { @@ -93,20 +90,8 @@ define('pages/pageloader', ['async', 'jquery'], function (async, $) { l.init(done) }, function (done) { - m.init(done) - }, - function (done) { - n.init(done) - }, - function (done) { - o.init(done) - }, - function (done) { - p.init(done) - }, - function (done) { - q.init() - r.init() + m.init() + n.init() return done() } diff --git a/src/public/js/pages/settings.js b/src/public/js/pages/settings.js deleted file mode 100644 index bced02d8c..000000000 --- a/src/public/js/pages/settings.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * . .o8 oooo - * .o8 "888 `888 - * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - * ======================================================================== - * Author: Chris Brame - * Updated: 1/20/19 4:43 PM - * Copyright (c) 2014-2019. All rights reserved. - */ - -define('pages/settings', ['jquery', 'underscore', 'modules/helpers', 'uikit', 'history'], function ( - $, - _, - helpers, - UIkit, - History -) { - var settingsPage = {} - - settingsPage.init = function (callback) { - $(document).ready(function () { - var testPage = $('#page-content').find('div[data-page="settings"]') - if (testPage.length < 1) { - if (typeof callback === 'function') { - return callback() - } - - return false - } - - if (typeof callback === 'function') { - return callback() - } - }) - } - - return settingsPage -}) diff --git a/src/public/js/pages/settingsTicketTypes.js b/src/public/js/pages/settingsTicketTypes.js deleted file mode 100644 index 593fdb1f2..000000000 --- a/src/public/js/pages/settingsTicketTypes.js +++ /dev/null @@ -1,56 +0,0 @@ -/* - * . .o8 oooo - * .o8 "888 `888 - * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - * ======================================================================== - * Author: Chris Brame - * Updated: 1/20/19 4:43 PM - * Copyright (c) 2014-2019. All rights reserved. - */ - -define('pages/settingsTicketTypes', [ - 'jquery', - 'modules/helpers', - 'datatables', - 'dt_responsive', - 'dt_grouping', - 'dt_scroller', - 'history' -], function ($, helpers) { - var settingsTicketTypesPage = {} - - settingsTicketTypesPage.init = function (callback) { - $(document).ready(function () { - var table = $('#ticketTypesTable') - table.dataTable({ - searching: false, - bLengthChange: false, - bPaginate: false, - bInfo: false, - bSort: false, - scrollY: '100%', - order: [[1, 'desc']], - columnDefs: [ - { width: '50px', targets: 0 }, - { width: '100%', targets: 1 } - // {"width": "15%", "targets": 2} - ], - oLanguage: { - sEmptyTable: 'No tags to display.' - } - }) - - helpers.resizeDataTables('.ticketTypeList') - - if (typeof callback === 'function') { - return callback() - } - }) - } - - return settingsTicketTypesPage -}) diff --git a/src/public/js/pages/tags.js b/src/public/js/pages/tags.js deleted file mode 100644 index 23fe56660..000000000 --- a/src/public/js/pages/tags.js +++ /dev/null @@ -1,56 +0,0 @@ -/* - * . .o8 oooo - * .o8 "888 `888 - * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - * ======================================================================== - * Author: Chris Brame - * Updated: 1/20/19 4:43 PM - * Copyright (c) 2014-2019. All rights reserved. - */ - -define('pages/tags', [ - 'jquery', - 'modules/helpers', - 'datatables', - 'dt_responsive', - 'dt_grouping', - 'dt_scroller', - 'history' -], function ($, helpers) { - var tagsPage = {} - - tagsPage.init = function (callback) { - $(document).ready(function () { - var table = $('#tagsTable') - table.dataTable({ - searching: false, - bLengthChange: false, - bPaginate: false, - bInfo: false, - bSort: false, - scrollY: '100%', - order: [[1, 'desc']], - columnDefs: [ - { width: '50px', targets: 0 }, - { width: '100%', targets: 1 } - // {"width": "15%", "targets": 2} - ], - oLanguage: { - sEmptyTable: 'No tags to display.' - } - }) - - helpers.resizeDataTables('.tagsList') - - if (typeof callback === 'function') { - return callback() - } - }) - } - - return tagsPage -}) diff --git a/yarn.lock b/yarn.lock index f8d4515a1..b075a26e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1322,6 +1322,11 @@ acorn@^4.0.4, acorn@~4.0.2: resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" integrity sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c= +acorn@^5.7.3: + version "5.7.3" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" + integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== + acorn@^6.0.2, acorn@^6.0.5: version "6.0.6" resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.6.tgz#cd75181670d5b99bdb1b1c993941d3a239ab1f56" @@ -1922,6 +1927,16 @@ better-assert@~1.0.0: dependencies: callsite "1.0.0" +bfj@^6.1.1: + version "6.1.1" + resolved "https://registry.yarnpkg.com/bfj/-/bfj-6.1.1.tgz#05a3b7784fbd72cfa3c22e56002ef99336516c48" + integrity sha512-+GUNvzHR4nRyGybQc2WpNJL4MJazMuvf92ueIyA0bIkPRwhhQu3IfZQ2PSoVPpCBJfmoSdOxu5rnotfFLlvYRQ== + dependencies: + bluebird "^3.5.1" + check-types "^7.3.0" + hoopy "^0.1.2" + tryer "^1.0.0" + big-integer@^1.6.17: version "1.6.41" resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.41.tgz#6fb0e51bc8661129ef3832d46c939170b81ca794" @@ -2560,6 +2575,11 @@ check-error@^1.0.2: resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= +check-types@^7.3.0: + version "7.4.0" + resolved "https://registry.yarnpkg.com/check-types/-/check-types-7.4.0.tgz#0378ec1b9616ec71f774931a3c6516fad8c152f4" + integrity sha512-YbulWHdfP99UfZ73NcUDlNJhEIDgm9Doq9GhpyXbF+7Aegi3CVV7qqMCKTTqJxlvEvnQBp9IA+dxsGN6xK/nSg== + cheerio@1.0.0-rc.2: version "1.0.0-rc.2" resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.2.tgz#4b9f53a81b27e4d5dac31c0ffd0cfa03cc6830db" @@ -2902,7 +2922,7 @@ commander@2.6.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.6.0.tgz#9df7e52fb2a0cb0fb89058ee80c3104225f37e1d" integrity sha1-nfflL7Kgyw+4kFjugMMQQiXzfh0= -commander@^2.14.1, commander@^2.15.1, commander@^2.19.0, commander@^2.9.0, commander@^2.x: +commander@^2.14.1, commander@^2.15.1, commander@^2.18.0, commander@^2.19.0, commander@^2.9.0, commander@^2.x: version "2.19.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== @@ -3984,6 +4004,11 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= +ejs@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.6.1.tgz#498ec0d495655abc6f23cd61868d926464071aa0" + integrity sha512-0xy4A/twfrRCnkhfk8ErDi5DqdAsAqeGxht4xkCUrsvhhbQNs7E+4jV0CN7+NKIY0aHE72+XvqtBIXzD31ZbXQ== + electron-to-chromium@^1.3.103: version "1.3.109" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.109.tgz#ee04a55a5157a5580a5ea88e526b02c84a3a7bc8" @@ -4722,7 +4747,7 @@ express-session@1.15.6: uid-safe "~2.1.5" utils-merge "1.0.1" -express@4.16.4: +express@4.16.4, express@^4.16.3: version "4.16.4" resolved "https://registry.yarnpkg.com/express/-/express-4.16.4.tgz#fddef61926109e24c515ea97fd2f1bdbf62df12e" integrity sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg== @@ -4963,6 +4988,11 @@ file-uri-to-path@1: resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== +filesize@^3.6.1: + version "3.6.1" + resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.6.1.tgz#090bb3ee01b6f801a8a8be99d31710b3422bb317" + integrity sha512-7KjR1vv6qnicaPMi1iiTcI85CyYwRO/PSFCu6SvqL8jN2Wjt/NIYQTFtFs7fSDCYOstUkEWIQGFUg5YZQfjlcg== + fill-range@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -5753,6 +5783,14 @@ gzip-size@^3.0.0: dependencies: duplexer "^0.1.1" +gzip-size@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-5.0.0.tgz#a55ecd99222f4c48fd8c01c625ce3b349d0a0e80" + integrity sha512-5iI7omclyqrnWw4XbXAmGhPsABkSIDQonv2K0h61lybgofWa6iZyvrI3r2zsJH4P8Nb64fFVzlvfhs0g7BBxAA== + dependencies: + duplexer "^0.1.1" + pify "^3.0.0" + handlebars@4.0.13: version "4.0.13" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.13.tgz#89fc17bf26f46fd7f6f99d341d92efaae64f997d" @@ -5967,6 +6005,11 @@ hooker@~0.2.3: resolved "https://registry.yarnpkg.com/hooker/-/hooker-0.2.3.tgz#b834f723cc4a242aa65963459df6d984c5d3d959" integrity sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk= +hoopy@^0.1.2: + version "0.1.4" + resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d" + integrity sha512-HRcs+2mr52W0K+x8RzcLzuPPmVIKMSv97RGHy0Ea9y/mpcaK+xTrjICA04KAHi4GRzxliNqNJEFYWHghy3rSfQ== + hosted-git-info@^2.1.4, hosted-git-info@^2.6.0, hosted-git-info@^2.7.1: version "2.7.1" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047" @@ -12781,6 +12824,11 @@ trim-right@^1.0.1: dependencies: glob "^7.1.2" +tryer@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8" + integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA== + tslib@1.9.3, tslib@^1, tslib@^1.9.0, tslib@^1.9.3: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" @@ -13325,6 +13373,24 @@ web-resource-inliner@^4.2.1: valid-data-url "^0.1.4" xtend "^4.0.0" +webpack-bundle-analyzer@3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-3.0.4.tgz#095638487a664162f19e3b2fb7e621b7002af4b8" + integrity sha512-ggDUgtKuQki4vmc93Ej65GlYxeCUR/0THa7gA+iqAGC2FFAxO+r+RM9sAUa8HWdw4gJ3/NZHX/QUcVgRjdIsDg== + dependencies: + acorn "^5.7.3" + bfj "^6.1.1" + chalk "^2.4.1" + commander "^2.18.0" + ejs "^2.6.1" + express "^4.16.3" + filesize "^3.6.1" + gzip-size "^5.0.0" + lodash "^4.17.10" + mkdirp "^0.5.1" + opener "^1.5.1" + ws "^6.0.0" + webpack-cli@3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.2.1.tgz#779c696c82482491f0803907508db2e276ed3b61"