refactor: move /admin into vue component (#3466)
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
window.PageAdmin = {
|
||||
template: '#page-admin',
|
||||
mixins: [windowMixin],
|
||||
data() {
|
||||
return {
|
||||
tab: 'funding',
|
||||
settings: {},
|
||||
formData: {
|
||||
lnbits_exchange_rate_providers: [],
|
||||
lnbits_audit_exclude_paths: [],
|
||||
lnbits_audit_include_paths: [],
|
||||
lnbits_audit_http_response_codes: []
|
||||
},
|
||||
isSuperUser: false,
|
||||
needsRestart: false
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
await this.getSettings()
|
||||
const hash = window.location.hash.replace('#', '')
|
||||
if (hash) {
|
||||
this.tab = hash
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
checkChanges() {
|
||||
return !_.isEqual(this.settings, this.formData)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getDefaultSetting(fieldName) {
|
||||
LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
`/admin/api/v1/settings/default?field_name=${fieldName}`
|
||||
)
|
||||
.then(response => {
|
||||
this.formData[fieldName] = response.data.default_value
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
restartServer() {
|
||||
LNbits.api
|
||||
.request('GET', '/admin/api/v1/restart/')
|
||||
.then(response => {
|
||||
this.$q.notify({
|
||||
type: 'positive',
|
||||
message: 'Success! Restarted Server',
|
||||
icon: null
|
||||
})
|
||||
this.needsRestart = false
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
},
|
||||
async getSettings() {
|
||||
await LNbits.api
|
||||
.request(
|
||||
'GET',
|
||||
'/admin/api/v1/settings',
|
||||
this.g.user.wallets[0].adminkey
|
||||
)
|
||||
.then(response => {
|
||||
this.isSuperUser = response.data.is_super_user || false
|
||||
this.settings = response.data
|
||||
this.formData = {...this.settings}
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
},
|
||||
updateSettings() {
|
||||
const data = _.omit(this.formData, [
|
||||
'is_super_user',
|
||||
'lnbits_allowed_funding_sources',
|
||||
'touch'
|
||||
])
|
||||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
'/admin/api/v1/settings',
|
||||
this.g.user.wallets[0].adminkey,
|
||||
data
|
||||
)
|
||||
.then(response => {
|
||||
this.needsRestart =
|
||||
this.settings.lnbits_backend_wallet_class !==
|
||||
this.formData.lnbits_backend_wallet_class
|
||||
this.settings = this.formData
|
||||
this.formData = _.clone(this.settings)
|
||||
Quasar.Notify.create({
|
||||
type: 'positive',
|
||||
message: `Success! Settings changed! ${
|
||||
this.needsRestart ? 'Restart required!' : ''
|
||||
}`,
|
||||
icon: null
|
||||
})
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
},
|
||||
deleteSettings() {
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to restore settings to default?')
|
||||
.onOk(() => {
|
||||
LNbits.api
|
||||
.request('DELETE', '/admin/api/v1/settings')
|
||||
.then(response => {
|
||||
Quasar.Notify.create({
|
||||
type: 'positive',
|
||||
message:
|
||||
'Success! Restored settings to defaults. Restarting...',
|
||||
icon: null
|
||||
})
|
||||
this.$q.localStorage.clear()
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
})
|
||||
},
|
||||
downloadBackup() {
|
||||
window.open('/admin/api/v1/backup', '_blank')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user