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 | 62x 65x 3x 3x 18x 3x 6x 3x 4x 3x 3x 62x 62x 62x 62x 62x 9x 9x 3x 6x 21x 12x 12x 6x 4x 10x 6x 6x 5x 4x 1x 1x 1x 9x | <template>
<div class="pack-schema">
<section
v-for="entity in entities"
:key="entity.tempId"
class="pack-schema-entity border rounded p-3 mb-3"
:data-temp-id="entity.tempId"
>
<h3 class="h6 mb-1">
<font-awesome-icon icon="fa-solid fa-cube" class="me-1" />
{{ getTranslation(entity.name) }}
</h3>
<p v-if="entity.description" class="small text-muted mb-2">
{{ getTranslation(entity.description) }}
</p>
<ul class="list-unstyled small mb-0">
<li v-for="field in entity.fields" :key="field.fieldId" class="pack-schema-field">
<strong>{{ getTranslation(field.name) }}</strong>
<span class="text-muted"> · {{ field.type }}</span>
<span v-if="field.mandatory" class="text-muted"> · {{ t('store.mandatory') }}</span>
<span v-if="field.type === 'entity_ref'" class="pack-schema-link text-muted">
<font-awesome-icon icon="fa-solid fa-link" class="ms-1 me-1" />
{{ linkLabel(field) }}
</span>
<ul v-if="stateLabels(field).length > 0" class="text-muted mb-0">
<li>{{ t('store.workflowStates') }}: {{ stateLabels(field).join(', ') }}</li>
</ul>
</li>
</ul>
<p v-if="entity.forms?.length" class="small text-muted mt-2 mb-0">
{{ t('store.forms') }}: {{ entity.forms.map((form) => formLabel(form)).join(', ') }}
</p>
<!-- Items for linked entities (UC-STORE-003.1): at most 20, all shown -->
<p v-if="entity.items?.length" class="small mt-2 mb-0 pack-schema-items">
<span class="fw-semibold">
{{ t('store.packItems').replace('{count}', String(entity.items.length)) }}
</span>
{{ entity.items.map((item) => itemLabel(entity, item)).join(', ') }}
</p>
<div v-if="entity.emailTemplates?.length" class="mt-2 pack-schema-templates">
<p class="small fw-semibold mb-1">{{ t('store.emailTemplates') }}</p>
<blockquote
v-for="template in entity.emailTemplates"
:key="template.id"
class="small text-muted border-start ps-2 mb-1"
>
<strong>{{ templateText(template.name) }}</strong>
<span v-if="template.subject"> — {{ templateText(template.subject) }}</span>
<span v-if="template.body" class="d-block pack-schema-template-body">
{{ templateText(template.body) }}
</span>
</blockquote>
</div>
</section>
</div>
</template>
<script setup lang="ts">
// @implements UC-STORE-002.1, UC-STORE-003.1
// Everything an install would create: nobody can judge what they are not shown.
import { computed } from 'vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useLanguage } from '@/composables/useLanguage'
type Text = string | Record<string, string>
export interface PackSchemaField {
fieldId?: string
name: Text
type?: string
mandatory?: boolean
reference?: { entityId?: string }
workflowDefinition?: { states?: Array<{ id: string; label?: Text; labels?: Text }> }
}
export interface PackSchemaEntity {
tempId: string
name: Text
description?: Text
fields?: PackSchemaField[]
forms?: Array<{ id?: string; name?: Text }>
emailTemplates?: Array<{ id: string; name?: Text; subject?: Text; body?: Text }>
items?: Array<Record<string, unknown>>
}
// The fields an item is named by on the pack page, the first one with a value
const LABEL_TYPES = ['text', 'textarea', 'email', 'number', 'select', 'date']
const props = defineProps<{ entities: PackSchemaEntity[] }>()
const { t } = useUILanguage()
const { getTranslation } = useLanguage()
const nameByTempId = computed(() => new Map(props.entities.map((e) => [e.tempId, e.name])))
function linkLabel(field: PackSchemaField): string {
const target = field.reference?.entityId
if (target && nameByTempId.value.has(target)) {
return t('store.linkTo').replace('{name}', getTranslation(nameByTempId.value.get(target)!))
}
return target === 'unavailable' ? t('store.linkUnavailable') : t('store.linkOutside')
}
function stateLabels(field: PackSchemaField): string[] {
return (field.workflowDefinition?.states ?? []).map((state) => {
const label = state.labels ?? state.label
return label ? getTranslation(label) : state.id
})
}
function formLabel(form: { id?: string; name?: Text }): string {
return form.name ? getTranslation(form.name) : (form.id ?? '')
}
function itemLabel(entity: PackSchemaEntity, item: Record<string, unknown>): string {
for (const field of entity.fields ?? []) {
if (!field.fieldId || !LABEL_TYPES.includes(field.type ?? '')) continue
const value = item[field.fieldId]
if (typeof value === 'number') return String(value)
if (typeof value === 'string' && value.trim()) return value
if (value && typeof value === 'object' && !Array.isArray(value)) {
const label = getTranslation(value as Record<string, string>)
Eif (label) return label
}
}
return String(item.originalId ?? '')
}
function templateText(value: Text | undefined): string {
return value ? getTranslation(value) : ''
}
</script>
<style scoped>
.pack-schema-template-body {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
</style>
|