Finalize Typescript restructure

This commit is contained in:
Darko Gjorgjijoski
2026-04-06 17:59:15 +02:00
parent cab785172e
commit 74b4b2df4e
209 changed files with 12419 additions and 1745 deletions

View File

@@ -0,0 +1,328 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useModalStore } from '@v2/stores/modal.store'
import { useDialogStore } from '@v2/stores/dialog.store'
import { useNotificationStore } from '@v2/stores/notification.store'
import { backupService, type Backup } from '@v2/api/services/backup.service'
import { diskService, type Disk } from '@v2/api/services/disk.service'
import {
getErrorTranslationKey,
handleApiError,
} from '@v2/utils/error-handling'
import AdminBackupModal from '@v2/features/admin/components/settings/AdminBackupModal.vue'
interface TableColumn {
key: string
label?: string
thClass?: string
tdClass?: string
sortable?: boolean
}
interface DiskOption extends Disk {
display_name: string
}
interface FetchParams {
page: number
filter: Record<string, unknown>
sort: { fieldName: string; order: string }
}
interface FetchResult {
data: Backup[]
pagination: {
totalPages: number
currentPage: number
totalCount: number
limit: number
}
}
const modalStore = useModalStore()
const dialogStore = useDialogStore()
const notificationStore = useNotificationStore()
const { t } = useI18n()
const table = ref<{ refresh: () => void } | null>(null)
const disks = ref<DiskOption[]>([])
const selectedDisk = ref<DiskOption | null>(null)
const isFetchingInitialData = ref(false)
const backupError = ref('')
const backupColumns = computed<TableColumn[]>(() => [
{
key: 'path',
label: t('settings.backup.path'),
thClass: 'extra',
tdClass: 'font-medium text-heading',
},
{
key: 'created_at',
label: t('settings.backup.created_at'),
tdClass: 'font-medium text-heading',
},
{
key: 'size',
label: t('settings.backup.size'),
tdClass: 'font-medium text-heading',
},
{
key: 'actions',
label: '',
tdClass: 'text-right text-sm font-medium',
sortable: false,
},
])
watch(
selectedDisk,
(newDisk, oldDisk) => {
if (newDisk?.id && oldDisk?.id && newDisk.id !== oldDisk.id) {
refreshTable()
}
}
)
loadDisks()
async function loadDisks(): Promise<void> {
isFetchingInitialData.value = true
try {
const response = await diskService.list({ limit: 'all' })
disks.value = response.data.map((disk) => ({
...disk,
display_name: `${disk.name} - [${disk.driver}]`,
}))
selectedDisk.value =
disks.value.find((disk) => disk.set_as_default) ?? disks.value[0] ?? null
} catch (error: unknown) {
showApiError(error)
} finally {
isFetchingInitialData.value = false
}
}
async function fetchData({ page }: FetchParams): Promise<FetchResult> {
if (!selectedDisk.value) {
return emptyResult(page)
}
backupError.value = ''
try {
const response = await backupService.list({
disk: selectedDisk.value.driver,
file_disk_id: selectedDisk.value.id,
})
if (response.error) {
backupError.value = t('settings.backup.invalid_disk_credentials')
return emptyResult(page)
}
return {
data: response.backups,
pagination: {
totalPages: 1,
currentPage: 1,
totalCount: response.backups.length,
limit: response.backups.length || 1,
},
}
} catch (error: unknown) {
showApiError(error)
return emptyResult(page)
}
}
async function removeBackup(backup: Backup): Promise<void> {
if (!selectedDisk.value) {
return
}
const confirmed = await dialogStore.openDialog({
title: t('general.are_you_sure'),
message: t('settings.backup.backup_confirm_delete'),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'danger',
hideNoButton: false,
size: 'lg',
})
if (!confirmed) {
return
}
try {
const response = await backupService.delete({
disk: selectedDisk.value.driver,
file_disk_id: selectedDisk.value.id,
path: backup.path,
})
if (response.success) {
notificationStore.showNotification({
type: 'success',
message: t('settings.backup.deleted_message'),
})
refreshTable()
}
} catch (error: unknown) {
showApiError(error)
}
}
async function downloadBackup(backup: Backup): Promise<void> {
if (!selectedDisk.value) {
return
}
isFetchingInitialData.value = true
let objectUrl = ''
try {
const blob = await backupService.download({
disk: selectedDisk.value.driver,
file_disk_id: selectedDisk.value.id,
path: backup.path,
})
objectUrl = window.URL.createObjectURL(blob)
const downloadLink = document.createElement('a')
downloadLink.href = objectUrl
downloadLink.setAttribute(
'download',
backup.path.split('/').pop() ?? 'backup.zip'
)
document.body.appendChild(downloadLink)
downloadLink.click()
document.body.removeChild(downloadLink)
} catch (error: unknown) {
showApiError(error)
} finally {
if (objectUrl) {
window.URL.revokeObjectURL(objectUrl)
}
isFetchingInitialData.value = false
}
}
function openCreateBackupModal(): void {
modalStore.openModal({
title: t('settings.backup.create_backup'),
componentName: 'AdminBackupModal',
size: 'sm',
data: {
disks: disks.value,
selectedDiskId: selectedDisk.value?.id ?? null,
},
refreshData: table.value?.refresh,
})
}
function refreshTable(): void {
table.value?.refresh()
}
function emptyResult(page: number): FetchResult {
return {
data: [],
pagination: {
totalPages: 1,
currentPage: page,
totalCount: 0,
limit: 1,
},
}
}
function showApiError(error: unknown): void {
const normalizedError = handleApiError(error)
const translationKey = getErrorTranslationKey(normalizedError.message)
notificationStore.showNotification({
type: 'error',
message: translationKey ? t(translationKey) : normalizedError.message,
})
}
</script>
<template>
<AdminBackupModal />
<BaseSettingCard
:title="$t('settings.backup.title', 1)"
:description="$t('settings.backup.description')"
>
<template #action>
<BaseButton variant="primary-outline" @click="openCreateBackupModal">
<template #left="slotProps">
<BaseIcon :class="slotProps.class" name="PlusIcon" />
</template>
{{ $t('settings.backup.new_backup') }}
</BaseButton>
</template>
<div class="grid my-14 md:grid-cols-3">
<BaseInputGroup
:label="$t('settings.disk.select_disk')"
:content-loading="isFetchingInitialData"
>
<BaseMultiselect
v-model="selectedDisk"
:content-loading="isFetchingInitialData"
:options="disks"
track-by="id"
value-prop="id"
label="display_name"
:placeholder="$t('settings.disk.select_disk')"
object
searchable
class="w-full"
/>
</BaseInputGroup>
</div>
<BaseErrorAlert
v-if="backupError"
class="mt-6"
:errors="[backupError]"
/>
<BaseTable
ref="table"
class="mt-10"
:show-filter="false"
:data="fetchData"
:columns="backupColumns"
>
<template #cell-actions="{ row }">
<BaseDropdown>
<template #activator>
<div class="inline-block">
<BaseIcon name="EllipsisHorizontalIcon" class="text-muted" />
</div>
</template>
<BaseDropdownItem @click="downloadBackup(row.data)">
<BaseIcon name="CloudArrowDownIcon" class="mr-3 text-body" />
{{ $t('general.download') }}
</BaseDropdownItem>
<BaseDropdownItem @click="removeBackup(row.data)">
<BaseIcon name="TrashIcon" class="mr-3 text-body" />
{{ $t('general.delete') }}
</BaseDropdownItem>
</BaseDropdown>
</template>
</BaseTable>
</BaseSettingCard>
</template>

