Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/automated backups #2142

Merged
merged 25 commits into from
May 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mostly working
MattDHill committed May 9, 2023
commit edea091674a375af731e901b433a6e52d04a0889
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ <h2 class="center">No services installed!</h2>
[disabled]="!hasSelection"
fill="solid"
color="primary"
(click)="execute()"
(click)="done()"
class="enter-click btn-128"
>
{{ btnText }}
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@ import { DataModel, PackageState } from 'src/app/services/patch-db/data-model'
import { PatchDB } from 'patch-db-client'
import { firstValueFrom } from 'rxjs'

export interface BackupSelectOptions {}

@Component({
selector: 'backup-select',
templateUrl: './backup-select.page.html',
styleUrls: ['./backup-select.page.scss'],
})
export class BackupSelectPage {
@Input() btnText!: string
@Input() selectedIds: string[] = []

hasSelection = false
selectAll = false
pkgs: {
@@ -41,7 +41,7 @@ export class BackupSelectPage {
title,
icon: pkg.icon,
disabled: pkg.state !== PackageState.Installed,
checked: pkg.state === PackageState.Installed,
checked: this.selectedIds.includes(id),
}
})
.sort((a, b) =>
@@ -56,7 +56,7 @@ export class BackupSelectPage {
this.modalCtrl.dismiss()
}

async execute() {
async done() {
const pkgIds = this.pkgs.filter(p => p.checked).map(p => p.id)
this.modalCtrl.dismiss(pkgIds)
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import { TargetSelectPage } from '../../../modals/target-select/target-select.pa
styleUrls: ['./job-options.component.scss'],
})
export class JobOptionsComponent {
@Input() job!: Omit<BackupJob, 'id'>
@Input() job!: BackupJobBuilder

constructor(private readonly modalCtrl: ModalController) {}

@@ -36,6 +36,7 @@ export class JobOptionsComponent {
component: BackupSelectPage,
componentProps: {
btnText: 'Done',
selectedIds: this.job['package-ids'],
},
})

@@ -69,7 +70,7 @@ export class BackupJobBuilder {

return {
name,
'target-id': (target as any).id, // @TODO fix
'target-id': target.id,
cron,
'package-ids': this['package-ids'],
now,
@@ -82,7 +83,7 @@ export class BackupJobBuilder {
return {
id,
name,
'target-id': (target as any).id, // @TODO fix
'target-id': target.id,
cron,
'package-ids': this['package-ids'],
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
<ion-item-group>
<job-options [job]="job"></job-options>

<ion-item *ngIf="">
<ion-item>
<ion-label>
<h2>Also Execute Now</h2>
</ion-label>
Original file line number Diff line number Diff line change
@@ -6,19 +6,29 @@ import cronstrue from 'cronstrue'
})
export class ToHumanCronPipe implements PipeTransform {
transform(cron: string): { message: string; color: string } {
const toReturn = {
message: '',
color: 'success',
}

try {
return {
message: cronstrue.toString(cron, {
verbose: true,
throwExceptionOnParseError: true,
}),
color: 'success',
const human = cronstrue.toString(cron, {
verbose: true,
throwExceptionOnParseError: true,
})
const zero = Number(cron[0])
const one = Number(cron[1])
if (Number.isNaN(zero) || Number.isNaN(one)) {
throw new Error(
`${human}. Cannot run cron jobs more than once per hour`,
)
}
toReturn.message = human
} catch (e) {
return {
message: e as string,
color: 'danger',
}
toReturn.message = e as string
toReturn.color = 'danger'
}

return toReturn
}
}