Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | 1x 79x 1x 1x 79x 1x 1x 17x 4x 2x 2x 34x 34x 1x 95x 73x 1x 4x 2x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 29x 16x 16x 16x 16x 39x 16x 39x 16x 16x 9x 8x 16x 16x 16x 128x 124x 108x 16x 16x 16x 20x 23x 16x 16x 3x 2x 1x 2x 2x 3x 3x 3x 16x 23x 22x 22x 22x 21x 21x 1x 22x 3x 4x 4x 4x 2x 4x 2x 4x 3x 3x 3x 2x 2x 1x 1x 1x 16x | <template>
<PageLayout :title="t('spacePages.title')" :description="t('spacePages.description')">
<template #action>
<a
v-if="flowSlug"
:href="`/space/${flowSlug}`"
target="_blank"
rel="noopener"
class="btn btn-outline-secondary me-2"
data-testid="space-pages-open-space"
>
<font-awesome-icon icon="fa-solid fa-globe" class="me-md-2" />
<span class="d-none d-md-inline">{{ t('spacePages.openSpace') }}</span>
</a>
<button
v-if="flowId && canEdit"
type="button"
class="btn btn-outline-secondary me-2"
:disabled="loading"
data-testid="space-pages-refresh"
@click="load"
>
<font-awesome-icon icon="fa-solid fa-rotate-right" class="me-md-2" />
<span class="d-none d-md-inline">{{ t('common.refresh') }}</span>
</button>
<button
v-if="flowId && canEdit"
type="button"
class="btn btn-success"
:disabled="loading || atLimit"
:title="atLimit ? t('spacePages.tooManyPages') : undefined"
data-testid="space-pages-create-button"
@click="openCreate"
>
<font-awesome-icon icon="fa-solid fa-plus" class="me-md-2" />
<span class="d-none d-md-inline">{{ t('spacePages.newPage') }}</span>
</button>
</template>
<SpacePageFormSidebar
v-if="flowId && canEdit"
ref="sidebarRef"
:is-open="sidebarOpen"
:page-slug="editedSlug"
:pages="pages"
@close="closeSidebar"
@saved="onSaved"
/>
<div class="container-fluid">
<NoActiveFlowNotice v-if="!flowId" />
<EmptyState v-else-if="!canEdit" variant="info">{{
t('spacePages.noPermission')
}}</EmptyState>
<LoadingSpinner v-else-if="loading && pages.length === 0" />
<template v-else>
<div
v-if="!spacePublished"
class="alert alert-warning"
data-testid="space-pages-unpublished"
>
<font-awesome-icon icon="fa-solid fa-eye-slash" class="me-2" />
{{ t('spacePages.spaceNotPublished') }}
</div>
<div v-if="atLimit" class="alert alert-info" data-testid="space-pages-limit">
{{ t('spacePages.tooManyPages') }}
</div>
<EmptyState v-if="pages.length === 0" variant="info">{{
t('spacePages.empty')
}}</EmptyState>
</template>
</div>
<SearchFilterHeader
v-if="flowId && canEdit && pages.length > 0"
v-model="searchQuery"
mode="client"
:items="pageViewModels"
:search-fields="searchFields"
:sort-value="sortField"
:sort-direction="sortDirection"
:get-sort-value="getSortValue"
:placeholder="t('spacePages.searchPlaceholder')"
>
<template #extra>
<SortControl
:options="sortOptions"
:field-value="sortField"
:direction="sortDirection"
:label="t('common.sortBy')"
@update:field-value="sortField = $event"
@toggle-direction="sortDirection = sortDirection === 'asc' ? 'desc' : 'asc'"
/>
</template>
<template #default="{ filteredItems }">
<SystemItemHeader
:fields="SPACE_PAGE_SCHEMA"
:get-translation="getTranslation"
:scrollbar-width="scrollbarWidth"
/>
<EmptyState v-if="filteredItems.length === 0" variant="info">
{{ t('common.noResults') }}
</EmptyState>
<VirtualCardGrid
v-else
:items="filteredItems"
:has-more="false"
:is-loading="loading"
single-column
data-testid="space-pages-list"
@scrollbar-width-change="scrollbarWidth = $event"
>
<template #card="{ item }">
<SystemItemCard
:fields="SPACE_PAGE_SCHEMA"
:item="item"
:get-translation="getTranslation"
:data-testid="`space-page-${item.slug}`"
>
<template #actions="{ item: page }">
<button
type="button"
class="btn btn-sm btn-secondary action-icon"
:title="t('common.edit')"
:data-testid="`space-page-edit-${page.slug}`"
@click.stop="openEdit(page.slug)"
>
<font-awesome-icon icon="fa-solid fa-pen" />
</button>
<button
type="button"
class="btn btn-sm action-icon"
:class="page.published ? 'btn-outline-warning' : 'btn-outline-success'"
:title="page.published ? t('spacePages.unpublish') : t('spacePages.publish')"
:disabled="busySlug === page.slug"
:data-testid="`space-page-publish-${page.slug}`"
@click.stop="togglePublished(page as SpacePageSummary)"
>
<font-awesome-icon
:icon="page.published ? 'fa-solid fa-eye-slash' : 'fa-solid fa-eye'"
/>
</button>
<!-- The space always keeps its home page -->
<button
v-if="!page.isHome"
type="button"
class="btn btn-sm btn-danger action-icon"
:title="t('common.delete')"
:data-testid="`space-page-delete-${page.slug}`"
@click.stop="pageToDelete = page as SpacePageSummary"
>
<font-awesome-icon icon="fa-solid fa-trash" />
</button>
</template>
</SystemItemCard>
</template>
</VirtualCardGrid>
</template>
</SearchFilterHeader>
<ConfirmModal
:is-open="!!pageToDelete"
:title="t('spacePages.deleteTitle')"
:message="t('spacePages.deleteMessage')"
:confirm-label="t('common.delete')"
variant="danger"
@confirm="doDelete"
@cancel="pageToDelete = null"
/>
</PageLayout>
<FloatingPageActions :scroll-top-title="t('common.backToTop')" />
</template>
<script setup lang="ts">
// @implements UC-SPACE-009.1
/**
* The pages of the flow's public space: listed like the other lists, created,
* published and deleted from here, edited in a sidebar over the list. The
* sidebar of a page has its own address (space-page-editor), so a link or a
* reload opens it again.
*/
import { computed, onMounted, ref } from 'vue'
import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import PageLayout from '@/components/PageLayout.vue'
import ConfirmModal from '@/components/ConfirmModal.vue'
import EmptyState from '@/components/EmptyState.vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import NoActiveFlowNotice from '@/components/NoActiveFlowNotice.vue'
import FloatingPageActions from '@/components/FloatingPageActions.vue'
import SearchFilterHeader from '@/components/SearchFilterHeader.vue'
import SortControl, { type SortOption } from '@/components/SortControl.vue'
import SystemItemHeader from '@/components/SystemItemHeader.vue'
import SystemItemCard from '@/components/SystemItemCard.vue'
import VirtualCardGrid from '@/components/VirtualCardGrid.vue'
import SpacePageFormSidebar from '@/components/SpacePageFormSidebar.vue'
import { SPACE_PAGE_SCHEMA } from '@/schemas/spacePage-schema'
import { toSpacePageViewModel, type SpacePageViewModel } from '@/utils/systemListViewModels'
import { useAuthStore } from '@/stores/auth'
import { useFlowsStore } from '@/stores/flows'
import { useToastStore } from '@/stores/toast'
import { useLanguage } from '@/composables/useLanguage'
import { useUILanguage } from '@/composables/useUILanguage'
import { usePermissions } from '@/composables/usePermissions'
import { flowRoute } from '@/router/flowRoutes'
import { getErrorMessage } from '@/utils/errors'
import {
localize,
pageLinkConflictMessage,
type SpacePageDraft,
type SpacePageSummary
} from '@/utils/spacePages'
import { deleteSpacePage, listSpacePages, publishSpacePage } from '@/services/spacePagesApi'
const route = useRoute()
const router = useRouter()
const authStore = useAuthStore()
const flowsStore = useFlowsStore()
const toastStore = useToastStore()
const { getTranslation } = useLanguage()
const { t, uiLanguage } = useUILanguage()
const { hasPermission } = usePermissions()
const flowId = computed(() => authStore.currentFlow || '')
const flow = computed(() => flowsStore.myFlows.find((f) => f.flowId === flowId.value))
const flowSlug = computed(() => flow.value?.flowSlug || '')
const defaultLanguage = computed(() => flow.value?.defaultLanguage || 'en')
const spacePublished = computed(() => flow.value?.space?.enabled === true)
const canEdit = computed(() => hasPermission('pages:update'))
const pages = ref<SpacePageSummary[]>([])
const maxPages = ref(30)
const loading = ref(false)
const atLimit = computed(() => pages.value.length >= maxPages.value)
const busySlug = ref<string | null>(null)
const pageToDelete = ref<SpacePageSummary | null>(null)
const scrollbarWidth = ref(0)
const localizeTitle = (page: SpacePageSummary) =>
localize(page.title, uiLanguage.value, defaultLanguage.value) || page.slug
const pageViewModels = computed(() =>
pages.value.map((page) => toSpacePageViewModel(page, { flowSlug: flowSlug.value, localizeTitle }))
)
const searchQuery = ref('')
const searchFields = [
(page: SpacePageViewModel) => page.titleDisplay,
(page: SpacePageViewModel) => page.slug
]
// The menu order first: the order visitors see the pages in
const sortField = ref('menuOrder')
const sortDirection = ref<'asc' | 'desc'>('asc')
const sortOptions = computed<SortOption[]>(() => [
{ value: 'menuOrder', label: t('spacePages.menuOrder') },
{ value: 'title', label: t('spacePages.fields.pageTitle') },
{ value: 'updatedAt', label: t('spacePages.updatedAt') }
])
function getSortValue(page: SpacePageViewModel, field: string): string | number {
if (field === 'updatedAt') return page.updatedAt ? new Date(page.updatedAt).getTime() : 0
if (field === 'title') return page.titleDisplay.toLowerCase()
return page.menuOrder
}
// --- The sidebar: an existing page's has its own route, a new page's none ---
const sidebarRef = ref<InstanceType<typeof SpacePageFormSidebar> | null>(null)
const creating = ref(false)
const editedSlug = computed(() =>
route.name === 'space-page-editor' ? String(route.params.pageSlug) : null
)
const sidebarOpen = computed(() => creating.value || editedSlug.value !== null)
const listRoute = () => flowRoute(flowSlug.value, 'space-pages')
const editorRoute = (pageSlug: string) =>
flowRoute(flowSlug.value, 'space-page-editor', { pageSlug })
function openCreate() {
creating.value = true
}
function openEdit(pageSlug: string) {
router.push(editorRoute(pageSlug))
}
function closeSidebar() {
creating.value = false
if (editedSlug.value !== null) router.push(listRoute())
}
/** The list shows the change; a page just created or renamed gets its own address */
async function onSaved(page: SpacePageDraft) {
void load()
if (editedSlug.value !== page.slug) await router.replace(editorRoute(page.slug))
creating.value = false
}
// Another page's sidebar drops the unsaved changes of this one; leaving the
// page is guarded by the sidebar itself (BaseFormSidebar)
onBeforeRouteUpdate(() => sidebarRef.value?.confirmDiscard() ?? true)
async function load() {
if (!flowId.value || !canEdit.value) return
loading.value = true
try {
const list = await listSpacePages(flowId.value)
pages.value = list.pages
if (list.maxPages) maxPages.value = list.maxPages
} catch (err) {
toastStore.error(getErrorMessage(err, t('spacePages.loadError'), t))
} finally {
loading.value = false
}
}
/** Why a change was refused: the pages it would break a link with, or the API's error */
function saveErrorMessage(err: unknown) {
return (
pageLinkConflictMessage(err, t, uiLanguage.value, defaultLanguage.value) ??
getErrorMessage(err, t('spacePages.saveError'), t)
)
}
async function togglePublished(page: SpacePageSummary) {
busySlug.value = page.slug
try {
await publishSpacePage(flowId.value, page.slug, !page.published)
toastStore.success(
page.published ? t('spacePages.unpublished') : t('spacePages.publishedToast')
)
await load()
} catch (err) {
toastStore.error(saveErrorMessage(err))
} finally {
busySlug.value = null
}
}
async function doDelete() {
const page = pageToDelete.value
pageToDelete.value = null
if (!page) return
try {
await deleteSpacePage(flowId.value, page.slug)
toastStore.success(t('spacePages.deleted'))
await load()
} catch (err) {
toastStore.error(saveErrorMessage(err))
}
}
onMounted(load)
</script>
|