delete recovered

This commit is contained in:
Drew Ansbacher
2021-10-11 12:52:43 -06:00
committed by Aiden McClelland
parent 7dcb4239df
commit 71ce2b064f
6 changed files with 69 additions and 25 deletions

View File

@@ -146,8 +146,8 @@
<p>{{ rec.version | displayEmver }}</p>
</ion-label>
<div *ngIf="!rec.installing" slot="end">
<ion-button fill="clear" color="danger" (click)="uninstall(rec, i)">
<ion-icon slot="icon-only" name="close"></ion-icon>
<ion-button fill="clear" color="danger" (click)="deleteRecovered(rec, i)">
<ion-icon slot="icon-only" name="trash"></ion-icon>
<!-- Remove -->
</ion-button>
<ion-button fill="clear" color="success" (click)="install(rec)">

View File

@@ -10,6 +10,8 @@ import { isEmptyObject, exists } from 'src/app/util/misc.util'
import { PackageLoadingService, ProgressData } from 'src/app/services/package-loading.service'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { ErrorToastService } from 'src/app/services/error-toast.service'
import { AlertController } from '@ionic/angular'
import { exec } from 'child_process'
@Component({
selector: 'app-list',
@@ -35,6 +37,7 @@ export class AppListPage {
private readonly api: ApiService,
private readonly patch: PatchDbService,
private readonly errToast: ErrorToastService,
private readonly alertCtrl: AlertController,
) { }
ngOnInit () {
@@ -129,15 +132,37 @@ export class AppListPage {
}
}
async uninstall (pkg: RecoveredInfo, index: number): Promise<void> {
pkg.installing = true
try {
await this.api.uninstallPackage({ id: pkg.id })
this.recoveredPkgs.splice(index, 1)
} catch (e) {
this.errToast.present(e)
pkg.installing = false
async deleteRecovered (pkg: RecoveredInfo, index: number): Promise<void> {
const execute = async () => {
pkg.installing = true
try {
await this.api.deleteRecoveredPackage({ id: pkg.id })
this.recoveredPkgs.splice(index, 1)
} catch (e) {
this.errToast.present(e)
pkg.installing = false
}
}
const alert = await this.alertCtrl.create({
header: 'Delete Data',
message: `This action will permanently delete all data associated with ${pkg.title}.`,
buttons: [
{
text: 'Cancel',
role: 'cancel',
},
{
text: 'Execute',
handler: () => {
execute()
},
cssClass: 'enter-click',
},
],
})
await alert.present()
}
private subscribeBoth (): Subscription {

View File

@@ -178,6 +178,9 @@ export module RR {
export type UninstallPackageReq = WithExpire<{ id: string }> // package.uninstall
export type UninstallPackageRes = WithRevision<null>
export type DeleteRecoveredPackageReq = { id: string } // package.delete-recovered
export type DeleteRecoveredPackageRes = WithRevision<null>
export type DryConfigureDependencyReq = { 'dependency-id': string, 'dependent-id': string } // package.dependency.configure.dry
export type DryConfigureDependencyRes = object

View File

@@ -175,6 +175,12 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
abstract dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise<RR.DryConfigureDependencyRes>
protected abstract deleteRecoveredPackageRaw (params: RR.UninstallPackageReq): Promise<RR.UninstallPackageRes>
deleteRecoveredPackage = (params: RR.UninstallPackageReq) => this.syncResponse(
() => this.deleteRecoveredPackageRaw(params),
)()
// Helper allowing quick decoration to sync the response patch and return the response contents.
// Pass in a tempUpdate function which returns a UpdateTemp corresponding to a temporary
// state change you'd like to enact prior to request and expired when request terminates.

View File

@@ -260,6 +260,10 @@ export class LiveApiService extends ApiService {
return this.http.rpcRequest({ method: 'package.uninstall.dry', params })
}
async deleteRecoveredPackageRaw (params: RR.DeleteRecoveredPackageReq): Promise <RR.DeleteRecoveredPackageRes> {
return this.http.rpcRequest({ method: 'package.delete-recovered', params })
}
async uninstallPackageRaw (params: RR.UninstallPackageReq): Promise <RR.UninstallPackageRes> {
return this.http.rpcRequest({ method: 'package.uninstall', params })
}

View File

@@ -478,26 +478,32 @@ export class MockApiService extends ApiService {
},
]
let res: any
try {
res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
setTimeout(async () => {
const patch = [
{
op: PatchOp.REMOVE,
path: `/package-data/${params.id}`,
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}, this.revertTime)
} catch (e) {
res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
setTimeout(async () => {
const patch = [
{
op: PatchOp.REMOVE,
path: `/recovered-packages/${params.id}`,
path: `/package-data/${params.id}`,
},
]
res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}, this.revertTime)
return res
}
async deleteRecoveredPackageRaw (params: RR.DeleteRecoveredPackageReq): Promise<RR.DeleteAllNotificationsRes> {
await pauseFor(2000)
let res: any
const patch = [
{
op: PatchOp.REMOVE,
path: `/recovered-packages/${params.id}`,
},
]
res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
return res
}