「kintone lookup」と組み合わせるとロックされたフィールドを除外します
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<q-field labelColor="primary" class="condition-object" :clearable="isSelected" stack-label :dense="true"
|
<q-field labelColor="primary" class="condition-object" dense outlined :label="label" :disable="disabled"
|
||||||
:outlined="true">
|
:clearable="isSelected">
|
||||||
<template v-slot:control>
|
<template v-slot:control>
|
||||||
<!-- <q-chip color="primary" text-color="white" v-if="isSelected && selectedObject.objectType==='field'" :dense="true" class="selected-obj">
|
<!-- <q-chip color="primary" text-color="white" v-if="isSelected && selectedObject.objectType==='field'" :dense="true" class="selected-obj">
|
||||||
{{ selectedObject.name }}
|
{{ selectedObject.name }}
|
||||||
@@ -44,6 +44,14 @@ export default defineComponent({
|
|||||||
// ConditionObjects
|
// ConditionObjects
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
config: {
|
config: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {
|
default: () => {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</q-card>
|
</q-card>
|
||||||
</template>
|
</template>
|
||||||
</q-field>
|
</q-field>
|
||||||
<show-dialog v-model:visible="dgIsShow" name="データマッピング" @close="closeDg" min-width="50vw" min-height="60vh">
|
<show-dialog v-model:visible="dgIsShow" name="データマッピング" @close="closeDg" min-width="55vw" min-height="60vh">
|
||||||
|
|
||||||
<div class="q-mx-none">
|
<div class="q-mx-none">
|
||||||
<div class="row q-col-gutter-x-xs flex-center">
|
<div class="row q-col-gutter-x-xs flex-center">
|
||||||
@@ -26,9 +26,13 @@
|
|||||||
<!-- <div class="col-1">
|
<!-- <div class="col-1">
|
||||||
</div> -->
|
</div> -->
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<div class="q-mx-xs">目標</div>
|
<div class="row justify-between q-mx-sm">
|
||||||
|
<div class="">目標</div>
|
||||||
|
<q-btn outline color="primary" size="xs" label="最新のフィールドを取得する"
|
||||||
|
@click="() => updateFields(sourceAppId!, undefined)" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-1">
|
<div class="col-1 q-pl-md">
|
||||||
キー
|
キー
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -36,12 +40,13 @@
|
|||||||
<!-- <div class="q-my-sm" v-for="(item, index) in mappingProps" :key="item.id"> -->
|
<!-- <div class="q-my-sm" v-for="(item, index) in mappingProps" :key="item.id"> -->
|
||||||
<div class="row q-my-md q-col-gutter-x-md flex-center">
|
<div class="row q-my-md q-col-gutter-x-md flex-center">
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<ConditionObject :config="config" v-model="item.from" />
|
<ConditionObject :config="config" v-model="item.from" :disabled="item.disabled" :label="item.disabled ? '「Lookup」によってロックされる': ''"/>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="col-1">
|
<!-- <div class="col-1">
|
||||||
</div> -->
|
</div> -->
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
<q-field v-model="item.vName" type="text" outlined dense>
|
<q-field v-model="item.vName" type="text" outlined dense
|
||||||
|
:disable="item.disabled" >
|
||||||
<!-- <template v-slot:append>
|
<!-- <template v-slot:append>
|
||||||
<q-icon name="search" class="cursor-pointer"
|
<q-icon name="search" class="cursor-pointer"
|
||||||
@click="() => { mappingProps[index].to.isDialogVisible = true }" />
|
@click="() => { mappingProps[index].to.isDialogVisible = true }" />
|
||||||
@@ -62,7 +67,7 @@
|
|||||||
</q-field>
|
</q-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<q-checkbox size="sm" v-model="item.isKey" />
|
<q-checkbox size="sm" v-model="item.isKey" :disable="item.disabled"/>
|
||||||
<!-- <q-btn flat round dense icon="delete" size="sm" @click="() => deleteMappingObject(index)" /> -->
|
<!-- <q-btn flat round dense icon="delete" size="sm" @click="() => deleteMappingObject(index)" /> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,9 +125,10 @@ type MappingValueType = {
|
|||||||
isDialogVisible: boolean;
|
isDialogVisible: boolean;
|
||||||
};
|
};
|
||||||
isKey: boolean;
|
isKey: boolean;
|
||||||
|
disabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blackListLabelName = ['レコード番号','作業者','更新者','更新日時','作成日時','作成者']
|
const blackListLabelName = ['レコード番号', '作業者', '更新者', '更新日時', '作成日時', '作成者']
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'DataMapping',
|
name: 'DataMapping',
|
||||||
@@ -163,7 +169,7 @@ export default defineComponent({
|
|||||||
const source = props.context.find(element => element?.props?.name === 'sources')
|
const source = props.context.find(element => element?.props?.name === 'sources')
|
||||||
|
|
||||||
const sourceApp = computed(() => source?.props?.modelValue?.app);
|
const sourceApp = computed(() => source?.props?.modelValue?.app);
|
||||||
|
|
||||||
const sourceAppId = computed(() => sourceApp.value?.id);
|
const sourceAppId = computed(() => sourceApp.value?.id);
|
||||||
|
|
||||||
const closeDg = () => {
|
const closeDg = () => {
|
||||||
@@ -180,6 +186,14 @@ export default defineComponent({
|
|||||||
|
|
||||||
watch(() => sourceAppId.value, async (newId, oldId) => {
|
watch(() => sourceAppId.value, async (newId, oldId) => {
|
||||||
if (!newId) return;
|
if (!newId) return;
|
||||||
|
updateFields(newId, oldId)
|
||||||
|
})
|
||||||
|
|
||||||
|
const updateFields = async (newId: string, oldId: string | undefined) => {
|
||||||
|
const modelValueData = props.modelValue?.data ?? [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const ktAppFields = await api.get('api/v1/appfields', {
|
const ktAppFields = await api.get('api/v1/appfields', {
|
||||||
params: {
|
params: {
|
||||||
app: newId
|
app: newId
|
||||||
@@ -191,31 +205,47 @@ export default defineComponent({
|
|||||||
.map(f => {
|
.map(f => {
|
||||||
return {
|
return {
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
from: {},
|
from: modelValueData.find(m => m.to.fields[0].code === f.code),
|
||||||
to: {
|
to: {
|
||||||
app: sourceApp.value,
|
app: sourceApp.value,
|
||||||
fields: [f],
|
fields: [f],
|
||||||
isDialogVisible: false
|
isDialogVisible: false
|
||||||
},
|
},
|
||||||
isKey: false
|
isKey: false,
|
||||||
|
disabled: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
const modelValueData = props.modelValue?.data ?? [];
|
|
||||||
|
|
||||||
const createWithNull = props.modelValue?.createWithNull ?? false
|
// const createWithNull = props.modelValue?.createWithNull ?? false
|
||||||
|
|
||||||
if (modelValueData.length === 0 || newId !== oldId) {
|
// if (modelValueData.length === 0 || newId !== oldId) {
|
||||||
emit('update:modelValue', { data: ktAppFields, createWithNull: createWithNull });
|
// emit('update:modelValue', { data: ktAppFields, createWithNull: createWithNull });
|
||||||
return;
|
// return;
|
||||||
|
// }
|
||||||
|
// const modelValueFieldNames = modelValueData.map(item => item.to.fields[0].name);
|
||||||
|
|
||||||
|
// const newFields = ktAppFields.filter(field => !modelValueFieldNames.includes(field.to.fields[0].name));
|
||||||
|
|
||||||
|
// const updatedModelValueData = [...modelValueData, ...newFields];
|
||||||
|
|
||||||
|
const lookupFixedField = ktAppFields
|
||||||
|
.filter(field => field.to.fields[0].lookup !== undefined)
|
||||||
|
.flatMap(field => field.to.fields[0].lookup.fieldMappings.map((m) => m.field))
|
||||||
|
|
||||||
|
console.log(lookupFixedField);
|
||||||
|
|
||||||
|
if (lookupFixedField.length > 0) {
|
||||||
|
|
||||||
|
ktAppFields.filter(f => lookupFixedField.includes( f.to.fields[0].code)).forEach(f => f.disabled = true)
|
||||||
|
// for (const field of ktAppFields) {
|
||||||
|
// field.disabled = true
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
const modelValueFieldNames = modelValueData.map(item => item.to.fields[0].name);
|
|
||||||
|
|
||||||
const newFields = ktAppFields.filter(field => !modelValueFieldNames.includes(field.to.fields[0].name));
|
emit('update:modelValue', { data: ktAppFields, createWithNull: createWithNull });
|
||||||
|
}
|
||||||
const updatedModelValueData = [...modelValueData, ...newFields];
|
|
||||||
emit('update:modelValue', { data: updatedModelValueData, createWithNull: createWithNull });
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(createWithNull.value);
|
console.log(createWithNull.value);
|
||||||
|
|
||||||
@@ -250,6 +280,7 @@ export default defineComponent({
|
|||||||
closeToDg,
|
closeToDg,
|
||||||
mappingProps,
|
mappingProps,
|
||||||
createWithNull,
|
createWithNull,
|
||||||
|
updateFields,
|
||||||
// addMappingObject: () => mappingProps.push(defaultMappingProp()),
|
// addMappingObject: () => mappingProps.push(defaultMappingProp()),
|
||||||
// deleteMappingObject,
|
// deleteMappingObject,
|
||||||
mappingObjectsInputDisplay,
|
mappingObjectsInputDisplay,
|
||||||
@@ -265,5 +296,7 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss"></style>
|
<style lang="scss"></style>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
} from "../types/ActionTypes";
|
} from "../types/ActionTypes";
|
||||||
import { actionAddins } from ".";
|
import { actionAddins } from ".";
|
||||||
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
||||||
|
import { Lookup } from "@kintone/rest-api-client/lib/src/KintoneFields/types/property";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@@ -86,19 +87,24 @@ export class DataMappingAction implements IAction {
|
|||||||
): Promise<IActionResult> {
|
): Promise<IActionResult> {
|
||||||
this.actionProps = prop.actionProps;
|
this.actionProps = prop.actionProps;
|
||||||
this.dataMappingProps = prop.ActionValue as Props;
|
this.dataMappingProps = prop.ActionValue as Props;
|
||||||
console.log(prop.ActionValue);
|
console.log(context);
|
||||||
let result = {
|
let result = {
|
||||||
canNext: true,
|
canNext: true,
|
||||||
result: "",
|
result: "",
|
||||||
} as IActionResult;
|
} as IActionResult;
|
||||||
try {
|
try {
|
||||||
|
const lookupFixedFieldCodes = await getLookupFixedFieldCodes(
|
||||||
|
this.dataMappingProps.sources.app.id
|
||||||
|
);
|
||||||
|
|
||||||
// createWithNull が有効な場合は、4 番目のパラメーターを true にして doUpdate 関数ブランチを実行します。
|
// createWithNull が有効な場合は、4 番目のパラメーターを true にして doUpdate 関数ブランチを実行します。
|
||||||
if (this.dataMappingProps.dataMapping.createWithNull === true) {
|
if (this.dataMappingProps.dataMapping.createWithNull === true) {
|
||||||
await doUpdate(
|
await doUpdate(
|
||||||
this.dataMappingProps.dataMapping.data,
|
this.dataMappingProps.dataMapping.data,
|
||||||
this.dataMappingProps.sources.app.id,
|
this.dataMappingProps.sources.app.id,
|
||||||
context,
|
context,
|
||||||
true // キーがない場合、またはキーでターゲットが見つからない場合に、マッピング条件によって新しいレコードを作成するかどうかを決定するために使用されます。
|
true, // キーがない場合、またはキーでターゲットが見つからない場合に、マッピング条件によって新しいレコードを作成するかどうかを決定するために使用されます。
|
||||||
|
lookupFixedFieldCodes
|
||||||
);
|
);
|
||||||
} else if (
|
} else if (
|
||||||
// キーがないと更新対象を取得できないため、この時点でのみ更新が行われます。 doUpdate 関数の 4 番目のパラメーターは false です。
|
// キーがないと更新対象を取得できないため、この時点でのみ更新が行われます。 doUpdate 関数の 4 番目のパラメーターは false です。
|
||||||
@@ -110,13 +116,15 @@ export class DataMappingAction implements IAction {
|
|||||||
this.dataMappingProps.dataMapping.data,
|
this.dataMappingProps.dataMapping.data,
|
||||||
this.dataMappingProps.sources.app.id,
|
this.dataMappingProps.sources.app.id,
|
||||||
context,
|
context,
|
||||||
false
|
false,
|
||||||
|
lookupFixedFieldCodes
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await doCreate(
|
await doCreate(
|
||||||
this.dataMappingProps.dataMapping.data,
|
this.dataMappingProps.dataMapping.data,
|
||||||
this.dataMappingProps.sources.app.id,
|
this.dataMappingProps.sources.app.id,
|
||||||
context
|
context,
|
||||||
|
lookupFixedFieldCodes
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -154,16 +162,21 @@ const doUpdate = async (
|
|||||||
mappingData: Mapping[],
|
mappingData: Mapping[],
|
||||||
appId: string,
|
appId: string,
|
||||||
context: any,
|
context: any,
|
||||||
needCreate: boolean
|
needCreate: boolean,
|
||||||
|
lookupFixedFieldCodes: string[]
|
||||||
) => {
|
) => {
|
||||||
const targetField = await findUpdateField(mappingData, appId, context);
|
const targetField = await findUpdateField(mappingData, appId, context);
|
||||||
console.log(targetField);
|
console.log(targetField);
|
||||||
if (targetField.records.length === 0 && needCreate) {
|
if (targetField.records.length === 0 && needCreate) {
|
||||||
await doCreate(mappingData, appId, context);
|
await doCreate(mappingData, appId, context, lookupFixedFieldCodes);
|
||||||
} else {
|
} else {
|
||||||
// マッピングデータを単純なオブジェクトに処理し、ソース値が変数の場合は変数を置き換えます。
|
// マッピングデータを単純なオブジェクトに処理し、ソース値が変数の場合は変数を置き換えます。
|
||||||
const mappingRules = mappingData
|
const mappingRules = mappingData
|
||||||
.filter((m) => Object.keys(m.from).length > 0)
|
.filter(
|
||||||
|
(m) =>
|
||||||
|
Object.keys(m.from).length > 0 &&
|
||||||
|
!lookupFixedFieldCodes.includes(m.to.fields[0].code)
|
||||||
|
)
|
||||||
.map((m) => {
|
.map((m) => {
|
||||||
if (m.from.objectType === "variable") {
|
if (m.from.objectType === "variable") {
|
||||||
return {
|
return {
|
||||||
@@ -198,8 +211,6 @@ const doUpdate = async (
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(updateRecords);
|
|
||||||
|
|
||||||
await client.record.updateRecords({
|
await client.record.updateRecords({
|
||||||
app: appId,
|
app: appId,
|
||||||
records: updateRecords,
|
records: updateRecords,
|
||||||
@@ -242,7 +253,8 @@ const findUpdateField = async (
|
|||||||
const doCreate = async (
|
const doCreate = async (
|
||||||
mappingData: Mapping[],
|
mappingData: Mapping[],
|
||||||
appId: string,
|
appId: string,
|
||||||
context: any
|
context: any,
|
||||||
|
lookupFixedFieldCodes: string[]
|
||||||
) => {
|
) => {
|
||||||
const record = mappingData
|
const record = mappingData
|
||||||
.filter(
|
.filter(
|
||||||
@@ -253,6 +265,7 @@ const doCreate = async (
|
|||||||
item.to.fields &&
|
item.to.fields &&
|
||||||
item.to.fields.length > 0
|
item.to.fields.length > 0
|
||||||
)
|
)
|
||||||
|
.filter((item) => !lookupFixedFieldCodes.includes(item.to.fields[0].code))
|
||||||
.reduce((accumulator, item) => {
|
.reduce((accumulator, item) => {
|
||||||
return {
|
return {
|
||||||
...accumulator,
|
...accumulator,
|
||||||
@@ -268,3 +281,13 @@ const doCreate = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getLookupFixedFieldCodes = async (appId: string) => {
|
||||||
|
return await client.app
|
||||||
|
.getFormFields({ app: appId, lang: "ja" })
|
||||||
|
.then((resp) =>
|
||||||
|
Object.values(resp.properties)
|
||||||
|
.filter((f) => (f as Lookup).lookup !== undefined)
|
||||||
|
.flatMap((f) => (f as Lookup).lookup.fieldMappings.map((m) => m.field))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user