From 14f117dbc8b6f2f618d923972f1a02aaf312bdc6 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 4 Dec 2024 17:04:35 +0700 Subject: [PATCH] add google sheet data source --- .../GoogleSheetDataSourceDashboards.cs | 39 +++++ e2e/Sandbox/MainWindow.xaml.cs | 7 +- e2e/Sandbox/Reveal/AuthenticationProvider.cs | 25 +++- e2e/Sandbox/Sandbox.csproj | 8 +- .../Dashboards/TestGoogleSheet.rdash | Bin 0 -> 1175 bytes .../GoogleDriveDataSourceItemFixture.cs | 6 +- .../GoogleSheetsDataSourceItemFixture.cs | 138 ++++++++++++++++-- .../GoogleSheetsDataSourceFixture.cs | 13 +- .../Reveal.Sdk.Dom.Tests.csproj | 7 +- .../Core/Constants/DataSourceIds.cs | 1 + .../GoogleDriveDataSourceItem.cs | 8 +- .../GoogleSheetsDataSourceItem.cs | 32 +++- .../Data/DataSources/GoogleDriveDataSource.cs | 2 +- .../DataSources/GoogleSheetsDataSource.cs | 7 +- 14 files changed, 254 insertions(+), 39 deletions(-) create mode 100644 e2e/Sandbox/Factories/GoogleSheetDataSourceDashboards.cs create mode 100644 src/Reveal.Sdk.Dom.Tests/Dashboards/TestGoogleSheet.rdash diff --git a/e2e/Sandbox/Factories/GoogleSheetDataSourceDashboards.cs b/e2e/Sandbox/Factories/GoogleSheetDataSourceDashboards.cs new file mode 100644 index 00000000..33c65aec --- /dev/null +++ b/e2e/Sandbox/Factories/GoogleSheetDataSourceDashboards.cs @@ -0,0 +1,39 @@ +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sandbox.Factories +{ + public class GoogleSheetDataSourceDashboards + { + public static RdashDocument CreateDashboard() + { + var googleSheetDS = new GoogleSheetsDataSourceItem("Google Sheet Data Source", "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms") + { + Title = "Google Sheet Data Source", + Subtitle = "Google Sheet Data Source Subtitle", + Sheet = "Class Data", + Fields = new List + { + new TextField("Student Name"), + new TextField("Gender"), + new TextField("Class Level"), + new TextField("Home State"), + new TextField("Major"), + new TextField("Extracurricular Activity") + } + }; + + var document = new RdashDocument("My Dashboard"); + + document.Visualizations.Add(new GridVisualization("Class List", googleSheetDS).SetColumns("Student Name", "Gender", "Major", "Extracurricular Activity")); + + return document; + } + } +} diff --git a/e2e/Sandbox/MainWindow.xaml.cs b/e2e/Sandbox/MainWindow.xaml.cs index 22381b2f..fc192278 100644 --- a/e2e/Sandbox/MainWindow.xaml.cs +++ b/e2e/Sandbox/MainWindow.xaml.cs @@ -58,7 +58,7 @@ public MainWindow() RevealSdkSettings.DataSourceProvider = new Sandbox.RevealSDK.DataSourceProvider(); RevealSdkSettings.AuthenticationProvider = new AuthenticationProvider(); - RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices(); + RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices().RegisterGoogleDrive(); _revealView.LinkedDashboardProvider = (string dashboardId, string linkTitle) => { @@ -219,14 +219,15 @@ private async void Read_Dashboard(object sender, RoutedEventArgs e) private async void Create_Dashboard(object sender, RoutedEventArgs e) { //var document = MarketingDashboard.CreateDashboard(); - var document = SalesDashboard.CreateDashboard(); + //var document = SalesDashboard.CreateDashboard(); //var document = CampaignsDashboard.CreateDashboard(); //var document = HealthcareDashboard.CreateDashboard(); //var document = ManufacturingDashboard.CreateDashboard(); //var document = CustomDashboard.CreateDashboard(); //var document = RestDataSourceDashboards.CreateDashboard(); //var document = SqlServerDataSourceDashboards.CreateDashboard(); - //var document = DashboardLinkingDashboard.CreateDashboard(); + //var document = DashboardLinkingDashboard.CreateDashboard(); + var document = GoogleSheetDataSourceDashboards.CreateDashboard(); var json = document.ToJsonString(); diff --git a/e2e/Sandbox/Reveal/AuthenticationProvider.cs b/e2e/Sandbox/Reveal/AuthenticationProvider.cs index 07e9fce2..c3b717b4 100644 --- a/e2e/Sandbox/Reveal/AuthenticationProvider.cs +++ b/e2e/Sandbox/Reveal/AuthenticationProvider.cs @@ -1,15 +1,20 @@ using Reveal.Sdk.Data; +using Reveal.Sdk.Data.Google.Drive; using Reveal.Sdk.Data.Microsoft.AnalysisServices; using Reveal.Sdk.Data.Microsoft.SqlServer; +using System; using System.Threading.Tasks; +using Google.Apis.Auth.OAuth2; +using System.IO; namespace Sandbox.RevealSDK { internal class AuthenticationProvider : IRVAuthenticationProvider { - public Task ResolveCredentialsAsync(RVDashboardDataSource dataSource) + public async Task ResolveCredentialsAsync(RVDashboardDataSource dataSource) { IRVDataSourceCredential userCredential = null; + string _token = string.Empty; if (dataSource is RVSqlServerDataSource) { userCredential = new RVUsernamePasswordDataSourceCredential(); @@ -17,8 +22,24 @@ public Task ResolveCredentialsAsync(RVDashboardDataSour else if (dataSource is RVNativeAnalysisServicesDataSource) { userCredential = new RVUsernamePasswordDataSourceCredential("username", "password", "domain"); + } else if (dataSource is RVGoogleDriveDataSource) + { + if (string.IsNullOrEmpty(_token)) + _token = await CreateJwtToken(); + + userCredential = new RVBearerTokenDataSourceCredential(_token, null); } - return Task.FromResult(userCredential); + return userCredential; + } + + async Task CreateJwtToken() + { + var pathToJsonFile = Path.Combine(Environment.CurrentDirectory, "Data/GoogleServiceAccountAuth.json"); + var credentials = GoogleCredential.FromFile(pathToJsonFile).CreateScoped("https://www.googleapis.com/auth/drive", + "https://www.googleapis.com/auth/userinfo.email", + "https://www.googleapis.com/auth/userinfo.profile"); + var token = await credentials.UnderlyingCredential.GetAccessTokenForRequestAsync().ConfigureAwait(false); + return token; } } } diff --git a/e2e/Sandbox/Sandbox.csproj b/e2e/Sandbox/Sandbox.csproj index f9767905..3dba1811 100644 --- a/e2e/Sandbox/Sandbox.csproj +++ b/e2e/Sandbox/Sandbox.csproj @@ -8,6 +8,7 @@ + @@ -48,6 +49,9 @@ PreserveNewest + + Always + PreserveNewest @@ -60,8 +64,4 @@ - - - - diff --git a/src/Reveal.Sdk.Dom.Tests/Dashboards/TestGoogleSheet.rdash b/src/Reveal.Sdk.Dom.Tests/Dashboards/TestGoogleSheet.rdash new file mode 100644 index 0000000000000000000000000000000000000000..10da6bfbdaa45b8c2ec86722fdba656c1a70e135 GIT binary patch literal 1175 zcmV;I1ZewEO9KQH0000807-*_Sq=nlco_r$0JsqV01f~E07PMPXku?+a%3)Qb8l|k zS6gq|NECiwY5#-8GnQ;H82U!SCDxL_0-;r_3XMGnGF{ul&WtHE%75SS81NO+Y#&w| zUXXq6=Q}=^=ih(RwAz9QA8H@8+5>#o`iMWd6fs<@E8>u{0Es0qPG~5ZjO6trhh8M; z7#(ONaHSIb1lcbe6Y?TuU&mw-RpQ#RxNll|^T1{x` z2H>V{b(>i4G(B6lO|xruF<=|4jL?jJpKnp@bkj)R-cmmb!U}@JRU(#z6IbQq9FrpV zkwEh;c#?4TI_viWxsi|9i7g+%NuEZ`14lrR*OJwf=PRl?=fX0KR-@Bd>s`C;>Xyua z-f6pC9fRR@Jl90nTNec9ktHvP?lD!(fkQO6xi+%&xBk|*NLUa zxs?2%t&z_Q)G4D|V1fWICL{J$S(MgqeZ;w@Ok`PJ3Za1zBvgg>Tp&#mLjed`z!hc| z&SE^6ubhX~(3#B_tJ&n^F_J6BX237v_!cD3Senp*wq;s+*EH6;Wi-0F-NkF&2HS0U z?G9?YW=Zt?)!rYpBbpU3Rp8meZr5uyO&xU%`4!onroJ`|TW>=bjCBKf4XagBQbM~7 zXdduVHN1kjN(O|2tO+ocl$$-dUvlHqtk(*M_xO+94ZivOZ4*2`{=F5x%WZ42*$o=e zHsHC^DB^XsJW2)fk^??{$cohl`z>KeBpuPTth9?HeT1QqZz%^{k*L~`fR8ghF!>d$ zNO3(#$KqVfMHJ^oQ_uA(PE}oslgU8Kb;j=qmMSg)2i`oDv^__y9-+|uIKsF^I9eLkz-lK2yo!9JOFBtM7#z^cA z(|VpDJ0cGM$EeeXui3twcI~u7=NSHsi1*i!_{UL^C-yKV@jyVnoRdD38Ro!t#DiD) zl<_g)A`@bdd*>0Cf>x8OYJ`09LrtRWjH}vDM~vV~fzqa$<2pe(nmPR(mxK^TGG%x{ zg+!=o(oN9@u-wA06X)bdY@wAKqC*;rBcV1Ake}<6vaSwl_sOr&L$U`vhP6mm{3@$4 z%&-?dpKQWFPSjX^EK%5PAEE$crRUgYWb;(yle-X5;pKBMZnitw4b<8`noLIWq`Dgn7URinZ#;CygXwItbozr? zUL@O}Q$lW4KL%0%x4ypZ)TxN0KXaD9?0yD=kxyOZmuATE{Sq-!7z*(<0l_w&g=ulT z`~v_0|NjF3P)h*<6aW+e000O8NrQq}4g_v^83X_TxDfyV4gdfE000000000000000 p002Z`b7*33VRB?HYIARHP)h{{000000RRC2JOBUyMFao<005V1BNzYx literal 0 HcmV?d00001 diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleDriveDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleDriveDataSourceItemFixture.cs index 1e0d645f..22b14fad 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleDriveDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleDriveDataSourceItemFixture.cs @@ -35,11 +35,11 @@ public void Identitifer_SaveValueAndProperties_WhenSet() var identifier = "IdentitiferTest"; // Act - dataSourceItem.Identitifer = identifier; + dataSourceItem.Identifier = identifier; // Assert - Assert.Equal(identifier, dataSourceItem.Identitifer); - Assert.Equal(identifier, dataSourceItem.Properties.GetValue("Identitifer")); + Assert.Equal(identifier, dataSourceItem.Identifier); + Assert.Equal(identifier, dataSourceItem.Properties.GetValue("Identifier")); } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleSheetsDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleSheetsDataSourceItemFixture.cs index 403e3d4b..c8ea6e91 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleSheetsDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/GoogleSheetsDataSourceItemFixture.cs @@ -1,10 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Reveal.Sdk.Dom.Core.Constants; using Reveal.Sdk.Dom.Core.Extensions; using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; using Xunit; namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems @@ -12,40 +15,84 @@ namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems public class GoogleSheetsDataSourceItemFixture { [Fact] - public void Constructor_SetsTitleAndDatasource_AsProvided() + public void Constructor_SetsTitleAndIdentifier_AsProvided() { // Arrange - var dataSource = new GoogleSheetsDataSource(); var title = "Test title"; + var identifier = "testIdentifier"; // Act - var dataSourceItem = new GoogleSheetsDataSourceItem(title, dataSource); + var dataSourceItem = new GoogleSheetsDataSourceItem(title, identifier); // Assert Assert.Equal(title, dataSourceItem.Title); - Assert.Equal(dataSource, dataSourceItem.DataSource); + Assert.Equal(identifier, dataSourceItem.Identifier); + } + + [Fact] + public void Constructor_SetsResourceItemToGoogleDrive_WhenCreate() + { + // Arrange + var title = "Test title"; + var identifier = "testIdentifier"; + + // Act + var dataSourceItem = new GoogleSheetsDataSourceItem(title, identifier); + + // Assert + Assert.Equal(DataSourceProvider.GoogleDrive, dataSourceItem.ResourceItemDataSource.Provider); + Assert.Equal(identifier, dataSourceItem.Identifier); } [Fact] public void FirstRowContainsLabels_SaveValueAndProperties_WhenSet() { // Arrange - var dataSource = new GoogleSheetsDataSource(); - var dataSourceItem = new GoogleSheetsDataSourceItem("Test", dataSource); + var dataSourceItem = new GoogleSheetsDataSourceItem("Test", "testIdentifier"); // Act 1 dataSourceItem.FirstRowContainsLabels = true; // Assert Assert.True(dataSourceItem.FirstRowContainsLabels); - Assert.True(dataSourceItem.Properties.GetValue("FirstRowContainsLabels")); + Assert.True(dataSourceItem.Parameters.GetValue("TITLES_IN_FIRST_ROW")); // Act 1 dataSourceItem.FirstRowContainsLabels = false; // Assert Assert.False(dataSourceItem.FirstRowContainsLabels); - Assert.False(dataSourceItem.Properties.GetValue("FirstRowContainsLabels")); + Assert.False(dataSourceItem.Parameters.GetValue("TITLES_IN_FIRST_ROW")); + } + + [Fact] + public void Identifier_SaveValueAndProperties_WhenSet() + { + // Arrange + var dataSourceItem = new GoogleSheetsDataSourceItem("Test", "testIdentifier"); + var testIdentifier = "anotherTestIdentifier"; + + // Act 1 + dataSourceItem.Identifier = testIdentifier; + + // Assert + Assert.Equal(testIdentifier, dataSourceItem.Identifier); + Assert.Equal(testIdentifier, dataSourceItem.ResourceItem.Properties.GetValue("Identifier")); + } + + [Fact] + public void ResourceItem_IsGoogleDriveDataSourceItem_WhenCreated() + { + // Arrange + var testIdentifier = "testIdentifier"; + + // Act + var dataSourceItem = new GoogleSheetsDataSourceItem("Test", testIdentifier); + + // Assert + Assert.Equal(DataSourceProvider.GoogleDrive, dataSourceItem.ResourceItem.DataSource.Provider); + Assert.IsType(dataSourceItem.ResourceItem); + Assert.Equal(testIdentifier, dataSourceItem.ResourceItem.Properties.GetValue("Identifier")); } [Fact] @@ -53,7 +100,7 @@ public void NamedRange_SaveValueAndProperties_WhenSet() { // Arrange var dataSource = new GoogleSheetsDataSource(); - var dataSourceItem = new GoogleSheetsDataSourceItem("Test", dataSource); + var dataSourceItem = new GoogleSheetsDataSourceItem("Test", "testIdentifier"); var namedRange = "NamedRangeTest"; // Act @@ -69,7 +116,7 @@ public void PivotTable_SaveValueAndProperties_WhenSet() { // Arrange var dataSource = new GoogleSheetsDataSource(); - var dataSourceItem = new GoogleSheetsDataSourceItem("Test", dataSource); + var dataSourceItem = new GoogleSheetsDataSourceItem("Test", "testIdentifier"); var pivotTable = "PivotTableTest"; // Act @@ -85,7 +132,7 @@ public void Sheet_SaveValueAndProperties_WhenSet() { // Arrange var dataSource = new GoogleSheetsDataSource(); - var dataSourceItem = new GoogleSheetsDataSourceItem("Test", dataSource); + var dataSourceItem = new GoogleSheetsDataSourceItem("Test", "testIdentifier"); var sheet = "SheetTest"; // Act @@ -95,5 +142,74 @@ public void Sheet_SaveValueAndProperties_WhenSet() Assert.Equal(sheet, dataSourceItem.Sheet); Assert.Equal(sheet, dataSourceItem.Properties.GetValue("Sheet")); } + + [Fact] + public void RDashDocument_CreateTwoDataSources_WhenUseGoogleSheetDataSourceItem() + { + // Arrange + var document = new RdashDocument("Test"); + var dataSource = new GoogleSheetsDataSource(); + var dataSourceItem = new GoogleSheetsDataSourceItem("My Google Sheet", "testIdentifier").SetFields(new List() { new TextField("Test") }); + + dataSourceItem.Sheet = "Sheet1"; + dataSourceItem.FirstRowContainsLabels = true; + + document.Visualizations.Add(new GridVisualization(dataSourceItem)); + + // Act + document.Validate(); + + // Assert + Assert.Equal(2, document.DataSources.Count); + Assert.Equal(DataSourceIds.GSHEET, document.DataSources[0].Id); + Assert.Equal(DataSourceProvider.GoogleSheets, document.DataSources[0].Provider); + Assert.Equal(DataSourceProvider.GoogleDrive, document.DataSources[1].Provider); + } + + [Fact] + public void RDashDocument_HasCorrectDataSourceItem_WhenLoadFromFile() + { + // Arrange + var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestGoogleSheet.rdash"); + + // Act + var document = RdashDocument.Load(filePath); + var gsheetDataSource = document.DataSources[0]; + var driveDataSource = document.DataSources[1]; + var dataSourceItem = document.Visualizations[0].DataDefinition.DataSourceItem; + + var value = dataSourceItem.Parameters.GetValue("TITLES_IN_FIRST_ROW"); + + // Assert + Assert.Equal(gsheetDataSource.Id, dataSourceItem.DataSourceId); + Assert.Equal(DataSourceProvider.GoogleSheets, gsheetDataSource.Provider); + Assert.Equal(DataSourceProvider.GoogleDrive, driveDataSource.Provider); + Assert.Equal("Class Data", dataSourceItem.Properties.GetValue("Sheet")); + Assert.True(dataSourceItem.Parameters.GetValue("TITLES_IN_FIRST_ROW")); + Assert.Equal("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", dataSourceItem.ResourceItem.Properties.GetValue("Identifier")); + } + + [Fact] + public void RDashDocument_CreateExpectedJson_WhenExport() + { + // Arrange + var document = new RdashDocument("Test"); + var dataSource = new GoogleSheetsDataSource(); + var dataSourceItem = new GoogleSheetsDataSourceItem("My Google Sheet", "testIdentifier").SetFields(new List() { new TextField("Test") }); + + dataSourceItem.Sheet = "Sheet1"; + dataSourceItem.FirstRowContainsLabels = true; + + document.Visualizations.Add(new GridVisualization(dataSourceItem)); + + // Act + document.Validate(); + + // Assert + Assert.Equal(2, document.DataSources.Count); + Assert.Equal(DataSourceIds.GSHEET, document.DataSources[0].Id); + Assert.Equal(DataSourceProvider.GoogleSheets, document.DataSources[0].Provider); + Assert.Equal(DataSourceProvider.GoogleDrive, document.DataSources[1].Provider); + } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/GoogleSheetsDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/GoogleSheetsDataSourceFixture.cs index d4d5f088..9d56feee 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/GoogleSheetsDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/GoogleSheetsDataSourceFixture.cs @@ -1,4 +1,5 @@ -using Reveal.Sdk.Dom.Core.Extensions; +using Reveal.Sdk.Dom.Core.Constants; +using Reveal.Sdk.Dom.Core.Extensions; using Reveal.Sdk.Dom.Data; using System; using System.Collections.Generic; @@ -21,5 +22,15 @@ public void Constructor_SetProviderToGoogleSheets_WhenConstructed() // Assert Assert.Equal(DataSourceProvider.GoogleSheets, dataSource.Provider); } + + [Fact] + public void Constructor_SetIdToGSheet_WhenConstructed() + { + // Act + var dataSource = new GoogleSheetsDataSource(); + + // Assert + Assert.Equal(DataSourceIds.GSHEET, dataSource.Id); + } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj index f3313f39..bf0292ba 100644 --- a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj +++ b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj @@ -36,10 +36,9 @@ PreserveNewest - - - - + + PreserveNewest + diff --git a/src/Reveal.Sdk.Dom/Core/Constants/DataSourceIds.cs b/src/Reveal.Sdk.Dom/Core/Constants/DataSourceIds.cs index 0584d55c..d67a1947 100644 --- a/src/Reveal.Sdk.Dom/Core/Constants/DataSourceIds.cs +++ b/src/Reveal.Sdk.Dom/Core/Constants/DataSourceIds.cs @@ -6,5 +6,6 @@ internal class DataSourceIds public const string Excel = "__EXCEL"; public const string JSON = "__JSON"; public const string LOCALFILE = "__LOCAL"; + public const string GSHEET = "__Gsheet"; } } diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleDriveDataSourceItem.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleDriveDataSourceItem.cs index 7fc4d263..e5a25cca 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleDriveDataSourceItem.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleDriveDataSourceItem.cs @@ -3,17 +3,17 @@ namespace Reveal.Sdk.Dom.Data { - internal class GoogleDriveDataSourceItem : DataSourceItem + public class GoogleDriveDataSourceItem : DataSourceItem { public GoogleDriveDataSourceItem(string title, DataSource dataSource) : base(title, dataSource) { } [JsonIgnore] - public string Identitifer + public string Identifier { - get => Properties.GetValue("Identitifer"); - set => Properties.SetItem("Identitifer", value); + get => Properties.GetValue("Identifier"); + set => Properties.SetItem("Identifier", value); } } } diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleSheetsDataSourceItem.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleSheetsDataSourceItem.cs index 3204e15b..f67820ea 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleSheetsDataSourceItem.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItems/GoogleSheetsDataSourceItem.cs @@ -3,17 +3,25 @@ namespace Reveal.Sdk.Dom.Data { - internal class GoogleSheetsDataSourceItem : DataSourceItem + public class GoogleSheetsDataSourceItem : DataSourceItem { + public GoogleSheetsDataSourceItem(string title, string identifier) : + base(title, new GoogleSheetsDataSource()) + { + InitializeResourceItem(title, identifier); + } + public GoogleSheetsDataSourceItem(string title, DataSource dataSource) : base(title, dataSource) - { } + { + InitializeResourceItem(title, null); + } [JsonIgnore] public bool FirstRowContainsLabels { - get => Properties.GetValue("FirstRowContainsLabels"); - set => Properties.SetItem("FirstRowContainsLabels", value); + get => Parameters.GetValue("TITLES_IN_FIRST_ROW"); + set => Parameters.SetItem("TITLES_IN_FIRST_ROW", value); } [JsonIgnore] @@ -40,5 +48,21 @@ public string Sheet get => Properties.GetValue("Sheet"); set => Properties.SetItem("Sheet", value); } + + [JsonIgnore] + public string Identifier + { + get => ResourceItem.Properties.GetValue("Identifier"); + set => ResourceItem.Properties.SetItem("Identifier", value); + } + + private void InitializeResourceItem(string title, string identifier) + { + ResourceItemDataSource = new GoogleDriveDataSource(); + ResourceItem = new GoogleDriveDataSourceItem(title, ResourceItemDataSource) + { + Identifier = identifier + }; + } } } diff --git a/src/Reveal.Sdk.Dom/Data/DataSources/GoogleDriveDataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSources/GoogleDriveDataSource.cs index 84540880..b70c82d3 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSources/GoogleDriveDataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSources/GoogleDriveDataSource.cs @@ -1,6 +1,6 @@ namespace Reveal.Sdk.Dom.Data { - internal class GoogleDriveDataSource : DataSource + public class GoogleDriveDataSource : DataSource { public GoogleDriveDataSource() { diff --git a/src/Reveal.Sdk.Dom/Data/DataSources/GoogleSheetsDataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSources/GoogleSheetsDataSource.cs index 4a88e5d6..1ec1da72 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSources/GoogleSheetsDataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSources/GoogleSheetsDataSource.cs @@ -1,9 +1,12 @@ -namespace Reveal.Sdk.Dom.Data +using Reveal.Sdk.Dom.Core.Constants; + +namespace Reveal.Sdk.Dom.Data { - internal class GoogleSheetsDataSource : DataSource + public class GoogleSheetsDataSource : DataSource { public GoogleSheetsDataSource() { + Id = DataSourceIds.GSHEET; Provider = DataSourceProvider.GoogleSheets; } }