mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-30 21:21:09 -04:00 
			
		
		
		
	Add steps for update app
This commit is contained in:
		
				
					committed by
					
						 Mohit Panjwani
						Mohit Panjwani
					
				
			
			
				
	
			
			
			
						parent
						
							e31b60bc48
						
					
				
				
					commit
					654395a175
				
			| @ -62,14 +62,14 @@ | ||||
|     "four_zero_four": "404", | ||||
|     "you_got_lost": "عفواً! يبدو أنك قد تهت!", | ||||
|     "go_home": "عودة إلى الرئيسية", | ||||
|  | ||||
|     "setting_updated": "تم تحديث الإعدادات بنجاح", | ||||
|     "select_state": "اختر الولاية/المنطقة", | ||||
|     "select_country": "اختر الدولة", | ||||
|     "select_city": "اختر المدينة", | ||||
|     "street_1": "عنوان الشارع 1", | ||||
|     "street_2": "عنوان الشارع 2", | ||||
|     "action_failed": "فشلت العملية" | ||||
|     "action_failed": "فشلت العملية", | ||||
|     "retry": "أعد المحاولة" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "اختر السنة", | ||||
| @ -752,7 +752,14 @@ | ||||
|       "progress_text": "سوف يستغرق التحديث بضع دقائق. يرجى عدم تحديث الشاشة أو إغلاق النافذة قبل انتهاء التحديث", | ||||
|       "update_success": "تم تحديث النظام! يرجى الانتظار حتى يتم إعادة تحميل نافذة المتصفح تلقائيًا.", | ||||
|       "latest_message": "لا يوجد تحديثات متوفرة! لديك حالياً أحدث نسخة.", | ||||
|       "current_version": "النسخة الحالية" | ||||
|       "current_version": "النسخة الحالية", | ||||
|       "download_zip_file": "تنزيل ملف ZIP", | ||||
|       "unzipping_package": "حزمة فك الضغط", | ||||
|       "copying_files": "نسخ الملفات", | ||||
|       "running_migrations": "إدارة عمليات الترحيل", | ||||
|       "finishing_update": "تحديث التشطيب", | ||||
|       "update_failed": "فشل التحديث", | ||||
|       "update_failed_text": "آسف! فشل التحديث الخاص بك في: {step} خطوة"      | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -76,7 +76,8 @@ | ||||
|     "select_city": "Stadt wählen", | ||||
|     "street_1": "Straße", | ||||
|     "street_2": "Zusatz Strasse", | ||||
|     "action_failed": "Aktion fehlgeschlagen" | ||||
|     "action_failed": "Aktion fehlgeschlagen", | ||||
|     "retry": "Wiederholen" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "Jahr wählen", | ||||
| @ -775,7 +776,14 @@ | ||||
|       "progress_text": "Es dauert nur ein paar Minuten. Bitte aktualisieren Sie den Bildschirm nicht und schließen Sie das Fenster nicht, bevor das Update abgeschlossen ist.", | ||||
|       "update_success": "App wurde aktualisiert! Bitte warten Sie, während Ihr Browserfenster automatisch neu geladen wird.", | ||||
|       "latest_message": "Kein Update verfügbar! Du bist auf der neuesten Version.", | ||||
|       "current_version": "Aktuelle Version" | ||||
|       "current_version": "Aktuelle Version", | ||||
|       "download_zip_file": "Laden Sie die ZIP-Datei herunter", | ||||
|       "unzipping_package": "Paket entpacken", | ||||
|       "copying_files": "Dateien kopieren", | ||||
|       "running_migrations": "Ausführen von Migrationen", | ||||
|       "finishing_update": "Update beenden", | ||||
|       "update_failed": "Update fehlgeschlagen", | ||||
|       "update_failed_text": "Es tut uns leid! Ihr Update ist am folgenden Schritt fehlgeschlagen: {step}"       | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -70,14 +70,14 @@ | ||||
|     "go_home": "Go Home", | ||||
|     "test_mail_conf": "Test Mail Configuration", | ||||
|     "send_mail_successfully": "Mail sent successfully", | ||||
|  | ||||
|     "setting_updated": "Setting updated successfully", | ||||
|     "select_state": "Select state", | ||||
|     "select_country": "Select Country", | ||||
|     "select_city": "Select City", | ||||
|     "street_1": "Street 1", | ||||
|     "street_2": "Street 2", | ||||
|     "action_failed": "Action Failed" | ||||
|     "action_failed": "Action Failed", | ||||
|     "retry": "Retry" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "Select year", | ||||
| @ -787,7 +787,14 @@ | ||||
|       "progress_text": "It will just take a few minutes. Please do not refresh the screen or close the window before the update finishes", | ||||
|       "update_success": "App has been updated! Please wait while your browser window gets reloaded automatically.", | ||||
|       "latest_message": "No update available! You are on the latest version.", | ||||
|       "current_version": "Current Version" | ||||
|       "current_version": "Current Version", | ||||
|       "download_zip_file": "Download ZIP file", | ||||
|       "unzipping_package": "Unzipping Package", | ||||
|       "copying_files": "Copying Files", | ||||
|       "running_migrations": "Running Migrations", | ||||
|       "finishing_update": "Finishing Update", | ||||
|       "update_failed": "Update Failed", | ||||
|       "update_failed_text": "Sorry! Your update failed on : {step} step"    | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -62,14 +62,14 @@ | ||||
|     "four_zero_four": "404", | ||||
|     "you_got_lost": "Whoops! ¡Te perdiste!", | ||||
|     "go_home": "Volver al Inicio", | ||||
|  | ||||
|     "setting_updated": "Configuración actualizada con éxito", | ||||
|     "select_state": "Seleccionar estado", | ||||
|     "select_country": "Seleccionar país", | ||||
|     "select_city": "Seleccionar ciudad", | ||||
|     "street_1": "Calle 1", | ||||
|     "street_2": "Calle 2", | ||||
|     "action_failed": "Accion Fallida" | ||||
|     "action_failed": "Accion Fallida", | ||||
|     "retry": "Procesar de nuevo" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "Seleccionar año", | ||||
| @ -751,7 +751,14 @@ | ||||
|       "progress_text": "Solo tomará unos minutos. No actualice la pantalla ni cierre la ventana antes de que finalice la actualización.", | ||||
|       "update_success": "¡La aplicación ha sido actualizada! Espere mientras la ventana de su navegador se vuelve a cargar automáticamente.", | ||||
|       "latest_message": "¡Actualización no disponible! Estás en la última versión.", | ||||
|       "current_version": "Versión actual" | ||||
|       "current_version": "Versión actual", | ||||
|       "download_zip_file": "Descargar archivo ZIP", | ||||
|       "unzipping_package": "Descomprimir paquete", | ||||
|       "copying_files": "Copiando documentos", | ||||
|       "running_migrations": "Ejecutar migraciones", | ||||
|       "finishing_update": "Actualización final", | ||||
|       "update_failed": "Actualización fallida", | ||||
|       "update_failed_text": "¡Lo siento! Su actualización falló el: {step} paso"  | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -76,7 +76,8 @@ | ||||
|     "ascending": "Ascendant", | ||||
|     "descending": "Descendant", | ||||
|     "subject": "matière", | ||||
|     "message": "Message" | ||||
|     "message": "Message", | ||||
|     "retry": "Réessayez" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "Sélectionnez l'année", | ||||
| @ -794,7 +795,14 @@ | ||||
|       "progress_text": "Cela ne prendra que quelques minutes. S'il vous plaît ne pas actualiser l'écran ou fermer la fenêtre avant la fin de la mise à jour", | ||||
|       "update_success": "App a été mis à jour! Veuillez patienter pendant le rechargement automatique de la fenêtre de votre navigateur.", | ||||
|       "latest_message": "Pas de mise a jour disponible! Vous êtes sur la dernière version.", | ||||
|       "current_version": "Version actuelle" | ||||
|       "current_version": "Version actuelle", | ||||
|       "download_zip_file": "Télécharger le fichier ZIP", | ||||
|       "unzipping_package": "Dézipper le package", | ||||
|       "copying_files": "Copie de fichiers", | ||||
|       "running_migrations": "Exécution de migrations", | ||||
|       "finishing_update": "Mise à jour de finition", | ||||
|       "update_failed": "Mise à jour a échoué", | ||||
|       "update_failed_text": "Désolé! Votre mise à jour a échoué à: {step} étape" | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -71,14 +71,14 @@ | ||||
|     "go_home": "Vai alla Home", | ||||
|     "test_mail_conf": "Configurazione della mail di test", | ||||
|     "send_mail_successfully": "Mail inviata con successo", | ||||
|  | ||||
|     "setting_updated": "Configurazioni aggiornate con successo", | ||||
|     "select_state": "Seleziona lo Stato", | ||||
|     "select_country": "Seleziona Paese", | ||||
|     "select_city": "Seleziona Città", | ||||
|     "street_1": "Indirizzo 1", | ||||
|     "street_2": "Indirizzo 2", | ||||
|     "action_failed": "Errore" | ||||
|     "action_failed": "Errore", | ||||
|     "retry": "Retry" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "Seleziona anno", | ||||
| @ -786,7 +786,14 @@ | ||||
|       "progress_text": "Sarà necessario qualche minuto. Per favore non aggiornare la pagina e non chiudere la finestra prima che l'aggiornamento sia completato", | ||||
|       "update_success": "L'App è aggiornata! Attendi che la pagina venga ricaricata automaticamente.", | ||||
|       "latest_message": "Nessun aggiornamneto disponibile! Sei già alla versione più recente.", | ||||
|       "current_version": "Versione corrente" | ||||
|       "current_version": "Versione corrente", | ||||
|       "download_zip_file": "Scarica il file ZIP", | ||||
|       "unzipping_package": "Pacchetto di decompressione", | ||||
|       "copying_files": "Copia dei file", | ||||
|       "running_migrations": "Esecuzione delle migrazioni", | ||||
|       "finishing_update": "Aggiornamento di finitura", | ||||
|       "update_failed": "Aggiornamento non riuscito", | ||||
|       "update_failed_text": "Scusate! L'aggiornamento non è riuscito il: passaggio {step}" | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -62,14 +62,14 @@ | ||||
|     "four_zero_four": "404", | ||||
|     "you_got_lost": "Ops! Se perdeu!", | ||||
|     "go_home": "Ir para Home", | ||||
|  | ||||
|     "setting_updated": "Configuração atualizada com sucesso", | ||||
|     "select_state": "Selecione Estado", | ||||
|     "select_country": "Selecionar pais", | ||||
|     "select_city": "Selecionar cidade", | ||||
|     "street_1": "Rua 1", | ||||
|     "street_2": "Rua # 2", | ||||
|     "action_failed": "Ação: Falhou" | ||||
|     "action_failed": "Ação: Falhou", | ||||
|     "retry": "Atualização falhou" | ||||
|   }, | ||||
|   "dashboard": { | ||||
|     "select_year": "Selecione Ano", | ||||
| @ -751,7 +751,14 @@ | ||||
|       "progress_text": "Levará apenas alguns minutos. Não atualize a tela ou feche a janela antes que a atualização seja concluída", | ||||
|       "update_success": "O aplicativo foi atualizado! Aguarde enquanto a janela do navegador é recarregada automaticamente.", | ||||
|       "latest_message": "Nenhuma atualização disponível! Você está na versão mais recente.", | ||||
|       "current_version": "Versão Atual" | ||||
|       "current_version": "Versão Atual", | ||||
|       "download_zip_file": "Baixar arquivo ZIP", | ||||
|       "unzipping_package": "Descompactando o pacote", | ||||
|       "copying_files": "Copiando arquivos", | ||||
|       "running_migrations": "Executando migrações", | ||||
|       "finishing_update": "Atualização de acabamento", | ||||
|       "update_failed": "Atualização falhou", | ||||
|       "update_failed_text": "Desculpa! Sua atualização falhou em: {step} step" | ||||
|     } | ||||
|   }, | ||||
|   "wizard": { | ||||
|  | ||||
| @ -1,33 +1,76 @@ | ||||
| <template> | ||||
|   <div class="setting-main-container"> | ||||
|   <div class="setting-main-container update-container"> | ||||
|     <div class="card setting-card"> | ||||
|       <div class="page-header"> | ||||
|         <h3 class="page-title">{{ $t('settings.update_app.title') }}</h3> | ||||
|         <p class="page-sub-title"> | ||||
|           {{ $t('settings.update_app.description') }} | ||||
|         </p> | ||||
|         <label class="input-label">{{ $t('settings.update_app.current_version') }}</label><br> | ||||
|         <label class="input-label">{{ | ||||
|           $t('settings.update_app.current_version') | ||||
|         }}</label | ||||
|         ><br /> | ||||
|         <label class="version mb-4">{{ currentVersion }}</label> | ||||
|         <base-button :outline="true" :disabled="isCheckingforUpdate || isUpdating" size="large" color="theme" class="mb-4" @click="checkUpdate"> | ||||
|           <font-awesome-icon :class="{'update': isCheckingforUpdate}" style="margin-right: 10px;" icon="sync-alt" /> | ||||
|         <base-button | ||||
|           :outline="true" | ||||
|           :disabled="isCheckingforUpdate || isUpdating" | ||||
|           size="large" | ||||
|           color="theme" | ||||
|           class="mb-4" | ||||
|           @click="checkUpdate" | ||||
|         > | ||||
|           <font-awesome-icon | ||||
|             :class="{ update: isCheckingforUpdate }" | ||||
|             style="margin-right: 10px;" | ||||
|             icon="sync-alt" | ||||
|           /> | ||||
|           {{ $t('settings.update_app.check_update') }} | ||||
|         </base-button> | ||||
|         <hr> | ||||
|         <hr /> | ||||
|         <div v-show="!isUpdating" v-if="isUpdateAvailable" class="mt-4 content"> | ||||
|           <h3 class="page-title mb-3">{{ $t('settings.update_app.avail_update') }}</h3> | ||||
|           <label class="input-label">{{ $t('settings.update_app.next_version') }}</label><br> | ||||
|           <h3 class="page-title mb-3"> | ||||
|             {{ $t('settings.update_app.avail_update') }} | ||||
|           </h3> | ||||
|           <label class="input-label">{{ | ||||
|             $t('settings.update_app.next_version') | ||||
|           }}</label | ||||
|           ><br /> | ||||
|           <label class="version">{{ updateData.version }}</label> | ||||
|           <p class="page-sub-title" style="white-space: pre-wrap;">{{ description }}</p> | ||||
|           <base-button size="large" icon="rocket" color="theme" @click="onUpdateApp"> | ||||
|           <base-button | ||||
|             size="large" | ||||
|             icon="rocket" | ||||
|             color="theme" | ||||
|             @click="onUpdateApp" | ||||
|           > | ||||
|             {{ $t('settings.update_app.update') }} | ||||
|           </base-button> | ||||
|         </div> | ||||
|         <div v-if="isUpdating" class="mt-4 content"> | ||||
|           <h3 class="page-title">{{ $t('settings.update_app.update_progress') }}</h3> | ||||
|           <p class="page-sub-title"> | ||||
|             {{ $t('settings.update_app.progress_text') }} | ||||
|           </p> | ||||
|           <font-awesome-icon icon="spinner" class="fa-spin"/> | ||||
|           <div class="d-flex flex-row justify-content-between"> | ||||
|             <div> | ||||
|               <h3 class="page-title"> | ||||
|                 {{ $t('settings.update_app.update_progress') }} | ||||
|               </h3> | ||||
|               <p class="page-sub-title"> | ||||
|                 {{ $t('settings.update_app.progress_text') }} | ||||
|               </p> | ||||
|             </div> | ||||
|             <font-awesome-icon icon="spinner" class="update-spinner fa-spin" /> | ||||
|           </div> | ||||
|           <ul class="update-steps-container"> | ||||
|             <li class="update-step" v-for="step in updateSteps"> | ||||
|               <p class="update-step-text">{{ $t(step.translationKey) }}</p> | ||||
|               <div class="update-status-container"> | ||||
|                 <span v-if="step.time" class="update-time">{{ | ||||
|                   step.time | ||||
|                 }}</span> | ||||
|                 <span :class="'update-status status-' + getStatus(step)">{{ | ||||
|                   getStatus(step) | ||||
|                 }}</span> | ||||
|               </div> | ||||
|             </li> | ||||
|           </ul> | ||||
|         </div> | ||||
|       </div> | ||||
|     </div> | ||||
| @ -36,7 +79,7 @@ | ||||
|  | ||||
| <script> | ||||
| export default { | ||||
|   data () { | ||||
|   data() { | ||||
|     return { | ||||
|       isShowProgressBar: false, | ||||
|       isUpdateAvailable: false, | ||||
| @ -46,60 +89,78 @@ export default { | ||||
|       interval: null, | ||||
|       description: '', | ||||
|       currentVersion: '', | ||||
|       updateSteps: [ | ||||
|         { | ||||
|           translationKey: 'settings.update_app.download_zip_file', | ||||
|           stepUrl: '/api/update/download', | ||||
|           time: null, | ||||
|           started: false, | ||||
|           completed: false, | ||||
|         }, | ||||
|         { | ||||
|           translationKey: 'settings.update_app.unzipping_package', | ||||
|           stepUrl: '/api/update/unzip', | ||||
|           time: null, | ||||
|           started: false, | ||||
|           completed: false, | ||||
|         }, | ||||
|         { | ||||
|           translationKey: 'settings.update_app.copying_files', | ||||
|           stepUrl: '/api/update/copy', | ||||
|           time: null, | ||||
|           started: false, | ||||
|           completed: false, | ||||
|         }, | ||||
|         { | ||||
|           translationKey: 'settings.update_app.running_migrations', | ||||
|           stepUrl: '/api/update/migrate', | ||||
|           time: null, | ||||
|           started: false, | ||||
|           completed: false, | ||||
|         }, | ||||
|         { | ||||
|           translationKey: 'settings.update_app.finishing_update', | ||||
|           stepUrl: '/api/update/finish', | ||||
|           time: null, | ||||
|           started: false, | ||||
|           completed: false, | ||||
|         }, | ||||
|       ], | ||||
|       updateData: { | ||||
|         isMinor: Boolean, | ||||
|         installed: '', | ||||
|         version: '' | ||||
|       } | ||||
|         version: '', | ||||
|       }, | ||||
|     } | ||||
|   }, | ||||
|   created () { | ||||
|   created() { | ||||
|     window.addEventListener('beforeunload', (event) => { | ||||
|       if (this.isUpdating) { | ||||
|         event.returnValue = 'Update is in progress!' | ||||
|       } | ||||
|     }) | ||||
|   }, | ||||
|   mounted () { | ||||
|   mounted() { | ||||
|     window.axios.get('/api/settings/app/version').then((res) => { | ||||
|       this.currentVersion = res.data.version | ||||
|     }) | ||||
|   }, | ||||
|   methods: { | ||||
|     closeHandler () { | ||||
|     closeHandler() { | ||||
|       console.log('closing') | ||||
|     }, | ||||
|     async onUpdateApp () { | ||||
|       try { | ||||
|         this.isUpdating = true | ||||
|         this.updateData.installed = this.currentVersion | ||||
|         let res = await window.axios.post('/api/update', this.updateData) | ||||
|  | ||||
|         if (res.data.success) { | ||||
|           setTimeout(async () => { | ||||
|             await window.axios.post('/api/update/finish', this.updateData) | ||||
|  | ||||
|             window.toastr['success'](this.$t('settings.update_app.update_success')) | ||||
|             this.currentVersion = this.updateData.version | ||||
|             this.isUpdateAvailable = false | ||||
|  | ||||
|             setTimeout(() => { | ||||
|               location.reload() | ||||
|             }, 2000) | ||||
|           }, 1000) | ||||
|         } else { | ||||
|           console.log(res.data) | ||||
|           window.toastr['error'](res.data.error) | ||||
|         } | ||||
|       } catch (e) { | ||||
|         console.log(e) | ||||
|         window.toastr['error']('Something went wrong') | ||||
|     getStatus(step) { | ||||
|       if (step.started && step.completed) { | ||||
|         return 'finished' | ||||
|       } else if (step.started && !step.completed) { | ||||
|         return 'running' | ||||
|       } else if (!step.started && !step.completed) { | ||||
|         return 'pending' | ||||
|       } else { | ||||
|         return 'error' | ||||
|       } | ||||
|  | ||||
|       this.isUpdating = false | ||||
|     }, | ||||
|  | ||||
|     async checkUpdate () { | ||||
|     async checkUpdate() { | ||||
|       try { | ||||
|         this.isCheckingforUpdate = true | ||||
|         let response = await window.axios.get('/api/check/update') | ||||
| @ -122,8 +183,67 @@ export default { | ||||
|         this.isCheckingforUpdate = false | ||||
|         window.toastr['error']('Something went wrong') | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|     }, | ||||
|     async onUpdateApp() { | ||||
|       let path = null | ||||
|  | ||||
|       for (let index = 0; index < this.updateSteps.length; index++) { | ||||
|         let currentStep = this.updateSteps[index] | ||||
|         try { | ||||
|           this.isUpdating = true | ||||
|           currentStep.started = true | ||||
|           let updateParams = { | ||||
|             version: this.updateData.version, | ||||
|             installed: this.currentVersion, | ||||
|             path: path || null, | ||||
|           } | ||||
|  | ||||
|           let requestResponse = await window.axios.post( | ||||
|             currentStep.stepUrl, | ||||
|             updateParams | ||||
|           ) | ||||
|           currentStep.completed = true | ||||
|           if (requestResponse.data && requestResponse.data.path) { | ||||
|             path = requestResponse.data.path | ||||
|           } | ||||
|  | ||||
|           // on finish | ||||
|           if ( | ||||
|             currentStep.translationKey == 'settings.update_app.finishing_update' | ||||
|           ) { | ||||
|             this.isUpdating = false | ||||
|             window.toastr['success']( | ||||
|               this.$t('settings.update_app.update_success') | ||||
|             ) | ||||
|  | ||||
|             setTimeout(() => { | ||||
|               location.reload() | ||||
|             }, 3000) | ||||
|           } | ||||
|         } catch (error) { | ||||
|           currentStep.started = false | ||||
|           currentStep.completed = true | ||||
|           window.toastr['error'](this.$t('validation.something_went_wrong')) | ||||
|           this.onUpdateFailed(currentStep.translationKey) | ||||
|           return false | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     onUpdateFailed(translationKey) { | ||||
|       let stepName = this.$t(translationKey)  | ||||
|       swal({ | ||||
|         title: this.$t('settings.update_app.update_failed'), | ||||
|         text: this.$tc('settings.update_app.update_failed_text', stepName, {step: stepName}), | ||||
|         buttons: [this.$t('general.cancel'), this.$t('general.retry')], | ||||
|       }).then(async (value) => { | ||||
|         if (value) { | ||||
|           this.onUpdateApp() | ||||
|           return  | ||||
|         } | ||||
|         this.isUpdating = false | ||||
|       }) | ||||
|     }, | ||||
|   }, | ||||
| } | ||||
| </script> | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user