| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | <template> | 
					
						
							|  |  |  |   <div> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |       ref="refImportDialog" | 
					
						
							|  |  |  |       :title="selectedBackup.name" | 
					
						
							|  |  |  |       :icon="$globals.icons.database" | 
					
						
							|  |  |  |       :submit-text="$t('general.import')" | 
					
						
							|  |  |  |       :loading="loading" | 
					
						
							|  |  |  |       @submit="restoreBackup" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-subtitle v-if="selectedBackup.date" class="mb-n3 mt-3"> | 
					
						
							|  |  |  |         {{ $d(new Date(selectedBackup.date), "medium") }} | 
					
						
							|  |  |  |       </v-card-subtitle> | 
					
						
							|  |  |  |       <v-divider></v-divider> | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <AdminBackupImportOptions v-model="importOptions" import-backup class="mt-5 mb-2" /> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       ref="refDeleteConfirmation" | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |       :title="$t('settings.backup.delete-backup')" | 
					
						
							|  |  |  |       color="error" | 
					
						
							|  |  |  |       :icon="$globals.icons.alertCircle" | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |       @confirm="deleteBackup(selectedBackup.name)" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         {{ $t("general.confirm-delete-generic") }} | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |     <BaseStatCard :icon="$globals.icons.backupRestore" :color="color"> | 
					
						
							|  |  |  |       <template #after-heading> | 
					
						
							|  |  |  |         <div class="ml-auto text-right"> | 
					
						
							|  |  |  |           <h2 class="body-3 grey--text font-weight-light"> | 
					
						
							|  |  |  |             {{ $t("settings.backup-and-exports") }} | 
					
						
							|  |  |  |           </h2> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <h3 class="display-2 font-weight-light text--primary"> | 
					
						
							|  |  |  |             <small> {{ total }}</small> | 
					
						
							|  |  |  |           </h3> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </template> | 
					
						
							|  |  |  |       <div class="d-flex row py-3 justify-end"> | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |         <AppButtonUpload url="/api/backups/upload" @uploaded="refreshBackups"> | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |           <template #default="{ isSelecting, onButtonClick }"> | 
					
						
							|  |  |  |             <v-btn :loading="isSelecting" class="mx-2" small color="info" @click="onButtonClick"> | 
					
						
							|  |  |  |               <v-icon left> {{ $globals.icons.upload }} </v-icon> {{ $t("general.upload") }} | 
					
						
							|  |  |  |             </v-btn> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  |         </AppButtonUpload> | 
					
						
							|  |  |  |         <AdminBackupDialog :color="color" /> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |         <v-btn :loading="loading" class="mx-2" small color="success" @click="createBackup(null)"> | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |           <v-icon left> {{ $globals.icons.create }} </v-icon> {{ $t("general.create") }} | 
					
						
							|  |  |  |         </v-btn> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <template #bottom> | 
					
						
							|  |  |  |         <v-virtual-scroll height="290" item-height="70" :items="availableBackups"> | 
					
						
							|  |  |  |           <template #default="{ item }"> | 
					
						
							|  |  |  |             <v-list-item @click.prevent="openDialog(item, btnEvent.IMPORT_EVENT)"> | 
					
						
							|  |  |  |               <v-list-item-avatar> | 
					
						
							|  |  |  |                 <v-icon large dark :color="color"> | 
					
						
							|  |  |  |                   {{ $globals.icons.database }} | 
					
						
							|  |  |  |                 </v-icon> | 
					
						
							|  |  |  |               </v-list-item-avatar> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               <v-list-item-content> | 
					
						
							|  |  |  |                 <v-list-item-title v-text="item.name"></v-list-item-title> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 <v-list-item-subtitle> | 
					
						
							|  |  |  |                   {{ $d(Date.parse(item.date), "medium") }} | 
					
						
							|  |  |  |                 </v-list-item-subtitle> | 
					
						
							|  |  |  |               </v-list-item-content> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               <v-list-item-action class="ml-auto"> | 
					
						
							|  |  |  |                 <v-btn large icon @click.stop="openDialog(item, btnEvent.DELETE_EVENT)"> | 
					
						
							|  |  |  |                   <v-icon color="error">{{ $globals.icons.delete }}</v-icon> | 
					
						
							|  |  |  |                 </v-btn> | 
					
						
							|  |  |  |               </v-list-item-action> | 
					
						
							|  |  |  |             </v-list-item> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  |         </v-virtual-scroll> | 
					
						
							|  |  |  |       </template> | 
					
						
							|  |  |  |     </BaseStatCard> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  | import { defineComponent, ref } from "@nuxtjs/composition-api"; | 
					
						
							|  |  |  | import AdminBackupImportOptions from "./AdminBackupImportOptions.vue"; | 
					
						
							|  |  |  | import AdminBackupDialog from "./AdminBackupDialog.vue"; | 
					
						
							|  |  |  | import { BackupFile } from "~/api/class-interfaces/backups"; | 
					
						
							|  |  |  | import { useBackups } from "~/composables/use-backups"; | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const IMPORT_EVENT = "import"; | 
					
						
							|  |  |  | const DELETE_EVENT = "delete"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  | type EVENTS = "import" | "delete"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |   components: { AdminBackupImportOptions, AdminBackupDialog }, | 
					
						
							|  |  |  |   props: { | 
					
						
							|  |  |  |     availableBackups: { | 
					
						
							|  |  |  |       type: Array, | 
					
						
							|  |  |  |       required: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     templates: { | 
					
						
							|  |  |  |       type: Array, | 
					
						
							|  |  |  |       required: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |     const refImportDialog = ref(); | 
					
						
							|  |  |  |     const refDeleteConfirmation = ref(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const { refreshBackups, importBackup, createBackup, deleteBackup } = useBackups(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       btnEvent: { IMPORT_EVENT, DELETE_EVENT }, | 
					
						
							|  |  |  |       refImportDialog, | 
					
						
							|  |  |  |       refDeleteConfirmation, | 
					
						
							|  |  |  |       refreshBackups, | 
					
						
							|  |  |  |       importBackup, | 
					
						
							|  |  |  |       createBackup, | 
					
						
							|  |  |  |       deleteBackup, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   data() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       color: "accent", | 
					
						
							|  |  |  |       loading: false, | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |       selectedBackup: { | 
					
						
							|  |  |  |         name: "", | 
					
						
							|  |  |  |         date: "", | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       importOptions: {}, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   computed: { | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |     total(): number { | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |       return this.availableBackups.length || 0; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-07 15:12:25 -08:00
										 |  |  |   methods: { | 
					
						
							|  |  |  |     openDialog(backup: BackupFile, event: EVENTS) { | 
					
						
							|  |  |  |       this.selectedBackup = backup; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       switch (event) { | 
					
						
							|  |  |  |         case IMPORT_EVENT: | 
					
						
							|  |  |  |           this.refImportDialog.open(); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case DELETE_EVENT: | 
					
						
							|  |  |  |           this.refDeleteConfirmation.open(); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     async restoreBackup() { | 
					
						
							|  |  |  |       const payload = { | 
					
						
							|  |  |  |         name: this.selectedBackup.name, | 
					
						
							|  |  |  |         ...this.importOptions, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await this.importBackup(this.selectedBackup.name, payload); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style scoped> | 
					
						
							|  |  |  | </style> |