bugfix:条件式の関連修正
This commit is contained in:
@@ -42,13 +42,10 @@ export class ErrorShowAction implements IAction {
|
|||||||
}
|
}
|
||||||
this.props = actionNode.ActionValue as IErrorShowProps;
|
this.props = actionNode.ActionValue as IErrorShowProps;
|
||||||
const conditionResult = this.getConditionResult(context);
|
const conditionResult = this.getConditionResult(context);
|
||||||
|
console.log("条件結果:",conditionResult);
|
||||||
if (conditionResult) {
|
if (conditionResult) {
|
||||||
event.error = this.props.message;
|
event.error = this.props.message;
|
||||||
} else {
|
result.canNext=false;
|
||||||
result = {
|
|
||||||
canNext: false,
|
|
||||||
result: true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ export interface IAction{
|
|||||||
register():void;
|
register():void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface IField{
|
export interface IField{
|
||||||
name?:string;
|
name?:string;
|
||||||
code:string;
|
code:string;
|
||||||
@@ -99,6 +97,14 @@ export interface IVarName{
|
|||||||
fields?:IVarName[];
|
fields?:IVarName[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ユーザー、グループ、組織などオブジェクト類型
|
||||||
|
*/
|
||||||
|
export interface ICodeValue {
|
||||||
|
code: string;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* アクションのプロパティ定義に基づいたクラス
|
* アクションのプロパティ定義に基づいたクラス
|
||||||
*/
|
*/
|
||||||
@@ -297,7 +303,7 @@ export class ErrorManager{
|
|||||||
|
|
||||||
public setEvent(event:any){
|
public setEvent(event:any){
|
||||||
const messages = this.errors.map((err)=>{
|
const messages = this.errors.map((err)=>{
|
||||||
return `「${err.action.name}」処理中例外発生しました。詳細:${err.error}`;
|
return `「${err.action.name}」処理中例外発生しました。\n詳細:${err.error}`;
|
||||||
});
|
});
|
||||||
event.error=messages.join('\n');
|
event.error=messages.join('\n');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IContext } from "./ActionTypes";
|
import { IContext,ICodeValue } from "./ActionTypes";
|
||||||
|
|
||||||
//ノード種別
|
//ノード種別
|
||||||
export enum NodeType{
|
export enum NodeType{
|
||||||
@@ -316,6 +316,37 @@ export class ConditionTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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の値を取得する
|
* Condition objectの値を取得する
|
||||||
* @param object
|
* @param object
|
||||||
@@ -331,10 +362,13 @@ export class ConditionTree {
|
|||||||
if(fieldValue.type==='NUMBER' && fieldValue.value!==undefined){
|
if(fieldValue.type==='NUMBER' && fieldValue.value!==undefined){
|
||||||
return Number(fieldValue.value);
|
return Number(fieldValue.value);
|
||||||
}else{
|
}else{
|
||||||
return fieldValue.value;
|
return this.convertCodeValue(fieldValue.value);
|
||||||
}
|
}
|
||||||
}else if(object.objectType==='variable'){
|
}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
|
* @param object
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getConditionValue(object:any){
|
getConditionValue(object:any,context:IContext){
|
||||||
if(!object || typeof object!=="object"){
|
if(!object || typeof object!=="object"){
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
if("objectType" in object){
|
||||||
|
return this.getObjectValue(object,context);
|
||||||
|
}
|
||||||
if("sharedText" in object){
|
if("sharedText" in object){
|
||||||
return object.sharedText;
|
return object.sharedText;
|
||||||
}
|
}
|
||||||
@@ -369,8 +406,16 @@ export class ConditionTree {
|
|||||||
*/
|
*/
|
||||||
evaluateCondition(condition: ConditionNode, context: IContext): boolean {
|
evaluateCondition(condition: ConditionNode, context: IContext): boolean {
|
||||||
const { object, operator, value } = condition;
|
const { object, operator, value } = condition;
|
||||||
const targetValue = this.getObjectValue(object,context);
|
const targetObject = this.getObjectValue(object,context);
|
||||||
const conditionValue = this.getConditionValue(value);
|
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) {
|
switch (operator) {
|
||||||
case Operator.Equal:
|
case Operator.Equal:
|
||||||
case Operator.NotEqual:
|
case Operator.NotEqual:
|
||||||
@@ -427,7 +472,6 @@ export class ConditionTree {
|
|||||||
else if (typeof targetValue === 'string') {
|
else if (typeof targetValue === 'string') {
|
||||||
value = String(value);
|
value = String(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case Operator.Equal:
|
case Operator.Equal:
|
||||||
return targetValue === value;
|
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
|
* @param targetValue
|
||||||
@@ -482,6 +560,4 @@ export class ConditionTree {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user