22import { Listing , DropdownItem , Header , Button } from " @statamic/cms/ui" ;
33import { requireElevatedSession } from " @statamic/cms"
44import { useBackupStore } from " ../store" ;
5+ import { ref , useTemplateRef } from " vue" ;
6+ import { useResumable } from " ../resumable" ;
7+
8+ const props = defineProps ([' chunkSize' ]);
59
610const backupStore = useBackupStore ();
711
12+ const dropZone = useTemplateRef (" dropZone" );
13+ const browseTarget = ref (null );
14+
15+ const { files } = useResumable ({ chunkSize: props .chunkSize ?? 2 * 1024 * 1024 , dropZone, browseTarget });
16+
817backupStore .startPolling ();
918
19+
20+
1021const restoreFrom = async (id ) => {
1122
1223 try {
@@ -44,12 +55,40 @@ const queueBackup = async () => {
4455 }
4556}
4657
58+ const deleteBackup = async (id ) => {
59+ try {
60+ await requireElevatedSession ();
61+
62+ const { data } = await window .Statamic .$app .config .globalProperties .$axios .delete (cp_url (` api/backups/${ id} ` ));
63+
64+ Statamic .$toast .info (__ (data .message ));
65+ } catch (e) {
66+ console .error (e);
67+
68+ if (error .response .data .message ) {
69+ Statamic .$toast .error (message);
70+ } else {
71+ Statamic .$toast .error (__ (' statamic-backup::backup.destroy.failed' ));
72+ }
73+ }
74+ }
75+
4776< / script>
77+
4878< template>
4979 < Header : icon= " database" : title= " __('statamic-backup::backup.title')" >
50- <Button icon =" save" variant =" primary" v-on:click =" queueBackup" :disabled =" !backupStore.abilities.backup.isPossible" >{{ __("statamic-backup::backup.create") }}</Button >
80+ < Button variant= " subtle" ref= " browseTarget" > {{ __ (" statamic-backup::backup.upload.label" ) }}< / Button>
81+ < Button variant= " primary" v- on: click= " queueBackup"
82+ : disabled= " !backupStore.abilities.backup.isPossible" > {{ __ (" statamic-backup::backup.create" ) }}< / Button>
5183 < / Header>
5284
85+ < p v- for = " file in files" : key= " file.file.uniqueIdentifier" class = " mb-2" >
86+ < span> {{ file .file .fileName }}< / span>
87+ < span v- if = " file.status === 'uploading'" > - {{ Math .round (file .progress * 100 ) }}% < / span>
88+ < span v- if = " file.status === 'retrying'" > - {{ __ (' statamic-backup::backup.upload.retrying' ) }}< / span>
89+ < span v- if = " file.status === 'error'" class = " text-red-600" > - {{ __ (' statamic-backup::backup.upload.error' ) }}< / span>
90+ < / p>
91+
5392 < Listing : allowSearch= " false" : allowCustomizingColumns= " false" : url= " cp_url('api/backups')" >
5493 < template #prepended- row- actions= " { row }" >
5594 < DropdownItem v- if = " backupStore.abilities.download.isPermitted"
@@ -58,8 +97,8 @@ const queueBackup = async () => {
5897 < DropdownItem v- if = " backupStore.abilities.restore.isPermitted"
5998 : disabled= " !backupStore.abilities.restore.isPossible" @click= " restoreFrom(row.id)"
6099 : text= " __('statamic-backup::backup.restore.label')" / >
61- <DropdownItem v-if =" backupStore.abilities.destroy.isPermitted" :dangerous = " true "
62- @click =" () => console.log( row.id, row.name )" :text =" __('statamic-backup::backup.destroy.label')" />
100+ < DropdownItem v- if = " backupStore.abilities.destroy.isPermitted" variant = " destructive "
101+ @click= " deleteBackup( row.id)" : text= " __('statamic-backup::backup.destroy.label')" / >
63102 < / template>
64103 < / Listing>
65104< / template>
0 commit comments