Skip to content

Commit

Permalink
feat: add button to delete remote config sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Clem-Fern authored and Eugeny committed Jan 30, 2023
1 parent 9ceb6b4 commit ce6ed52
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
Expand Down
18 changes: 18 additions & 0 deletions tabby-settings/src/components/configSyncSettingsTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
16 changes: 15 additions & 1 deletion tabby-settings/src/services/configSync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit ce6ed52

Please sign in to comment.