1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-02-24 21:46:08 +00:00
bramw_baserow/web-frontend/modules/builder/mixins/element.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
4.1 KiB
JavaScript
Raw Normal View History

import RuntimeFormulaContext from '@baserow/modules/core/runtimeFormulaContext'
2023-09-04 12:17:41 +00:00
import { resolveFormula } from '@baserow/modules/core/formula'
import { resolveColor } from '@baserow/modules/core/utils/colors'
2024-05-24 18:18:11 +00:00
import applicationContextMixin from '@baserow/modules/builder/mixins/applicationContext'
2024-07-03 12:05:50 +00:00
import { ThemeConfigBlockType } from '@baserow/modules/builder/themeConfigBlockTypes'
2023-06-27 09:29:02 +00:00
export default {
inject: ['workspace', 'builder', 'currentPage', 'elementPage', 'mode'],
2024-05-24 18:18:11 +00:00
mixins: [applicationContextMixin],
2023-06-27 09:29:02 +00:00
props: {
element: {
type: Object,
required: true,
},
},
computed: {
workflowActionsInProgress() {
const workflowActions = this.$store.getters[
'workflowAction/getElementWorkflowActions'
](this.elementPage, this.element.id)
const { recordIndexPath } = this.applicationContext
const dispatchedById = this.elementType.uniqueElementId(
this.element,
recordIndexPath
)
return workflowActions.some((workflowAction) =>
this.$store.getters['workflowAction/getDispatching'](
workflowAction,
dispatchedById
)
)
},
elementType() {
return this.$registry.get('element', this.element.type)
},
2024-01-04 13:10:44 +00:00
isEditMode() {
return this.mode === 'editing'
},
2024-09-19 13:39:45 +00:00
elementIsInError() {
return this.elementType.isInError({
page: this.elementPage,
2024-09-19 13:39:45 +00:00
element: this.element,
builder: this.builder,
})
},
runtimeFormulaContext() {
/**
* This proxy allow the RuntimeFormulaContextClass to act like a regular object.
*/
return new Proxy(
new RuntimeFormulaContext(
this.$registry.getAll('builderDataProvider'),
2023-10-24 11:50:14 +00:00
this.applicationContext
),
{
get(target, prop) {
return target.get(prop)
},
}
)
},
formulaFunctions() {
return {
get: (name) => {
return this.$registry.get('runtimeFormulaFunction', name)
},
}
},
2024-07-03 12:05:50 +00:00
themeConfigBlocks() {
return this.$registry.getOrderedList('themeConfigBlock')
},
colorVariables() {
2024-07-03 12:05:50 +00:00
return ThemeConfigBlockType.getAllColorVariables(
this.themeConfigBlocks,
this.builder.theme
)
},
},
methods: {
resolveFormula(formula, formulaContext = null) {
2023-12-20 09:01:03 +00:00
try {
return resolveFormula(
formula,
this.formulaFunctions,
formulaContext || this.runtimeFormulaContext
2023-12-20 09:01:03 +00:00
)
} catch (e) {
return ''
}
},
2024-05-24 18:18:11 +00:00
async fireEvent(event) {
2023-09-21 10:07:04 +00:00
if (this.mode !== 'editing') {
if (this.workflowActionsInProgress) {
return false
}
2023-11-06 12:03:48 +00:00
const workflowActions = this.$store.getters[
'workflowAction/getElementWorkflowActions'
](this.elementPage, this.element.id).filter(
2024-05-24 18:18:11 +00:00
({ event: eventName }) => eventName === event.name
)
2023-11-06 12:03:48 +00:00
2024-03-22 09:22:34 +00:00
try {
2024-05-24 18:18:11 +00:00
await event.fire({
2024-03-22 09:22:34 +00:00
workflowActions,
resolveFormula: this.resolveFormula,
applicationContext: this.applicationContext,
})
} catch (e) {
let toastTitle = this.$i18n.t(
'dispatchWorkflowActionError.defaultTitle'
)
let toastMessage = this.$i18n.t(
'dispatchWorkflowActionError.defaultMessage'
)
if (e.error !== 'ERROR_WORKFLOW_ACTION_FORM_DATA_INVALID') {
toastTitle = this.$i18n.t(
'dispatchWorkflowActionError.formDataInvalidTitle'
)
toastMessage = this.$i18n.t(
'dispatchWorkflowActionError.formDataInvalidMessage'
)
}
return this.$store.dispatch('toast/error', {
title: toastTitle,
message: toastMessage,
})
}
2023-09-21 10:07:04 +00:00
}
},
2024-07-03 12:05:50 +00:00
getStyleOverride(key, colorVariables = null) {
return ThemeConfigBlockType.getAllStyles(
this.themeConfigBlocks,
this.element.styles?.[key] || {},
colorVariables || this.colorVariables,
this.builder.theme
2024-07-03 12:05:50 +00:00
)
},
resolveColor,
},
2023-06-27 09:29:02 +00:00
}