-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow.js
More file actions
158 lines (133 loc) · 6.07 KB
/
Copy pathworkflow.js
File metadata and controls
158 lines (133 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// workflow.js
// =====================================================================
// Rule: Orchestration only.
// No low level detail. No Google API calls.
// Reads like a plain English description of the process.
// =====================================================================
// =====================================================================
/**
* Main entry point for the Import Completed Dailies workflow.
* Called from menu.js when the user selects 'Import Completed Dailies'.
*
* Steps:
* 0. Read and validate input configuration
* 2. Extract tables marked for transfer
* 3. Write the extracted data to the Google Sheet
* 4. Mark transferred tables as complete
*/
function transferDailiesWorkflow() {
Logger.log(`Entered: transferDailiesWorkflow`);
const errLogString = `transferDailiesWorkflow Error.`;
const ui = SpreadsheetApp.getUi();
let returnResult;
// --- Step 0: Read raw config data from sheet ---
returnResult = readInput( getRequiredInitInfo(),getConfigHash(),getValidators());
if (!returnResult.ok) {
Logger.log(`${errLogString}` + returnResult.message);
ui.alert(`${errLogString}`, returnResult.message, ui.ButtonSet.OK);
return;
}
const config = returnResult.data;
// debug:
// print out the required data keys along with what
// is in the actual config data
Object.keys(getConfigHash()).forEach(function(key) {
const value = config[key];
Logger.log(`transferDailiesWorkflow. debug. Input Data: config[getConfigHash()_key] = ${value}`);
});
returnResult = getMarkedTablesFromDoc(config.docId, config.topTabTitle, config.subTabTitle, config.unCheckedCheckboxChar);
if (!returnResult.ok) {
Logger.log(`${errLogString}` + returnResult.message);
ui.alert(`${errLogString}`, returnResult.message, ui.ButtonSet.OK);
return;
}
const arry = returnResult.data;
// --- Step: Write the Marked Tables to the sheet
// Logger.log(`transferDailiesWorkflow: getRequiredInitInfo().sheetID = ${getRequiredInitInfo().sheetID}, config.sheetTabTitle = ${config.sheetTabTitle}.`);
returnResult = appendTableRowsToSheet(arry, config.sheetID, config.sheetTabTitle);
if (!returnResult.ok) {
Logger.log(`${errLogString}` + returnResult.message);
ui.alert(`${errLogString}`, returnResult.message, ui.ButtonSet.OK);
return;
}
// --- Step 4: Mark transferred tables as complete ---
returnResult = markTablesAsComplete(config.docId, config.topTabTitle, config.subTabTitle, config.unCheckedCheckboxChar, config.checkedCheckboxChar);
if (!returnResult.ok) {
Logger.log(`${errLogString}` + returnResult.message);
ui.alert(`${errLogString}`, returnResult.message, ui.ButtonSet.OK);
return;
}
Logger.log(`transferDailiesWorkflow: Exiting`);
}
/**
* Creates a timestamped snapshot of the specified sheet tab by copying its data and dimensions to a new sheet.
* The new sheet is named using a combination of a prefix and a timestamp.
* Alerts the user with a success or error message based on the operation outcome.
*
* @return {void} Does not return a value. Displays alerts to inform the user of success or failure. Handles errors gracefully within the method.
*/
function createTimestampedSnapshot() {
const functionName = 'createTimestampedSnapshot';
Logger.log(`${functionName}. Started.`);
const errLogString = `${functionName} Error.`;
let returnResult;
const ui = SpreadsheetApp.getUi(); // Get the UI object for alerts
returnResult = readInput(getRequiredInitInfo(),getConfigHash(),getValidators());
if (!returnResult.ok) {
Logger.log(`${errLogString}` + returnResult.message);
ui.alert(`${errLogString}`, returnResult.message, ui.ButtonSet.OK);
return;
}
const config = returnResult.data;
const newSheetTitle = config.copiedSheetPrefix + "-" + getTimestampString();
returnResult = createCurrentSheetTabSnapshot(config.sheetTabTitle,newSheetTitle,config.dateHeader,config.topicHeader);
if (!returnResult.ok) {
ui.alert("Error", returnResult.message, ui.ButtonSet.OK);
return;
}
ui.alert("Success", `Values and dimensions from '${config.sheetTabTitle}' have been copied to a new sheet: '${newSheetTitle}'!`, ui.ButtonSet.OK);
}
/**
* Deletes all snapshot tabs in a Google Spreadsheet that match a specific prefix.
*
* The function retrieves initialization and configuration information required for the operation.
* It validates the inputs and deletes all snapshot tabs matching the provided prefix.
* Alerts are shown to the user in case of errors or to provide informational messages indicating the operation's results.
* Internal logging is performed for debugging purposes.
*
* Process:
* - Retrieves required initialization and configuration data.
* - Validates the input parameters.
* - Deletes all tabs that match the specified snapshot prefix.
* - Alerts the user with success or error messages.
*
* Function relies on:
* - `getRequiredInitInfo()` for initialization data.
* - `getConfigHash()` for configuration data.
* - `getValidators()` for validating input parameters.
* - `deleteSnapshotTabs()` for the tab deletion process based on prefix.
*
* Alerts:
* - Displays an alert if initialization or validation fails.
* - Displays an alert after completing the delete operation or if an error occurs during the deletion process.
*/
const deleteAllSnapshotTabs = () => {
const functionName = 'deleteAllSnapshotTabs';
Logger.log(`${functionName}. Started.`);
const errLogString = `${functionName} Error.`;
let returnResult;
const ui = SpreadsheetApp.getUi(); // Get the UI object for alerts
returnResult = readInput(getRequiredInitInfo(),getConfigHash(),getValidators());
if (!returnResult.ok) {
Logger.log(`${errLogString}` + returnResult.message);
ui.alert(`${errLogString}`, returnResult.message, ui.ButtonSet.OK);
return;
}
const config = returnResult.data;
returnResult = deleteSnapshotTabs(config.copiedSheetPrefix);
if (!returnResult.ok) {
ui.alert("Error", returnResult.message, ui.ButtonSet.OK);
return;
}
ui.alert("Information", returnResult.message, ui.ButtonSet.OK);
}