Commit 4806ef53 authored by Janis Streib's avatar Janis Streib 🦉
Browse files

UPD: refactored ta-metadata gathering

parent d41ce99e
......@@ -7,7 +7,8 @@
:static="false"
ref="modal"
@show="shown">
<form style="min-height: 400px" ref="form" :id="modal_id + '-dbeditform'" v-if="object_definition != null" @submit.stop.prevent="commit">
<form style="min-height: 400px" ref="form" :id="modal_id + '-dbeditform'" v-if="object_definition != null"
@submit.stop.prevent="commit">
<input type="submit" hidden/>
<template v-if="!non_optionals_order">
<template v-for="(data,attr) in object_functions[object_function].parameters">
......@@ -59,7 +60,7 @@
:input_reducer="input_reducer[attr]"
v-bind:key="attr"
v-if="'new' in data && !non_optionals_order.includes(attr)"
></DataEditField>
></DataEditField>
</template>
</b-collapse>
......@@ -70,9 +71,6 @@
</template>
<script>
import ObjectTypeService from '@/api-services.gen/wapi.object_type'
import FunctionService from '@/api-services.gen/wapi.function'
import ApiUtil from '@/util/apiutil'
import DataEditField from './DataEditField'
import TransactionUtil from '@/util/transactionutil'
import {v4 as uuidv4} from 'uuid'
......@@ -150,33 +148,6 @@ export default {
this.$bvModal.hide(this.modal_id)
})
},
async validateObjectFQName() {
const parts = this.object_fq_name.split('.')
const system = parts[0]
const name = parts[1]
const object_result = ObjectTypeService.list(this.$store.state.netdb_axios_config, {
name_list: [name],
system_list: [system]
})
try {
let object_definition = await object_result
object_definition = object_definition.data[0]
if (object_definition.length !== 1) {
return false
}
const obj_functions = await FunctionService.list(this.$store.state.netdb_axios_config, {
object_type_list: [name],
system_list: [system]
})
window.console.debug(ApiUtil.dict_by_value_of_array(obj_functions.data[0], 'name'))
return {
object_definition: object_definition[0],
object_functions: ApiUtil.dict_by_value_of_array(obj_functions.data[0], 'name')
}
} catch (e) {
return false
}
},
function2variant: TransactionUtil.function2variant,
function2text: TransactionUtil.function2text,
async validateObjectFunction() {
......@@ -276,45 +247,14 @@ export default {
}
return
}
if (this.object_fq_name in this.$store.state.db_editor_cache) {
window.console.debug('DBEditor cache hit')
const entry = this.$store.state.db_editor_cache[this.object_fq_name]
this.object_definition = entry.object_definition
this.object_functions = entry.object_functions
this.object_definition_referencing_by_attribute = entry.object_definition_referencing_by_attribute
this.object_definition_reference_names_by_attribute = entry.object_definition_reference_names_by_attribute
this.$emit('ready')
if (this.should_open) {
this.$root.$nextTick(() => this.$root.$emit('bv::show::modal', this.modal_id))
}
return
}
const data = await this.validateObjectFQName()
if (data === false) {
window.console.error('Invalid object_fq_name!')
} else {
this.object_definition = data.object_definition
this.object_definition_referencing_by_attribute = {}
this.object_definition_reference_names_by_attribute = {}
for (const ref in this.object_definition.referencing) {
for (const attrib of this.object_definition.referencing[ref].attributes) {
this.object_definition_referencing_by_attribute[attrib] = this.object_definition.referencing[ref].references
this.object_definition_reference_names_by_attribute[attrib] = ref
}
}
this.object_functions = data.object_functions
this.$store.commit('cacheDBEditorData', {
object_fq_name: this.object_fq_name,
object_definition: this.object_definition,
object_functions: this.object_functions,
object_definition_referencing_by_attribute: this.object_definition_referencing_by_attribute,
object_definition_reference_names_by_attribute: this.object_definition_reference_names_by_attribute
})
this.$emit('ready')
if (this.should_open) {
this.$root.$nextTick(() => this.$root.$emit('bv::show::modal', this.modal_id))
}
const res = await TransactionUtil.getObjectMetadata(this, this.object_fq_name)
this.object_definition = res.object_definition
this.object_functions = res.object_functions
this.object_definition_reference_names_by_attribute = res.object_definition_reference_names_by_attribute
this.object_definition_referencing_by_attribute = res.object_definition_referencing_by_attribute
this.$emit('ready')
if (this.should_open) {
this.$root.$nextTick(() => this.$root.$emit('bv::show::modal', this.modal_id))
}
}
}
......
import { v4 as uuidv4 } from 'uuid'
import ObjectTypeService from '@/api-services.gen/wapi.object_type'
import FunctionService from '@/api-services.gen/wapi.function'
import ApiUtil from '@/util/apiutil'
export default {
function2variant (function_name, outline = false) {
......@@ -69,5 +72,67 @@ export default {
ta.object_functions = null
ta.object_title = title
return ta
},
async validateObjectFQName(vm, object_fq_name) {
const parts = object_fq_name.split('.')
const system = parts[0]
const name = parts[1]
const object_result = ObjectTypeService.list(vm.$store.state.netdb_axios_config, {
name_list: [name],
system_list: [system]
})
try {
let object_definition = await object_result
object_definition = object_definition.data[0]
if (object_definition.length !== 1) {
return false
}
const obj_functions = await FunctionService.list(vm.$store.state.netdb_axios_config, {
object_type_list: [name],
system_list: [system]
})
window.console.debug(ApiUtil.dict_by_value_of_array(obj_functions.data[0], 'name'))
return {
object_definition: object_definition[0],
object_functions: ApiUtil.dict_by_value_of_array(obj_functions.data[0], 'name')
}
} catch (e) {
return false
}
},
async getObjectMetadata(vm, object_fq_name) {
const res = {}
if (object_fq_name in vm.$store.state.db_editor_cache) {
window.console.debug('DBEditor cache hit')
const entry = vm.$store.state.db_editor_cache[object_fq_name]
res.object_definition = entry.object_definition
res.object_functions = entry.object_functions
res.object_definition_referencing_by_attribute = entry.object_definition_referencing_by_attribute
res.object_definition_reference_names_by_attribute = entry.object_definition_reference_names_by_attribute
return res
}
const data = await this.validateObjectFQName(vm, object_fq_name)
if (data === false) {
return null
} else {
res.object_definition = data.object_definition
res.object_definition_referencing_by_attribute = {}
res.object_definition_reference_names_by_attribute = {}
for (const ref in res.object_definition.referencing) {
for (const attrib of res.object_definition.referencing[ref].attributes) {
res.object_definition_referencing_by_attribute[attrib] = res.object_definition.referencing[ref].references
res.object_definition_reference_names_by_attribute[attrib] = ref
}
}
res.object_functions = data.object_functions
vm.$store.commit('cacheDBEditorData', {
object_fq_name: res.object_fq_name,
object_definition: res.object_definition,
object_functions: res.object_functions,
object_definition_referencing_by_attribute: res.object_definition_referencing_by_attribute,
object_definition_reference_names_by_attribute: res.object_definition_reference_names_by_attribute
})
return res
}
}
}
Markdown is supported
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