mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
refactor: rework async SystemUpdate
This commit is contained in:
parent
09e9c272b7
commit
f7c563afb2
2 changed files with 55 additions and 57 deletions
|
@ -296,6 +296,26 @@ export type MigrationList = {
|
||||||
migrations: MigrationInfo[]
|
migrations: MigrationInfo[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SystemUpdate = {
|
||||||
|
system: {
|
||||||
|
name: string
|
||||||
|
new_version: string
|
||||||
|
current_version: string
|
||||||
|
}[]
|
||||||
|
apps: {
|
||||||
|
name: string
|
||||||
|
id: string
|
||||||
|
new_version: string
|
||||||
|
current_version: string
|
||||||
|
notifications: {
|
||||||
|
PRE_UPGRADE: Obj<string> | null
|
||||||
|
POST_UPGRADE: Obj<string> | null
|
||||||
|
}
|
||||||
|
}[]
|
||||||
|
important_yunohost_upgrade: boolean
|
||||||
|
pending_migrations: MigrationInfo[]
|
||||||
|
}
|
||||||
|
|
||||||
// DOMAINS
|
// DOMAINS
|
||||||
|
|
||||||
export type DNSRecord = {
|
export type DNSRecord = {
|
||||||
|
|
|
@ -6,60 +6,40 @@ import api from '@/api'
|
||||||
import CardCollapse from '@/components/CardCollapse.vue'
|
import CardCollapse from '@/components/CardCollapse.vue'
|
||||||
import { useAutoModal } from '@/composables/useAutoModal'
|
import { useAutoModal } from '@/composables/useAutoModal'
|
||||||
import { useInfos } from '@/composables/useInfos'
|
import { useInfos } from '@/composables/useInfos'
|
||||||
import { useInitialQueries } from '@/composables/useInitialQueries'
|
import type { SystemUpdate } from '@/types/core/api'
|
||||||
|
import { formatAppNotifs } from '../app/appData'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { tryToReconnect } = useInfos()
|
const { tryToReconnect } = useInfos()
|
||||||
const modalConfirm = useAutoModal()
|
const modalConfirm = useAutoModal()
|
||||||
const { loading } = useInitialQueries(
|
|
||||||
[{ method: 'PUT', uri: 'update/all', humanKey: 'update' }],
|
|
||||||
{ showModal: true, onQueriesResponse },
|
|
||||||
)
|
|
||||||
|
|
||||||
const system = ref()
|
const { apps, system, importantYunohostUpgrade, pendingMigrations } = await api
|
||||||
const apps = ref()
|
.put<SystemUpdate>({ uri: 'update/all', humanKey: 'update' })
|
||||||
const importantYunohostUpgrade = ref()
|
.then(({ apps, system, important_yunohost_upgrade, pending_migrations }) => {
|
||||||
const pendingMigrations = ref()
|
return {
|
||||||
const showPreUpgradeModal = ref(false)
|
apps: ref(apps),
|
||||||
const preUpgrade = ref({
|
system: ref(system),
|
||||||
apps: [],
|
importantYunohostUpgrade: important_yunohost_upgrade,
|
||||||
notifs: [],
|
pendingMigrations: !!pending_migrations.length,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
const preUpgrade = ref<
|
||||||
|
| { apps: { id: string; name: string; notif: string }[]; hasNotifs: boolean }
|
||||||
|
| undefined
|
||||||
|
>()
|
||||||
|
|
||||||
function onQueriesResponse({
|
async function confirmAppsUpgrade(id?: string) {
|
||||||
apps_,
|
const appList = id ? [apps.value.find((app) => app.id === id)!] : apps.value
|
||||||
system_,
|
|
||||||
important_yunohost_upgrade,
|
|
||||||
pending_migrations,
|
|
||||||
}: any) {
|
|
||||||
apps.value = apps_.length ? apps_ : null
|
|
||||||
system.value = system_.length ? system_ : null
|
|
||||||
// eslint-disable-next-line camelcase
|
|
||||||
importantYunohostUpgrade.value = important_yunohost_upgrade
|
|
||||||
pendingMigrations.value = pending_migrations.length !== 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatAppNotifs(notifs) {
|
|
||||||
return Object.keys(notifs).reduce((acc, key) => {
|
|
||||||
return acc + '\n\n' + notifs[key]
|
|
||||||
}, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
async function confirmAppsUpgrade(id = null) {
|
|
||||||
const appList = id ? [apps.value.find((app) => app.id === id)] : apps.value
|
|
||||||
const apps_ = appList.map((app) => ({
|
const apps_ = appList.map((app) => ({
|
||||||
id: app.id,
|
id: app.id,
|
||||||
name: app.name,
|
name: app.name,
|
||||||
notif: app.notifications.PRE_UPGRADE
|
notif: formatAppNotifs(app.notifications.PRE_UPGRADE),
|
||||||
? formatAppNotifs(app.notifications.PRE_UPGRADE)
|
|
||||||
: '',
|
|
||||||
}))
|
}))
|
||||||
preUpgrade.value = { apps: apps_, hasNotifs: apps_.some((app) => app.notif) }
|
preUpgrade.value = { apps: apps_, hasNotifs: apps_.some((app) => app.notif) }
|
||||||
showPreUpgradeModal.value = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function performAppsUpgrade(ids) {
|
async function performAppsUpgrade(ids: string[]) {
|
||||||
const apps_ = ids.map((id) => apps.value.find((app) => app.id === id))
|
const apps_ = ids.map((id) => apps.value.find((app) => app.id === id)!)
|
||||||
const lastAppId = apps_[apps_.length - 1].id
|
const lastAppId = apps_[apps_.length - 1].id
|
||||||
|
|
||||||
for (const app of apps_) {
|
for (const app of apps_) {
|
||||||
|
@ -68,7 +48,7 @@ async function performAppsUpgrade(ids) {
|
||||||
uri: `apps/${app.id}/upgrade`,
|
uri: `apps/${app.id}/upgrade`,
|
||||||
humanKey: { key: 'upgrade.app', app: app.name },
|
humanKey: { key: 'upgrade.app', app: app.name },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response: Pick<SystemUpdate['apps'][number], 'notifications'>) => {
|
||||||
const postMessage = formatAppNotifs(response.notifications.POST_UPGRADE)
|
const postMessage = formatAppNotifs(response.notifications.POST_UPGRADE)
|
||||||
const isLast = app.id === lastAppId
|
const isLast = app.id === lastAppId
|
||||||
apps.value = apps.value.filter((a) => app.id !== a.id)
|
apps.value = apps.value.filter((a) => app.id !== a.id)
|
||||||
|
@ -88,15 +68,11 @@ async function performAppsUpgrade(ids) {
|
||||||
{ markdown: true, cancelable: !isLast },
|
{ markdown: true, cancelable: !isLast },
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve(true)
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!continue_) break
|
if (!continue_) break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!apps.value.length) {
|
|
||||||
apps.value = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function performSystemUpgrade() {
|
async function performSystemUpgrade() {
|
||||||
|
@ -111,13 +87,13 @@ async function performSystemUpgrade() {
|
||||||
initialDelay: 2000,
|
initialDelay: 2000,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
system.value = null
|
system.value = []
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ViewBase :loading="loading" skeleton="CardListSkeleton">
|
<div>
|
||||||
<!-- MIGRATIONS WARN -->
|
<!-- MIGRATIONS WARN -->
|
||||||
<YAlert v-if="pendingMigrations" variant="warning" alert>
|
<YAlert v-if="pendingMigrations" variant="warning" alert>
|
||||||
<span v-html="$t('pending_migrations')" />
|
<span v-html="$t('pending_migrations')" />
|
||||||
|
@ -130,7 +106,7 @@ async function performSystemUpgrade() {
|
||||||
|
|
||||||
<!-- SYSTEM UPGRADE -->
|
<!-- SYSTEM UPGRADE -->
|
||||||
<YCard :title="$t('system')" icon="server" no-body>
|
<YCard :title="$t('system')" icon="server" no-body>
|
||||||
<BListGroup v-if="system" flush>
|
<BListGroup v-if="system.length" flush>
|
||||||
<BListGroupItem
|
<BListGroupItem
|
||||||
v-for="{ name, current_version, new_version } in system"
|
v-for="{ name, current_version, new_version } in system"
|
||||||
:key="name"
|
:key="name"
|
||||||
|
@ -144,14 +120,14 @@ async function performSystemUpgrade() {
|
||||||
</BListGroupItem>
|
</BListGroupItem>
|
||||||
</BListGroup>
|
</BListGroup>
|
||||||
|
|
||||||
<BCardBody v-else-if="system === null">
|
<BCardBody v-else>
|
||||||
<span class="text-success">
|
<span class="text-success">
|
||||||
<YIcon iname="check-circle" />
|
<YIcon iname="check-circle" />
|
||||||
{{ $t('system_packages_nothing') }}
|
{{ $t('system_packages_nothing') }}
|
||||||
</span>
|
</span>
|
||||||
</BCardBody>
|
</BCardBody>
|
||||||
|
|
||||||
<template #buttons v-if="system">
|
<template v-if="system.length" #buttons>
|
||||||
<BButton
|
<BButton
|
||||||
variant="success"
|
variant="success"
|
||||||
v-t="'system_upgrade_all_packages_btn'"
|
v-t="'system_upgrade_all_packages_btn'"
|
||||||
|
@ -162,7 +138,7 @@ async function performSystemUpgrade() {
|
||||||
|
|
||||||
<!-- APPS UPGRADE -->
|
<!-- APPS UPGRADE -->
|
||||||
<YCard :title="$t('applications')" icon="cubes" no-body>
|
<YCard :title="$t('applications')" icon="cubes" no-body>
|
||||||
<BListGroup v-if="apps" flush>
|
<BListGroup v-if="apps.length" flush>
|
||||||
<BListGroupItem
|
<BListGroupItem
|
||||||
v-for="{ name, id, current_version, new_version } in apps"
|
v-for="{ name, id, current_version, new_version } in apps"
|
||||||
:key="id"
|
:key="id"
|
||||||
|
@ -185,13 +161,13 @@ async function performSystemUpgrade() {
|
||||||
</BListGroupItem>
|
</BListGroupItem>
|
||||||
</BListGroup>
|
</BListGroup>
|
||||||
|
|
||||||
<BCardBody v-else-if="apps === null">
|
<BCardBody v-else>
|
||||||
<span class="text-success">
|
<span class="text-success">
|
||||||
<YIcon iname="check-circle" /> {{ $t('system_apps_nothing') }}
|
<YIcon iname="check-circle" /> {{ $t('system_apps_nothing') }}
|
||||||
</span>
|
</span>
|
||||||
</BCardBody>
|
</BCardBody>
|
||||||
|
|
||||||
<template #buttons v-if="apps">
|
<template v-if="apps.length" #buttons>
|
||||||
<BButton
|
<BButton
|
||||||
variant="success"
|
variant="success"
|
||||||
v-t="'system_upgrade_all_applications_btn'"
|
v-t="'system_upgrade_all_applications_btn'"
|
||||||
|
@ -201,8 +177,9 @@ async function performSystemUpgrade() {
|
||||||
</YCard>
|
</YCard>
|
||||||
|
|
||||||
<BModal
|
<BModal
|
||||||
v-model="showPreUpgradeModal"
|
v-if="preUpgrade"
|
||||||
id="apps-pre-upgrade"
|
id="apps-pre-upgrade"
|
||||||
|
:model-value="true"
|
||||||
:title="$t('app.upgrade.confirm.title')"
|
:title="$t('app.upgrade.confirm.title')"
|
||||||
header-bg-variant="warning"
|
header-bg-variant="warning"
|
||||||
header-class="text-black"
|
header-class="text-black"
|
||||||
|
@ -210,6 +187,7 @@ async function performSystemUpgrade() {
|
||||||
ok-variant="success"
|
ok-variant="success"
|
||||||
:cancel-title="$t('cancel')"
|
:cancel-title="$t('cancel')"
|
||||||
@ok="performAppsUpgrade(preUpgrade.apps.map((app) => app.id))"
|
@ok="performAppsUpgrade(preUpgrade.apps.map((app) => app.id))"
|
||||||
|
@cancel="preUpgrade = undefined"
|
||||||
>
|
>
|
||||||
<h3>
|
<h3>
|
||||||
{{ $t('app.upgrade.confirm.apps') }}
|
{{ $t('app.upgrade.confirm.apps') }}
|
||||||
|
@ -248,7 +226,7 @@ async function performSystemUpgrade() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</BModal>
|
</BModal>
|
||||||
</ViewBase>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
Loading…
Add table
Reference in a new issue