|
| 1 | +<!-- |
| 2 | + SPDX-License-Identifier: AGPL-3.0-or-later |
| 3 | + SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 4 | +--> |
| 5 | + |
| 6 | +<script setup lang="ts"> |
| 7 | +import type { IAppstoreApp, IAppstoreExApp } from '../apps.d.ts' |
| 8 | +
|
| 9 | +import { mdiCheck, mdiInformationOutline, mdiUpdate, mdiWeb } from '@mdi/js' |
| 10 | +import { showError } from '@nextcloud/dialogs' |
| 11 | +import { getLanguage, t } from '@nextcloud/l10n' |
| 12 | +import { NcButton, NcDialog, NcIconSvgWrapper, NcLoadingIcon, NcNoteCard } from '@nextcloud/vue' |
| 13 | +import { computed, ref } from 'vue' |
| 14 | +import MarkdownPreview from './MarkdownPreview.vue' |
| 15 | +import { useUpdatesStore } from '../store/updates.ts' |
| 16 | +import logger from '../utils/logger.ts' |
| 17 | +
|
| 18 | +const props = defineProps<{ |
| 19 | + apps: (IAppstoreApp | IAppstoreExApp)[] |
| 20 | +}>() |
| 21 | +
|
| 22 | +const emit = defineEmits<{ |
| 23 | + close: [] |
| 24 | +}>() |
| 25 | +
|
| 26 | +const store = useUpdatesStore() |
| 27 | +const showDetails = ref('') |
| 28 | +const isUpdating = ref(false) |
| 29 | +
|
| 30 | +const changelogText = computed(() => { |
| 31 | + if (!showDetails.value) { |
| 32 | + return '' |
| 33 | + } |
| 34 | +
|
| 35 | + const app = props.apps.find((app) => app.id === showDetails.value) |
| 36 | + if (!app || !app.releases || app.releases.length === 0) { |
| 37 | + return '' |
| 38 | + } |
| 39 | +
|
| 40 | + const [release] = app.releases |
| 41 | + const localizedEntry = release.translations[getLanguage()] |
| 42 | + return localizedEntry?.changelog ?? release.translations.en?.changelog ?? '' |
| 43 | +}) |
| 44 | +
|
| 45 | +/** |
| 46 | + * Handle update all apps |
| 47 | + */ |
| 48 | +async function onUpdate() { |
| 49 | + isUpdating.value = true |
| 50 | + for (const app of props.apps) { |
| 51 | + try { |
| 52 | + await store.updateApp(app.id) |
| 53 | + } catch (error) { |
| 54 | + logger.error(`Failed to update app ${app.id}`, { error }) |
| 55 | + showError(t('appstore', 'Failed to update app {appName}', { appName: app.name })) |
| 56 | + } |
| 57 | + } |
| 58 | + isUpdating.value = false |
| 59 | + emit('close') |
| 60 | +} |
| 61 | +</script> |
| 62 | + |
| 63 | +<template> |
| 64 | + <NcDialog :contentClasses="$style.updateAllDialog" size="normal" :name="t('appstore', 'Update all apps')"> |
| 65 | + <p>{{ t('appstore', 'Are you sure you want to update all apps?') }}</p> |
| 66 | + <ul> |
| 67 | + <li v-for="app in apps" :key="app.id" :class="$style.updateAllDialog__listEntry"> |
| 68 | + <div :class="$style.updateAllDialog__listEntryContent"> |
| 69 | + <div :class="$style.updateAllDialog__listEntryHeading"> |
| 70 | + <NcIconSvgWrapper |
| 71 | + :path="app.update ? mdiUpdate : mdiCheck" |
| 72 | + :name="app.update ? undefined : t('appstore', 'Update done')" /> |
| 73 | + <span :class="$style.updateAllDialog__listEntryName">{{ app.name }} ({{ app.version }} → {{ app.update }})</span> |
| 74 | + </div> |
| 75 | + <div :class="$style.updateAllDialog__listEntryActions"> |
| 76 | + <NcButton |
| 77 | + v-if="app.website" |
| 78 | + :aria-label="t('appstore', 'View website')" |
| 79 | + :title="t('appstore', 'View website')" |
| 80 | + :href="app.website" |
| 81 | + target="_blank" |
| 82 | + variant="tertiary"> |
| 83 | + <template #icon> |
| 84 | + <NcIconSvgWrapper :path="mdiWeb" /> |
| 85 | + </template> |
| 86 | + </NcButton> |
| 87 | + <NcButton |
| 88 | + v-if="app.releases" |
| 89 | + :aria-label="t('appstore', 'Show details')" |
| 90 | + :title="t('appstore', 'Show details')" |
| 91 | + :pressed="showDetails === app.id" |
| 92 | + @update:pressed="showDetails = $event ? app.id : ''"> |
| 93 | + <template #icon> |
| 94 | + <NcIconSvgWrapper :path="mdiInformationOutline" /> |
| 95 | + </template> |
| 96 | + </NcButton> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </li> |
| 100 | + </ul> |
| 101 | + |
| 102 | + <NcNoteCard |
| 103 | + :class="$style.updateAllDialog__listEntryDetails" |
| 104 | + :heading="t('appstore', 'Details')" |
| 105 | + type="info"> |
| 106 | + <MarkdownPreview |
| 107 | + :minHeadingLevel="3" |
| 108 | + :text="changelogText" /> |
| 109 | + </NcNoteCard> |
| 110 | + |
| 111 | + <template #actions> |
| 112 | + <NcButton variant="tertiary" @click="emit('close')"> |
| 113 | + {{ t('appstore', 'Cancel') }} |
| 114 | + </NcButton> |
| 115 | + <NcButton variant="primary" @click="onUpdate"> |
| 116 | + <template v-if="isUpdating" #icon> |
| 117 | + <NcLoadingIcon /> |
| 118 | + </template> |
| 119 | + {{ t('appstore', 'Update all') }} |
| 120 | + </NcButton> |
| 121 | + </template> |
| 122 | + </NcDialog> |
| 123 | +</template> |
| 124 | + |
| 125 | +<style module> |
| 126 | +.updateAllDialog { |
| 127 | + min-height: 50vh !important; |
| 128 | +} |
| 129 | +
|
| 130 | +.updateAllDialog__list { |
| 131 | + display: flex; |
| 132 | + flex-direction: row; |
| 133 | + gap: calc(3 * var(--default-grid-baseline)); |
| 134 | +} |
| 135 | +
|
| 136 | +.updateAllDialog__listEntry { |
| 137 | + display: flex; |
| 138 | + flex-direction: column; |
| 139 | + gap: calc(2 * var(--default-grid-baseline)); |
| 140 | + padding: calc(2 * var(--default-grid-baseline)); |
| 141 | +} |
| 142 | +
|
| 143 | +.updateAllDialog__listEntryHeading { |
| 144 | + display: flex; |
| 145 | +} |
| 146 | +
|
| 147 | +.updateAllDialog__listEntryName { |
| 148 | + font-weight: 500; |
| 149 | + line-height: var(--default-clickable-area); |
| 150 | +} |
| 151 | +
|
| 152 | +.updateAllDialog__listEntryActions { |
| 153 | + display: flex; |
| 154 | + flex-direction: row; |
| 155 | + gap: var(--default-grid-baseline); |
| 156 | +} |
| 157 | +
|
| 158 | +.updateAllDialog__listEntryContent { |
| 159 | + display: flex; |
| 160 | + justify-content: space-between; |
| 161 | +} |
| 162 | +
|
| 163 | +.updateAllDialog__listEntryDetails { |
| 164 | + margin: 0; |
| 165 | +} |
| 166 | +</style> |
0 commit comments