Skip to content

Commit

Permalink
Add interpolation except for metic
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmyMay committed Dec 16, 2023
1 parent 3e1d7bd commit 9be17d4
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
v-model="block.title"
:placeholder="$t('general.titlePlaceholder')"
/>

<b-input-group-append>
<page-translator
v-if="page"
Expand Down
27 changes: 26 additions & 1 deletion client/web/compose/src/components/PageBlocks/ContentBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,40 @@
>
<p
:style="{ 'white-space': 'pre-wrap' }"
v-html="options.body"
v-html="contentBody"
/>
</div>
</wrap>
</template>
<script>
import base from './base'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
import { NoID } from '@cortezaproject/corteza-js'
export default {
extends: base,
computed: {
contentBody () {
const { body } = this.options
// Regular expression to match ${} tokens
const tokenRegex = /\${(.*?)}/g
// Replace each token with its prefiltered content
const prefilteredBody = body.replace(tokenRegex, (match, tokenContent) => {
const reconstructedToken = '${' + tokenContent + '}'
return evaluatePrefilter(reconstructedToken, {
record: this.record,
recordID: (this.record || {}).recordID || NoID,
ownerID: (this.record || {}).ownedBy || NoID,
userID: (this.$auth.user || {}).userID || NoID,
})
})
return prefilteredBody
},
},
}
</script>
11 changes: 10 additions & 1 deletion client/web/compose/src/components/PageBlocks/IFrameBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
</template>
<script>
import base from './base'
import { NoID } from '@cortezaproject/corteza-js'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
export default {
extends: base,
Expand All @@ -29,7 +31,14 @@ export default {
}
}
return src || blank
const prefilteredSource = evaluatePrefilter(src, {
record: this.record,
recordID: (this.record || {}).recordID || NoID,
ownerID: (this.record || {}).ownedBy || NoID,
userID: (this.$auth.user || {}).userID || NoID,
})
return prefilteredSource || blank
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,21 @@
v-model="edit.transformFx"
placeholder="v"
class="mb-1"
@change="evaluateTransformation"
/>

<small>{{ $t('metric.edit.transformFunctionDescription') }}</small>
<b-form-text>
<i18next
path="metric.edit.transformFootnote"
tag="label"
>
<code>${record.values.fieldName}</code>
<code>${recordID}</code>
<code>${ownerID}</code>
<code>${userID}</code>
</i18next>
</b-form-text>
</b-form-group>

<b-form-group
Expand Down Expand Up @@ -343,6 +355,7 @@ import { mapGetters } from 'vuex'
import MetricBase from '../MetricBase'
import { VueSelect } from 'vue-select'
import { compose, NoID } from '@cortezaproject/corteza-js'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
export default {
i18nOptions: {
Expand Down Expand Up @@ -492,6 +505,15 @@ export default {
this.dimensionModifiers = []
this.aggregationOperations = []
},
evaluateTransformation (t) {
this.edit.transformFx = evaluatePrefilter(t, {
record: this.record,
recordID: (this.record || {}).recordID || NoID,
ownerID: (this.record || {}).ownedBy || NoID,
userID: (this.$auth.user || {}).userID || NoID,
})
},
},
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
:class="buttonClass"
@click.prevent="handle(b)"
>
{{ b.label || '-' }}
{{ handleButtonLabel(b.label) || '-' }}
</b-button>
</div>
</template>
<script>
import { compose, automation } from '@cortezaproject/corteza-js'
import { compose, automation, NoID } from '@cortezaproject/corteza-js'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
import base from '../base'
export default {
Expand Down Expand Up @@ -181,6 +182,15 @@ export default {
this.processing = false
}
},
handleButtonLabel (label) {
return evaluatePrefilter(label, {
record: this.record,
recordID: (this.record || {}).recordID || NoID,
ownerID: (this.record || {}).ownedBy || NoID,
userID: (this.$auth.user || {}).userID || NoID,
})
},
},
}
</script>
13 changes: 11 additions & 2 deletions client/web/compose/src/components/PageBlocks/TabsBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@

<script>
import base from './base'
import { compose } from '@cortezaproject/corteza-js'
import { compose, NoID } from '@cortezaproject/corteza-js'
import { fetchID } from 'corteza-webapp-compose/src/lib/block'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
export default {
i18nOptions: {
Expand Down Expand Up @@ -234,7 +235,14 @@ export default {
getTabTitle ({ title, block = {} }, tabIndex) {
const { title: blockTitle, kind } = block
return title || blockTitle || kind || `${this.$t('tab')} ${tabIndex + 1}`
const prefilteredTitle = evaluatePrefilter(blockTitle, {
record: this.record,
recordID: (this.record || {}).recordID || NoID,
ownerID: (this.record || {}).ownedBy || NoID,
userID: (this.$auth.user || {}).userID || NoID,
})
return title || prefilteredTitle || blockTitle || kind || `${this.$t('tab')} ${tabIndex + 1}`
},
isTabLazy ({ block = {} }) {
Expand All @@ -257,6 +265,7 @@ export default {
.card {
border-radius: 0;
}
.card-header {
border-radius: 0;
}
Expand Down
4 changes: 2 additions & 2 deletions client/web/compose/src/components/PageBlocks/Wrap/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<div v-if="!headerSet">
<div class="d-flex">
<h5
v-if="block.title"
v-if="blockTitle"
class="text-truncate mb-0"
>
{{ block.title }}
{{ blockTitle }}

<slot name="title-badge" />
</h5>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h5
class="text-truncate mb-0"
>
{{ block.title }}
{{ blockTitle }}

<slot name="title-badge" />
</h5>
Expand Down
10 changes: 10 additions & 0 deletions client/web/compose/src/components/PageBlocks/Wrap/base.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import { compose, NoID } from '@cortezaproject/corteza-js'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
export default {
i18nOptions: {
Expand Down Expand Up @@ -79,6 +80,15 @@ export default {
const params = this.block.blockID === NoID ? { block: this.block } : { blockID: this.block.blockID }
return this.isBlockMagnified ? undefined : params
},
blockTitle () {
return evaluatePrefilter(this.block.title, {
record: this.$attrs.record,
recordID: (this.$attrs.record || {}).recordID || NoID,
ownerID: (this.$attrs.record || {}).ownedBy || NoID,
userID: (this.$auth.user || {}).userID || NoID,
})
},
},
}
</script>
3 changes: 2 additions & 1 deletion locale/en/corteza-webapp-compose/block.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ metric:
dimensionFieldLabel: Field
dimensionFieldPlaceholder: Dimension field
dimensionLabel: Dimension
filterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available)
filterLabel: Filter
filterFootnote: Simplified SQL condition (WHERE ...) syntax is supported. Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available)
transformFootnote: Variables like {{0}}, {{1}}, {{2}} and {{3}} are evaluated (when available)
labelLabel: Label
labelPlaceholder: Label
metricFieldLabel: Field
Expand Down

0 comments on commit 9be17d4

Please sign in to comment.