ken_nogi/Pleasanter/.claude/js/site-scripts/★マスターシート/disable-autopostback-488755.js
Kenichiro NOGI ce58cb4be4 初回コミット: dev配下(NodeSrv/Pleasanter等)をGitea管理下に統合
GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。
NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは
別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter
インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:37:06 +09:00

153 lines
6.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* disable-autopostback-488755.js
* ------------------------------------------------------------
* 488755「【開発中】★建売マスターシート」の担当者系LookupカラムClassF・Class171〜174から
* AutoPostBackプロパティと、ChoicesText内のLookups設定サーバー側の自動転記
* 削除する。転記はクライアント側スクリプト4_3.テーブルリンクと情報取得.js の
* change ハンドラに完全に置き換えるサーバー側Lookupとの二重転記をやめる
* 選択肢自体ChoicesTextのSiteId指定は残すプルダウンの候補元は維持、自動転記のみ削除
* 189112「★マスターシート」で実施済みの対応の横展開189112とSiteSettings構成が同一と確認済み
*
* updatesitefullで送信するが、他のSiteSettingsColumns他項目/GridColumns等
* Permissions・Title等は現状のまま一切変更しない対象5カラムのAutoPostBack・
* Lookups削除のみ
*
* 使い方:
* node disable-autopostback-488755.js --project="★マスターシート" --env=staging
* … 差分表示のみ(送信なし)
* node disable-autopostback-488755.js --project="★マスターシート" --env=staging --execute
* … 上記に加えて実際に送信する
* ------------------------------------------------------------
*/
const path = require("path");
const { resolveProjectRoot, loadServerConfig } = require("../../resolve-project");
const { findSiteDir, newModifyDir } = require("../../site-paths");
const fs = require("fs");
const { baseDir, env } = resolveProjectRoot();
const execute = process.argv.includes("--execute");
const SITE_ID = 488755;
const TARGET_COLUMNS = ["ClassF", "Class171", "Class172", "Class173", "Class174"];
function maskApiKey(key) {
if (!key) return key;
return key.length > 8 ? key.slice(0, 4) + "****" + key.slice(-4) : "****";
}
(async () => {
const config = loadServerConfig(env);
console.log("========================================");
console.log(` 488755 AutoPostBack無効化${env}${execute ? "(実行)" : "(プレビューのみ)"}`);
console.log("========================================");
const getUrl = `${config.BaseUrl.replace(/\/+$/, "")}/api/items/${SITE_ID}/getsite`;
const getRes = await fetch(getUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ApiVersion: config.ApiVersion || "1.1", ApiKey: config.ApiKey }),
});
const getJson = await getRes.json();
if (getJson.StatusCode !== 200) {
console.error("[エラー] getsiteに失敗しました:", JSON.stringify(getJson).slice(0, 500));
process.exit(1);
}
const data = getJson.Response.Data;
const siteSettings = data.SiteSettings;
console.log(`[OK] 取得しました現在のVer: ${data.Ver}, UpdatedTime: ${data.UpdatedTime}`);
console.log("\n--- AutoPostBack / Lookups変更対象 ---");
let changed = 0;
TARGET_COLUMNS.forEach((name) => {
const col = siteSettings.Columns.find((c) => c.ColumnName === name);
if (!col) {
console.error(`[エラー] Column not found: ${name}`);
process.exit(1);
}
let colChanged = false;
if (col.AutoPostBack) {
console.log(` ${name} (${col.LabelText}): AutoPostBack true -> 削除`);
delete col.AutoPostBack;
colChanged = true;
} else {
console.log(` ${name} (${col.LabelText}): 既にAutoPostBackなし`);
}
if (col.ChoicesText) {
let choices;
try {
choices = JSON.parse(col.ChoicesText);
} catch (e) {
console.error(`[エラー] ${name} のChoicesTextがJSONとして解析できません: ${e.message}`);
process.exit(1);
}
let lookupsRemoved = 0;
if (Array.isArray(choices)) {
choices.forEach((entry) => {
if (entry && entry.Lookups) {
delete entry.Lookups;
lookupsRemoved++;
}
});
}
if (lookupsRemoved > 0) {
col.ChoicesText = JSON.stringify(choices);
console.log(` ${name}: Lookups設定 ${lookupsRemoved}件を削除(選択肢自体(SiteId指定)は維持)`);
colChanged = true;
} else {
console.log(` ${name}: Lookups設定なし変更なし`);
}
}
if (colChanged) changed++;
});
console.log(`変更対象: ${changed}件(${TARGET_COLUMNS.length}件中)`);
console.log("ColumnsReturnedWhenAutomaticPostbackはAutoPostBackが無効なら参照されないため、値は変更せず残す。");
console.log("他のSiteSettings他Columns/GridColumns等・Permissions・Title等は一切変更しません。");
const body = {
ApiVersion: config.ApiVersion || "1.1",
ApiKey: config.ApiKey,
SiteId: SITE_ID,
Title: data.Title,
ReferenceType: data.ReferenceType,
ParentId: data.ParentId,
InheritPermission: data.InheritPermission,
Permissions: data.Permissions,
SiteSettings: siteSettings,
};
const siteDir = findSiteDir(path.join(baseDir, "configs", env), SITE_ID);
const maskedBody = { ...body, ApiKey: maskApiKey(body.ApiKey) };
const ts = new Date().toISOString().replace(/[:.]/g, "-");
if (siteDir) {
const modifyDir = newModifyDir(siteDir, "autopostback-disable");
fs.writeFileSync(
path.join(modifyDir, `site-${SITE_ID}_autopostback_preview_${ts}.json`),
JSON.stringify(maskedBody, null, 2),
"utf-8"
);
console.log(`\n[OK] 送信予定内容を保存しました: ${path.join(modifyDir, `site-${SITE_ID}_autopostback_preview_${ts}.json`)}`);
}
if (!execute) {
console.log("\n[注意] --execute が指定されていないため、送信は行っていません。");
console.log("内容を確認の上、問題なければ次を実行してください: node disable-autopostback-488755.js --execute");
process.exit(0);
}
console.log("\n実際に送信しますupdatesite...");
const url = `${config.BaseUrl.replace(/\/+$/, "")}/api/items/${SITE_ID}/updatesite`;
const res = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const text = await res.text();
console.log(`HTTP ${res.status} ${res.statusText}`);
if (siteDir) {
const modifyDir = newModifyDir(siteDir, "autopostback-disable");
fs.writeFileSync(path.join(modifyDir, `site-${SITE_ID}_autopostback_result_${ts}.json`), text, "utf-8");
}
console.log(text);
})();