View File

@@ -0,0 +1,295 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useModalStore } from '@v2/stores/modal.store'
import { useDialogStore } from '@v2/stores/dialog.store'
import { useGlobalStore } from '@v2/stores/global.store'
import { useNotificationStore } from '@v2/stores/notification.store'
import { diskService, type Disk } from '@v2/api/services/disk.service'
import {
getErrorTranslationKey,
handleApiError,
} from '@v2/utils/error-handling'
import AdminFileDiskModal from '@v2/features/admin/components/settings/AdminFileDiskModal.vue'
interface TableColumn {
key: string
label?: string
thClass?: string
tdClass?: string
sortable?: boolean
}
interface FetchParams {
page: number
filter: Record<string, unknown>
sort: { fieldName: string; order: string }
}
interface FetchResult {
data: Disk[]
pagination: {
totalPages: number
currentPage: number
totalCount: number
limit: number
}
}
const modalStore = useModalStore()
const dialogStore = useDialogStore()
const globalStore = useGlobalStore()
const notificationStore = useNotificationStore()
const { t } = useI18n()
const table = ref<{ refresh: () => void } | null>(null)
const savePdfToDisk = ref(
(globalStore.globalSettings?.save_pdf_to_disk ?? 'NO') === 'YES'
)
const fileDiskColumns = computed<TableColumn[]>(() => [
{
key: 'name',
label: t('settings.disk.disk_name'),
thClass: 'extra',
tdClass: 'font-medium text-heading',
},
{
key: 'driver',
label: t('settings.disk.filesystem_driver'),
thClass: 'extra',
tdClass: 'font-medium text-heading',
},
{
key: 'type',
label: t('settings.disk.disk_type'),
thClass: 'extra',
tdClass: 'font-medium text-heading',
},
{
key: 'set_as_default',
label: t('settings.disk.is_default'),
thClass: 'extra',
tdClass: 'font-medium text-heading',
},
{
key: 'actions',
label: '',
tdClass: 'text-right text-sm font-medium',
sortable: false,
},
])
const savePdfToDiskField = computed<boolean>({
get: () => savePdfToDisk.value,
set: async (enabled) => {
savePdfToDisk.value = enabled
await globalStore.updateGlobalSettings({
data: {
settings: {
save_pdf_to_disk: enabled ? 'YES' : 'NO',
},
},
message: t('general.setting_updated'),
})
},
})
async function fetchData({ page, sort }: FetchParams): Promise<FetchResult> {
const response = await diskService.list({
orderByField: sort.fieldName || 'created_at',
orderBy: sort.order || 'desc',
page,
})
return {
data: response.data,
pagination: {
totalPages: response.meta.last_page,
currentPage: page,
totalCount: response.meta.total,
limit: Number(response.meta.per_page) || 5,
},
}
}
async function setDefaultDisk(id: number): Promise<void> {
const confirmed = await dialogStore.openDialog({
title: t('general.are_you_sure'),
message: t('settings.disk.set_default_disk_confirm'),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'primary',
hideNoButton: false,
size: 'lg',
})
if (!confirmed) {
return
}
try {
await diskService.update(id, { set_as_default: true })
notificationStore.showNotification({
type: 'success',
message: t('settings.disk.success_set_default_disk'),
})
refreshTable()
} catch (error: unknown) {
showApiError(error)
}
}
async function removeDisk(id: number): Promise<void> {
const confirmed = await dialogStore.openDialog({
title: t('general.are_you_sure'),
message: t('settings.disk.confirm_delete'),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'danger',
hideNoButton: false,
size: 'lg',
})
if (!confirmed) {
return
}
try {
const response = await diskService.delete(id)
if (response.success) {
notificationStore.showNotification({
type: 'success',
message: t('settings.disk.deleted_message'),
})
refreshTable()
}
} catch (error: unknown) {
showApiError(error)
}
}
function openCreateDiskModal(): void {
modalStore.openModal({
title: t('settings.disk.new_disk'),
componentName: 'AdminFileDiskModal',
size: 'lg',
refreshData: table.value?.refresh,
})
}
function openEditDiskModal(disk: Disk): void {
modalStore.openModal({
title: t('settings.disk.edit_file_disk'),
componentName: 'AdminFileDiskModal',
id: disk.id,
data: disk,
size: 'lg',
refreshData: table.value?.refresh,
})
}
function canShowActions(disk: Disk): boolean {
return !disk.set_as_default || disk.type !== 'SYSTEM'
}
function refreshTable(): void {
table.value?.refresh()
}
function showApiError(error: unknown): void {
const normalizedError = handleApiError(error)
const translationKey = getErrorTranslationKey(normalizedError.message)
notificationStore.showNotification({
type: 'error',
message: translationKey ? t(translationKey) : normalizedError.message,
})
}
</script>
<template>
<AdminFileDiskModal />
<BaseSettingCard
:title="$t('settings.disk.title', 1)"
:description="$t('settings.disk.description')"
>
<template #action>
<BaseButton variant="primary-outline" @click="openCreateDiskModal">
<template #left="slotProps">
<BaseIcon :class="slotProps.class" name="PlusIcon" />
</template>
{{ $t('settings.disk.new_disk') }}
</BaseButton>
</template>
<BaseTable
ref="table"
class="mt-16"
:data="fetchData"
:columns="fileDiskColumns"
>
<template #cell-set_as_default="{ row }">
<span
:class="
row.data.set_as_default
? 'bg-success text-status-green'
: 'bg-surface-muted text-muted'
"
class="inline-flex rounded-full px-2 py-1 text-xs font-medium uppercase"
>
{{
row.data.set_as_default ? $t('general.yes') : $t('general.no')
}}
</span>
</template>
<template #cell-actions="{ row }">
<BaseDropdown v-if="canShowActions(row.data)">
<template #activator>
<div class="inline-block">
<BaseIcon name="EllipsisHorizontalIcon" class="text-muted" />
</div>
</template>
<BaseDropdownItem
v-if="!row.data.set_as_default"
@click="setDefaultDisk(row.data.id)"
>
<BaseIcon class="mr-3 text-body" name="CheckCircleIcon" />
{{ $t('settings.disk.set_default_disk') }}
</BaseDropdownItem>
<BaseDropdownItem
v-if="row.data.type !== 'SYSTEM'"
@click="openEditDiskModal(row.data)"
>
<BaseIcon name="PencilIcon" class="mr-3 text-body" />
{{ $t('general.edit') }}
</BaseDropdownItem>
<BaseDropdownItem
v-if="row.data.type !== 'SYSTEM' && !row.data.set_as_default"
@click="removeDisk(row.data.id)"
>
<BaseIcon name="TrashIcon" class="mr-3 text-body" />
{{ $t('general.delete') }}
</BaseDropdownItem>
</BaseDropdown>
</template>
</BaseTable>
<BaseDivider class="mt-8 mb-2" />
<BaseSwitchSection
v-model="savePdfToDiskField"
:title="$t('settings.disk.save_pdf_to_disk')"
:description="$t('settings.disk.disk_setting_description')"
/>
</BaseSettingCard>
</template>

