From 9f42050b39f733ab5fa6789df91e4c84d8dc0b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Thu, 13 Jul 2023 15:35:08 +0200 Subject: [PATCH] Add option to define custom record page layout titles with interpolation --- .../components/Chart/Report/ReportEdit.vue | 1 + .../ModuleFields/Configurator/Record.vue | 1 + .../PageBlocks/CommentConfigurator.vue | 1 + .../PageBlocks/MetricConfigurator/index.vue | 1 + .../PageBlocks/ProgressConfigurator.vue | 3 + .../PageBlocks/RecordListConfigurator.vue | 3 +- .../RecordOrganizerConfigurator.vue | 1 + .../compose/src/views/Admin/Pages/Edit.vue | 79 +++++++++++++++++++ .../src/views/Public/Pages/Records/View.vue | 18 +++++ lib/js/src/compose/types/page-layout.ts | 3 + locale/en/corteza-webapp-compose/block.yaml | 6 +- locale/en/corteza-webapp-compose/chart.yaml | 2 +- locale/en/corteza-webapp-compose/field.yaml | 2 +- locale/en/corteza-webapp-compose/page.yaml | 4 + server/compose/types/page_layout.go | 2 + 15 files changed, 120 insertions(+), 7 deletions(-) diff --git a/client/web/compose/src/components/Chart/Report/ReportEdit.vue b/client/web/compose/src/components/Chart/Report/ReportEdit.vue index 0e7f8897f..64b811eb0 100644 --- a/client/web/compose/src/components/Chart/Report/ReportEdit.vue +++ b/client/web/compose/src/components/Chart/Report/ReportEdit.vue @@ -76,6 +76,7 @@ tag="small" class="text-muted" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} diff --git a/client/web/compose/src/components/ModuleFields/Configurator/Record.vue b/client/web/compose/src/components/ModuleFields/Configurator/Record.vue index bc0c52a2e..68928fdaf 100644 --- a/client/web/compose/src/components/ModuleFields/Configurator/Record.vue +++ b/client/web/compose/src/components/ModuleFields/Configurator/Record.vue @@ -61,6 +61,7 @@ path="kind.record.prefilterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} diff --git a/client/web/compose/src/components/PageBlocks/CommentConfigurator.vue b/client/web/compose/src/components/PageBlocks/CommentConfigurator.vue index a42a66a00..5fe5f602e 100644 --- a/client/web/compose/src/components/PageBlocks/CommentConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/CommentConfigurator.vue @@ -47,6 +47,7 @@ path="recordList.record.prefilterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} diff --git a/client/web/compose/src/components/PageBlocks/MetricConfigurator/index.vue b/client/web/compose/src/components/PageBlocks/MetricConfigurator/index.vue index 91545fd3a..3dd5efaa4 100644 --- a/client/web/compose/src/components/PageBlocks/MetricConfigurator/index.vue +++ b/client/web/compose/src/components/PageBlocks/MetricConfigurator/index.vue @@ -161,6 +161,7 @@ path="metric.edit.filterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} diff --git a/client/web/compose/src/components/PageBlocks/ProgressConfigurator.vue b/client/web/compose/src/components/PageBlocks/ProgressConfigurator.vue index 87c3a2502..9d46f762c 100644 --- a/client/web/compose/src/components/PageBlocks/ProgressConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/ProgressConfigurator.vue @@ -59,6 +59,7 @@ path="metric.edit.filterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} @@ -169,6 +170,7 @@ path="metric.edit.filterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} @@ -279,6 +281,7 @@ path="metric.edit.filterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} diff --git a/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue b/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue index 45a22a3f2..47c622114 100644 --- a/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue @@ -240,10 +240,9 @@ path="recordList.record.prefilterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} - ${ownerID} - ${userID} diff --git a/client/web/compose/src/components/PageBlocks/RecordOrganizerConfigurator.vue b/client/web/compose/src/components/PageBlocks/RecordOrganizerConfigurator.vue index deeb0529e..1f956d30a 100644 --- a/client/web/compose/src/components/PageBlocks/RecordOrganizerConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/RecordOrganizerConfigurator.vue @@ -48,6 +48,7 @@ path="recordList.record.prefilterFootnote" tag="label" > + ${record.values.fieldName} ${recordID} ${ownerID} ${userID} diff --git a/client/web/compose/src/views/Admin/Pages/Edit.vue b/client/web/compose/src/views/Admin/Pages/Edit.vue index 953771d44..295381f07 100644 --- a/client/web/compose/src/views/Admin/Pages/Edit.vue +++ b/client/web/compose/src/views/Admin/Pages/Edit.vue @@ -380,6 +380,7 @@ :title="$t('page-layout.configure', { title: ((layoutEditor.layout || {}).meta || {}).title, interpolation: { escapeValue: false } })" :ok-title="$t('general:label.saveAndClose')" ok-variant="primary" + :ok-disabled="!layoutEditor.layout.meta.title" cancel-variant="link" size="xl" scrollable @@ -388,6 +389,79 @@ @cancel="layoutEditor.layout = undefined" @hide="layoutEditor.layout = undefined" > +
+ {{ $t('page-layout.general') }} +
+ + + + + + + + + + + + + + + + + + + + + + + + + ${record.values.fieldName} + ${recordID} + ${ownerID} + ${userID} + + + +
+
{{ $t('page-layout.visibility') }}
@@ -824,6 +898,11 @@ export default { processing: false, options: [], }, + + checkboxLabel: { + on: this.$t('general:label.yes'), + off: this.$t('general:label.no'), + }, } }, diff --git a/client/web/compose/src/views/Public/Pages/Records/View.vue b/client/web/compose/src/views/Public/Pages/Records/View.vue index 7447b8519..f232fd63e 100644 --- a/client/web/compose/src/views/Public/Pages/Records/View.vue +++ b/client/web/compose/src/views/Public/Pages/Records/View.vue @@ -113,6 +113,7 @@ import Grid from 'corteza-webapp-compose/src/components/Public/Page/Grid' import RecordToolbar from 'corteza-webapp-compose/src/components/Common/RecordToolbar' import record from 'corteza-webapp-compose/src/mixins/record' import { compose, NoID } from '@cortezaproject/corteza-js' +import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter' export default { i18nOptions: { @@ -218,7 +219,24 @@ export default { }, title () { + if (!this.layout) { + return '' + } + + const { config = {}, meta = {} } = this.layout || {} + const { useTitle = false } = config + + if (useTitle) { + return evaluatePrefilter(meta.title, { + record: this.record, + recordID: (this.record || {}).recordID || NoID, + ownerID: (this.record || {}).ownedBy || NoID, + userID: (this.$auth.user || {}).userID || NoID, + }) + } + const { name, handle } = this.module + const titlePrefix = this.inCreating ? 'create' : this.inEditing ? 'edit' : 'view' return this.$t(`page:public.record.${titlePrefix}.title`, { name: name || handle, interpolation: { escapeValue: false } }) diff --git a/lib/js/src/compose/types/page-layout.ts b/lib/js/src/compose/types/page-layout.ts index 441d57a9d..20e70a122 100644 --- a/lib/js/src/compose/types/page-layout.ts +++ b/lib/js/src/compose/types/page-layout.ts @@ -16,6 +16,8 @@ interface PageLayoutConfig { submit: Button; }; actions: Action[]; + // Only used for record pages + useTitle: Boolean; } interface Action { @@ -67,6 +69,7 @@ export class PageLayout { submit: { enabled: true }, }, actions: [], + useTitle: false, } public meta: Meta = { diff --git a/locale/en/corteza-webapp-compose/block.yaml b/locale/en/corteza-webapp-compose/block.yaml index 232569f7b..de0d90709 100644 --- a/locale/en/corteza-webapp-compose/block.yaml +++ b/locale/en/corteza-webapp-compose/block.yaml @@ -198,7 +198,7 @@ metric: dimensionFieldLabel: Field dimensionFieldPlaceholder: Dimension field dimensionLabel: Dimension - filterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}} and {{2}} are evaluated (when available) + filterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available) filterLabel: Filter labelLabel: Label labelPlaceholder: Label @@ -302,7 +302,7 @@ recordList: filter: label: Record filter placeholder: field1 = 1 AND field2 = 232 - footnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}} and {{2}} are evaluated (when available) + footnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available) createdAt: Record created custom: Custom lastMonth: Last month @@ -450,7 +450,7 @@ recordList: recordsLabel: Records noPermission: No permission to read record perPage: Records per page - prefilterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}} and {{2}} are evaluated (when available) + prefilterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available) prefilterHideSearch: Users will be able to search the record list filterHide: Users will be able to filter the list prefilterLabel: Filtering diff --git a/locale/en/corteza-webapp-compose/chart.yaml b/locale/en/corteza-webapp-compose/chart.yaml index f9449982f..011898bbd 100644 --- a/locale/en/corteza-webapp-compose/chart.yaml +++ b/locale/en/corteza-webapp-compose/chart.yaml @@ -51,7 +51,7 @@ edit: customize: Customize filter label: Filter preset: Preset filters - footnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}} and {{2}} are evaluated (when available) + footnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available) placeholder: field1 = 1 AND field2 = 232 noFilter: Select a filter or make a custom one recordsCreatedLastMonth: Records created last month diff --git a/locale/en/corteza-webapp-compose/field.yaml b/locale/en/corteza-webapp-compose/field.yaml index 2819511e8..9ec230d53 100644 --- a/locale/en/corteza-webapp-compose/field.yaml +++ b/locale/en/corteza-webapp-compose/field.yaml @@ -106,7 +106,7 @@ kind: fieldFromModuleField: Label field from related module field pickField: Pick field suggestionPlaceholder: Start typing to search for records - prefilterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}} and {{2}} are evaluated (when available) + prefilterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available) prefilterLabel: Prefilter records prefilterPlaceholder: field1 = 1 AND field2 = 232 select: diff --git a/locale/en/corteza-webapp-compose/page.yaml b/locale/en/corteza-webapp-compose/page.yaml index e9f183096..85c81c060 100644 --- a/locale/en/corteza-webapp-compose/page.yaml +++ b/locale/en/corteza-webapp-compose/page.yaml @@ -4,7 +4,10 @@ page-layout: add: Add layout configure: 'Configure layout - "{{title}}"' visibility: Visibility + general: General + useTitle: Use layout title tooltip: + title: Use the layout title instead of the record page default. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available) configure: Configure layout builder: Open layout in builder condition: @@ -96,6 +99,7 @@ notVisible: Hidden pageMoveFailed: Could not move this page reordered: Page reordered showSubPages: Expand sub-pages in the sidebar +customTitle: Use custom title title: List of Pages tooltip: unsavedChanges: Unsaved Changes diff --git a/server/compose/types/page_layout.go b/server/compose/types/page_layout.go index 169dfbccc..79cc70a13 100644 --- a/server/compose/types/page_layout.go +++ b/server/compose/types/page_layout.go @@ -84,6 +84,8 @@ type ( Buttons PageLayoutButtonConfig `json:"buttons"` Actions []PageLayoutAction `json:"actions,omitempty"` + + UseTitle bool `json:"useTitle"` } PageLayoutVisibility struct {