1
1
from Standard.Base import all
2
2
import Standard.Base.Data.Array_Proxy.Array_Proxy
3
3
import Standard.Base.Metadata.Display
4
- from Standard.Base.Metadata import make_single_choice, Widget
5
- from Standard.Base.Metadata.Widget import Single_Choice, Vector_Editor
4
+ from Standard.Base.Metadata import make_single_choice
6
5
from Standard.Base.Enso_Cloud.Enso_Secret import as_credential_reference
7
6
8
7
from Standard.Table import Table
9
8
10
9
polyglot java import java.io.IOException
11
10
12
- polyglot java import org.enso.google.GoogleSheetsHelpers
11
+ polyglot java import org.enso.google.GoogleSheetsForEnso
13
12
polyglot java import org.enso.google.WrappedGoogleCredentials
14
13
15
14
type Google_Sheets
16
15
## PRIVATE
17
- Service java_service
16
+ private Service java_service
18
17
19
18
## ICON cloud
20
19
Initializes the Google Sheets instance using the given credentials file.
@@ -25,21 +24,26 @@ type Google_Sheets
25
24
Google Admin Console when generating a key.
26
25
initialize : File|Enso_Secret -> Google_Sheets
27
26
initialize credentials =
28
- service = GoogleSheetsHelpers.createService (_wrap_credentials credentials)
27
+ service = GoogleSheetsForEnso.create (_wrap_credentials credentials)
29
28
Google_Sheets.Service service
30
29
30
+ ## PRIVATE
31
+ get_sheet_names self (workbook_id : Text) =
32
+ _handle_exceptions <|
33
+ self.java_service.getSheetNames workbook_id
34
+
31
35
## ICON data_input
32
36
Gets a table with the given ID and sheet range.
33
37
34
38
Arguments:
35
- - sheet_id : the ID of the downloaded spreadsheet. It can be read from the
39
+ - workbook_id : the ID of the downloaded spreadsheet. It can be read from the
36
40
spreadsheet URL.
37
41
- sheet_range: specifies the sheet and cell range to read, e.g.
38
42
`'Sheet1!A1:B7'`.
39
- get_table : Text -> Text -> Table
40
- get_table self sheet_id sheet_range =
43
+ @sheet_range _make_sheet_name_widget
44
+ get_table self (workbook_id : Text) ( sheet_range : Text) -> Table =
41
45
values = _handle_exceptions <|
42
- self.java_service.getSheetRange sheet_id sheet_range
46
+ self.java_service.getSheetRange workbook_id sheet_range
43
47
# The first entry is the column name (A, B, ...) and the rest are the values.
44
48
column_vectors = values.map v-> [v.first, v.drop 1]
45
49
# The column lengths may not necessarily be the same, but Table.new expects the same lengths, so we normalize:
@@ -58,8 +62,14 @@ private _handle_exceptions ~action =
58
62
private _wrap_credentials credential:File|Enso_Secret =
59
63
case credential of
60
64
secret : Enso_Secret ->
61
- WrappedGoogleCredentials.SecretCredentials.new (as_credential_reference secret)
65
+ WrappedGoogleCredentials.fromCredentialReference (as_credential_reference secret)
62
66
secret_file : File ->
63
67
secret_file.with_input_stream [File_Access.Read] stream->
64
68
stream.with_java_stream java_input_stream->
65
- WrappedGoogleCredentials.LocalFileCredentials.fromStream java_input_stream
69
+ WrappedGoogleCredentials.fromStream java_input_stream
70
+
71
+ private _make_sheet_name_widget service:Google_Sheets cache=Nothing =
72
+ workbook_id = cache.if_not_nothing <| cache "workbook_id"
73
+ sheet_names = if workbook_id.is_nothing || workbook_id == "" then [] else
74
+ service.get_sheet_names workbook_id
75
+ make_single_choice sheet_names display=..Always
0 commit comments