|
| 1 | +<!-- |
| 2 | + - SPDX-License-Identifier: EUPL-1.2 |
| 3 | + - |
| 4 | + - BuilderHost mounts a NESTED CnAppRoot for the virtual app addressed by |
| 5 | + - the :slug param. Per design.md Decision 4/5, this preserves the |
| 6 | + - OpenBuilt outer chrome and forwards path segments after the slug to |
| 7 | + - the inner router. The :key="slug" prop forces a clean remount when |
| 8 | + - the user navigates between virtual apps. |
| 9 | + - |
| 10 | + - Version routing (spec `openbuilt-version-routing` REQ-OBVR-004): |
| 11 | + - Reads `?_version=<versionSlug>` from `$route.query._version` (the |
| 12 | + - underscore-prefix form to avoid colliding with user-defined `?version=` |
| 13 | + - params). The CnAppRoot endpoint URL includes the `_version` param when |
| 14 | + - present, so the server-side ManifestResolverService resolves the correct |
| 15 | + - ApplicationVersion manifest. On 404 (unknown or unauthorised version), |
| 16 | + - the view renders the "version not found" UI state (REQ-OBVR-009). |
| 17 | + - |
| 18 | + - Loader workaround (design.md Decision 4): until the in-memory |
| 19 | + - useAppManifest overload ships in nextcloud-vue (chain spec #2), we |
| 20 | + - point the library's backend fetch at our per-slug manifest endpoint |
| 21 | + - via options.endpoint. The bundled-manifest argument is a placeholder |
| 22 | + - skeleton; the real manifest arrives from the backend merge. |
| 23 | + --> |
| 24 | +<template> |
| 25 | + <div class="openbuilt-builder-host" data-testid="openbuilt-builder-host"> |
| 26 | + <!-- REQ-OBVR-009: show version-not-found when useApplicationVersion resolved to 404 --> |
| 27 | + <div |
| 28 | + v-if="versionNotFound" |
| 29 | + class="openbuilt-builder-host__version-not-found" |
| 30 | + role="alert" |
| 31 | + aria-live="polite"> |
| 32 | + {{ t('openbuilt', 'Version not found') }} |
| 33 | + </div> |
| 34 | + <CnAppRoot |
| 35 | + v-else |
| 36 | + :key="cacheKey" |
| 37 | + :app-id="appId" |
| 38 | + :bundled-manifest="placeholderManifest" |
| 39 | + :options="manifestOptions" /> |
| 40 | + </div> |
| 41 | +</template> |
| 42 | + |
| 43 | +<script> |
| 44 | +import { CnAppRoot } from '@conduction/nextcloud-vue' |
| 45 | +import { generateUrl } from '@nextcloud/router' |
| 46 | +
|
| 47 | +import { useApplicationVersion } from '../composables/useApplicationVersion.js' |
| 48 | +import placeholderManifest from '../manifests/placeholder.json' |
| 49 | +
|
| 50 | +export default { |
| 51 | + name: 'BuilderHost', |
| 52 | + components: { |
| 53 | + CnAppRoot, |
| 54 | + }, |
| 55 | + data() { |
| 56 | + return { |
| 57 | + // REQ-OBVR-004: reactive version state from useApplicationVersion. |
| 58 | + applicationVersion: null, |
| 59 | + versionLoading: false, |
| 60 | + versionError: null, |
| 61 | + } |
| 62 | + }, |
| 63 | + computed: { |
| 64 | + slug() { |
| 65 | + return this.$route.params.slug |
| 66 | + }, |
| 67 | + /** |
| 68 | + * REQ-OBVR-004: read `?_version=` from the URL query. |
| 69 | + * Underscore-prefix to avoid colliding with user-defined `?version=` params. |
| 70 | + * |
| 71 | + * @return {string|undefined} |
| 72 | + */ |
| 73 | + versionSlug() { |
| 74 | + return this.$route.query._version || undefined |
| 75 | + }, |
| 76 | + appId() { |
| 77 | + return `openbuilt-${this.slug}` |
| 78 | + }, |
| 79 | + /** |
| 80 | + * Cache key forces CnAppRoot remount when slug OR version changes. |
| 81 | + * |
| 82 | + * @return {string} |
| 83 | + */ |
| 84 | + cacheKey() { |
| 85 | + return `${this.slug}:${this.versionSlug || 'default'}` |
| 86 | + }, |
| 87 | + /** |
| 88 | + * REQ-OBVR-009: true when the version fetch completed with an error |
| 89 | + * (e.g. 404 for unknown or unauthorised version). The view renders a |
| 90 | + * "version not found" state identical for both "doesn't exist" and |
| 91 | + * "you can't see it" cases — no auth cue exposed to the caller. |
| 92 | + * |
| 93 | + * @return {boolean} |
| 94 | + */ |
| 95 | + versionNotFound() { |
| 96 | + return !this.versionLoading && this.versionError !== null && this.applicationVersion === null |
| 97 | + }, |
| 98 | + placeholderManifest() { |
| 99 | + return placeholderManifest |
| 100 | + }, |
| 101 | + manifestOptions() { |
| 102 | + // Forward `?_version=` to the manifest endpoint so the server resolves |
| 103 | + // the correct ApplicationVersion manifest (REQ-OBVR-001). |
| 104 | + const endpoint = generateUrl(`/apps/openbuilt/api/applications/${this.slug}/manifest`) |
| 105 | + return { |
| 106 | + endpoint: this.versionSlug |
| 107 | + ? `${endpoint}?_version=${encodeURIComponent(this.versionSlug)}` |
| 108 | + : endpoint, |
| 109 | + } |
| 110 | + }, |
| 111 | + }, |
| 112 | + watch: { |
| 113 | + slug() { |
| 114 | + this.resolveVersion() |
| 115 | + }, |
| 116 | + versionSlug() { |
| 117 | + this.resolveVersion() |
| 118 | + }, |
| 119 | + }, |
| 120 | + created() { |
| 121 | + // REQ-OBVR-004: resolve the active ApplicationVersion on mount. |
| 122 | + // NOTE: we do NOT call $router.replace() — that would strip ?_version= |
| 123 | + // and break bookmarkability (REQ-OBVR-008). |
| 124 | + this.resolveVersion() |
| 125 | + }, |
| 126 | + methods: { |
| 127 | + /** |
| 128 | + * Kick off useApplicationVersion and mirror reactive state into component data. |
| 129 | + * |
| 130 | + * @return {void} |
| 131 | + */ |
| 132 | + resolveVersion() { |
| 133 | + this.versionError = null |
| 134 | + const { applicationVersion, loading, error } = useApplicationVersion( |
| 135 | + this.slug, |
| 136 | + this.versionSlug, |
| 137 | + ) |
| 138 | + this.applicationVersion = applicationVersion.value |
| 139 | + this.versionLoading = loading.value |
| 140 | + const unwatch = this.$watch(() => applicationVersion.value, (v) => { |
| 141 | + this.applicationVersion = v |
| 142 | + }) |
| 143 | + const unwatchLoading = this.$watch(() => loading.value, (v) => { |
| 144 | + this.versionLoading = v |
| 145 | + if (!v) { |
| 146 | + unwatch() |
| 147 | + unwatchLoading() |
| 148 | + this.versionError = error.value |
| 149 | + } |
| 150 | + }) |
| 151 | + }, |
| 152 | + }, |
| 153 | +} |
| 154 | +</script> |
| 155 | + |
| 156 | +<style scoped> |
| 157 | +.openbuilt-builder-host { |
| 158 | + display: flex; |
| 159 | + flex-direction: column; |
| 160 | + flex: 1 1 auto; |
| 161 | + min-height: 0; |
| 162 | +} |
| 163 | +</style> |
0 commit comments