Commit f19eb7d5 authored by dbulatovicx32's avatar dbulatovicx32
Browse files

KNOWAGE-7111, KNOWAGE-7114

parent 92cfee09
......@@ -3,3 +3,11 @@ export interface IKnCalculatedField {
type?: string
formula?: string
}
export interface IKnCalculatedFieldFunction {
category: string
formula: string
label: string
name: string
help: string
}
......@@ -85,10 +85,11 @@
</template>
<script lang="ts">
import { PropType } from 'vue'
import { AxiosResponse } from 'axios'
import { createValidations } from '@/helpers/commons/validationHelper'
import { defineComponent } from 'vue'
import { IKnCalculatedField } from '@/components/functionalities/KnCalculatedField/KnCalculatedField'
import { IKnCalculatedField, IKnCalculatedFieldFunction } from '@/components/functionalities/KnCalculatedField/KnCalculatedField'
import { VCodeMirror } from 'vue3-code-mirror'
import Dropdown from 'primevue/dropdown'
......@@ -109,7 +110,8 @@ export default defineComponent({
descriptor: Object,
template: {} as any,
valid: Boolean,
source: String
source: String,
propCalcFieldFunctions: { type: Array as PropType<IKnCalculatedFieldFunction[]>, required: true }
},
data() {
return {
......@@ -132,12 +134,14 @@ export default defineComponent({
},
v$: useValidate() as any,
formulaValidationInterval: {} as any,
isValidFormula: false
isValidFormula: false,
calcFieldFunctions: [] as IKnCalculatedFieldFunction[]
}
},
emits: ['save', 'cancel', 'update:readOnly'],
created() {
this.availableFunctions = [...this.descriptor?.availableFunctions].sort((a, b) => {
this.calcFieldFunctions = [...this.propCalcFieldFunctions]
this.availableFunctions = [...this.calcFieldFunctions].sort((a, b) => {
return a.name.localeCompare(b.name)
})
this.availableFunctions.forEach((x) => {
......@@ -186,7 +190,7 @@ export default defineComponent({
this.selectedCategory = ''
},
filterFunctions() {
let tmp = [...this.descriptor?.availableFunctions].sort((a, b) => {
let tmp = [...this.calcFieldFunctions].sort((a, b) => {
return a.name.localeCompare(b.name)
})
tmp.forEach((x) => {
......@@ -201,7 +205,7 @@ export default defineComponent({
handleOptions() {
let tmp = [] as any
this.descriptor?.availableFunctions
this.calcFieldFunctions
.sort((a, b) => {
return a.name.localeCompare(b.name)
})
......
......@@ -16,7 +16,7 @@
<template #header>
<span>{{ $t('metaweb.businessModel.title') }}</span>
</template>
<BusinessModelTab :propMeta="meta" :observer="observer" :metaUpdated="metaUpdated" @metaUpdated="onMetaUpdated" />
<BusinessModelTab :businessModelId="businessModel.dataSourceId" :propMeta="meta" :observer="observer" :metaUpdated="metaUpdated" @metaUpdated="onMetaUpdated" />
</TabPanel>
<TabPanel>
<template #header>
......
......@@ -91,7 +91,7 @@
<span>{{ $t('metaweb.businessModel.tabView.calcField') }}</span>
</template>
<div :style="mainDescriptor.style.absoluteScroll">
<CalculatedField :selectedBusinessModel="selectedBusinessModel" :propMeta="meta" @metaUpdated="$emit('metaUpdated')" :observer="observer" />
<CalculatedField :selectedBusinessModel="selectedBusinessModel" :propMeta="meta" :propCustomFunctions="customFunctions" @metaUpdated="$emit('metaUpdated')" :observer="observer" />
</div>
</TabPanel>
<TabPanel>
......@@ -191,7 +191,7 @@ export default defineComponent({
MetawebPhysicalTableTab,
MetawebFilterTab
},
props: { propMeta: { type: Object }, observer: { type: Object }, metaUpdated: { type: Boolean } },
props: { propMeta: { type: Object }, observer: { type: Object }, metaUpdated: { type: Boolean }, businessModelId: Number },
emits: ['loading', 'metaUpdated'],
computed: {},
data() {
......@@ -200,6 +200,7 @@ export default defineComponent({
mainDescriptor,
meta: null as any,
menuButtons: [] as any,
customFunctions: [] as any,
showBusinessClassDialog: false,
showBusinessViewDialog: false,
selectedBusinessModel: {} as iBusinessModel,
......@@ -219,6 +220,7 @@ export default defineComponent({
this.loadMeta()
this.createMenuItems()
this.loadRoles()
this.loadCustomFunctions()
},
methods: {
showMenu(event) {
......@@ -264,6 +266,15 @@ export default defineComponent({
await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + '2.0/roles').then((response: AxiosResponse<any>) => (this.roles = response.data))
this.loading = false
},
async loadCustomFunctions() {
this.loading = true
await this.$http.get(process.env.VUE_APP_RESTFUL_SERVICES_PATH + `2.0/configs/KNOWAGE.CUSTOMIZED_DATABASE_FUNCTIONS/${this.businessModelId}`).then((response: AxiosResponse<any>) => {
if (response.data.data && response.data.data.length > 0) {
this.customFunctions = response.data.data.map((funct) => ({ category: 'CUSTOM', formula: funct.value, label: funct.label, name: funct.name, help: 'dataPreparation.custom' }))
} else this.customFunctions = null
})
this.loading = false
},
async onRowReorder(event: any) {
this.loading = true
const postData = { data: { index: event.dragIndex, direction: event.dropIndex - event.dragIndex }, diff: generate(this.observer) }
......
<template>
'SHJOULD HIDE: '{{ isGeographicBm }}
<DataTable :value="businessModel.calculatedBusinessColumns" class="p-datatable-sm kn-table p-ml-2" responsiveLayout="stack" breakpoint="960px">
<template #empty>
{{ $t('common.info.noDataFound') }}
......@@ -15,7 +16,19 @@
</Column>
</DataTable>
<KnCalculatedField v-model:template="selectedCalcField" v-model:visibility="calcFieldDialogVisible" :fields="calcFieldColumns" :descriptor="calcFieldDescriptor" :source="'QBE'" :readOnly="false" :valid="true" @save="onCalcFieldSave" @cancel="calcFieldDialogVisible = false">
<KnCalculatedField
v-if="calcFieldDialogVisible"
v-model:template="selectedCalcField"
v-model:visibility="calcFieldDialogVisible"
:fields="calcFieldColumns"
:descriptor="calcFieldDescriptor"
:propCalcFieldFunctions="calcFieldFunctions"
:source="'QBE'"
:readOnly="false"
:valid="true"
@save="onCalcFieldSave"
@cancel="calcFieldDialogVisible = false"
>
<template #additionalInputs>
<div class="p-field p-col-4">
<span class="p-float-label ">
......@@ -37,6 +50,7 @@
import { AxiosResponse } from 'axios'
import { defineComponent, PropType } from 'vue'
import { iBusinessModel } from '../../../Metaweb'
import { IKnCalculatedFieldFunction } from '@/components/functionalities/KnCalculatedField/KnCalculatedField'
import DataTable from 'primevue/datatable'
import Column from 'primevue/column'
import descriptor from './MetawebCalculatedFieldDescriptor.json'
......@@ -45,11 +59,12 @@ import KnCalculatedField from '@/components/functionalities/KnCalculatedField/Kn
import Dropdown from 'primevue/dropdown'
const { generate, applyPatch } = require('fast-json-patch')
const deepcopy = require('deepcopy')
export default defineComponent({
name: 'metaweb-filter-tab',
components: { DataTable, Column, KnCalculatedField, Dropdown },
props: { selectedBusinessModel: { type: Object as PropType<iBusinessModel | null> }, propMeta: { type: Object }, observer: { type: Object, required: true } },
props: { selectedBusinessModel: { type: Object as PropType<iBusinessModel | null> }, propMeta: { type: Object }, propCustomFunctions: { type: Array }, observer: { type: Object, required: true } },
emits: ['metaUpdated'],
data() {
return {
......@@ -60,18 +75,34 @@ export default defineComponent({
calcFieldDialogVisible: false,
readOnly: false,
selectedCalcField: {} as any,
calcFieldColumns: [] as any
calcFieldColumns: [] as any,
calcFieldFunctions: [] as IKnCalculatedFieldFunction[]
}
},
computed: {
isGeographicBm(): boolean {
let hideFields = false
this.businessModel?.properties?.forEach((el: any) => {
const key = Object.keys(el)[0]
if (key === 'structural.tabletype' && el[key].value === 'geographic dimension') {
hideFields = true
} else hideFields = false
})
return hideFields
}
},
watch: {
selectedBusinessModel() {
this.loadMeta()
this.loadBusinessModel()
this.calcFieldFunctions = this.createCalcFieldFunctions(calcFieldDescriptor.availableFunctions, this.propCustomFunctions)
console.log('WATCHER', this.calcFieldFunctions)
}
},
created() {
this.loadMeta()
this.loadBusinessModel()
this.calcFieldFunctions = this.createCalcFieldFunctions(calcFieldDescriptor.availableFunctions, this.propCustomFunctions)
},
methods: {
loadMeta() {
......@@ -167,6 +198,29 @@ export default defineComponent({
})
.catch(() => {})
.finally(() => generate(this.observer))
},
createCalcFieldFunctions(providedFunctions, customFunctions?) {
let functions = deepcopy(providedFunctions)
if (customFunctions) {
console.log('I HAVE CUSTOM FUNCT')
customFunctions.forEach((funct) => {
functions.push(funct)
})
}
if (this.isGeographicBm) {
console.log('SHOW SPATIALS', this.isGeographicBm)
} else {
let tempFunctions = deepcopy(functions)
console.log('HIDE SPATIALS')
functions = tempFunctions.filter((funct) => {
console.log(funct.category)
return funct.category !== 'SPATIAL'
})
console.log(functions)
}
return functions
}
}
})
......
<template>
<div class="kn-page kn-data-preparation">
<KnCalculatedField v-model:visibility="showCFDialog" @save="saveCFDialog" @cancel="cancelCFDialog" :fields="columns" :descriptor="cfDescriptor" :readOnly="readOnly" @update:readOnly="updateReadOnly" v-model:template="selectedTransformation" :valid="cfType !== ''">
<KnCalculatedField
v-model:visibility="showCFDialog"
@save="saveCFDialog"
@cancel="cancelCFDialog"
:fields="columns"
:descriptor="cfDescriptor"
:propCalcFieldFunctions="cfDescriptor.availableFunctions"
:readOnly="readOnly"
@update:readOnly="updateReadOnly"
v-model:template="selectedTransformation"
:valid="cfType !== ''"
>
<template #additionalInputs>
<div class="p-col-4">
<span v-if="cfDescriptor.availableTypes" class="p-float-label p-field p-ml-2 kn-flex">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment