Add button to remove all datasync settings from DB
seems useful for someone testing, as prep to make the switch
This commit is contained in:
parent
8aff5d519d
commit
4229798c7b
|
@ -50,9 +50,57 @@
|
|||
</b-button>
|
||||
${h.end_form()}
|
||||
</div>
|
||||
<div class="level-item">
|
||||
<b-button type="is-danger"
|
||||
@click="purgeSettingsInit()"
|
||||
icon-pack="fas"
|
||||
icon-left="trash">
|
||||
Remove All Settings
|
||||
</b-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<b-modal has-modal-card
|
||||
:active.sync="purgeSettingsShowDialog">
|
||||
<div class="modal-card">
|
||||
|
||||
<header class="modal-card-head">
|
||||
<p class="modal-card-title">Remove All Settings</p>
|
||||
</header>
|
||||
|
||||
<section class="modal-card-body">
|
||||
<p class="block">
|
||||
If you like we can remove all DataSync settings from the DB.
|
||||
</p>
|
||||
<p class="block">
|
||||
Note that this tool normally removes all settings first,
|
||||
every time you click "Save Settings". Here though you
|
||||
can "just remove" and <span class="is-italic">not</span>
|
||||
save the current settings.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<footer class="modal-card-foot">
|
||||
<b-button @click="purgeSettingsShowDialog = false">
|
||||
Cancel
|
||||
</b-button>
|
||||
${h.form(request.current_route_url())}
|
||||
${h.csrf_token(request)}
|
||||
${h.hidden('purge_settings', 'true')}
|
||||
<b-button type="is-danger"
|
||||
native-type="submit"
|
||||
:disabled="purgingSettings"
|
||||
icon-pack="fas"
|
||||
icon-left="trash"
|
||||
@click="purgingSettings = true">
|
||||
{{ purgingSettings ? "Working, please wait..." : "Remove All Settings" }}
|
||||
</b-button>
|
||||
${h.end_form()}
|
||||
</footer>
|
||||
</div>
|
||||
</b-modal>
|
||||
|
||||
<b-notification type="is-warning"
|
||||
:active.sync="showConfigFilesNote">
|
||||
## TODO: should link to some ratman page here, yes?
|
||||
|
@ -448,6 +496,9 @@
|
|||
|
||||
ThisPageData.restartCommand = ${json.dumps(restart_command)|n}
|
||||
|
||||
ThisPageData.purgeSettingsShowDialog = false
|
||||
ThisPageData.purgingSettings = false
|
||||
|
||||
ThisPageData.settingsNeedSaved = false
|
||||
ThisPageData.undoChanges = false
|
||||
ThisPageData.savingSettings = false
|
||||
|
@ -692,6 +743,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
ThisPage.methods.purgeSettingsInit = function() {
|
||||
this.purgeSettingsShowDialog = true
|
||||
}
|
||||
|
||||
ThisPage.methods.saveSettings = function() {
|
||||
this.savingSettings = true
|
||||
let url = ${json.dumps(request.current_route_url())|n}
|
||||
|
|
|
@ -30,11 +30,9 @@ import getpass
|
|||
import subprocess
|
||||
import logging
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.datasync.config import load_profiles
|
||||
from rattail.datasync.util import get_lastrun
|
||||
from rattail.datasync.util import get_lastrun, purge_datasync_settings
|
||||
|
||||
from tailbone.views import MasterView
|
||||
from tailbone.util import csrf_token
|
||||
|
@ -100,11 +98,17 @@ class DataSyncChangeView(MasterView):
|
|||
View for configuring the DataSync daemon.
|
||||
"""
|
||||
if self.request.method == 'POST':
|
||||
data = self.request.json_body
|
||||
self.save_settings(data)
|
||||
self.request.session.flash("Settings have been saved. "
|
||||
"You should probably restart DataSync now.")
|
||||
return self.json_response({'success': True})
|
||||
# if self.request.is_xhr and not self.request.POST:
|
||||
if self.request.POST.get('purge_settings'):
|
||||
self.delete_settings()
|
||||
self.request.session.flash("Settings have been removed.")
|
||||
return self.redirect(self.request.current_route_url())
|
||||
else:
|
||||
data = self.request.json_body
|
||||
self.save_settings(data)
|
||||
self.request.session.flash("Settings have been saved. "
|
||||
"You should probably restart DataSync now.")
|
||||
return self.json_response({'success': True})
|
||||
|
||||
profiles = load_profiles(self.rattail_config,
|
||||
include_disabled=True,
|
||||
|
@ -221,28 +225,7 @@ class DataSyncChangeView(MasterView):
|
|||
value=setting['value']))
|
||||
|
||||
def delete_settings(self):
|
||||
model = self.model
|
||||
|
||||
to_delete = [
|
||||
'rattail.datasync.watch',
|
||||
'tailbone.datasync.restart',
|
||||
]
|
||||
for setting in to_delete:
|
||||
setting = self.Session.query(model.Setting).get(setting)
|
||||
if setting:
|
||||
self.Session.delete(setting)
|
||||
|
||||
self.Session.query(model.Setting)\
|
||||
.filter(sa.or_(
|
||||
model.Setting.name.like('rattail.datasync.%.watcher'),
|
||||
model.Setting.name.like('rattail.datasync.%.watcher.db'),
|
||||
model.Setting.name.like('rattail.datasync.%.watcher.delay'),
|
||||
model.Setting.name.like('rattail.datasync.%.watcher.retry_attempts'),
|
||||
model.Setting.name.like('rattail.datasync.%.watcher.retry_delay'),
|
||||
model.Setting.name.like('rattail.datasync.%.consumers'),
|
||||
model.Setting.name.like('rattail.datasync.%.consumers.runas'),
|
||||
model.Setting.name.like('rattail.datasync.%.consumer.%')))\
|
||||
.delete(synchronize_session=False)
|
||||
purge_datasync_settings(self.rattail_config, self.Session())
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
|
|
Loading…
Reference in a new issue