-
Notifications
You must be signed in to change notification settings - Fork 42
/
utils.js
100 lines (86 loc) · 2.45 KB
/
utils.js
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
(function() {
/**
* @param {DOMElement} el
*/
function hideEl(el) {
el.style.display = "none";
}
/**
* @param {DOMElement} el
* @param {String} displayStyle - (optional) flex, inline
*/
function showEl(el, displayStyle) {
el.style.display = displayStyle ? displayStyle : "block";
}
/**
* show loader, hide forms
*/
function showLoader(forms, loader) {
hideEl(forms);
showEl(loader);
}
/**
* hide loader, show forms
*/
function hideLoader(forms, loader) {
hideEl(loader);
showEl(forms);
}
/**
* Generate append request object - for given sheet and values to append
* Docs: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append
*
* @param {String} spreadsheetId Expense sheet ID
* @param {Array} values values to be appended
* @returns {Object} request object for append
*/
function appendRequestObj(spreadsheetId, values) {
return {
// The ID of the spreadsheet to update.
spreadsheetId,
// The A1 notation of a range to search for a logical table of data.
// Values will be appended after the last row of the table.
range: "Expenses!A1",
includeValuesInResponse: true,
responseDateTimeRenderOption: "FORMATTED_STRING",
responseValueRenderOption: "FORMATTED_VALUE",
// How the input data should be interpreted.
valueInputOption: "USER_ENTERED",
// How the input data should be inserted.
insertDataOption: "INSERT_ROWS",
resource: {
values
}
};
}
/**
* Generate batchGet request object - for given sheet, and range.
* Docs: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet
*
* @param {String} sheetID Expense sheet ID
* @param {Array} ranges List of ranges in A1 notation
* @returns {Object} request object for batchGet
*/
function batchGetRequestObj(spreadsheetId, ranges) {
return {
spreadsheetId,
ranges,
dateTimeRenderOption: "FORMATTED_STRING",
majorDimension: "COLUMNS",
valueRenderOption: "FORMATTED_VALUE"
};
}
function wrapInOption(option) {
return `<option value='${option}'>${option}</option>`;
}
window.expenseManager = window.expenseManager || {};
window.expenseManager.utils = window.expenseManager.utils || {
showEl,
hideEl,
hideLoader,
showLoader,
wrapInOption,
batchGetRequestObj,
appendRequestObj
};
})();