View File

@@ -0,0 +1,127 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useModalStore } from '@v2/stores/modal.store'
import { useNotificationStore } from '@v2/stores/notification.store'
import { mailService } from '@v2/api/services/mail.service'
import type { MailConfig, MailDriver } from '@v2/api/services/mail.service'
import SmtpMailDriver from '@v2/features/company/settings/components/SmtpMailDriver.vue'
import MailgunMailDriver from '@v2/features/company/settings/components/MailgunMailDriver.vue'
import SesMailDriver from '@v2/features/company/settings/components/SesMailDriver.vue'
import BasicMailDriver from '@v2/features/company/settings/components/BasicMailDriver.vue'
import MailTestModal from '@v2/features/company/settings/components/MailTestModal.vue'
const { t } = useI18n()
const modalStore = useModalStore()
const notificationStore = useNotificationStore()
const isSaving = ref(false)
const isFetchingInitialData = ref(false)
const mailConfigData = ref<Record<string, unknown> | null>(null)
const mailDrivers = ref<MailDriver[]>([])
const currentMailDriver = ref('smtp')
loadData()
async function loadData(): Promise<void> {
isFetchingInitialData.value = true
try {
const [driversResponse, configResponse] = await Promise.all([
mailService.getDrivers(),
mailService.getConfig(),
])
mailDrivers.value = driversResponse
mailConfigData.value = configResponse
currentMailDriver.value = configResponse.mail_driver ?? 'smtp'
} finally {
isFetchingInitialData.value = false
}
}
const mailDriver = computed(() => {
switch (currentMailDriver.value) {
case 'mailgun':
return MailgunMailDriver
case 'ses':
return SesMailDriver
case 'sendmail':
case 'mail':
return BasicMailDriver
default:
return SmtpMailDriver
}
})
function changeDriver(value: string): void {
currentMailDriver.value = value
if (mailConfigData.value) {
mailConfigData.value.mail_driver = value
}
}
async function saveEmailConfig(value: MailConfig): Promise<void> {
isSaving.value = true
try {
const response = await mailService.saveConfig(value)
if (response.success) {
notificationStore.showNotification({
type: 'success',
message: t(`settings.success.${response.success}`),
})
if (mailConfigData.value) {
mailConfigData.value = {
...mailConfigData.value,
...value,
}
}
}
} finally {
isSaving.value = false
}
}
function openMailTestModal(): void {
modalStore.openModal({
title: t('general.test_mail_conf'),
componentName: 'MailTestModal',
size: 'sm',
})
}
</script>
<template>
<MailTestModal store-type="global" />
<BaseSettingCard
:title="$t('settings.mail.mail_config')"
:description="$t('settings.mail.mail_config_desc')"
>
<div v-if="mailConfigData" class="mt-14">
<component
:is="mailDriver"
:config-data="mailConfigData"
:is-saving="isSaving"
:mail-drivers="mailDrivers"
:is-fetching-initial-data="isFetchingInitialData"
@on-change-driver="changeDriver"
@submit-data="saveEmailConfig"
>
<BaseButton
variant="primary-outline"
type="button"
class="ml-2"
:content-loading="isFetchingInitialData"
@click="openMailTestModal"
>
{{ $t('general.test_mail_conf') }}
</BaseButton>
</component>
</div>
</BaseSettingCard>
</template>

