Add page titles (#4775)

* restructure template rendering

* add useTitle composable

* Split up render-string-template from getFieldsFromTemplate

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Nitwel
2021-03-31 16:53:57 +02:00
committed by GitHub
parent 8df659325c
commit 6f9b2cafcd
13 changed files with 81 additions and 50 deletions

View File

@@ -207,6 +207,8 @@ import useShortcut from '@/composables/use-shortcut';
import { NavigationGuard } from 'vue-router';
import { usePermissions } from '@/composables/use-permissions';
import unsavedChanges from '@/composables/unsaved-changes';
import { useTitle } from '@/composables/use-title';
import { renderStringTemplate } from '@/utils/render-string-template';
export default defineComponent({
name: 'collections-item',
@@ -300,6 +302,24 @@ export default defineComponent({
: i18n.t('editing_in', { collection: collectionInfo.value?.name });
});
const tabTitle = computed(() => {
let tabTitle = (collectionInfo.value?.name || '') + ' | ';
if (collectionInfo.value && collectionInfo.value.meta) {
if (collectionInfo.value.meta.singleton === true) {
return tabTitle + collectionInfo.value.name;
} else if (isNew.value === false && collectionInfo.value.meta.display_template) {
const { displayValue } = renderStringTemplate(collectionInfo.value.meta.display_template, templateValues);
if (displayValue.value !== undefined) return tabTitle + displayValue.value;
}
}
return tabTitle + title.value;
});
useTitle(tabTitle);
const archiveTooltip = computed(() => {
if (archiveAllowed.value === false) return i18n.t('not_allowed');
if (isArchived.value === true) return i18n.t('unarchive');