Merge branch 'mvp_step2_dev' of https://dev.azure.com/alicorn-dev/KintoneAppBuilder/_git/KintoneAppBuilder into mvp_step2_dev
This commit is contained in:
97
plugin/kintone-addins/src/actions/error-show.ts
Normal file
97
plugin/kintone-addins/src/actions/error-show.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
import { actionAddins } from ".";
|
||||
import { IAction, IActionProperty, IActionNode, IContext, IActionResult } from "../types/ActionTypes";
|
||||
import { ConditionTree } from '../types/Conditions';
|
||||
|
||||
interface IErrorShowProps {
|
||||
message: string;
|
||||
condition: string;
|
||||
}
|
||||
|
||||
export class ErrorShowAction implements IAction {
|
||||
name: string;
|
||||
actionProps: IActionProperty[];
|
||||
props: IErrorShowProps;
|
||||
constructor() {
|
||||
this.name = "エラー表示";
|
||||
this.actionProps = [];
|
||||
this.props = {
|
||||
message: '',
|
||||
condition: ''
|
||||
}
|
||||
this.register();
|
||||
}
|
||||
|
||||
/**
|
||||
* アクションの実行を呼び出す
|
||||
* @param actionNode
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
async process(actionNode: IActionNode, event: any, context: IContext): Promise<IActionResult> {
|
||||
let result = {
|
||||
canNext: true,
|
||||
result: false
|
||||
};
|
||||
try {
|
||||
this.actionProps = actionNode.actionProps;
|
||||
if (!('message' in actionNode.ActionValue) && !('condition' in actionNode.ActionValue)) {
|
||||
return result
|
||||
}
|
||||
this.props = actionNode.ActionValue as IErrorShowProps;
|
||||
const conditionResult = this.getConditionResult(context);
|
||||
if (conditionResult) {
|
||||
event.error = this.props.message
|
||||
} else {
|
||||
result = {
|
||||
canNext: false,
|
||||
result: true
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (error) {
|
||||
event.error = error;
|
||||
console.error(error);
|
||||
result.canNext = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param context 条件式を実行する
|
||||
* @returns
|
||||
*/
|
||||
getConditionResult(context: any): boolean {
|
||||
const tree = this.getCondition(this.props.condition);
|
||||
if (!tree) {
|
||||
//条件を設定されていません
|
||||
return true;
|
||||
}
|
||||
return tree.evaluate(tree.root, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param condition 条件式ツリーを取得する
|
||||
* @returns
|
||||
*/
|
||||
getCondition(condition: string): ConditionTree | null {
|
||||
try {
|
||||
const tree = new ConditionTree();
|
||||
tree.fromJson(condition);
|
||||
if (tree.getConditions(tree.root).length > 0) {
|
||||
return tree;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
register(): void {
|
||||
actionAddins[this.name] = this;
|
||||
}
|
||||
|
||||
}
|
||||
new ErrorShowAction();
|
||||
Reference in New Issue
Block a user