这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions changesInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@
- レイアウトの調整
- バグの修正"></textarea>
<div class="button-container">
<button id="publishButton" onclick="sendChanges()">出版</button>
<button id="publishButton" onclick="saveChanges()">保存</button>
<button onclick="google.script.host.close()">キャンセル</button>
</div>
<div id="status"></div>
<script>
function sendChanges() {
function saveChanges() {
// 出版ボタンを取得し、処理中は無効にする
const publishButton = document.getElementById('publishButton');
publishButton.disabled = true;
publishButton.textContent = '送信中...'; // ボタンのテキストを変更してユーザーにフィードバック
publishButton.textContent = '保存中...'; // ボタンのテキストを変更してユーザーにフィードバック

const changesTxt = document.getElementById('changesInput').value;
const statusDiv = document.getElementById('status');
Expand All @@ -77,15 +77,15 @@
// Google Apps Scriptの関数を呼び出してデータを渡す
google.script.run
.withSuccessHandler(function() {
statusDiv.textContent = '送信完了';
statusDiv.textContent = '保存完了';
google.script.host.close(); // 成功したらダイアログを閉じる
})
.withFailureHandler(function(error) {
statusDiv.textContent = 'エラーが発生しました: ' + error.message;
publishButton.disabled = false; // エラー時はボタンを再度有効にする
publishButton.textContent = '出版';
publishButton.textContent = '保存';
})
.processAndSend(changes);
.saveCommitRevision(changes);
}

document.getElementById('changesInput').addEventListener('keydown', function(event) {
Expand All @@ -94,7 +94,7 @@
// デフォルトのEnterキーの動作(改行)をキャンセル
event.preventDefault();
// 送信関数を呼び出し
sendChanges();
saveChanges();
}
});
</script>
Expand Down
68 changes: 57 additions & 11 deletions main.gs
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
// onOpen関数は変更不要です。
function onOpen() {
var ui = SpreadsheetApp.getUi();
var menu = ui.createMenu('出版');
menu.addItem('Google Chat に送信', 'showChangesDialog'); // 関数名を変更
menu.addItem('変更内容を登録', 'showCommitRevision')
menu.addItem('Google Chat に送信', 'mergeMain');
menu.addToUi();
}

// ユーザーに変更内容を尋ねるダイアログを表示する関数
function showChangesDialog() {
function showCommitRevision() {
const html = HtmlService.createTemplateFromFile('changesInput')
.evaluate()
.setTitle('変更内容を記述')
.setWidth(400); // 必要に応じて幅を調整
SpreadsheetApp.getUi().showSidebar(html);
}

// メニュー: Google Chat に送信 (変更内容の処理を含む)
function processAndSend(changes) {
// ユーザーがキャンセルした場合や何も入力しなかった場合の処理
if (!changes) {
SpreadsheetApp.getUi().alert('出版がキャンセルされました。');
return;
// 変更内容の保存
function saveCommitRevision(changes) {
const activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const changelogSheet = activeSpreadsheet.getSheetByName('.changelog');
const editorEmail = Session.getActiveUser().getEmail();

const timeStamp = new Date()

var changelogSheet_array = []
for (let i = 0; i < changes.length; i++) {
changelogSheet_array.push([timeStamp, editorEmail, changes[i], false])
}


changelogSheet.getRange(changelogSheet.getLastRow() + 1, 1, changelogSheet_array.length, changelogSheet_array[0].length).setValues(changelogSheet_array)
}

// 変更内容の取得
function getChangelogs(spreadsheetId, sheetName) {
const changelogSheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
const allChangelogs = changelogSheet.getRange(1, 1, changelogSheet.getLastRow(), changelogSheet.getLastColumn()).getValues();

var changelog = []
var isMergedFlags = []
var sellIndex = 1
for (let i = 0; i < allChangelogs.length - 1; i++) {
if (allChangelogs[sellIndex][3] == false) {
changelog.push(allChangelogs[sellIndex]);
isMergedFlags.push([true])
} else {
isMergedFlags.push([true])
}
sellIndex += 1
}

changelogSheet.getRange(2, 4, changelogSheet.getLastRow()-1).setValues(isMergedFlags)

return changelog
}

// メニュー: Google Chat に送信 (変更内容の処理を含む)
function mergeMain() {
const scriptProperties = PropertiesService.getScriptProperties();
const PARENT_FOLDER_ID = scriptProperties.getProperty("PARENT_FOLDER_ID");
const GOOGLE_CHAT_WEBHOOK_URL = scriptProperties.getProperty("GOOGLE_CHAT_WEBHOOK_URL");
Expand All @@ -35,6 +68,19 @@ function processAndSend(changes) {
Logger.log('シート名: ' + sheetName);
Logger.log('スプレッドシートID: ' + spreadsheetId);

// 変更内容の取得
const changelogs = getChangelogs(ss.getId(), '.changelog');
var changes = []
for (let i = 0; i < changelogs.length; i++) {
changes.push(changelogs[i][2])
}

// バージョン表記の更新
// '.config'!B2: バージョン情報が記載されたせる
const configSheet = ss.getSheetByName(".config")
const nowDocVer = configSheet.getRange("B2").getValue();
const newDocVer = configSheet.getRange("B2").setValue(Number(nowDocVer) + 1);

// ブランチファイル(キャッシュファイル)を削除
deleteSheetsStartingWithBracket(spreadsheetId);

Expand Down Expand Up @@ -62,4 +108,4 @@ function processAndSend(changes) {
sendGooglechat(message_content, GOOGLE_CHAT_WEBHOOK_URL);

SpreadsheetApp.getUi().alert('出版が完了しました。');
}
}