View File

@@ -0,0 +1,96 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useNotificationStore } from '@v2/stores/notification.store'
import { pdfService } from '@v2/api/services/pdf.service'
import type { PdfConfig, PdfDriver } from '@v2/api/services/pdf.service'
import AdminPdfDomDriver from '@v2/features/admin/components/settings/AdminPdfDomDriver.vue'
import AdminPdfGotenbergDriver from '@v2/features/admin/components/settings/AdminPdfGotenbergDriver.vue'
const { t } = useI18n()
const notificationStore = useNotificationStore()
const isSaving = ref(false)
const isFetchingInitialData = ref(false)
const configData = ref<Record<string, unknown> | null>(null)
const drivers = ref<PdfDriver[]>([])
const currentDriver = ref('dompdf')
loadData()
async function loadData(): Promise<void> {
isFetchingInitialData.value = true
try {
const [driversResponse, configResponse] = await Promise.all([
pdfService.getDrivers(),
pdfService.getConfig(),
])
drivers.value = driversResponse
configData.value = configResponse
currentDriver.value = configResponse.pdf_driver ?? 'dompdf'
} finally {
isFetchingInitialData.value = false
}
}
const pdfDriver = computed(() => {
if (currentDriver.value === 'gotenberg') {
return AdminPdfGotenbergDriver
}
return AdminPdfDomDriver
})
function changeDriver(value: string): void {
currentDriver.value = value
if (configData.value) {
configData.value.pdf_driver = value
}
}
async function saveConfig(value: PdfConfig): Promise<void> {
isSaving.value = true
try {
const response = await pdfService.saveConfig(value)
if (response.success) {
notificationStore.showNotification({
type: 'success',
message: t(`settings.pdf.${response.success}`),
})
if (configData.value) {
configData.value = {
...configData.value,
...value,
}
}
}
} finally {
isSaving.value = false
}
}
</script>
<template>
<BaseSettingCard
:title="$t('settings.pdf.pdf_configuration')"
:description="$t('settings.pdf.section_description')"
>
<div v-if="configData" class="mt-14">
<component
:is="pdfDriver"
:config-data="configData"
:is-saving="isSaving"
:drivers="drivers"
:is-fetching-initial-data="isFetchingInitialData"
@on-change-driver="changeDriver"
@submit-data="saveConfig"
/>
</div>
</BaseSettingCard>
</template>

