Skip to content

Commit fd1e2d9

Browse files
committed
1st commit
0 parents  commit fd1e2d9

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- stable
4+
script:
5+
- echo "test temporarily disabled"

LICENCE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2019 Kanshi TANAIKE
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# syncGoogleScriptRun
2+
3+
[![Build Status](https://travis-ci.org/tanaikech/syncGoogleScriptRun.svg?branch=master)](https://travis-ci.org/tanaikech/syncGoogleScriptRun)
4+
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENCE)
5+
6+
<a name="top"></a>
7+
8+
# Overview
9+
10+
This is a Javascript library to use "google.script.run" with the synchronous process.
11+
12+
# Description
13+
14+
When I create Web Apps, add-on using a side bar and dialog, there is the case that I want to use `google.script.run` with the synchronous process. As you know, [`google.script.run` works with the asynchronous process](https://developers.google.com/apps-script/guides/html/reference/run). So in order to use it as the synchronous process, the script is required to be prepared. I also saw several issues for such situation at Stackoverflow and other sites. I thought that when the script for achieving this was prepared as a library, it might be useful for users. So I created this.
15+
16+
# Install
17+
18+
```html
19+
<script src="syncGoogleScriptRun.min.js"></script>
20+
```
21+
22+
Or, using jsdelivr cdn
23+
24+
```html
25+
<script src="https://cdn.jsdelivr.net/gh/tanaikech/syncGoogleScriptRun@master/syncGoogleScriptRun.min.js"></script>
26+
```
27+
28+
- Of course, you can use this by directly copying and paste the script of [syncGoogleScriptRun.js](https://github.com/tanaikech/syncGoogleScriptRun/blob/master/syncGoogleScriptRun.js) to the script editor.
29+
30+
<a name="method"></a>
31+
32+
# Method
33+
34+
| Method | Explanation |
35+
| :-------------------------- | :----------------------------------------------------------------- |
36+
| syncGoogleScriptRun(object) | Run a function of Google Apps Script with the synchronous process. |
37+
38+
- `object`: There are 2 properties.
39+
- `gasFunction`: Function name.
40+
- `arguments`: Arguments for the function.
41+
42+
<a name="usage"></a>
43+
44+
# Usage
45+
46+
## Sample script
47+
48+
In this sample script, the result is returned every 1 second.
49+
50+
When you use the following sample script, please copy and paste the following scripts to the container-bound script of Spreadsheet. And run `openDialog()`. By this, a dialog is opened at Spreadsheet. When you clicked the button, you can see the result at the console.
51+
52+
#### HTML side: `index.html`
53+
54+
```HTML
55+
<input type="button" value="Run script" onClick="run()">
56+
57+
<script src="https://cdn.jsdelivr.net/gh/tanaikech/syncGoogleScriptRun@master/syncGoogleScriptRun.min.js"></script>
58+
59+
<script>
60+
async function run() {
61+
for (let i = 0; i < 5; i++) {
62+
const resource = {
63+
gasFunction: "myFunction", // Function name
64+
arguments: i // Arguments for the function
65+
};
66+
const res = await syncGoogleScriptRun(resource).catch(e => {throw new Error(e)});
67+
console.log(res);
68+
}
69+
}
70+
</script>
71+
```
72+
73+
#### Google Apps Script side: `Code.gs`
74+
75+
```javascript
76+
function myFunction(e) {
77+
Utilities.sleep(1000);
78+
return e;
79+
}
80+
81+
function openDialog() {
82+
var html = HtmlService.createTemplateFromFile("index").evaluate();
83+
SpreadsheetApp.getUi().showModalDialog(html, "sample");
84+
}
85+
```
86+
87+
---
88+
89+
<a name="licence"></a>
90+
91+
# Licence
92+
93+
[MIT](LICENCE)
94+
95+
<a name="author"></a>
96+
97+
# Author
98+
99+
[Tanaike](https://tanaikech.github.io/about/)
100+
101+
If you have any questions and commissions for me, feel free to tell me.
102+
103+
<a name="updatehistory"></a>
104+
105+
# Update History
106+
107+
- v1.0.0 (September 13, 2019)
108+
109+
1. Initial release.
110+
111+
[TOP](#top)

syncGoogleScriptRun.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* syncGoogleScriptRun for Javascript library
3+
* GitHub https://github.com/tanaikech/syncGoogleScriptRun<br>
4+
*
5+
* Run google.script.run with the synchronous process.
6+
* @param {Object} resource the object for using syncGoogleScriptRun.
7+
* @return {Object} Returned value from the function of Google Apps Script side.
8+
*/
9+
const syncGoogleScriptRun = resource => {
10+
return new Promise((resolve, reject) => {
11+
google.script.run
12+
.withFailureHandler(e => reject(e))
13+
.withSuccessHandler(e => resolve(e))
14+
[resource.gasFunction](resource.arguments);
15+
});
16+
};

syncGoogleScriptRun.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)