From 3e737995322c34a8d67406c71018f89867ec0a0f Mon Sep 17 00:00:00 2001 From: wtl Date: Fri, 2 Feb 2024 12:52:00 +0900 Subject: [PATCH] New Plagin Error Show --- .../kintone-addins/src/actions/error-show.ts | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 plugin/kintone-addins/src/actions/error-show.ts diff --git a/plugin/kintone-addins/src/actions/error-show.ts b/plugin/kintone-addins/src/actions/error-show.ts new file mode 100644 index 0000000..03b7dca --- /dev/null +++ b/plugin/kintone-addins/src/actions/error-show.ts @@ -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 { + 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(); \ No newline at end of file