From 2e69dc4dcfe8c1a6ce4a2f28160f2fabc985975e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=8E=89?= Date: Mon, 3 Jun 2024 17:39:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:#239=E6=96=87=E5=AD=97=E7=B5=90=E5=90=88?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=8D=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kintone-addins/src/actions/string-join.ts | 211 ++++++++++++++++++ .../src/types/action-process.ts | 6 + 2 files changed, 217 insertions(+) create mode 100644 plugin/kintone-addins/src/actions/string-join.ts diff --git a/plugin/kintone-addins/src/actions/string-join.ts b/plugin/kintone-addins/src/actions/string-join.ts new file mode 100644 index 0000000..36781a0 --- /dev/null +++ b/plugin/kintone-addins/src/actions/string-join.ts @@ -0,0 +1,211 @@ +import { actionAddins } from "."; +import { IField, IAction,IActionResult, IActionNode, IActionProperty } from "../types/ActionTypes"; +import { Formatter } from "../util/format"; + +//右UI画面propertyのname:型: +interface IStringJoinProps{ + //保存先フィールド + saveField:IField; + //結合元フィールド1 + joinField1:IField; + //結合元フィールド2 + joinField2:IField; + //区切り文字 + delimiter:string; +} + +//IActionインタフェースを実装する新しいクラスActionを作成: +export class StringJoinAction implements IAction{ + name: string; + //importから導入顕示定義 + actionProps: IActionProperty[]; + //上方のinterface Propsから、props受ける属性を定義: + props:IStringJoinProps; + //関数定義に必要な類名を構築: + constructor(){ + //pgAdminDBに登録したアクション名(name/subtitle)一致する必要がある: + this.name="文字結合"; + this.actionProps=[]; + this.register(); + //プロパティ属性初期化: + this.props={ + saveField:{code:''}, + joinField1:{code:''}, + joinField2:{code:''}, + delimiter:'' + } + //リセット上記登録表: + this.register(); + } +/** + * アクションの処理を実装する + * @param actionNode アクションノード + * @param event Kintoneのイベント + * @param context コンテキスト(レコード、変数情報を持っている) + * @returns + */ +  //非同期処理ある関数下のある属性: + async process(actionNode:IActionNode,event:any):Promise { + let result={ + //後継処理不可: + canNext:false, + result:false + }; + try{ + //属性設定を取得する: + this.actionProps=actionNode.actionProps; + //プロパティ設定のデータ型は必要な情報含めますか?全部不存在時return: + if (!('saveField' in actionNode.ActionValue) && !('joinField1' in actionNode.ActionValue) && !('joinField2' in actionNode.ActionValue)) { + return result + } + + //既定のプロパティのインタフェースへ変換: + this.props = actionNode.ActionValue as IStringJoinProps; + const record = event.record; + + //kintoneフィールドタイプ取得: + const joinField1type=this.props.joinField1.type; + const joinField2type=this.props.joinField2.type; + const saveFieldtype=this.props.saveField.type; + +////////////////////////////////////////////////////////////////////////////////////////////////////// + // //保存先フィールドは文字列フィールドではない場合、エラー発生: + if(!(saveFieldtype==='SINGLE_LINE_TEXT'||saveFieldtype==='MULTI_LINE_TEXT'||saveFieldtype==='RICH_TEXT')){ + event.error='[エラーメッセージ]:結合保存先対応不可。結合しません'; + if (event.type.includes('success')){ + window.alert("[windows alert]:"+event.error); + } + result = { + canNext: false, + result: false + } + return result; + } +////////////////////////////////////////////////////////////////////////////////////////// + //値取得方法定義: + function getValue(value:string,type:string|undefined,fieldCode:string,event:any){ + if(event.record[fieldCode]?.value===undefined||event.record[fieldCode]?.value===null){ + event.record[fieldCode].value=''; + } + //作成者、更新者: + if(type==='CREATOR'||type==='MODIFIER'){ + value = event.record[fieldCode]?.value.name; + //日時、作成日時、更新日時: + }else if(type==='DATETIME'||type==='CREATED_TIME'||type==='UPDATED_TIME'){ + if(event.record[fieldCode]?.value!==undefined && event.record[fieldCode]?.value!==''){ + value = Formatter.dateFormat(new Date(event.record[fieldCode]?.value),'yyyy-MM-dd HH:mm'); + }else{ + value=event.record[fieldCode]?.value; + } + //ユーザ選択、組織選択、グループ選択、添付ファイル名、作業者、カテゴリー: + }else if(type==='USER_SELECT'||type==='ORGANIZATION_SELECT'||type==='GROUP_SELECT'||type==='FILE'||type==='STATUS_ASSIGNEE'){ + if(event.record[fieldCode]?.value===undefined || event.record[fieldCode]?.value===''){ + value = event.record[fieldCode]?.value; + }else{ + const mototext=event.record[fieldCode]?.value; + let arr=[]; + for(let i=0;i { + //kintone保存先フィールド存在確認: + record[this.props.saveField.code].value=saveValue; + if (event.type.includes('index')){ + window.alert("文字結合行いました。"+this.props.joinField1.name+":"+joinValue1+","+this.props.joinField2.name+":"+joinValue2+"。一覧画面更新成功後自動リロードしません。必要に応じて手動リロードください。"); + }else{ + window.alert("文字結合行いました。"+this.props.joinField1.name+":"+joinValue1+","+this.props.joinField2.name+":"+joinValue2+"。"); + } + //一覧画面更新成功後リロード: + // if (event.type.includes('index')){ + // event.url = location.href.endsWith('/') || location.href.endsWith('&') ? + // location.href.slice(0, -1) : + // location.href + (location.href.includes('?') ? '&' : '/'); + // } + }).catch((error) => { + event.error = 'エラーが発生しました。結合しません。システム管理者へお問合せください'; + window.alert(event.error+"error message:"+error); + return event; + }); + } +////////////////////////////////////////////////////////////////////////////////////////////////////// + result= { + canNext:true, + result:true + } + return result; + }catch(error){; + if (event.type.includes('success')){ + window.alert("[windows alert]:処理中異常が発生しました。結合しません。システム担当者へお問合せください。errorメッセージ:"+error) + } + event.error="[エラーメッセージ]:処理中異常が発生しました。結合しません。システム担当者へお問合せください。errorメッセージ:"+error; + return { + canNext:false, + result:false + } + } + } +/////////////////////////////////////////////////////////////////////////////////////////////// + register(): void { + actionAddins[this.name]=this; + } +} +new StringJoinAction(); \ 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 1f1889d..91f38b8 100644 --- a/plugin/kintone-addins/src/types/action-process.ts +++ b/plugin/kintone-addins/src/types/action-process.ts @@ -6,6 +6,12 @@ import '../actions/field-shown'; import '../actions/error-show'; import '../actions/button-add'; import '../actions/condition-action'; +import '../actions/regular-check'; +import '../actions/mail-check'; +import '../actions/counter-check'; +import '../actions/datetime-getter'; +import '../actions/insert-value'; +import '../actions/string-join'; import { ActionFlow,IActionFlow, IActionResult,IContext } from "./ActionTypes"; export class ActionProcess{