View File

@@ -0,0 +1,481 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useDialogStore } from '@v2/stores/dialog.store'
import { useNotificationStore } from '@v2/stores/notification.store'
import { settingService } from '@v2/api/services/setting.service'
import { updateService, type UpdateRelease } from '@v2/api/services/update.service'
import {
getErrorTranslationKey,
handleApiError,
} from '@v2/utils/error-handling'
type UpdateStepKey =
| 'download'
| 'unzip'
| 'copy'
| 'delete'
| 'migrate'
| 'finish'
type UpdateStepStatus = 'pending' | 'running' | 'finished' | 'error'
interface UpdateStep {
key: UpdateStepKey
translationKey: string
status: UpdateStepStatus
time: string | null
}
const dialogStore = useDialogStore()
const notificationStore = useNotificationStore()
const { t } = useI18n()
const isCheckingForUpdate = ref(false)
const isUpdating = ref(false)
const insiderChannel = ref(false)
const currentVersion = ref('')
const updateRelease = ref<UpdateRelease | null>(null)
const isMinorUpdate = ref(false)
const updateSteps = ref<UpdateStep[]>([
{
key: 'download',
translationKey: 'settings.update_app.download_zip_file',
status: 'pending',
time: null,
},
{
key: 'unzip',
translationKey: 'settings.update_app.unzipping_package',
status: 'pending',
time: null,
},
{
key: 'copy',
translationKey: 'settings.update_app.copying_files',
status: 'pending',
time: null,
},
{
key: 'delete',
translationKey: 'settings.update_app.deleting_files',
status: 'pending',
time: null,
},
{
key: 'migrate',
translationKey: 'settings.update_app.running_migrations',
status: 'pending',
time: null,
},
{
key: 'finish',
translationKey: 'settings.update_app.finishing_update',
status: 'pending',
time: null,
},
])
const isUpdateAvailable = computed<boolean>(() => {
return Boolean(updateRelease.value)
})
const requirementEntries = computed(() => {
return Object.entries(updateRelease.value?.extensions ?? {})
})
const allowToUpdate = computed<boolean>(() => {
return requirementEntries.value.every(([, isAvailable]) => isAvailable)
})
onMounted(async () => {
window.addEventListener('beforeunload', preventUnloadDuringUpdate)
await loadCurrentVersion()
})
onBeforeUnmount(() => {
window.removeEventListener('beforeunload', preventUnloadDuringUpdate)
})
async function loadCurrentVersion(): Promise<void> {
try {
const response = await settingService.getAppVersion()
currentVersion.value = response.version
insiderChannel.value = response.channel === 'insider'
} catch (error: unknown) {
showApiError(error)
}
}
async function checkUpdate(): Promise<void> {
isCheckingForUpdate.value = true
try {
const response = await updateService.check(
insiderChannel.value ? 'insider' : 'stable'
)
if (!response.release) {
updateRelease.value = null
notificationStore.showNotification({
type: 'info',
message: t('settings.update_app.latest_message'),
})
return
}
updateRelease.value = response.release
isMinorUpdate.value = Boolean(response.is_minor)
resetUpdateProgress()
} catch (error: unknown) {
updateRelease.value = null
showApiError(error)
} finally {
isCheckingForUpdate.value = false
}
}
async function startUpdate(): Promise<void> {
if (!updateRelease.value) {
return
}
const confirmed = await dialogStore.openDialog({
title: t('general.are_you_sure'),
message: t('settings.update_app.update_warning'),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'danger',
hideNoButton: false,
size: 'lg',
})
if (!confirmed) {
return
}
if (!allowToUpdate.value) {
notificationStore.showNotification({
type: 'error',
message: t('settings.update_app.requirements_not_met'),
})
return
}
resetUpdateProgress()
isUpdating.value = true
let updatePath: string | null = null
try {
for (const step of updateSteps.value) {
step.status = 'running'
switch (step.key) {
case 'download': {
const response = await updateService.download({
version: updateRelease.value.version,
})
updatePath = extractPath(response.path)
break
}
case 'unzip': {
if (!updatePath) {
throw new Error('Missing update package path.')
}
const response = await updateService.unzip({ path: updatePath })
updatePath = extractPath(response.path) ?? updatePath
break
}
case 'copy': {
if (!updatePath) {
throw new Error('Missing extracted update path.')
}
const response = await updateService.copy({ path: updatePath })
updatePath = extractPath(response.path) ?? updatePath
break
}
case 'delete':
await updateService.delete({
deleted_files: updateRelease.value.deleted_files ?? null,
})
break
case 'migrate':
await updateService.migrate()
break
case 'finish':
await updateService.finish({
installed: currentVersion.value,
version: updateRelease.value.version,
})
break
}
step.status = 'finished'
step.time = new Date().toLocaleTimeString()
}
notificationStore.showNotification({
type: 'success',
message: t('settings.update_app.update_success'),
})
setTimeout(() => {
window.location.reload()
}, 3000)
} catch (error: unknown) {
const currentStep = updateSteps.value.find((step) => step.status === 'running')
if (currentStep) {
currentStep.status = 'error'
currentStep.time = new Date().toLocaleTimeString()
}
showApiError(error)
} finally {
isUpdating.value = false
}
}
function resetUpdateProgress(): void {
updateSteps.value = updateSteps.value.map((step) => ({
...step,
status: 'pending',
time: null,
}))
}
function statusClass(step: UpdateStep): string {
if (step.status === 'finished') {
return 'text-status-green bg-success'
}
if (step.status === 'running') {
return 'text-primary-700 bg-primary-100'
}
if (step.status === 'error') {
return 'text-danger bg-red-200'
}
return 'text-muted bg-surface-muted'
}
function preventUnloadDuringUpdate(event: BeforeUnloadEvent): void {
if (!isUpdating.value) {
return
}
event.preventDefault()
event.returnValue = 'Update is in progress!'
}
function extractPath(value: unknown): string | null {
if (typeof value === 'string') {
return value
}
return null
}
function showApiError(error: unknown): void {
const normalizedError = handleApiError(error)
const translationKey = getErrorTranslationKey(normalizedError.message)
notificationStore.showNotification({
type: 'error',
message: translationKey ? t(translationKey) : normalizedError.message,
})
}
</script>
<template>
<BaseSettingCard
:title="$t('settings.update_app.title')"
:description="$t('settings.update_app.description')"
>
<div class="pb-8">
<label class="text-sm font-medium input-label">
{{ $t('settings.update_app.current_version') }}
</label>
<div class="w-full border-b-2 border-line-light border-solid pb-4">
<div
class="my-2 inline-block rounded-md border border-line-default bg-surface-muted p-3 text-sm text-body"
>
{{ currentVersion }}
</div>
</div>
<div class="pt-4">
<BaseCheckbox
v-model="insiderChannel"
:label="$t('settings.update_app.insider_consent')"
/>
</div>
<BaseButton
:loading="isCheckingForUpdate"
:disabled="isCheckingForUpdate || isUpdating"
variant="primary-outline"
class="mt-6"
@click="checkUpdate"
>
{{ $t('settings.update_app.check_update') }}
</BaseButton>
<BaseDivider v-if="isUpdateAvailable" class="mt-6 mb-4" />
<div v-if="isUpdateAvailable && updateRelease && !isUpdating" class="mt-4">
<BaseHeading type="heading-title" class="mb-2">
{{ $t('settings.update_app.avail_update') }}
</BaseHeading>
<div class="mb-3 rounded-md bg-primary-50 p-4">
<div class="flex">
<div class="shrink-0">
<BaseIcon
name="InformationCircleIcon"
class="h-5 w-5 text-primary-400"
/>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-primary-800">
{{ $t('general.note') }}
</h3>
<div class="mt-2 text-sm text-primary-700">
<p>{{ $t('settings.update_app.update_warning') }}</p>
</div>
</div>
</div>
</div>
<label class="text-sm font-medium input-label">
{{ $t('settings.update_app.next_version') }}
</label>
<br />
<div
class="my-2 inline-block rounded-md border border-line-default bg-surface-muted p-3 text-sm text-body"
>
{{ updateRelease.version }}
<span v-if="isMinorUpdate" class="ml-2 text-xs text-muted">
(minor)
</span>
</div>
<div
v-if="updateRelease.description"
class="update-rich-text mt-4 max-w-[680px] text-sm leading-snug text-muted"
v-html="updateRelease.description"
/>
<div
v-if="updateRelease.changelog"
class="update-rich-text mt-4 max-w-[680px] text-sm leading-snug text-muted"
v-html="updateRelease.changelog"
/>
<div v-if="requirementEntries.length" class="mt-6">
<label class="text-sm font-medium input-label">
{{ $t('settings.update_app.requirements') }}
</label>
<table class="mt-2 w-full max-w-xl border border-line-default">
<tbody>
<tr
v-for="([extension, available], index) in requirementEntries"
:key="extension"
:class="index === requirementEntries.length - 1 ? '' : 'border-b border-line-default'"
>
<td class="p-3 text-sm">
{{ extension }}
</td>
<td class="p-3 text-right text-sm">
<span
:class="available ? 'bg-success' : 'bg-red-500'"
class="inline-block h-4 w-4 rounded-full"
/>
</td>
</tr>
</tbody>
</table>
</div>
<div
v-if="!allowToUpdate"
class="mt-6 rounded-md bg-red-50 p-4 text-sm text-red-700"
>
{{ $t('settings.update_app.requirements_not_met') }}
</div>
<BaseButton
class="mt-10"
variant="primary"
:disabled="!allowToUpdate"
@click="startUpdate"
>
{{ $t('settings.update_app.update') }}
</BaseButton>
</div>
<div v-if="isUpdating" class="mt-4">
<div class="mb-6 flex items-start justify-between">
<div>
<BaseHeading type="heading-title" class="mb-2">
{{ $t('settings.update_app.update_progress') }}
</BaseHeading>
<p class="max-w-[480px] text-sm leading-snug text-muted">
{{ $t('settings.update_app.progress_text') }}
</p>
</div>
<BaseIcon
name="ArrowPathIcon"
class="h-6 w-6 animate-spin text-primary-400"
/>
</div>
<ul class="w-full list-none p-0">
<li
v-for="step in updateSteps"
:key="step.key"
class="flex w-full justify-between border-b border-line-default py-3 last:border-b-0"
>
<p class="m-0 text-sm leading-8">{{ $t(step.translationKey) }}</p>
<div class="flex items-center">
<span v-if="step.time" class="mr-3 text-xs text-muted">
{{ step.time }}
</span>
<span
:class="statusClass(step)"
class="block rounded-full px-3 py-1 text-sm uppercase"
>
{{ step.status }}
</span>
</div>
</li>
</ul>
</div>
</div>
</BaseSettingCard>
</template>
<style scoped>
.update-rich-text :deep(ul) {
list-style: disc;
margin-left: 1.5rem;
}
.update-rich-text :deep(li) {
margin-bottom: 0.25rem;
}
</style>