2023-08-04 14:29:34 +00:00
|
|
|
import RuntimeFormulaContext from '@baserow/modules/core/runtimeFormulaContext'
|
2023-09-04 12:17:41 +00:00
|
|
|
import { resolveFormula } from '@baserow/modules/core/formula'
|
2023-12-22 10:06:35 +00:00
|
|
|
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-08-04 14:29:34 +00:00
|
|
|
|
2023-06-27 09:29:02 +00:00
|
|
|
export default {
|
2024-11-28 08:47:54 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
2023-07-31 09:05:38 +00:00
|
|
|
computed: {
|
2024-03-28 16:51:11 +00:00
|
|
|
workflowActionsInProgress() {
|
|
|
|
const workflowActions = this.$store.getters[
|
|
|
|
'workflowAction/getElementWorkflowActions'
|
2024-11-28 08:47:54 +00:00
|
|
|
](this.elementPage, this.element.id)
|
2024-06-26 08:14:09 +00:00
|
|
|
const { recordIndexPath } = this.applicationContext
|
|
|
|
const dispatchedById = this.elementType.uniqueElementId(
|
|
|
|
this.element,
|
|
|
|
recordIndexPath
|
|
|
|
)
|
2024-03-28 16:51:11 +00:00
|
|
|
return workflowActions.some((workflowAction) =>
|
2024-06-26 08:14:09 +00:00
|
|
|
this.$store.getters['workflowAction/getDispatching'](
|
|
|
|
workflowAction,
|
|
|
|
dispatchedById
|
|
|
|
)
|
2024-03-28 16:51:11 +00:00
|
|
|
)
|
|
|
|
},
|
2023-08-08 13:28:03 +00:00
|
|
|
elementType() {
|
|
|
|
return this.$registry.get('element', this.element.type)
|
|
|
|
},
|
2024-01-04 13:10:44 +00:00
|
|
|
isEditMode() {
|
2023-07-31 09:05:38 +00:00
|
|
|
return this.mode === 'editing'
|
|
|
|
},
|
2024-09-19 13:39:45 +00:00
|
|
|
elementIsInError() {
|
|
|
|
return this.elementType.isInError({
|
2024-11-28 08:47:54 +00:00
|
|
|
page: this.elementPage,
|
2024-09-19 13:39:45 +00:00
|
|
|
element: this.element,
|
|
|
|
builder: this.builder,
|
|
|
|
})
|
|
|
|
},
|
2023-08-04 14:29:34 +00:00
|
|
|
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
|
2023-08-04 14:29:34 +00:00
|
|
|
),
|
|
|
|
{
|
|
|
|
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')
|
|
|
|
},
|
2023-12-22 10:06:35 +00:00
|
|
|
colorVariables() {
|
2024-07-03 12:05:50 +00:00
|
|
|
return ThemeConfigBlockType.getAllColorVariables(
|
|
|
|
this.themeConfigBlocks,
|
|
|
|
this.builder.theme
|
|
|
|
)
|
2023-12-22 10:06:35 +00:00
|
|
|
},
|
2023-08-04 14:29:34 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2024-05-07 08:25:48 +00:00
|
|
|
resolveFormula(formula, formulaContext = null) {
|
2023-12-20 09:01:03 +00:00
|
|
|
try {
|
|
|
|
return resolveFormula(
|
|
|
|
formula,
|
|
|
|
this.formulaFunctions,
|
2024-05-07 08:25:48 +00:00
|
|
|
formulaContext || this.runtimeFormulaContext
|
2023-12-20 09:01:03 +00:00
|
|
|
)
|
|
|
|
} catch (e) {
|
|
|
|
return ''
|
|
|
|
}
|
2023-08-04 14:29:34 +00:00
|
|
|
},
|
2024-05-24 18:18:11 +00:00
|
|
|
async fireEvent(event) {
|
2023-09-21 10:07:04 +00:00
|
|
|
if (this.mode !== 'editing') {
|
2024-03-28 16:51:11 +00:00
|
|
|
if (this.workflowActionsInProgress) {
|
|
|
|
return false
|
|
|
|
}
|
2023-12-15 13:49:54 +00:00
|
|
|
|
2023-11-06 12:03:48 +00:00
|
|
|
const workflowActions = this.$store.getters[
|
|
|
|
'workflowAction/getElementWorkflowActions'
|
2024-11-28 08:47:54 +00:00
|
|
|
](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,
|
2024-07-05 15:41:24 +00:00
|
|
|
this.element.styles?.[key] || {},
|
2024-07-04 11:57:41 +00:00
|
|
|
colorVariables || this.colorVariables,
|
|
|
|
this.builder.theme
|
2024-07-03 12:05:50 +00:00
|
|
|
)
|
|
|
|
},
|
2023-12-22 10:06:35 +00:00
|
|
|
resolveColor,
|
2023-07-31 09:05:38 +00:00
|
|
|
},
|
2023-06-27 09:29:02 +00:00
|
|
|
}
|