diff --git a/src/client/containers/Settings/Elasticsearch/index.jsx b/src/client/containers/Settings/Elasticsearch/index.jsx index 4f04f15c3..6731164dd 100644 --- a/src/client/containers/Settings/Elasticsearch/index.jsx +++ b/src/client/containers/Settings/Elasticsearch/index.jsx @@ -122,7 +122,10 @@ class ElasticsearchSettingsContainer extends React.Component { onFormSubmit (e) { e.preventDefault() - const payload = [{ name: 'es:host', value: this.state.host }, { name: 'es:port', value: this.state.port }] + const payload = [ + { name: 'es:host', value: this.state.host }, + { name: 'es:port', value: this.state.port } + ] this.props.updateMultipleSettings(payload) } @@ -310,7 +313,4 @@ const mapStateToProps = state => ({ settings: state.settings.settings }) -export default connect( - mapStateToProps, - { updateSetting, updateMultipleSettings } -)(ElasticsearchSettingsContainer) +export default connect(mapStateToProps, { updateSetting, updateMultipleSettings })(ElasticsearchSettingsContainer) diff --git a/src/controllers/install.js b/src/controllers/install.js index cce85e9bc..60e2b5e18 100644 --- a/src/controllers/install.js +++ b/src/controllers/install.js @@ -138,6 +138,8 @@ installController.install = function (req, res) { // ElasticSearch var eEnabled = data['elastic[enable]'] + if (typeof eEnabled === 'string') eEnabled = eEnabled.toLowerCase() === 'true' + var eHost = data['elastic[host]'] var ePort = data['elastic[port]'] @@ -172,14 +174,14 @@ installController.install = function (req, res) { }) }, function (next) { - if (!eEnabled) return next() + // if (!eEnabled) return next() async.parallel( [ function (done) { SettingsSchema.create( { name: 'es:enable', - value: true + value: eEnabled }, done ) diff --git a/src/elasticsearch/index.js b/src/elasticsearch/index.js index 76db6def0..3cbdcb875 100644 --- a/src/elasticsearch/index.js +++ b/src/elasticsearch/index.js @@ -247,6 +247,7 @@ ES.init = function (callback) { var settings = s.data.settings var ENABLED = settings.elasticSearchConfigured.value + if (!ENABLED) { if (_.isFunction(callback)) return callback() diff --git a/src/install/mongotest.js b/src/install/mongotest.js index 4d0aee6e9..465c01b3e 100644 --- a/src/install/mongotest.js +++ b/src/install/mongotest.js @@ -44,7 +44,8 @@ winston.add(winston.transports.Console, { keepAlive: 0, auto_reconnect: false, connectTimeoutMS: 5000, - useNewUrlParser: true + useNewUrlParser: true, + useUnifiedTopology: true } database.init( function (e, db) { diff --git a/src/public/js/angularjs/controllers/settingsElasticSearch.js b/src/public/js/angularjs/controllers/settingsElasticSearch.js index 2dc0f4757..9cb5cf279 100644 --- a/src/public/js/angularjs/controllers/settingsElasticSearch.js +++ b/src/public/js/angularjs/controllers/settingsElasticSearch.js @@ -12,155 +12,173 @@ **/ -define(['angular', 'underscore', 'jquery', 'modules/helpers', 'modules/socket', 'uikit', 'history', 'angularjs/services'], function(angular, _, $, helpers, socketClient, Uikit) { - return angular.module('trudesk.controllers.settingsElasticSearch', ['trudesk.services.settings']) - .controller('settingsElasticSearchCtrl', function(SettingsService, $scope, $http, $timeout, $document, $log) { - - // Local Functions - function toggleAnimation(forceState, state) { - var animateItems = $('.setting-item-wrap.animate-in'); - var docElemStyle = $document[0].documentElement.style; - var transitionProp = angular.isString(docElemStyle.transition) ? 'transition' : 'WebkitTransition'; - - for (var i = 0; i < animateItems.length; i++) { - var item = animateItems[i]; - item.style[ transitionProp + 'Delay' ] = ( i * 50 ) + 'ms'; - if (forceState) { - if (state) - item.classList.add('is-in'); - else - item.classList.remove('is-in'); - } else - item.classList.toggle('is-in'); - } - } - - function getStatus() { - console.log(SettingsService.getSettings().elasticSearchConfigured.value); - if (!SettingsService.getSettings().elasticSearchConfigured.value) { - $scope.esStatus = 'Not Configured'; - $scope.indexCount = '0'; - $scope.inSyncText = 'Not Configured'; - return false; - } - - // Get Elastic Search Status - $http.get('/api/v1/admin/elasticsearch/status') - .then(function success(response) { - $scope.esStatus = response.data.status.esStatus; - $scope.esStatusClass = 'none'; - if ($scope.esStatus.toLowerCase() === 'connected') - $scope.esStatusClass = 'success'; - if ($scope.esStatus.toLowerCase() === 'error') - $scope.esStatusClass = 'danger'; - - $scope.indexCount = response.data.status.indexCount; - $scope.indexCountFormatted = $scope.indexCount.toLocaleString(); - - if (response.data.status.inSync) { - $scope.inSyncText = 'In Sync'; - $scope.inSyncClass = 'bg-success'; - } else { - $scope.inSyncText = 'Out of Sync'; - $scope.inSyncClass = 'bg-warning'; - } - - // Refresh on Rebuild every 5s - if ($scope.esStatus.toLowerCase() === 'rebuilding...') { - $timeout(getStatus, 5000); - $('#es-rebuild-btn').attr('disabled', true); - } - }, function error(err) { - $log.error(err); - $scope.esStatus = 'Error'; - $scope.esStatusClass = 'danger'; - $scope.inSyncText = 'Unknown'; - if (err.data.error.message) - helpers.UI.showSnackbar('Error: ' + err.data.error.message, true); - else if (err.data.error.msg) - helpers.UI.showSnackbar('Error: An unknown error occurred. Check Console.', true); - else - helpers.UI.showSnackbar('Error: ' + err.data.error, true); - }); - } - - // Scope - - // Vars - $scope.esStatus = 'Please Wait...'; - $scope.indexCount = 0; - $scope.indexCountFormatted = 0; - $scope.inSyncText = 'Please Wait...'; - - $scope.init = function() { - // Animate if enabled - if ($scope.elasticSearchEnable) - toggleAnimation(true, true); - - getStatus(); - }; - - $scope.elasticSearchEnableChange = function() { - toggleAnimation(true, $scope.elasticSearchEnable); - - $http.put('/api/v1/settings', { - name: 'es:enable', - value: $scope.elasticSearchEnable - }, { - headers: { - 'Content-Type': 'application/json' - } - }).then(function successCallback() { - - }, function errorCallback(err) { - helpers.UI.showSnackbar('Error: ' + err, true); - }); - }; - - $scope.esServerFormSubmit = function($event) { - $event.preventDefault(); - - $http.put('/api/v1/settings', [ - { name: 'es:host', value: $scope.esServer }, - { name: 'es:port', value: $scope.esPort } - ], { - headers: { - 'Content-Type': 'application/json' - } - }).then(function successCallback() { - SettingsService.getSettings().elasticSearchConfigured.value = true; - SettingsService.getSettings().elasticSearchHost.value = $scope.esServer; - SettingsService.getSettings().elasticSearchPort.value = $scope.esPort; - helpers.UI.showSnackbar('Settings Saved', false); - }, function errorCallback(err) { - helpers.UI.showSnackbar('Error: ' + err, true); - }); - }; - - $scope.rebuildIndexClicked = function($event) { - $event.preventDefault(); - - Uikit.modal.confirm('Are you sure you want to rebuild the index?', function() { - $http.get( - '/api/v1/admin/elasticsearch/rebuild' - ) - .success(function() { - $scope.esStatus = 'Rebuilding...'; - $scope.esStatusClass = 'text-warning'; - helpers.UI.showSnackbar('Rebuilding Index...', false); - $($event.currentTarget).attr('disabled', true); - $timeout(function() { - getStatus(); - }, 3000); - }) - .error(function(err) { - $log.error('[trudesk:settings:es:RebuildIndex] - Error: ' + err.error); - helpers.UI.showSnackbar('Error: An unknown error occurred. Check Console.', true); - }); - }, { - labels: {'Ok': 'Yes', 'Cancel': 'No'}, confirmButtonClass: 'md-btn-danger' - }); - }; - - }); - }); \ No newline at end of file +define([ + 'angular', + 'underscore', + 'jquery', + 'modules/helpers', + 'modules/socket', + 'uikit', + 'history', + 'angularjs/services' +], function (angular, _, $, helpers, socketClient, Uikit) { + return angular + .module('trudesk.controllers.settingsElasticSearch', ['trudesk.services.settings']) + .controller('settingsElasticSearchCtrl', function (SettingsService, $scope, $http, $timeout, $document, $log) { + // Local Functions + function toggleAnimation (forceState, state) { + var animateItems = $('.setting-item-wrap.animate-in') + var docElemStyle = $document[0].documentElement.style + var transitionProp = angular.isString(docElemStyle.transition) ? 'transition' : 'WebkitTransition' + + for (var i = 0; i < animateItems.length; i++) { + var item = animateItems[i] + item.style[transitionProp + 'Delay'] = i * 50 + 'ms' + if (forceState) { + if (state) item.classList.add('is-in') + else item.classList.remove('is-in') + } else item.classList.toggle('is-in') + } + } + + function getStatus () { + if (!SettingsService.getSettings().elasticSearchConfigured.value) { + $scope.esStatus = 'Not Configured' + $scope.indexCount = '0' + $scope.inSyncText = 'Not Configured' + return false + } + + // Get Elastic Search Status + $http.get('/api/v1/admin/elasticsearch/status').then( + function success (response) { + $scope.esStatus = response.data.status.esStatus + $scope.esStatusClass = 'none' + if ($scope.esStatus.toLowerCase() === 'connected') $scope.esStatusClass = 'success' + if ($scope.esStatus.toLowerCase() === 'error') $scope.esStatusClass = 'danger' + + $scope.indexCount = response.data.status.indexCount + $scope.indexCountFormatted = $scope.indexCount.toLocaleString() + + if (response.data.status.inSync) { + $scope.inSyncText = 'In Sync' + $scope.inSyncClass = 'bg-success' + } else { + $scope.inSyncText = 'Out of Sync' + $scope.inSyncClass = 'bg-warning' + } + + // Refresh on Rebuild every 5s + if ($scope.esStatus.toLowerCase() === 'rebuilding...') { + $timeout(getStatus, 5000) + $('#es-rebuild-btn').attr('disabled', true) + } + }, + function error (err) { + $log.error(err) + $scope.esStatus = 'Error' + $scope.esStatusClass = 'danger' + $scope.inSyncText = 'Unknown' + if (err.data.error.message) helpers.UI.showSnackbar('Error: ' + err.data.error.message, true) + else if (err.data.error.msg) + helpers.UI.showSnackbar('Error: An unknown error occurred. Check Console.', true) + else helpers.UI.showSnackbar('Error: ' + err.data.error, true) + } + ) + } + + // Scope + + // Vars + $scope.esStatus = 'Please Wait...' + $scope.indexCount = 0 + $scope.indexCountFormatted = 0 + $scope.inSyncText = 'Please Wait...' + + $scope.init = function () { + // Animate if enabled + if ($scope.elasticSearchEnable) toggleAnimation(true, true) + + getStatus() + } + + $scope.elasticSearchEnableChange = function () { + toggleAnimation(true, $scope.elasticSearchEnable) + + $http + .put( + '/api/v1/settings', + { + name: 'es:enable', + value: $scope.elasticSearchEnable + }, + { + headers: { + 'Content-Type': 'application/json' + } + } + ) + .then( + function successCallback () {}, + function errorCallback (err) { + helpers.UI.showSnackbar('Error: ' + err, true) + } + ) + } + + $scope.esServerFormSubmit = function ($event) { + $event.preventDefault() + + $http + .put( + '/api/v1/settings', + [{ name: 'es:host', value: $scope.esServer }, { name: 'es:port', value: $scope.esPort }], + { + headers: { + 'Content-Type': 'application/json' + } + } + ) + .then( + function successCallback () { + SettingsService.getSettings().elasticSearchConfigured.value = true + SettingsService.getSettings().elasticSearchHost.value = $scope.esServer + SettingsService.getSettings().elasticSearchPort.value = $scope.esPort + helpers.UI.showSnackbar('Settings Saved', false) + }, + function errorCallback (err) { + helpers.UI.showSnackbar('Error: ' + err, true) + } + ) + } + + $scope.rebuildIndexClicked = function ($event) { + $event.preventDefault() + + Uikit.modal.confirm( + 'Are you sure you want to rebuild the index?', + function () { + $http + .get('/api/v1/admin/elasticsearch/rebuild') + .success(function () { + $scope.esStatus = 'Rebuilding...' + $scope.esStatusClass = 'text-warning' + helpers.UI.showSnackbar('Rebuilding Index...', false) + $($event.currentTarget).attr('disabled', true) + $timeout(function () { + getStatus() + }, 3000) + }) + .error(function (err) { + $log.error('[trudesk:settings:es:RebuildIndex] - Error: ' + err.error) + helpers.UI.showSnackbar('Error: An unknown error occurred. Check Console.', true) + }) + }, + { + labels: { Ok: 'Yes', Cancel: 'No' }, + confirmButtonClass: 'md-btn-danger' + } + ) + } + }) +}) diff --git a/src/settings/defaults.js b/src/settings/defaults.js index e219952ff..cb9394d42 100644 --- a/src/settings/defaults.js +++ b/src/settings/defaults.js @@ -593,7 +593,7 @@ function mailTemplates (callback) { function elasticSearchConfToDB (callback) { var nconf = require('nconf') var elasticsearch = { - enable: nconf.get('elasticsearch:enable'), + enable: nconf.get('elasticsearch:enable') || false, host: nconf.get('elasticsearch:host'), port: nconf.get('elasticsearch:port') } @@ -606,7 +606,7 @@ function elasticSearchConfToDB (callback) { nconf.save(done) }, function (done) { - if (!elasticsearch.enable) return done() + // if (!elasticsearch.enable) return done() SettingsSchema.getSettingByName('es:enable', function (err, setting) { if (err) return done(err) if (!setting) { @@ -617,11 +617,11 @@ function elasticSearchConfToDB (callback) { }, done ) - } + } else done() }) }, function (done) { - if (!elasticsearch.host) return done() + if (!elasticsearch.host) elasticsearch.host = 'localhost' SettingsSchema.getSettingByName('es:host', function (err, setting) { if (err) return done(err) if (!setting) { @@ -632,7 +632,7 @@ function elasticSearchConfToDB (callback) { }, done ) - } + } else done() }) }, function (done) { @@ -647,7 +647,7 @@ function elasticSearchConfToDB (callback) { }, done ) - } + } else done() }) } ], diff --git a/src/settings/settingsUtil.js b/src/settings/settingsUtil.js index b3a9549ec..318e6f652 100644 --- a/src/settings/settingsUtil.js +++ b/src/settings/settingsUtil.js @@ -108,7 +108,7 @@ util.getSettings = function (callback) { s.elasticSearchHost = parseSetting(settings, 'es:host', '') s.elasticSearchPort = parseSetting(settings, 'es:port', 9200) s.elasticSearchConfigured = { - value: s.elasticSearchEnabled.value !== false && !_.isEmpty(s.elasticSearchHost.value) + value: s.elasticSearchEnabled.value === true && !_.isEmpty(s.elasticSearchHost.value) } s.tpsEnabled = parseSetting(settings, 'tps:enable', false) diff --git a/src/views/install.hbs b/src/views/install.hbs index 62c607978..e7a0cde22 100644 --- a/src/views/install.hbs +++ b/src/views/install.hbs @@ -539,6 +539,7 @@ var $connectBtn = $(this); $connectBtn.prop('disabled', true).text('Trying to connect...'); var elasticFormData = $('form#elasticConnection').serializeObject(); + $.ajax({ method: 'POST', url: '/install/elastictest',