Skip to content

Commit

Permalink
fix(install): default setting for skipping elastic search
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Sep 19, 2021
1 parent 3678292 commit 88df9b0
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 167 deletions.
10 changes: 5 additions & 5 deletions src/client/containers/Settings/Elasticsearch/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
6 changes: 4 additions & 2 deletions src/controllers/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]']

Expand Down Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions src/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion src/install/mongotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
322 changes: 170 additions & 152 deletions src/public/js/angularjs/controllers/settingsElasticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
};

});
});
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'
}
)
}
})
})
Loading

0 comments on commit 88df9b0

Please sign in to comment.