diff --git a/e2e/Sandbox/MainWindow.xaml.cs b/e2e/Sandbox/MainWindow.xaml.cs index e439f3b6..e278278e 100644 --- a/e2e/Sandbox/MainWindow.xaml.cs +++ b/e2e/Sandbox/MainWindow.xaml.cs @@ -1,16 +1,17 @@ using Reveal.Sdk; using Reveal.Sdk.Data; +using Reveal.Sdk.Data.Json; +using Reveal.Sdk.Data.Microsoft.SqlServer; +using Reveal.Sdk.Data.Rest; using Reveal.Sdk.Dom; using Reveal.Sdk.Dom.Data; using Reveal.Sdk.Dom.Visualizations; -using Sandbox.Factories; using Sandbox.Helpers; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using System.Windows; -using System.Windows.Documents; namespace Sandbox { @@ -125,54 +126,12 @@ private async void Create_Dashboard(object sender, RoutedEventArgs e) //document.Save(_saveRdashToPath); - //var dsi = new RestBuilder("Excel Data Source", "Marketing Sheet") - // .SetUrl("https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9") - // .SetFields( - // new TextField("CategoryName"), - // new TextField("ProductName"), - // new NumberField("ProductSales") - // ).Build(); - - //var dsi = Reveal.Sdk.Dom.Data.DataSourceFactory.Create(DataSourceType.REST, "Excel Data Source", "Marketing Sheet") - // .SetFields(new List - // { - // new TextField("CategoryName"), - // new TextField("ProductName"), - // new NumberField("ProductSales") - // }).Build(); - - var dsi = new RemoteFileBuilder("Excel Data Source", "Marketing Sheet") - .SetUrl("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .UseExcel("Marketing") - .SetFields(new List - { - new DateField("Date"), - new NumberField("Spend"), - new NumberField("Budget"), - new NumberField("CTR"), - new NumberField("Avg. CPC"), - new NumberField("Traffic"), - new NumberField("Paid Traffic"), - new NumberField("Other Traffic"), - new NumberField("Conversions"), - new TextField("Territory"), - new TextField("CampaignID"), - new NumberField("New Seats"), - new NumberField("Paid %"), - new NumberField("Organic %") - }).Build(); - - var document = new RdashDocument() { Title = "My Dashboard", Description = "I created" }; - //var gridViz = new GridVisualization(dsi).SetColumns("CategoryName", "ProductName", "ProductSales"); - var gridViz = new GridVisualization(dsi).SetColumns("Spend", "Budget", "CTR"); - document.Visualizations.Add(gridViz); - var json = document.ToJsonString(); //json.Save(_saveJsonToPath); _revealView.Dashboard = await RVDashboard.LoadFromJsonAsync(json); diff --git a/src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs deleted file mode 100644 index d480fd51..00000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Reveal.Sdk.Dom.Visualizations; -using System; -using System.Collections.Generic; - -namespace Reveal.Sdk.Dom.Data -{ - public class DataSourceBuilder : IDataSourceBuilder - { - protected DataSource DataSource { get; } = new DataSource(); - protected DataSourceItem DataSourceItem { get; } = new DataSourceItem(); - - public DataSourceBuilder(DataSourceProvider provider, string title, string subtitle) - { - DataSource.Provider = provider; - DataSourceItem.DataSource = DataSource; - DataSourceItem.DataSourceId = DataSource.Id; - SetTitle(title); - SetSubtitle(subtitle); - } - - public DataSourceItem Build() - { - if (DataSourceItem.Fields.Count == 0) - throw new ArgumentException("You must provide the field definitions for the data source item. Call the SetFields method and provide the fields."); - - return DataSourceItem; - } - - public IDataSourceBuilder SetId(string id) - { - DataSource.Id = id; - DataSourceItem.DataSourceId = id; - return this; - } - - public virtual IDataSourceBuilder SetFields(IEnumerable fields) - { - DataSourceItem.Fields.Clear(); - DataSourceItem.Fields.AddRange(fields); - return this; - } - - public virtual IDataSourceBuilder SetFields(params IField[] fields) - { - return SetFields((IEnumerable)fields); - } - - public IDataSourceBuilder SetSubtitle(string subtitle) - { - DataSourceItem.Subtitle = subtitle; - return this; - } - - public IDataSourceBuilder SetTitle(string title) - { - DataSourceItem.Title = title; - return this; - } - } - -} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs deleted file mode 100644 index 683e774c..00000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Reveal.Sdk.Dom.Visualizations; -using System.Collections.Generic; - -namespace Reveal.Sdk.Dom.Data -{ - public interface IDataSourceBuilder - { - IDataSourceBuilder SetFields(IEnumerable fields); - IDataSourceBuilder SetFields(params IField[] fields); - IDataSourceBuilder SetTitle(string title); - IDataSourceBuilder SetSubtitle(string subtitle); - DataSourceItem Build(); - } - -} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs deleted file mode 100644 index 38e6d17f..00000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Reveal.Sdk.Dom.Data -{ - public interface IRestBuilder : IDataSourceBuilder - { - IRestBuilder AddHeader(HeaderType headerType, string value); - IRestBuilder SetUrl(string url); - IRestBuilder SetMethod(string method); - IRestBuilder SetAnonymous(bool isAnonymous); - } - -} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs deleted file mode 100644 index bd61fbfa..00000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Reveal.Sdk.Dom.Core.Constants; - -namespace Reveal.Sdk.Dom.Data -{ - public class RemoteFileBuilder : DataSourceBuilder, IRemoteFileBuilder - { - readonly DataSource _resourceItemDataSource = new DataSource() { Provider = DataSourceProvider.WebService }; //data source - readonly DataSourceItem _resourceItem = new DataSourceItem(); //resource item that points to the data source - - public RemoteFileBuilder(string title, string subtitle) : base(DataSourceProvider.WebService, title, subtitle) - { - DataSourceItem.ResourceItemDataSource = _resourceItemDataSource; - _resourceItem.DataSourceId = _resourceItemDataSource.Id; - DataSourceItem.ResourceItem = _resourceItem; - - SetAnonymous(true); - } - - public IRemoteFileBuilder SetAnonymous(bool isAnonymous) - { - _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; - return this; - } - - public IRemoteFileBuilder SetUrl(string url) - { - _resourceItemDataSource.Properties.Add("Url", url); - _resourceItem.Properties.Add("Url", url); - return this; - } - - public IRemoteFileBuilder UseCsv() - { - DataSource.Id = DataSourceIds.CSV; - DataSource.Provider = DataSourceProvider.CSV; - _resourceItemDataSource.Properties["Result-Type"] = ".csv"; - DataSourceItem.DataSourceId = DataSource.Id; - return this; - } - - public IRemoteFileBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx) - { - DataSource.Id = DataSourceIds.Excel; - DataSource.Provider = DataSourceProvider.MicrosoftExcel; - - if (sheet != null) - { - DataSourceItem.Subtitle = sheet; - - if (DataSourceItem.Properties.ContainsKey("Sheet")) - DataSourceItem.Properties["Sheet"] = sheet; - else - DataSourceItem.Properties.Add("Sheet", sheet); - } - - DataSourceItem.DataSourceId = DataSource.Id; - - return this; - } - - } - - public interface IRemoteFileBuilder : IDataSourceBuilder - { - IRemoteFileBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx); - IRemoteFileBuilder UseCsv(); - } -} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs deleted file mode 100644 index cf0633d1..00000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs +++ /dev/null @@ -1,107 +0,0 @@ -using Reveal.Sdk.Dom.Visualizations; -using System.Collections.Generic; -using System.Linq; - -namespace Reveal.Sdk.Dom.Data -{ - public class RestBuilder : DataSourceBuilder, IRestBuilder - { - readonly DataSource _resourceItemDataSource = new DataSource() { Provider = DataSourceProvider.REST }; //rest data source - readonly DataSourceItem _resourceItem = new DataSourceItem(); //resource item that points to the rest data source - - public RestBuilder(string title, string subtitle) : - base(DataSourceProvider.JSON, title, subtitle) - { - DataSourceItem.HasTabularData = true; - DataSourceItem.ResourceItemDataSource = _resourceItemDataSource; - _resourceItem.DataSourceId = _resourceItemDataSource.Id; - DataSourceItem.ResourceItem = _resourceItem; - - SetAnonymous(true); - SetMethod("GET"); - _resourceItemDataSource.Properties.Add("Result-Type", ".json"); - } - - public IRestBuilder AddHeader(HeaderType headerType, string value) - { - var propertyKey = "Headers"; - - var headerValue = $"{AddDashesToEnumName(headerType.ToString())}={value}"; - - if (!_resourceItemDataSource.Properties.ContainsKey(propertyKey)) - { - _resourceItemDataSource.Properties.Add(propertyKey, new List { headerValue }); - } - else - { - var headers = (List)_resourceItemDataSource.Properties[propertyKey]; - headers.Add(headerValue); - } - - return this; - } - - public IRestBuilder SetAnonymous(bool isAnonymous) - { - _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; - return this; - } - - public IRestBuilder SetMethod(string method) - { - _resourceItemDataSource.Properties.Add("Method", method); - return this; - } - - public IRestBuilder SetUrl(string url) - { - _resourceItemDataSource.Properties.Add("Url", url); - return this; - } - - public override IDataSourceBuilder SetFields(IEnumerable fields) - { - DataSourceItem.Parameters.Add("config", BuildConfig(fields)); - return base.SetFields(fields); - } - - string AddDashesToEnumName(string name) - { - return string.Concat(name.Select(x => char.IsUpper(x) ? "-" + x : x.ToString())).TrimStart('-'); - } - - Dictionary BuildConfig(IEnumerable fields) - { - Dictionary config = new Dictionary(); - List columnConfigs = new List(); - foreach (var field in fields) - { - if (field == null) - continue; - - var columnConfig = new ColumnConfig - { - Key = field.FieldName - }; - - - int type = ((IFieldDataType)field).DataType switch - { - DataType.Number => 1, - DataType.Date => 2, - DataType.DateTime => 3, - DataType.Time => 4, - _ => 0 - }; - - columnConfig.Type = type; - columnConfigs.Add(columnConfig); - } - - config.Add("iterationDepth", 0); - config.Add("columnsConfig", columnConfigs); - return config; - } - } - -} diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs b/src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs deleted file mode 100644 index 030fe591..00000000 --- a/src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace Reveal.Sdk.Dom.Data -{ - public class DataSourceFactory - { - public static IDataSourceBuilder Create(DataSourceType type, string title, string subtitle) - { - return type switch - { - DataSourceType.RemoteFile => new RemoteFileBuilder(title, subtitle), - DataSourceType.REST => new RestBuilder(title, subtitle), - //DataSourceType.MicrosoftSqlServer => new SqlServerBuilder("", "", ""), - _ => throw new NotImplementedException($"No builder implemented for provider: {type}") - }; - } - } -}