From bf4ddba490a984c43de8ccee7ea6e9007c789a79 Mon Sep 17 00:00:00 2001 From: "xiaozhe.ma" Date: Fri, 2 Aug 2024 10:03:55 +0900 Subject: [PATCH] =?UTF-8?q?bugfix:=E6=9D=A1=E4=BB=B6=E5=BC=8F=E3=81=AE?= =?UTF-8?q?=E9=96=A2=E9=80=A3=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kintone-addins/src/actions/error-show.ts | 7 +- .../kintone-addins/src/types/ActionTypes.ts | 12 ++- plugin/kintone-addins/src/types/Conditions.ts | 96 +++++++++++++++++-- 3 files changed, 97 insertions(+), 18 deletions(-) diff --git a/plugin/kintone-addins/src/actions/error-show.ts b/plugin/kintone-addins/src/actions/error-show.ts index 7ef1f00..94c8ab1 100644 --- a/plugin/kintone-addins/src/actions/error-show.ts +++ b/plugin/kintone-addins/src/actions/error-show.ts @@ -42,13 +42,10 @@ export class ErrorShowAction implements IAction { } this.props = actionNode.ActionValue as IErrorShowProps; const conditionResult = this.getConditionResult(context); + console.log("条件結果:",conditionResult); if (conditionResult) { event.error = this.props.message; - } else { - result = { - canNext: false, - result: true - } + result.canNext=false; } return result; } catch (error) { diff --git a/plugin/kintone-addins/src/types/ActionTypes.ts b/plugin/kintone-addins/src/types/ActionTypes.ts index 5371bd3..e1976c8 100644 --- a/plugin/kintone-addins/src/types/ActionTypes.ts +++ b/plugin/kintone-addins/src/types/ActionTypes.ts @@ -84,8 +84,6 @@ export interface IAction{ register():void; } - - export interface IField{ name?:string; code:string; @@ -99,6 +97,14 @@ export interface IVarName{ fields?:IVarName[]; } +/** + * ユーザー、グループ、組織などオブジェクト類型 + */ +export interface ICodeValue { + code: string; + name?: string; +} + /** * アクションのプロパティ定義に基づいたクラス */ @@ -297,7 +303,7 @@ export class ErrorManager{ public setEvent(event:any){ const messages = this.errors.map((err)=>{ - return `「${err.action.name}」処理中例外発生しました。詳細:${err.error}`; + return `「${err.action.name}」処理中例外発生しました。\n詳細:${err.error}`; }); event.error=messages.join('\n'); } diff --git a/plugin/kintone-addins/src/types/Conditions.ts b/plugin/kintone-addins/src/types/Conditions.ts index 641c5de..050f9d3 100644 --- a/plugin/kintone-addins/src/types/Conditions.ts +++ b/plugin/kintone-addins/src/types/Conditions.ts @@ -1,4 +1,4 @@ -import { IContext } from "./ActionTypes"; +import { IContext,ICodeValue } from "./ActionTypes"; //ノード種別 export enum NodeType{ @@ -315,7 +315,38 @@ export class ConditionTree { throw new Error('Unsupported node type'); } } - + + + getCodeValue(value: any): any { + if (value && typeof value === 'object' && 'code' in value) { + return value.code; + } else { + return value; + } + } + + /** + * ICodeValue型のcodeに変換する + * @param value + * @returns + */ + convertCodeValue(value:any):any{ + if (Array.isArray(value)) { + return value.map(v => this.getCodeValue(v)); + } else { + return this.getCodeValue(value); + } + } + /** + * + * @param vars 変数値を取得する + * @param path + * @returns + */ + getContextVarByPath (vars: {[key:string]:any}, path: string){ + return path.split(".").reduce((o, k) => (o || {})[k], vars); + }; + /** * Condition objectの値を取得する * @param object @@ -331,10 +362,13 @@ export class ConditionTree { if(fieldValue.type==='NUMBER' && fieldValue.value!==undefined){ return Number(fieldValue.value); }else{ - return fieldValue.value; + return this.convertCodeValue(fieldValue.value); } }else if(object.objectType==='variable'){ - return context.variables[object.name].value; + const varValue = this.getContextVarByPath(context.variables,object.name.name); + return this.convertCodeValue(varValue); + }else if(object.objectType==='text'){ + return object.sharedText; } } @@ -343,10 +377,13 @@ export class ConditionTree { * @param object * @returns */ - getConditionValue(object:any){ + getConditionValue(object:any,context:IContext){ if(!object || typeof object!=="object"){ return object; } + if("objectType" in object){ + return this.getObjectValue(object,context); + } if("sharedText" in object){ return object.sharedText; } @@ -369,8 +406,16 @@ export class ConditionTree { */ evaluateCondition(condition: ConditionNode, context: IContext): boolean { const { object, operator, value } = condition; - const targetValue = this.getObjectValue(object,context); - const conditionValue = this.getConditionValue(value); + const targetObject = this.getObjectValue(object,context); + const conditionObject = this.getConditionValue(value,context); + const isArrayTarget = Array.isArray(targetObject); + const isArrayValue = Array.isArray(conditionObject); + //配列の比較 + if((isArrayTarget && targetObject.length > 1)||(isArrayValue && conditionObject.length>1)){ + return this.compareArray(operator,targetObject,conditionObject) + } + const targetValue = isArrayTarget?targetObject[0]:targetObject; + const conditionValue = isArrayValue?conditionObject[0]:conditionObject; switch (operator) { case Operator.Equal: case Operator.NotEqual: @@ -427,7 +472,6 @@ export class ConditionTree { else if (typeof targetValue === 'string') { value = String(value); } - switch (operator) { case Operator.Equal: return targetValue === value; @@ -446,6 +490,40 @@ export class ConditionTree { } } + /** + * 配列値の比較 + * @param operator + * @param targetValue + * @param value + */ + /** + * 配列値の比較 + * @param operator + * @param targetValue + * @param value + */ + compareArray(operator: Operator, targetValue: any, value: any): boolean { + const isArrayTarget = Array.isArray(targetValue); + const isArrayValue = Array.isArray(value); + const sortArray = (arr: any[]) => arr.slice().sort(); + targetValue = isArrayTarget?targetValue:[targetValue]; + value= isArrayValue?value:[value]; + const targetArray=sortArray(targetValue); + const valueArray=sortArray(value); + switch (operator) { + case Operator.Equal: + return targetArray.every((v, i) => v === valueArray[i]); + case Operator.NotEqual: + return !targetArray.every((v, i) => v === valueArray[i]); + case Operator.Contains: + return valueArray.every(v => targetArray.includes(v)); + case Operator.NotContains: + return !valueArray.every(v => targetArray.includes(v)); + default: + return false; + } +} + /** * 含む計算 * @param targetValue @@ -482,6 +560,4 @@ export class ConditionTree { } return false; } - - }