新しい統合されたフィールド入力、すべての関連部品の一致修正. フィールドの値を取得する に新しいアクションを追加
This commit is contained in:
74
plugin/kintone-addins/src/actions/current-field-get.ts
Normal file
74
plugin/kintone-addins/src/actions/current-field-get.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import {
|
||||
IAction,
|
||||
IActionResult,
|
||||
IActionNode,
|
||||
IActionProperty,
|
||||
IContext,
|
||||
} from "../types/ActionTypes";
|
||||
import { actionAddins } from ".";
|
||||
|
||||
|
||||
interface Props {
|
||||
displayName: string;
|
||||
field: Field;
|
||||
verName: VerName;
|
||||
}
|
||||
|
||||
interface VerName {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Field {
|
||||
name: string;
|
||||
type: string;
|
||||
code: string;
|
||||
label: string;
|
||||
noLabel: boolean;
|
||||
required: boolean;
|
||||
minLength: string;
|
||||
maxLength: string;
|
||||
expression: string;
|
||||
hideExpression: boolean;
|
||||
unique: boolean;
|
||||
defaultValue: string;
|
||||
}
|
||||
|
||||
export class CurrentFieldGetAction implements IAction {
|
||||
name: string;
|
||||
actionProps: IActionProperty[];
|
||||
currentFieldGetProps: Props;
|
||||
constructor() {
|
||||
this.name = "フィールドの値を取得する";
|
||||
this.actionProps = [];
|
||||
this.currentFieldGetProps = {} as Props;
|
||||
this.register();
|
||||
}
|
||||
|
||||
async process(
|
||||
prop: IActionNode,
|
||||
event: any,
|
||||
context: IContext
|
||||
): Promise<IActionResult> {
|
||||
this.currentFieldGetProps = prop.ActionValue as Props;
|
||||
this.actionProps = prop.actionProps;
|
||||
|
||||
let result = {
|
||||
canNext: true,
|
||||
result: "",
|
||||
} as IActionResult;
|
||||
|
||||
try {
|
||||
context.variables[this.currentFieldGetProps.verName.name] = context.record[this.currentFieldGetProps.field.code].value;
|
||||
} catch (error) {
|
||||
console.error("CurrentFieldGetAction error", error);
|
||||
result.canNext = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
register(): void {
|
||||
actionAddins[this.name] = this;
|
||||
}
|
||||
}
|
||||
|
||||
new CurrentFieldGetAction();
|
||||
@@ -7,41 +7,70 @@ import {
|
||||
} from "../types/ActionTypes";
|
||||
import { actionAddins } from ".";
|
||||
|
||||
export type IApp = {
|
||||
interface Props {
|
||||
displayName: string;
|
||||
sources: Sources;
|
||||
dataMapping: DataMapping[];
|
||||
}
|
||||
|
||||
interface DataMapping {
|
||||
id: string;
|
||||
from: From;
|
||||
to: To;
|
||||
}
|
||||
|
||||
interface To {
|
||||
app: App;
|
||||
fields: Field[];
|
||||
isDialogVisible: boolean;
|
||||
}
|
||||
|
||||
interface Field {
|
||||
name: string;
|
||||
};
|
||||
export type IField = {
|
||||
name: string;
|
||||
code: string;
|
||||
type: string;
|
||||
};
|
||||
code: string;
|
||||
label: string;
|
||||
noLabel: boolean;
|
||||
required: boolean;
|
||||
minLength: string;
|
||||
maxLength: string;
|
||||
expression: string;
|
||||
hideExpression: boolean;
|
||||
unique: boolean;
|
||||
defaultValue: string;
|
||||
}
|
||||
|
||||
export type IAppFields = {
|
||||
app?: IApp;
|
||||
fields: IField[];
|
||||
};
|
||||
|
||||
type ValueType = {
|
||||
interface From {
|
||||
sharedText: string;
|
||||
_t: string;
|
||||
id: string;
|
||||
from: {
|
||||
objectType: "variable" | "field";
|
||||
name: { name: string };
|
||||
code: string;
|
||||
};
|
||||
to: IAppFields & {
|
||||
isDialogVisible: boolean;
|
||||
};
|
||||
};
|
||||
objectType: string;
|
||||
name: Name;
|
||||
actionName: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
type Props = { app: IApp; field: ValueType[] };
|
||||
interface Name {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Sources {
|
||||
app: App;
|
||||
}
|
||||
|
||||
interface App {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
createdate: string;
|
||||
}
|
||||
|
||||
export class DataMappingAction implements IAction {
|
||||
name: string;
|
||||
actionProps: IActionProperty[];
|
||||
dataMappingProps: Props;
|
||||
constructor() {
|
||||
this.name = "DataMapping";
|
||||
this.name = "データマッピング";
|
||||
this.actionProps = [];
|
||||
this.dataMappingProps = {} as Props;
|
||||
this.register();
|
||||
@@ -52,14 +81,17 @@ export class DataMappingAction implements IAction {
|
||||
event: any,
|
||||
context: IContext
|
||||
): Promise<IActionResult> {
|
||||
this.initActionProps(prop);
|
||||
this.initTypedActionProps();
|
||||
this.actionProps = prop.actionProps;
|
||||
this.dataMappingProps = prop.ActionValue as Props;
|
||||
console.log(prop.ActionValue);
|
||||
|
||||
// this.initTypedActionProps();
|
||||
let result = {
|
||||
canNext: true,
|
||||
result: "",
|
||||
} as IActionResult;
|
||||
try {
|
||||
for (const item of this.dataMappingProps.field) {
|
||||
for (const item of this.dataMappingProps.dataMapping) {
|
||||
if (item.from.objectType === "variable") {
|
||||
if (
|
||||
item.from.name.name &&
|
||||
@@ -86,32 +118,6 @@ export class DataMappingAction implements IAction {
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (item.from.objectType === "field") {
|
||||
if (
|
||||
item.from.code &&
|
||||
item.to.app &&
|
||||
item.to.fields &&
|
||||
item.to.fields.length > 0
|
||||
) {
|
||||
const value = await selectData(
|
||||
item.to.app.id,
|
||||
item.to.fields[0].code
|
||||
);
|
||||
if (value && value.type === context.record[item.from.code].type) {
|
||||
await kintone.api(
|
||||
kintone.api.url("/k/v1/records.json", true),
|
||||
"POST",
|
||||
{
|
||||
app: item.to.app.id,
|
||||
records: value.value.map((v) => ({
|
||||
[item.to.fields[0].code]: {
|
||||
value: v,
|
||||
},
|
||||
})),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -123,19 +129,6 @@ export class DataMappingAction implements IAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
private initActionProps(nodes: IActionNode) {
|
||||
this.actionProps = nodes.actionProps;
|
||||
}
|
||||
private initTypedActionProps() {
|
||||
for (const action of this.actionProps) {
|
||||
if (action.component === "DataMapping") {
|
||||
this.dataMappingProps.field = action.props.modelValue as ValueType[];
|
||||
} else if (action.component === "AppSelect") {
|
||||
this.dataMappingProps.app = action.props.modelValue.app as IApp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
register(): void {
|
||||
actionAddins[this.name] = this;
|
||||
}
|
||||
|
||||
@@ -7,31 +7,135 @@ import {
|
||||
} from "../types/ActionTypes";
|
||||
import { actionAddins } from ".";
|
||||
|
||||
interface Props {
|
||||
displayName: string;
|
||||
sources: Sources;
|
||||
condition: Condition;
|
||||
verName: VerName;
|
||||
}
|
||||
|
||||
type DataProcessingProps = {
|
||||
app: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
conditionsQuery: string;
|
||||
propcessing: {
|
||||
varRootName: string;
|
||||
fields: Field[];
|
||||
};
|
||||
};
|
||||
|
||||
type Field = {
|
||||
name: string;
|
||||
code: string;
|
||||
interface Condition {
|
||||
queryString: string;
|
||||
index: number;
|
||||
type: string;
|
||||
varName: string;
|
||||
children: Child[];
|
||||
parent: null;
|
||||
logicalOperator: string;
|
||||
}
|
||||
|
||||
interface Child {
|
||||
index: number;
|
||||
type: string;
|
||||
parent: string;
|
||||
object: Object;
|
||||
operator: ChildOperator;
|
||||
value: Value;
|
||||
}
|
||||
|
||||
interface Value {
|
||||
sharedText: string;
|
||||
_t: string;
|
||||
objectType: string;
|
||||
actionName: string;
|
||||
displayName: string;
|
||||
name: Name;
|
||||
}
|
||||
|
||||
interface Name {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ChildOperator {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Object {
|
||||
sharedText: string;
|
||||
_t: string;
|
||||
name: string;
|
||||
objectType: string;
|
||||
type: string;
|
||||
code: string;
|
||||
label: string;
|
||||
noLabel: boolean;
|
||||
required: boolean;
|
||||
minLength: string;
|
||||
maxLength: string;
|
||||
expression: string;
|
||||
hideExpression: boolean;
|
||||
unique: boolean;
|
||||
defaultValue: string;
|
||||
}
|
||||
|
||||
interface VerName {
|
||||
name: string;
|
||||
actionName: string;
|
||||
displayName: string;
|
||||
vars: Var[];
|
||||
}
|
||||
|
||||
interface Var {
|
||||
id: string;
|
||||
field: Field2;
|
||||
logicalOperator: LogicalOperator;
|
||||
vName: string;
|
||||
}
|
||||
|
||||
interface LogicalOperator {
|
||||
operator: string;
|
||||
};
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface Field2 {
|
||||
sharedText: string;
|
||||
_t: string;
|
||||
name: string;
|
||||
objectType: string;
|
||||
type: string;
|
||||
code: string;
|
||||
label: string;
|
||||
noLabel: boolean;
|
||||
required: boolean;
|
||||
minLength: string;
|
||||
maxLength: string;
|
||||
expression: string;
|
||||
hideExpression: boolean;
|
||||
unique: boolean;
|
||||
defaultValue: string;
|
||||
}
|
||||
|
||||
interface Sources {
|
||||
app: App;
|
||||
fields: Field[];
|
||||
}
|
||||
|
||||
interface Field {
|
||||
name: string;
|
||||
type: string;
|
||||
code: string;
|
||||
label: string;
|
||||
noLabel: boolean;
|
||||
required: boolean;
|
||||
minLength: string;
|
||||
maxLength: string;
|
||||
expression: string;
|
||||
hideExpression: boolean;
|
||||
unique: boolean;
|
||||
defaultValue: string;
|
||||
}
|
||||
|
||||
interface App {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
createdate: string;
|
||||
}
|
||||
|
||||
export class DataProcessingAction implements IAction {
|
||||
name: string;
|
||||
actionProps: IActionProperty[];
|
||||
dataProcessingProps: DataProcessingProps | null;
|
||||
dataProcessingProps: Props | null;
|
||||
constructor() {
|
||||
this.name = "データ処理";
|
||||
this.actionProps = [];
|
||||
@@ -40,10 +144,13 @@ export class DataProcessingAction implements IAction {
|
||||
}
|
||||
|
||||
async process(
|
||||
nodes: IActionNode,event: any,context: IContext
|
||||
nodes: IActionNode,
|
||||
event: any,
|
||||
context: IContext
|
||||
): Promise<IActionResult> {
|
||||
this.initActionProps(nodes);
|
||||
this.initTypedActionProps();
|
||||
this.actionProps = nodes.actionProps;
|
||||
this.dataProcessingProps = nodes.ActionValue as Props;
|
||||
|
||||
let result = {
|
||||
canNext: true,
|
||||
result: "",
|
||||
@@ -52,24 +159,24 @@ export class DataProcessingAction implements IAction {
|
||||
if (!this.dataProcessingProps) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const data = await selectData(this.dataProcessingProps.conditionsQuery);
|
||||
|
||||
const data = await selectData(varGet(this.dataProcessingProps.condition.queryString,context.variables));
|
||||
console.log("data ", data);
|
||||
|
||||
context.variables[this.dataProcessingProps.propcessing.varRootName] =
|
||||
this.dataProcessingProps.propcessing.fields.reduce((acc, f) => {
|
||||
context.variables[this.dataProcessingProps.verName.name] =
|
||||
this.dataProcessingProps.verName.vars.reduce((acc, f) => {
|
||||
const v = calc(f, data);
|
||||
if (v) {
|
||||
acc[f.varName] = calc(f, data);
|
||||
acc[f.vName] = calc(f, data);
|
||||
}
|
||||
return acc;
|
||||
}, {} as Var);
|
||||
}, {} as AnyObject);
|
||||
|
||||
console.log("context ", context);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
event.error=error;
|
||||
event.error = error;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -77,50 +184,24 @@ export class DataProcessingAction implements IAction {
|
||||
register(): void {
|
||||
actionAddins[this.name] = this;
|
||||
}
|
||||
|
||||
private initActionProps(nodes: IActionNode) {
|
||||
this.actionProps = nodes.actionProps;
|
||||
}
|
||||
|
||||
private initTypedActionProps() {
|
||||
this.dataProcessingProps = {
|
||||
app: {
|
||||
id: "",
|
||||
name: "",
|
||||
},
|
||||
conditionsQuery: "",
|
||||
propcessing: {
|
||||
varRootName: "",
|
||||
fields: [],
|
||||
},
|
||||
};
|
||||
for (const action of this.actionProps) {
|
||||
if (action.component === "AppFieldSelect") {
|
||||
this.dataProcessingProps.app.id = action.props.modelValue.app.id;
|
||||
this.dataProcessingProps.app.name = action.props.modelValue.app.name;
|
||||
} else if (action.component === "DataProcessing") {
|
||||
this.dataProcessingProps.propcessing.varRootName =
|
||||
action.props.modelValue.name;
|
||||
for (const f of action.props.modelValue.vars) {
|
||||
this.dataProcessingProps.propcessing.fields.push({
|
||||
name: f.field.name,
|
||||
code: f.field.code,
|
||||
type: f.field.type,
|
||||
varName: f.vName,
|
||||
operator: f.logicalOperator.operator,
|
||||
});
|
||||
}
|
||||
} else if (action.component === "ConditionInput") {
|
||||
this.dataProcessingProps.conditionsQuery = JSON.parse(
|
||||
action.props.modelValue
|
||||
).queryString;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new DataProcessingAction();
|
||||
|
||||
const varGet = (str: string, vars: any) => {
|
||||
const regex = /var\((.*?)\)/g;
|
||||
let match;
|
||||
while ((match = regex.exec(str)) !== null) {
|
||||
const varName = match[1];
|
||||
if (varName in vars) {
|
||||
str = str.replace(match[0], vars[varName]);
|
||||
} else {
|
||||
throw new Error(`変数${varName}が見つかりません`);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const selectData = async (query?: string) => {
|
||||
return kintone
|
||||
.api(kintone.api.url("/k/v1/records", true), "GET", {
|
||||
@@ -157,24 +238,24 @@ type Result = {
|
||||
};
|
||||
};
|
||||
|
||||
type Var = {
|
||||
type AnyObject = {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
const ERROR_TYPE = "ERROR_TYPE";
|
||||
|
||||
const calc = (field: Field, result: Result) => {
|
||||
const type = typeCheck(field.type);
|
||||
const calc = (f: Var, result: Result) => {
|
||||
const type = typeCheck(f.field.type);
|
||||
if (!type) {
|
||||
return ERROR_TYPE;
|
||||
}
|
||||
|
||||
const fun =
|
||||
calcFunc[`${type}_${Operator[field.operator as keyof typeof Operator]}`];
|
||||
calcFunc[`${type}_${Operator[f.logicalOperator.operator as keyof typeof Operator]}`];
|
||||
if (!fun) {
|
||||
return ERROR_TYPE;
|
||||
}
|
||||
const values = result[field.code].value;
|
||||
const values = result[f.field.code].value;
|
||||
if (!values) {
|
||||
return null;
|
||||
}
|
||||
@@ -208,7 +289,7 @@ enum Operator {
|
||||
MAX = "MAX",
|
||||
MIN = "MIN",
|
||||
COUNT = "COUNT",
|
||||
FIRST = "FIRST"
|
||||
FIRST = "FIRST",
|
||||
}
|
||||
|
||||
enum CalcType {
|
||||
@@ -274,7 +355,7 @@ const calcFunc: Record<string, (value: string[]) => string | null> = {
|
||||
? minDateTime
|
||||
: currentDateTime
|
||||
),
|
||||
[`${CalcType.STRING}_${Operator.FIRST}`]:(value: string[])=>{
|
||||
[`${CalcType.STRING}_${Operator.FIRST}`]: (value: string[]) => {
|
||||
return value[0];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../actions/button-add';
|
||||
import '../actions/condition-action';
|
||||
import '../actions/data-processing';
|
||||
import '../actions/data-mapping';
|
||||
import '../actions/current-field-get';
|
||||
import { ActionFlow,IActionFlow, IActionResult,IContext } from "./ActionTypes";
|
||||
|
||||
export class ActionProcess{
|
||||
|
||||
Reference in New Issue
Block a user