Rename resources/scripts-v2 to resources/scripts and drop @v2 alias

Now that the legacy v1 frontend (commit 064bdf53) is gone, the v2 directory is the only frontend and the v2 suffix is just noise. Renames resources/scripts-v2 to resources/scripts via git mv (so git records the move as renames, preserving blame and log --follow), then bulk-rewrites the 152 files that imported via @v2/... to use @/scripts/... instead. The existing @ alias (resources/) covers the new path with no extra config needed.

Drops the now-unused @v2 alias from vite.config.js and points the laravel-vite-plugin entry at resources/scripts/main.ts. Updates the only blade reference (resources/views/app.blade.php) to match. The package.json test script (eslint ./resources/scripts) automatically targets the right place after the rename without any edit.

Verified: npm run build exits clean and the Vite warning lines now reference resources/scripts/plugins/i18n.ts, confirming every import resolved through the new path. git log --follow on any moved file walks back through its scripts-v2 history.
This commit is contained in:
Darko Gjorgjijoski
2026-04-07 12:50:16 +02:00
parent 064bdf5395
commit 71388ec6a5
448 changed files with 381 additions and 382 deletions

View File

@@ -0,0 +1,313 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useModalStore } from '@/scripts/stores/modal.store'
import { useDialogStore } from '@/scripts/stores/dialog.store'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import { backupService, type Backup } from '@/scripts/api/services/backup.service'
import { diskService, type Disk } from '@/scripts/api/services/disk.service'
import {
getErrorTranslationKey,
handleApiError,
} from '@/scripts/utils/error-handling'
import AdminBackupModal from '@/scripts/features/admin/components/settings/AdminBackupModal.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: 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 backupDisk = ref<Disk | 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: 'disk_name',
label: t('settings.disk.title', 1),
tdClass: 'font-medium text-muted',
sortable: false,
},
{
key: 'actions',
label: '',
tdClass: 'text-right text-sm font-medium',
sortable: false,
},
])
loadBackupDisk()
async function loadBackupDisk(): Promise<void> {
isFetchingInitialData.value = true
try {
const [diskResponse, purposesResponse] = await Promise.all([
diskService.list({ limit: 'all' }),
diskService.getDiskPurposes(),
])
const disks = diskResponse.data
const backupDiskId = purposesResponse.backup_disk_id
backupDisk.value =
(backupDiskId ? disks.find((disk) => disk.id === Number(backupDiskId)) : null) ??
disks.find((disk) => disk.set_as_default) ??
disks[0] ??
null
// Refresh table now that we know which disk to query
refreshTable()
} catch (error: unknown) {
showApiError(error)
} finally {
isFetchingInitialData.value = false
}
}
async function fetchData({ page }: FetchParams): Promise<FetchResult> {
if (!backupDisk.value) {
return emptyResult(page)
}
backupError.value = ''
try {
const response = await backupService.list({
disk: backupDisk.value.driver,
file_disk_id: backupDisk.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 (!backupDisk.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: backupDisk.value.driver,
file_disk_id: backupDisk.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 (!backupDisk.value) {
return
}
isFetchingInitialData.value = true
let objectUrl = ''
try {
const blob = await backupService.download({
disk: backupDisk.value.driver,
file_disk_id: backupDisk.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 {
if (!backupDisk.value) {
return
}
modalStore.openModal({
title: t('settings.backup.create_backup'),
componentName: 'AdminBackupModal',
size: 'sm',
data: {
file_disk_id: backupDisk.value.id,
},
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>
<BaseErrorAlert
v-if="backupError"
class="mt-6"
:errors="[backupError]"
/>
<BaseTable
ref="table"
class="mt-10"
:show-filter="false"
:data="fetchData"
:columns="backupColumns"
>
<template #cell-disk_name>
{{ backupDisk?.name ?? '-' }}
</template>
<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,433 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import type { DiskPurposes } from '@/scripts/api/services/disk.service'
import { useI18n } from 'vue-i18n'
import { useModalStore } from '@/scripts/stores/modal.store'
import { useDialogStore } from '@/scripts/stores/dialog.store'
import { useGlobalStore } from '@/scripts/stores/global.store'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import { diskService, type Disk } from '@/scripts/api/services/disk.service'
import {
getErrorTranslationKey,
handleApiError,
} from '@/scripts/utils/error-handling'
import AdminFileDiskModal from '@/scripts/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'
)
// Disk purpose assignments
const allDisks = ref<Disk[]>([])
const purposes = ref<DiskPurposes>({
media_disk_id: null,
pdf_disk_id: null,
backup_disk_id: null,
})
const originalPurposes = ref<DiskPurposes>({
media_disk_id: null,
pdf_disk_id: null,
backup_disk_id: null,
})
const isSavingPurposes = ref(false)
onMounted(async () => {
try {
const [disksRes, purposesRes] = await Promise.all([
diskService.list({ limit: 'all' as unknown as number }),
diskService.getDiskPurposes(),
])
allDisks.value = disksRes.data
const normalized = {
media_disk_id: purposesRes.media_disk_id ? Number(purposesRes.media_disk_id) : null,
pdf_disk_id: purposesRes.pdf_disk_id ? Number(purposesRes.pdf_disk_id) : null,
backup_disk_id: purposesRes.backup_disk_id ? Number(purposesRes.backup_disk_id) : null,
}
purposes.value = { ...normalized }
originalPurposes.value = { ...normalized }
} catch {
// Silently fail
}
})
function hasChangedPurposes(): boolean {
return (
purposes.value.media_disk_id !== originalPurposes.value.media_disk_id ||
purposes.value.pdf_disk_id !== originalPurposes.value.pdf_disk_id ||
purposes.value.backup_disk_id !== originalPurposes.value.backup_disk_id
)
}
async function savePurposes(): Promise<void> {
if (hasChangedPurposes()) {
const confirmed = await dialogStore.openDialog({
title: t('general.are_you_sure'),
message: t('settings.disk.change_disk_warning'),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'danger',
hideNoButton: false,
size: 'lg',
})
if (!confirmed) {
return
}
}
isSavingPurposes.value = true
try {
await diskService.updateDiskPurposes(purposes.value)
originalPurposes.value = { ...purposes.value }
notificationStore.showNotification({
type: 'success',
message: t('settings.disk.purposes_saved'),
})
} catch (error: unknown) {
showApiError(error)
} finally {
isSavingPurposes.value = false
}
}
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>
<!-- Disk Assignments -->
<BaseSettingCard
:title="$t('settings.disk.disk_assignments')"
:description="$t('settings.disk.disk_assignments_description')"
class="mt-6"
>
<BaseInputGrid class="mt-4">
<BaseInputGroup :label="$t('settings.disk.media_storage')">
<BaseMultiselect
v-model="purposes.media_disk_id"
:options="allDisks"
value-prop="id"
label="name"
track-by="name"
:can-deselect="false"
:placeholder="$t('settings.disk.select_disk')"
/>
<span class="text-xs text-subtle mt-1 block">
{{ $t('settings.disk.media_storage_description') }}
</span>
</BaseInputGroup>
<BaseInputGroup :label="$t('settings.disk.pdf_storage')">
<BaseMultiselect
v-model="purposes.pdf_disk_id"
:options="allDisks"
value-prop="id"
label="name"
track-by="name"
:can-deselect="false"
:placeholder="$t('settings.disk.select_disk')"
/>
<span class="text-xs text-subtle mt-1 block">
{{ $t('settings.disk.pdf_storage_description') }}
</span>
</BaseInputGroup>
<BaseInputGroup :label="$t('settings.disk.backup_storage')">
<BaseMultiselect
v-model="purposes.backup_disk_id"
:options="allDisks"
value-prop="id"
label="name"
track-by="name"
:can-deselect="false"
:placeholder="$t('settings.disk.select_disk')"
/>
<span class="text-xs text-subtle mt-1 block">
{{ $t('settings.disk.backup_storage_description') }}
</span>
</BaseInputGroup>
</BaseInputGrid>
<BaseButton
:loading="isSavingPurposes"
:disabled="isSavingPurposes"
variant="primary"
class="mt-6"
@click="savePurposes"
>
{{ $t('general.save') }}
</BaseButton>
</BaseSettingCard>
</template>

View File

@@ -0,0 +1,126 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import { client } from '@/scripts/api/client'
import { API } from '@/scripts/api/endpoints'
interface FontPackage {
key: string
name: string
family: string
locales: string[]
size: string
installed: boolean
bundled?: boolean
}
const { t } = useI18n()
const notificationStore = useNotificationStore()
const packages = ref<FontPackage[]>([])
const isLoading = ref(false)
const installing = ref<Set<string>>(new Set())
onMounted(async () => {
await loadStatus()
})
async function loadStatus(): Promise<void> {
isLoading.value = true
try {
const { data } = await client.get(API.FONTS_STATUS)
packages.value = data.packages
} catch {
// Silently fail
} finally {
isLoading.value = false
}
}
async function installFont(pkg: FontPackage): Promise<void> {
installing.value.add(pkg.key)
try {
await client.post(`${API.FONTS_INSTALL}/${pkg.key}/install`)
pkg.installed = true
notificationStore.showNotification({
type: 'success',
message: t('settings.fonts.download_complete', { name: pkg.name }),
})
} catch {
notificationStore.showNotification({
type: 'error',
message: t('settings.fonts.download_failed', { name: pkg.name }),
})
} finally {
installing.value.delete(pkg.key)
}
}
</script>
<template>
<BaseSettingCard
:title="$t('settings.fonts.title')"
:description="$t('settings.fonts.description')"
>
<p class="text-sm text-muted mb-6">
{{ $t('settings.fonts.bundled_info') }}
</p>
<div class="space-y-3">
<div
v-for="pkg in packages"
:key="pkg.key"
class="flex items-center justify-between p-4 border border-line-light rounded-lg"
>
<div>
<div class="font-medium text-heading">{{ pkg.name }}</div>
<div class="text-xs text-subtle mt-1">
{{ pkg.locales.join(', ') }} {{ pkg.size }}
</div>
</div>
<div class="flex items-center gap-3">
<span
v-if="pkg.bundled"
class="inline-flex items-center rounded-full bg-primary-50 px-2.5 py-1 text-xs font-medium text-primary-600"
>
{{ $t('settings.fonts.bundled') }}
</span>
<span
v-else-if="pkg.installed"
class="inline-flex items-center rounded-full bg-success px-2.5 py-1 text-xs font-medium text-status-green"
>
{{ $t('settings.fonts.installed') }}
</span>
<BaseButton
v-else
size="sm"
variant="primary-outline"
:loading="installing.has(pkg.key)"
:disabled="installing.has(pkg.key)"
@click="installFont(pkg)"
>
<template #left="slotProps">
<BaseIcon
v-if="!installing.has(pkg.key)"
name="CloudArrowDownIcon"
:class="slotProps.class"
/>
</template>
{{ installing.has(pkg.key) ? $t('settings.fonts.downloading') : $t('settings.fonts.install') }}
</BaseButton>
</div>
</div>
</div>
<div v-if="!packages.length && !isLoading" class="text-center py-8 text-muted">
{{ $t('settings.fonts.no_packages') }}
</div>
</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 '@/scripts/stores/modal.store'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import { mailService } from '@/scripts/api/services/mail.service'
import type { MailConfig, MailDriver } from '@/scripts/api/services/mail.service'
import SmtpMailDriver from '@/scripts/features/company/settings/components/SmtpMailDriver.vue'
import MailgunMailDriver from '@/scripts/features/company/settings/components/MailgunMailDriver.vue'
import SesMailDriver from '@/scripts/features/company/settings/components/SesMailDriver.vue'
import BasicMailDriver from '@/scripts/features/company/settings/components/BasicMailDriver.vue'
import MailTestModal from '@/scripts/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 '@/scripts/stores/notification.store'
import { pdfService } from '@/scripts/api/services/pdf.service'
import type { PdfConfig, PdfDriver } from '@/scripts/api/services/pdf.service'
import AdminPdfDomDriver from '@/scripts/features/admin/components/settings/AdminPdfDomDriver.vue'
import AdminPdfGotenbergDriver from '@/scripts/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 '@/scripts/stores/dialog.store'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import { settingService } from '@/scripts/api/services/setting.service'
import { updateService, type UpdateRelease } from '@/scripts/api/services/update.service'
import {
getErrorTranslationKey,
handleApiError,
} from '@/scripts/utils/error-handling'
type UpdateStepKey =
| 'download'
| 'unzip'
| 'copy'
| 'clean'
| '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: 'clean',
translationKey: 'settings.update_app.cleaning_stale_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 'clean':
await updateService.clean({
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>