1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-22 20:55:03 +03:00

feat: add button to delete remote config sync

This commit is contained in:
Clem 2023-01-30 15:38:53 +01:00 committed by Eugene
parent 9ceb6b4416
commit ce6ed5267c
3 changed files with 39 additions and 1 deletions

View File

@ -77,6 +77,12 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
)
i.fas.fa-arrow-down
span.ml-2(translate) Download
button.btn.btn-link.ml-1(
(click)='delete(cfg)',
[class.hover-reveal]='!isActiveConfig(cfg)'
)
i.fas.fa-trash
span.ml-2(translate) Delete
a.list-group-item.list-group-item-action.d-flex.align-items-center(
href='#',
(click)='uploadAsNew()'

View File

@ -108,6 +108,24 @@ export class ConfigSyncSettingsTabComponent extends BaseComponent {
this.notifications.info(this.translate.instant('Config downloaded'))
}
async delete (cfg: Config) {
if ((await this.platform.showMessageBox({
type: 'warning',
message: this.translate.instant('Delete the config on the remote side?'),
buttons: [
this.translate.instant('Delete'),
this.translate.instant('Cancel'),
],
defaultId: 1,
cancelId: 1,
})).response === 1) {
return
}
await this.configSync.delete(cfg)
this.loadConfigs()
this.notifications.info(this.translate.instant('Config deleted'))
}
hasMatchingRemoteConfig () {
return !!this.configs?.find(c => this.isActiveConfig(c))
}

View File

@ -75,6 +75,10 @@ export class ConfigSyncService {
})
}
async deleteConfig (id: number): Promise<any> {
return this.request('DELETE', `/api/1/configs/${id}`)
}
setConfig (config: Config): void {
this.config.store.configSync.configID = config.id
this.config.save()
@ -133,6 +137,16 @@ export class ConfigSyncService {
}
}
async delete (config: Config): Promise<void> {
try {
await this.deleteConfig(config.id)
this.logger.debug('Config deleted')
} catch (error) {
this.logger.error('Delete failed:', error)
throw error
}
}
private async readConfigDataForSync (): Promise<any> {
const data = yaml.load(await this.platform.loadConfig()) as any
delete data.configSync
@ -145,7 +159,7 @@ export class ConfigSyncService {
await this.config.save()
}
private async request (method: 'GET'|'POST'|'PATCH', url: string, params = {}) {
private async request (method: 'GET'|'POST'|'PATCH'|'DELETE', url: string, params = {}) {
if (this.config.store.configSync.host.endsWith('/')) {
this.config.store.configSync.host = this.config.store.configSync.host.slice(0, -1)
}