diff --git a/plugin/kintone-addins/src/actions/date-specified.ts b/plugin/kintone-addins/src/actions/date-specified.ts new file mode 100644 index 0000000..caf13e8 --- /dev/null +++ b/plugin/kintone-addins/src/actions/date-specified.ts @@ -0,0 +1,86 @@ +import { actionAddins } from "."; +import { IAction, IActionResult, IActionNode, IActionProperty, IField ,IContext, IVarName} from "../types/ActionTypes"; +/** + * アクションの属性定義 + */ +interface IDateSpecifiedProps { + verNameGet:string; + newYear:number; + newMonth:number; + newDay:number; + verName:IVarName; +} +/** + * 日付指定アクション + */ +export class DateSpecifiedAction implements IAction { + name: string; + actionProps: IActionProperty[]; + props: IDateSpecifiedProps; + constructor() { + this.name = "日付指定"; + this.actionProps = []; + this.props = { + verNameGet:'', + newYear:0, + newMonth:0, + newDay:0, + verName:{name:''} + } + 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 (!('verName' in actionNode.ActionValue) && !('verNameGet' in actionNode.ActionValue) ) { + return result + } + this.props = actionNode.ActionValue as IDateSpecifiedProps; +//////////////////////////////////////////////////////////////////////////////////////////////// + //本番コード開始: + //取得変数の値を呼び出して代入する: + const getContextVarByPath = (obj: any, path: string) => { + return path.split(".").reduce((o, k) => (o || {})[k], obj); + }; + let verNameGetValue = getContextVarByPath(context.variables,this.props.verNameGet); +//////////////////////////////////////////////////////////////////////////////////////////////// + //取得変数の値Dateオブジェクトに変換: + let dateObj = new Date(verNameGetValue); + // 年の設定(newYearが設定されていない場合は、元の値を使用) + dateObj.setFullYear(this.props.newYear >=1900 && this.props.newYear <=9999 ? this.props.newYear : dateObj.getFullYear()); + // 月の設定(newMonthが設定されていない場合は、元の値を使用)// 月は0始まりなので、12月は11。 + dateObj.setMonth(this.props.newMonth >=1 && this.props.newMonth <=12 ? this.props.newMonth-1 : dateObj.getMonth()); + // 日の設定(newDayが設定されていない場合は、元の値を使用) + dateObj.setDate(this.props.newDay >=1 && this.props.newDay <=31 ?this.props.newDay : dateObj.getDate()); + // 変数に新しい値を設定 + if(this.props.verName && this.props.verName.name!==''){ + context.variables[this.props.verName.name]=dateObj.toISOString(); + } +//////////////////////////////////////////////////////////////////////////////////////////////// + result = { + canNext:true, + result:true + } + return result; + }catch(error){ + context.errors.handleError(error,actionNode); + result.canNext=false; + return result; + } + }; + register(): void { + actionAddins[this.name] = this; + } +} +new DateSpecifiedAction(); \ No newline at end of file diff --git a/plugin/kintone-addins/src/actions/end-of-month.ts b/plugin/kintone-addins/src/actions/end-of-month.ts new file mode 100644 index 0000000..2495dc8 --- /dev/null +++ b/plugin/kintone-addins/src/actions/end-of-month.ts @@ -0,0 +1,77 @@ +import { actionAddins } from "."; +import { IAction, IActionResult, IActionNode, IActionProperty, IField ,IContext, IVarName} from "../types/ActionTypes"; +/** + * アクションの属性定義 + */ +interface IEndOfMonthProps { + verNameGet:string; + verName:IVarName; +} +/** + * 月末算出アクション + */ +export class EndOfMonthAction implements IAction { + name: string; + actionProps: IActionProperty[]; + props: IEndOfMonthProps; + constructor() { + this.name = "月末算出"; + this.actionProps = []; + this.props = { + verNameGet:'', + verName:{name:''} + } + 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 (!('verName' in actionNode.ActionValue) && !('verNameGet' in actionNode.ActionValue) ) { + return result + } + this.props = actionNode.ActionValue as IEndOfMonthProps; +//////////////////////////////////////////////////////////////////////////////////////////////// + //本番コード開始: + //取得変数の値を呼び出して代入する: + const getContextVarByPath = (obj: any, path: string) => { + return path.split(".").reduce((o, k) => (o || {})[k], obj); + }; + let verNameGetValue = getContextVarByPath(context.variables,this.props.verNameGet); +//////////////////////////////////////////////////////////////////////////////////////////////// + //取得変数の値Dateオブジェクトに変換: + let dateObj = new Date(verNameGetValue); + // 月末を計算 + let year = dateObj.getFullYear(); + let month = dateObj.getMonth() + 1; //月は0から始まるため、1を足す + let lastDayOfMonth = new Date(year, month, 0); // 翌月の0日目は今月の月末 + if(this.props.verName && this.props.verName.name!==''){ + context.variables[this.props.verName.name]=lastDayOfMonth.toISOString(); + } +//////////////////////////////////////////////////////////////////////////////////////////////// + result = { + canNext:true, + result:true + } + return result; + }catch(error){ + context.errors.handleError(error,actionNode); + result.canNext=false; + return result; + } + }; + register(): void { + actionAddins[this.name] = this; + } +} +new EndOfMonthAction(); \ No newline at end of file diff --git a/plugin/kintone-addins/src/types/action-process.ts b/plugin/kintone-addins/src/types/action-process.ts index e0fe403..4ac88b8 100644 --- a/plugin/kintone-addins/src/types/action-process.ts +++ b/plugin/kintone-addins/src/types/action-process.ts @@ -24,6 +24,8 @@ import '../actions/auto-lookup'; import '../actions/field-disable'; import '../actions/style-field'; import '../actions/datetime-calc'; +import '../actions/end-of-month'; +import '../actions/date-specified'; import { ActionFlow,ErrorManager,IActionFlow, IActionResult,IContext } from "./ActionTypes"; const ShowErrorEvents:string[] = [ "app.record.create.submit.success",