{"version":3,"file":"utils.js","sources":["../../../Framework/FieldTypes/utils.ts"],"sourcesContent":["// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Component, computed, defineComponent, PropType, ref, watch } from \"vue\";\r\nimport { binaryComparisonTypes, containsComparisonTypes, isCompareVisibleForComparisonFilter, isSingleComparisonType, stringComparisonTypes } from \"@Obsidian/Core/Reporting/comparisonType\";\r\nimport { getFilteredComparisonTypeOptions } from \"@Obsidian/Core/Reporting/comparisonTypeOptions\";\r\nimport { ComparisonValue } from \"@Obsidian/Types/Reporting/comparisonValue\";\r\nimport { ComparisonType } from \"@Obsidian/Enums/Reporting/comparisonType\";\r\nimport { FilterMode } from \"@Obsidian/Core/Reporting/filterMode\";\r\nimport DropDownList from \"@Obsidian/Controls/dropDownList.obs\";\r\nimport FieldFilterContainer from \"@Obsidian/Controls/fieldFilterContainer.obs\";\r\nimport { toNumberOrNull } from \"@Obsidian/Utility/numberUtils\";\r\nimport { DataEntryMode } from \"@Obsidian/Utility/fieldTypes\";\r\nimport { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\r\n\r\nexport type ConfigurationValues = Record;\r\n\r\n/**\r\n * The basic properties that all field editor components must support.\r\n */\r\ntype FieldEditorBaseProps = {\r\n modelValue: {\r\n type: PropType,\r\n required: true\r\n };\r\n\r\n configurationValues: {\r\n type: PropType;\r\n default: () => ConfigurationValues;\r\n };\r\n\r\n /**\r\n * This is used internally by the fieldTypeEditor to allow controls to make adjustments based\r\n * on how it's being used (e.g. to define a default value vs to edit a value)\r\n */\r\n dataEntryMode: {\r\n type: PropType;\r\n };\r\n};\r\n\r\n/**\r\n * The basic properties that all field configuration components must support.\r\n */\r\ntype FieldConfigurationBaseProps = {\r\n modelValue: {\r\n type: PropType>,\r\n required: true\r\n };\r\n\r\n configurationProperties: {\r\n type: PropType>,\r\n required: true\r\n };\r\n};\r\n\r\n/**\r\n * Get the standard properties that all field editor components must support.\r\n */\r\nexport function getFieldEditorProps(): FieldEditorBaseProps {\r\n return {\r\n modelValue: {\r\n type: String as PropType,\r\n required: true\r\n },\r\n\r\n configurationValues: {\r\n type: Object as PropType,\r\n default: () => ({})\r\n },\r\n\r\n dataEntryMode: {\r\n type: String as PropType\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * The properties that all field filter components must support.\r\n */\r\ntype FieldFilterProps = {\r\n modelValue: {\r\n type: PropType,\r\n required: true\r\n },\r\n\r\n configurationValues: {\r\n type: PropType,\r\n required: true\r\n },\r\n\r\n filterMode: {\r\n type: PropType,\r\n required: true\r\n },\r\n\r\n required: {\r\n type: PropType,\r\n required: true\r\n }\r\n};\r\n\r\n/**\r\n * The properties that all field filter components must support.\r\n */\r\nexport const fieldFilterProps: FieldFilterProps = {\r\n modelValue: {\r\n type: Object as PropType,\r\n required: true\r\n },\r\n\r\n configurationValues: {\r\n type: Object as PropType,\r\n required: true\r\n },\r\n\r\n filterMode: {\r\n type: Number as PropType,\r\n required: true\r\n },\r\n\r\n required: {\r\n type: Boolean as PropType,\r\n required: true\r\n }\r\n};\r\n\r\n/**\r\n * Gets the standard field configuration properties that all field configuration\r\n * components must support.\r\n */\r\nexport function getFieldConfigurationProps(): FieldConfigurationBaseProps {\r\n return {\r\n modelValue: {\r\n type: Object as PropType>,\r\n required: true\r\n },\r\n configurationProperties: {\r\n type: Object as PropType>,\r\n required: true\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Allows callers to modify the names of the comparison type options. The values\r\n * and the array itself should not be modified.\r\n */\r\nexport type UpdateComparisonTypeNamesCallback = (comparisonTypeOptions: ListItemBag[]) => void;\r\n\r\n/**\r\n * Options that can be passed to the getStandardFilterComponent method which\r\n * will alter it's default behavior.\r\n */\r\nexport type StandardFilterComponentOptions = {\r\n updateComparisonTypeNames?: UpdateComparisonTypeNamesCallback;\r\n};\r\n\r\n/**\r\n * Gets a standard filter component that uses a constant string in place of the\r\n * comparison type picker. This component will always emit a ComparisonValue\r\n * with a null type.\r\n *\r\n * @param compareLabel The string to display in place of a comparison picker.\r\n * @param valueComponent The component that will handle editing the value.\r\n *\r\n * @returns A component that will handle editing a filter value.\r\n */\r\nexport function getStandardFilterComponent(compareLabel: string, valueComponent: Component, options?: StandardFilterComponentOptions): Component;\r\n\r\n/**\r\n * Gets a standard filter component that uses a picker to let the individual\r\n * select the comparison type to perform. If a single comparison type bit is\r\n * set then the picker will be hidden. If null is used for the comparison types\r\n * then no picker component will be shown and null will be emitted for the\r\n * type property.\r\n *\r\n * @param comparisonTypes One or more comparison types the user can select from.\r\n * @param valueComponent The component that will handle editing the value.\r\n *\r\n * @returns A component that will handle editing a filter value.\r\n */\r\nexport function getStandardFilterComponent(comparisonTypes: ComparisonType | null, valueComponent: Component, options?: StandardFilterComponentOptions): Component;\r\n\r\n/**\r\n * Gets a standard filter component that can be used by field types to generate\r\n * their filter component without having to write one from scratch.\r\n *\r\n * @param comparisonLabelOrTypes The comparison label or the comparison types that will be shown.\r\n * @param valueComponent The component that will handle value entry from the individual.\r\n *\r\n * @returns A component that will handle editing a filter value.\r\n */\r\nexport function getStandardFilterComponent(comparisonLabelOrTypes: ComparisonType | string | null, valueComponent: Component, options?: StandardFilterComponentOptions): Component {\r\n const comparisonTypes: ComparisonType | null = typeof comparisonLabelOrTypes === \"number\" ? comparisonLabelOrTypes : null;\r\n const compareLabel: string = typeof comparisonLabelOrTypes === \"string\" ? comparisonLabelOrTypes : \"\";\r\n\r\n let comparisonTypeOptions = comparisonTypes !== null ? getFilteredComparisonTypeOptions(comparisonTypes) : [];\r\n\r\n if (options?.updateComparisonTypeNames) {\r\n // Create a new array with new objects so we don't modify the core\r\n // set for every component on the page.\r\n comparisonTypeOptions = comparisonTypeOptions.map(o => {\r\n return {\r\n value: o.value,\r\n text: o.text\r\n };\r\n });\r\n\r\n options.updateComparisonTypeNames(comparisonTypeOptions);\r\n }\r\n\r\n return defineComponent({\r\n name: \"StandardFilterComponent\",\r\n\r\n components: {\r\n DropDownList,\r\n FieldFilterContainer,\r\n ValueComponent: valueComponent\r\n },\r\n\r\n props: fieldFilterProps,\r\n\r\n emits: [\r\n \"update:modelValue\"\r\n ],\r\n\r\n setup(props, { emit }) {\r\n /** The comparison type currently selected in the UI. */\r\n const internalComparisonType = ref(props.modelValue.comparisonType?.toString() ?? \"\");\r\n const comparisonType = ref(props.modelValue.comparisonType ?? null);\r\n\r\n /** The comparison value currently entered in the UI. */\r\n const internalComparisonValue = ref(props.modelValue.value);\r\n\r\n /** True if the compare component should be visible. */\r\n const hasCompareComponent = computed(() => {\r\n return comparisonTypes !== null\r\n && props.filterMode !== FilterMode.Simple\r\n && !isSingleComparisonType(comparisonTypes)\r\n && isCompareVisibleForComparisonFilter(comparisonTypes, props.filterMode);\r\n });\r\n\r\n /** True if the value component should be visible. */\r\n const hasValueComponent = computed((): boolean => {\r\n return internalComparisonType.value !== ComparisonType.IsBlank.toString()\r\n && internalComparisonType.value !== ComparisonType.IsNotBlank.toString();\r\n });\r\n\r\n /** True if the comparison type is optional. */\r\n const isTypeOptional = computed(() => !props.required);\r\n\r\n /**\r\n * Constructs the new value and emits it if it has changed from\r\n * the current modelValue.\r\n */\r\n const emitValueIfChanged = (): void => {\r\n let type: ComparisonType | null | undefined;\r\n\r\n // Determine the comparison type.\r\n if (compareLabel || comparisonTypes === null) {\r\n // No comparison type to be selected.\r\n type = null;\r\n }\r\n else if (isSingleComparisonType(comparisonTypes)) {\r\n // Only a single comparison type, so it is forced.\r\n type = comparisonTypes;\r\n }\r\n else {\r\n // If the filter mode is simple, then the comparison type is\r\n // not shown so we come up with a sane default.\r\n if (props.filterMode === FilterMode.Simple) {\r\n if (comparisonTypes === binaryComparisonTypes) {\r\n type = ComparisonType.EqualTo;\r\n }\r\n else if (comparisonTypes === stringComparisonTypes || comparisonTypes === containsComparisonTypes) {\r\n type = ComparisonType.Contains;\r\n }\r\n else {\r\n type = null;\r\n }\r\n }\r\n else {\r\n // Get the comparison type selected by the user if we are\r\n // in advanced mode.\r\n type = toNumberOrNull(internalComparisonType.value);\r\n }\r\n }\r\n\r\n comparisonType.value = type;\r\n\r\n // Construct the new value to be emitted.\r\n const newValue: ComparisonValue = {\r\n comparisonType: type,\r\n value: internalComparisonValue.value\r\n };\r\n\r\n // Check if it has changed from the original value.\r\n if (newValue.comparisonType !== props.modelValue.comparisonType || newValue.value !== props.modelValue.value) {\r\n emit(\"update:modelValue\", newValue);\r\n }\r\n };\r\n\r\n // Watch for changes in our modelValue and update our internal\r\n // values to match.\r\n watch(() => props.modelValue, () => {\r\n internalComparisonType.value = props.modelValue.comparisonType?.toString() ?? \"\";\r\n comparisonType.value = props.modelValue.comparisonType ?? null;\r\n internalComparisonValue.value = props.modelValue.value;\r\n });\r\n\r\n // Watch for changes in our internal values and update the modelValue.\r\n watch([internalComparisonType, internalComparisonValue], () => {\r\n emitValueIfChanged();\r\n });\r\n\r\n // This is primarily here to sync up state with default values.\r\n emitValueIfChanged();\r\n\r\n return {\r\n compareLabel,\r\n comparisonType,\r\n comparisonTypeOptions,\r\n hasCompareComponent,\r\n hasValueComponent,\r\n internalComparisonType,\r\n internalComparisonValue,\r\n isTypeOptional\r\n };\r\n },\r\n\r\n template: `\r\n\r\n \r\n\r\n \r\n\r\n`\r\n });\r\n}\r\n\r\n"],"names":["getFieldEditorProps","modelValue","type","String","required","configurationValues","Object","default","dataEntryMode","fieldFilterProps","filterMode","Number","Boolean","getFieldConfigurationProps","configurationProperties","getStandardFilterComponent","comparisonLabelOrTypes","valueComponent","options","comparisonTypes","compareLabel","comparisonTypeOptions","getFilteredComparisonTypeOptions","updateComparisonTypeNames","map","o","value","text","defineComponent","name","components","DropDownList","FieldFilterContainer","ValueComponent","props","emits","setup","_ref","_props$modelValue$com","_props$modelValue$com2","_props$modelValue$com3","emit","internalComparisonType","ref","comparisonType","toString","internalComparisonValue","hasCompareComponent","computed","FilterMode","Simple","isSingleComparisonType","isCompareVisibleForComparisonFilter","hasValueComponent","ComparisonType","IsBlank","IsNotBlank","isTypeOptional","emitValueIfChanged","binaryComparisonTypes","EqualTo","stringComparisonTypes","containsComparisonTypes","Contains","toNumberOrNull","newValue","watch","_props$modelValue$com4","_props$modelValue$com5","_props$modelValue$com6","template"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwEO,SAASA,mBAAmBA,GAAyB;cACxD,OAAO;YACHC,IAAAA,UAAU,EAAE;YACRC,MAAAA,IAAI,EAAEC,MAA0B;YAChCC,MAAAA,QAAQ,EAAE,IAAA;iBACb;YAEDC,IAAAA,mBAAmB,EAAE;YACjBH,MAAAA,IAAI,EAAEI,MAAuC;YAC7CC,MAAAA,OAAO,EAAEA,OAAO,EAAE,CAAA;iBACrB;YAEDC,IAAAA,aAAa,EAAE;YACXN,MAAAA,IAAI,EAAEC,MAAAA;YACV,KAAA;eACH,CAAA;YACL,CAAA;AA8BO,gBAAMM,gBAAkC,+BAAG;YAC9CR,EAAAA,UAAU,EAAE;YACRC,IAAAA,IAAI,EAAEI,MAAmC;YACzCF,IAAAA,QAAQ,EAAE,IAAA;eACb;YAEDC,EAAAA,mBAAmB,EAAE;YACjBH,IAAAA,IAAI,EAAEI,MAAuC;YAC7CF,IAAAA,QAAQ,EAAE,IAAA;eACb;YAEDM,EAAAA,UAAU,EAAE;YACRR,IAAAA,IAAI,EAAES,MAA8B;YACpCP,IAAAA,QAAQ,EAAE,IAAA;eACb;YAEDA,EAAAA,QAAQ,EAAE;YACNF,IAAAA,IAAI,EAAEU,OAA4B;YAClCR,IAAAA,QAAQ,EAAE,IAAA;YACd,GAAA;YACJ,GAAC;YAMM,SAAS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