diff --git a/e2e/Sandbox/Factories/CustomDashboard.cs b/e2e/Sandbox/Factories/CustomDashboard.cs index c29d651..074b96d 100644 --- a/e2e/Sandbox/Factories/CustomDashboard.cs +++ b/e2e/Sandbox/Factories/CustomDashboard.cs @@ -1,305 +1,315 @@ -using Reveal.Sdk.Dom; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Visualizations; -using Sandbox.Helpers; -using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; - -namespace Sandbox.Factories -{ - internal class CustomDashboard - { - internal static RdashDocument CreateDashboard() - { - var excelDataSourceItem = new RestServiceBuilder("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .SetTitle("Excel Data Source") - .SetSubtitle("Marketing Sheet") - .UseExcel("Marketing") - .SetFields(DataSourceFactory.GetMarketingDataSourceFields()) - .Build(); - - var csvDataSourceItem = new RestServiceBuilder("https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto") - .UseCsv() - .SetTitle("CSV Data Source") - .SetSubtitle("Illinois School Info") - .SetFields(DataSourceFactory.GetCsvDataSourceFields()) - .Build(); - - var financialDataSourceItem = new RestServiceBuilder("https://excel2json.io/api/share/8bb2cd78-1b87-4142-00a2-08da188ec9ab") - .SetTitle("Finance Data Source") - .SetSubtitle("OHLC") - .SetFields(DataSourceFactory.GetOHLCDataSourceFields()) - .Build(); - - var revenueDataSourceItem = new RestServiceBuilder("https://excel2json.io/api/share/818e7b9a-f463-4565-435d-08da496bf5f2") - .SetTitle("Choropleth Data Source") - .SetSubtitle("Revenue") - .SetFields(DataSourceFactory.GetRevenueDataSourceFields()) - .Build(); - - var document = new RdashDocument() - { - Title = "Custom Dashboard", - Description = "Playing with the Fluent API", - Theme = Theme.TropicalIsland - }; - - //grid - document.Visualizations.Add(new GridVisualization("Grid", excelDataSourceItem) - .SetColumns("Territory", "Conversions", "Spend")); - - //text view - document.Visualizations.Add(new TextViewVisualization("TextView", excelDataSourceItem) - .SetColumns("Territory", "Conversions", "Spend")); - - //pivot - document.Visualizations.Add(new PivotVisualization("Pivot", excelDataSourceItem) - .SetRow("Territory").SetValue("New Seats").SetColumn("CampaignID") - .ConfigureSettings(settings => - { - settings.ShowGrandTotals = true; - })); - - //column - document.Visualizations.Add(new ColumnChartVisualization("Column", excelDataSourceItem) - .SetLabel("Date").SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //bar - document.Visualizations.Add(new BarChartVisualization("Bar", excelDataSourceItem) - .SetLabel("Date").SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //pie - document.Visualizations.Add(new PieChartVisualization("Pie", excelDataSourceItem) - .SetLabel("Territory").SetValue("Conversions") - .ConfigureSettings(settings => - { - settings.SliceLabelDisplay = LabelDisplayMode.Value; - })); - - //doughnut - document.Visualizations.Add(new DoughnutChartVisualization("Doughnut", excelDataSourceItem) - .SetLabel("Territory").SetValue("Conversions") - .ConfigureSettings(settings => - { - settings.SliceLabelDisplay = LabelDisplayMode.ValueAndPercentage; - settings.StartPosition = 90; - })); - - //funnel - document.Visualizations.Add(new FunnelChartVisualization("Funnel", excelDataSourceItem) - .SetLabel("Territory") - .SetValue("Conversions") - .ConfigureSettings(settings => - { - settings.SliceLabelDisplay = LabelDisplayMode.Percentage; - })); - - //combo - document.Visualizations.Add(new ComboChartVisualization("Combo", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetChart1Value("Spend") - .SetChart2Value("Budget") - .ConfigureSettings(settings => - { - settings.Chart1Type = ComboChartType.Column; - settings.Chart2Type = ComboChartType.Line; - settings.ShowRightAxis = false; - settings.StartColorIndex = 5; - })); - - //stacked column - document.Visualizations.Add(new StackedColumnChartVisualization("Stacked Column", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //stacked bar - document.Visualizations.Add(new StackedBarChartVisualization("Stacked Bar", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //stacked area - document.Visualizations.Add(new StackedAreaChartVisualization("Stacked Area", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //area - document.Visualizations.Add(new AreaChartVisualization("Area", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //line - document.Visualizations.Add(new LineChartVisualization("Line", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValue("Conversions")); - - //step area - document.Visualizations.Add(new StepAreaChartVisualization("Step Area", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Spend", "Budget")); - - //step line - document.Visualizations.Add(new StepLineChartVisualization("Step Line", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Spend", "Budget")); - - //spline area - document.Visualizations.Add(new SplineAreaChartVisualization("Spline Area", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Spend", "Budget")); - - //spline - document.Visualizations.Add(new SplineChartVisualization("Spline", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Spend", "Budget")); - - //linear gauge - document.Visualizations.Add(new LinearGaugeVisualization("Linear", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }).SetValue("Spend") - .ConfigureSettings(settings => - { - settings.ValueComparisonType = ValueComparisonType.Number; - settings.UpperBand.Value = 10000; - settings.MiddleBand.Value = 5000; - })); - - //circular gauge - document.Visualizations.Add(new CircularGaugeVisualization("Circular", excelDataSourceItem).SetLabel("Budget").SetValue("Spend") - .ConfigureSettings(settings => - { - settings.MiddleBand.Value = 30; - })); - - //text - document.Visualizations.Add(new TextVisualization("Text", excelDataSourceItem).SetLabel("Budget").SetValue("Spend") - .ConfigureSettings(settings => - { - settings.ConditionalFormattingEnabled = true; - settings.UpperBand.Shape = ShapeType.ArrowUp; - settings.MiddleBand.Shape = ShapeType.Dash; - settings.LowerBand.Shape = ShapeType.ArrowDown; - })); - - //kpi target - document.Visualizations.Add(new KpiTargetVisualization("KPI vs Target", excelDataSourceItem).SetDate("Date").SetValue("Spend").SetTarget("Budget") - .ConfigureSettings(settings => - { - settings.DifferenceMode = IndicatorDifferenceMode.ValueAndPercentage; - settings.GoalPeriod = KpiGoalPeriod.ThisYear; - })); - - //kpi time - document.Visualizations.Add(new KpiTimeVisualization("KPI vs Time", excelDataSourceItem).SetDate("Date").SetValue("Traffic") - .ConfigureSettings(settings => - { - settings.DifferenceMode = IndicatorDifferenceMode.ValueAndPercentage; - settings.TimePeriod = KpiTimePeriod.MonthToDatePreviousMonth; - })); - - //bullet graph - document.Visualizations.Add(new BulletGraphVisualization("Bullet Graph", excelDataSourceItem).SetLabel("CampaignID").SetValue("Spend").SetTarget("Budget") - .ConfigureSettings(setting => - { - setting.ValueComparisonType = ValueComparisonType.Number; - setting.UpperBand.Value = 72000; - setting.MiddleBand.Value = 65000; - })); - - //choropleth map - document.Visualizations.Add(new ChoroplethVisualization("Choropleth", revenueDataSourceItem) - .SetMap(Maps.NorthAmerica.UnitedStates.States.AllStates) - .SetLocation("State") - .SetValue("Revenue") - .ConfigureSettings(settings => - { - settings.ColorIndex = 5; - settings.ColorStyle = MapColorStyle.SingleColor; - settings.LabelStyle = MapLabelStyle.Values; - })); - - //scatter map - document.Visualizations.Add(new ScatterMapVisualization("Scatter Map", csvDataSourceItem) - .SetMap(Maps.NorthAmerica.UnitedStates.States.Illinois) - .SetLongitude("X") - .SetLatitude("Y") - .SetLabel("School_Nm") - .SetColorByValue(new NumberDataField("Grades") { AggregationType = AggregationType.Avg }) - .ConfigureSettings(settings => - { - settings.ColorIndex = 5; - settings.ColorMode = MapColorMode.ConditionalFormatting; - - settings.ConditionalFormatting.ValueComparisonType = ValueComparisonType.Percentage; - settings.ConditionalFormatting.UpperBand.Value = 90; - settings.ConditionalFormatting.MiddleBand.Value = 60; - - settings.Zoom.Longitude = 1.38; - settings.Zoom.Latitude = 41.65; - settings.Zoom.DegreesLongitude = 1.04; - settings.Zoom.DegreesLatitude = 0.39; - })); - - //tree map - document.Visualizations.Add(new TreeMapVisualization("Tree Map", excelDataSourceItem) - .SetLabel("Territory").SetValue("Traffic")); - - //bubble - document.Visualizations.Add(new BubbleVisualization("Bubble", excelDataSourceItem) - .SetLabel("CampaignID").SetXAxis("Budget").SetYAxis("Spend").SetRadius("Traffic")); - - //scatter - document.Visualizations.Add(new ScatterVisualization("Scatter", excelDataSourceItem) - .SetLabel("CampaignID").SetXAxis("Budget").SetYAxis("Spend")); - - //time series - document.Visualizations.Add(new TimeSeriesVisualization("Time Series", excelDataSourceItem) - .SetDate(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); - - //radial - document.Visualizations.Add(new RadialVisualization("Radial", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Spend", "Budget")); - - //image - document.Visualizations.Add(new ImageVisualization("Image", excelDataSourceItem).SetUrl("Territory")); - - //sparkline - document.Visualizations.Add(new SparklineVisualization("Sparkline", excelDataSourceItem) - .SetDate("Date") - .SetValue("Spend") - .SetCategory("Territory") - .ConfigureSettings(settings => - { - settings.ShowLastTwoValues = false; - settings.NumberOfPeriods = 10; - settings.AggregationType = SparklineAggregationType.Months; - })); - - //textbox - document.Visualizations.Add(new TextBoxVisualization("TextBox").SetText("This is some text").SetFontSize(FontSize.Large)); - - //custom - document.Visualizations.Add(new CustomVisualization("Custom", excelDataSourceItem) - .SetUrl("https://dl.infragistics.com/reportplus/diy/HelloWorld-Desktop-EN.html") - .SetRows("Territory", "CampaignID") - .SetValues("Spend", "Budget")); - - //OHLC - document.Visualizations.Add(new OHLCVisualization("OHLC", financialDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Day }) - .SetOpen("Open") - .SetHigh("High") - .SetLow("Low") - .SetClose("Close")); - - //Candle stick - document.Visualizations.Add(new CandleStickVisualization("Candlestick", financialDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Day }) - .SetOpen("Open") - .SetHigh("High") - .SetLow("Low") - .SetClose("Close")); - - return document; - } - } +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using Sandbox.Helpers; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; + +namespace Sandbox.Factories +{ + internal class CustomDashboard + { + internal static RdashDocument CreateDashboard() + { + var factory = new DataSourceItemFactory(); + + var excelDataSourceItem = factory.Create(DataSourceType.REST, "Marketing Sheet") + .Subtitle("Excel Data Source Item") + .Fields(DataSourceFactory.GetMarketingDataSourceFields()) + .As() + .Uri("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") + .IsAnonymous(true) + .UseExcel("Marketing") + .Build(); + + var csvDataSourceItem = factory.Create(DataSourceType.REST, "Illinois School Info") + .Subtitle("CSV Data Source Item") + .Fields(DataSourceFactory.GetCsvDataSourceFields()) + .As() + .Uri("https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto") + .IsAnonymous(true) + .UseCsv() + .Build(); + + var financialDataSourceItem = factory.Create(DataSourceType.REST, "OHLC") + .Subtitle("Financial Data Source Item") + .Fields(DataSourceFactory.GetOHLCDataSourceFields()) + .As() + .Uri("https://excel2json.io/api/share/8bb2cd78-1b87-4142-00a2-08da188ec9ab") + .IsAnonymous(true) + .Build(); + + var revenueDataSourceItem = factory.Create(DataSourceType.REST, "Revenue") + .Subtitle("Choropleth Data Source Item") + .Fields(DataSourceFactory.GetRevenueDataSourceFields()) + .As() + .Uri("https://excel2json.io/api/share/818e7b9a-f463-4565-435d-08da496bf5f2") + .IsAnonymous(true) + .Build(); + + var document = new RdashDocument() + { + Title = "Custom Dashboard", + Description = "Playing with the Fluent API", + Theme = Theme.TropicalIsland + }; + + //grid + document.Visualizations.Add(new GridVisualization("Grid", excelDataSourceItem) + .SetColumns("Territory", "Conversions", "Spend")); + + //text view + document.Visualizations.Add(new TextViewVisualization("TextView", excelDataSourceItem) + .SetColumns("Territory", "Conversions", "Spend")); + + //pivot + document.Visualizations.Add(new PivotVisualization("Pivot", excelDataSourceItem) + .SetRow("Territory").SetValue("New Seats").SetColumn("CampaignID") + .ConfigureSettings(settings => + { + settings.ShowGrandTotals = true; + })); + + //column + document.Visualizations.Add(new ColumnChartVisualization("Column", excelDataSourceItem) + .SetLabel("Date").SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //bar + document.Visualizations.Add(new BarChartVisualization("Bar", excelDataSourceItem) + .SetLabel("Date").SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //pie + document.Visualizations.Add(new PieChartVisualization("Pie", excelDataSourceItem) + .SetLabel("Territory").SetValue("Conversions") + .ConfigureSettings(settings => + { + settings.SliceLabelDisplay = LabelDisplayMode.Value; + })); + + //doughnut + document.Visualizations.Add(new DoughnutChartVisualization("Doughnut", excelDataSourceItem) + .SetLabel("Territory").SetValue("Conversions") + .ConfigureSettings(settings => + { + settings.SliceLabelDisplay = LabelDisplayMode.ValueAndPercentage; + settings.StartPosition = 90; + })); + + //funnel + document.Visualizations.Add(new FunnelChartVisualization("Funnel", excelDataSourceItem) + .SetLabel("Territory") + .SetValue("Conversions") + .ConfigureSettings(settings => + { + settings.SliceLabelDisplay = LabelDisplayMode.Percentage; + })); + + //combo + document.Visualizations.Add(new ComboChartVisualization("Combo", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetChart1Value("Spend") + .SetChart2Value("Budget") + .ConfigureSettings(settings => + { + settings.Chart1Type = ComboChartType.Column; + settings.Chart2Type = ComboChartType.Line; + settings.ShowRightAxis = false; + settings.StartColorIndex = 5; + })); + + //stacked column + document.Visualizations.Add(new StackedColumnChartVisualization("Stacked Column", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //stacked bar + document.Visualizations.Add(new StackedBarChartVisualization("Stacked Bar", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //stacked area + document.Visualizations.Add(new StackedAreaChartVisualization("Stacked Area", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //area + document.Visualizations.Add(new AreaChartVisualization("Area", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //line + document.Visualizations.Add(new LineChartVisualization("Line", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValue("Conversions")); + + //step area + document.Visualizations.Add(new StepAreaChartVisualization("Step Area", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Spend", "Budget")); + + //step line + document.Visualizations.Add(new StepLineChartVisualization("Step Line", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Spend", "Budget")); + + //spline area + document.Visualizations.Add(new SplineAreaChartVisualization("Spline Area", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Spend", "Budget")); + + //spline + document.Visualizations.Add(new SplineChartVisualization("Spline", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Spend", "Budget")); + + //linear gauge + document.Visualizations.Add(new LinearGaugeVisualization("Linear", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }).SetValue("Spend") + .ConfigureSettings(settings => + { + settings.ValueComparisonType = ValueComparisonType.Number; + settings.UpperBand.Value = 10000; + settings.MiddleBand.Value = 5000; + })); + + //circular gauge + document.Visualizations.Add(new CircularGaugeVisualization("Circular", excelDataSourceItem).SetLabel("Budget").SetValue("Spend") + .ConfigureSettings(settings => + { + settings.MiddleBand.Value = 30; + })); + + //text + document.Visualizations.Add(new TextVisualization("Text", excelDataSourceItem).SetLabel("Budget").SetValue("Spend") + .ConfigureSettings(settings => + { + settings.ConditionalFormattingEnabled = true; + settings.UpperBand.Shape = ShapeType.ArrowUp; + settings.MiddleBand.Shape = ShapeType.Dash; + settings.LowerBand.Shape = ShapeType.ArrowDown; + })); + + //kpi target + document.Visualizations.Add(new KpiTargetVisualization("KPI vs Target", excelDataSourceItem).SetDate("Date").SetValue("Spend").SetTarget("Budget") + .ConfigureSettings(settings => + { + settings.DifferenceMode = IndicatorDifferenceMode.ValueAndPercentage; + settings.GoalPeriod = KpiGoalPeriod.ThisYear; + })); + + //kpi time + document.Visualizations.Add(new KpiTimeVisualization("KPI vs Time", excelDataSourceItem).SetDate("Date").SetValue("Traffic") + .ConfigureSettings(settings => + { + settings.DifferenceMode = IndicatorDifferenceMode.ValueAndPercentage; + settings.TimePeriod = KpiTimePeriod.MonthToDatePreviousMonth; + })); + + //bullet graph + document.Visualizations.Add(new BulletGraphVisualization("Bullet Graph", excelDataSourceItem).SetLabel("CampaignID").SetValue("Spend").SetTarget("Budget") + .ConfigureSettings(setting => + { + setting.ValueComparisonType = ValueComparisonType.Number; + setting.UpperBand.Value = 72000; + setting.MiddleBand.Value = 65000; + })); + + //choropleth map + document.Visualizations.Add(new ChoroplethVisualization("Choropleth", revenueDataSourceItem) + .SetMap(Maps.NorthAmerica.UnitedStates.States.AllStates) + .SetLocation("State") + .SetValue("Revenue") + .ConfigureSettings(settings => + { + settings.ColorIndex = 5; + settings.ColorStyle = MapColorStyle.SingleColor; + settings.LabelStyle = MapLabelStyle.Values; + })); + + //scatter map + document.Visualizations.Add(new ScatterMapVisualization("Scatter Map", csvDataSourceItem) + .SetMap(Maps.NorthAmerica.UnitedStates.States.Illinois) + .SetLongitude("X") + .SetLatitude("Y") + .SetLabel("School_Nm") + .SetColorByValue(new NumberDataField("Grades") { AggregationType = AggregationType.Avg }) + .ConfigureSettings(settings => + { + settings.ColorIndex = 5; + settings.ColorMode = MapColorMode.ConditionalFormatting; + + settings.ConditionalFormatting.ValueComparisonType = ValueComparisonType.Percentage; + settings.ConditionalFormatting.UpperBand.Value = 90; + settings.ConditionalFormatting.MiddleBand.Value = 60; + + settings.Zoom.Longitude = 1.38; + settings.Zoom.Latitude = 41.65; + settings.Zoom.DegreesLongitude = 1.04; + settings.Zoom.DegreesLatitude = 0.39; + })); + + //tree map + document.Visualizations.Add(new TreeMapVisualization("Tree Map", excelDataSourceItem) + .SetLabel("Territory").SetValue("Traffic")); + + //bubble + document.Visualizations.Add(new BubbleVisualization("Bubble", excelDataSourceItem) + .SetLabel("CampaignID").SetXAxis("Budget").SetYAxis("Spend").SetRadius("Traffic")); + + //scatter + document.Visualizations.Add(new ScatterVisualization("Scatter", excelDataSourceItem) + .SetLabel("CampaignID").SetXAxis("Budget").SetYAxis("Spend")); + + //time series + document.Visualizations.Add(new TimeSeriesVisualization("Time Series", excelDataSourceItem) + .SetDate(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Paid Traffic", "Organic Traffic", "Other Traffic")); + + //radial + document.Visualizations.Add(new RadialVisualization("Radial", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Spend", "Budget")); + + //image + document.Visualizations.Add(new ImageVisualization("Image", excelDataSourceItem).SetUrl("Territory")); + + //sparkline + document.Visualizations.Add(new SparklineVisualization("Sparkline", excelDataSourceItem) + .SetDate("Date") + .SetValue("Spend") + .SetCategory("Territory") + .ConfigureSettings(settings => + { + settings.ShowLastTwoValues = false; + settings.NumberOfPeriods = 10; + settings.AggregationType = SparklineAggregationType.Months; + })); + + //textbox + document.Visualizations.Add(new TextBoxVisualization("TextBox").SetText("This is some text").SetFontSize(FontSize.Large)); + + //custom + document.Visualizations.Add(new CustomVisualization("Custom", excelDataSourceItem) + .SetUrl("https://dl.infragistics.com/reportplus/diy/HelloWorld-Desktop-EN.html") + .SetRows("Territory", "CampaignID") + .SetValues("Spend", "Budget")); + + //OHLC + document.Visualizations.Add(new OHLCVisualization("OHLC", financialDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Day }) + .SetOpen("Open") + .SetHigh("High") + .SetLow("Low") + .SetClose("Close")); + + //Candle stick + document.Visualizations.Add(new CandleStickVisualization("Candlestick", financialDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Day }) + .SetOpen("Open") + .SetHigh("High") + .SetLow("Low") + .SetClose("Close")); + + return document; + } + } } \ No newline at end of file diff --git a/e2e/Sandbox/Factories/RestDataSourceDashboards.cs b/e2e/Sandbox/Factories/RestDataSourceDashboards.cs index 1db4d5f..ffad529 100644 --- a/e2e/Sandbox/Factories/RestDataSourceDashboards.cs +++ b/e2e/Sandbox/Factories/RestDataSourceDashboards.cs @@ -1,60 +1,82 @@ -using Reveal.Sdk.Dom; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Visualizations; -using Sandbox.Helpers; -using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; - -namespace Sandbox.Factories -{ - internal class RestDataSourceDashboards - { - internal static RdashDocument CreateDashboard() - { - var document = new RdashDocument("My Dashboard"); - - //json - default - var jsonDataSourceItem = new RestServiceBuilder("https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9") - .SetTitle("JSON Data Source") - .SetSubtitle("Sales by Category") - .SetFields(DataSourceFactory.GetSalesByCategoryFields()) - .Build(); - - document.Visualizations.Add(new PieChartVisualization("JSON", jsonDataSourceItem) - .SetLabel("CategoryName").SetValue("ProductSales")); - - //excel - var excelDataSourceItem = new RestServiceBuilder("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .UseExcel() - .SetTitle("Excel Data Source") - .SetSubtitle("Marketing") - .SetFields(DataSourceFactory.GetMarketingDataSourceFields()) - .Build(); - - document.Visualizations.Add(new PieChartVisualization("Excel", excelDataSourceItem) - .SetLabel("Territory").SetValue("Conversions")); - - //csv - var csvDataSourceItem = new RestServiceBuilder("https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto") - .UseCsv() - .SetTitle("CSV Data Source") - .SetSubtitle("Illinois School Info") - .SetFields(DataSourceFactory.GetCsvDataSourceFields()) - .Build(); - - document.Visualizations.Add(new ScatterMapVisualization("Scatter", csvDataSourceItem) - .SetMap(Maps.NorthAmerica.UnitedStates.States.Illinois) - .SetLongitude("X") - .SetLatitude("Y") - .SetLabel("School_Nm") - .ConfigureSettings(settings => - { - settings.Zoom.Longitude = 1.38; - settings.Zoom.Latitude = 41.65; - settings.Zoom.DegreesLongitude = 1.04; - settings.Zoom.DegreesLatitude = 0.39; - })); - - return document; - } - } -} +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using Sandbox.Helpers; + +namespace Sandbox.Factories +{ + internal class RestDataSourceDashboards + { + static IDataSourceItemFactory _factory = new DataSourceItemFactory(); + + internal static RdashDocument CreateDashboard() + { + var document = new RdashDocument("My Dashboard"); + + //json - default + var jsonDataSourceItem = _factory.Create(DataSourceType.REST, "Sales by Category") + .Subtitle("JSON Data Source Item") + .Fields(DataSourceFactory.GetSalesByCategoryFields()) + .As() + .Uri("https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9") + .IsAnonymous(true) + .ConfigureDataSource(d => + { + d.Title = "JSON DS"; + d.Subtitle = "JSON DS Subtitle"; + }) + .Build(); + + document.Visualizations.Add(new PieChartVisualization("JSON", jsonDataSourceItem) + .SetLabel("CategoryName").SetValue("ProductSales")); + + //excel + var excelDataSourceItem = _factory.Create(DataSourceType.REST, "Marketing") + .Subtitle("Excel Data Source Item") + .Fields(DataSourceFactory.GetMarketingDataSourceFields()) + .As() + .Uri("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") + .IsAnonymous(true) + .UseExcel("Marketing") + .ConfigureDataSource(d => + { + d.Title = "Excel DS"; + d.Subtitle = "Excel DS Subtitle"; + }) + .Build(); + + document.Visualizations.Add(new PieChartVisualization("Excel", excelDataSourceItem) + .SetLabel("Territory").SetValue("Conversions")); + + //csv + var csvDataSourceItem = _factory.Create(DataSourceType.REST, "Illinois School Info") + .Subtitle("CSV Data Source Item") + .Fields(DataSourceFactory.GetCsvDataSourceFields()) + .As() + .Uri("https://query.data.world/s/y32gtgblzpemyyvtig47dz7tedgkto") + .IsAnonymous(true) + .UseCsv() + .ConfigureDataSource(d => + { + d.Title = "CSV DS"; + d.Subtitle = "CSV DS Subtitle"; + }) + .Build(); + + document.Visualizations.Add(new ScatterMapVisualization("Scatter", csvDataSourceItem) + .SetMap(Maps.NorthAmerica.UnitedStates.States.Illinois) + .SetLongitude("X") + .SetLatitude("Y") + .SetLabel("School_Nm") + .ConfigureSettings(settings => + { + settings.Zoom.Longitude = 1.38; + settings.Zoom.Latitude = 41.65; + settings.Zoom.DegreesLongitude = 1.04; + settings.Zoom.DegreesLatitude = 0.39; + })); + + return document; + } + } +} diff --git a/e2e/Sandbox/Factories/SqlServerDataSourceDashboards.cs b/e2e/Sandbox/Factories/SqlServerDataSourceDashboards.cs index 75f9252..ed16ed5 100644 --- a/e2e/Sandbox/Factories/SqlServerDataSourceDashboards.cs +++ b/e2e/Sandbox/Factories/SqlServerDataSourceDashboards.cs @@ -1,30 +1,33 @@ -using Reveal.Sdk.Dom; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Visualizations; -using System.Collections.Generic; - -namespace Sandbox.Factories -{ - internal class SqlServerDataSourceDashboards - { - internal static RdashDocument CreateDashboard() - { - var document = new RdashDocument("My Dashboard"); - - var sqlServerDataSourceItem = new SqlServerBuilder("host", "database", "table") - .SetTitle("SQL Server") - .SetSubtitle("Orders") - .SetFields(new List() - { - new TextField("CustomerID"), - new NumberField("OrderID"), - }) - .Build(); - - document.Visualizations.Add(new BarChartVisualization("SQL Server Bar Chart", sqlServerDataSourceItem) - .SetLabel("CustomerID").SetValue(new NumberDataField("OrderID") { AggregationType = AggregationType.CountRows })); - - return document; - } - } -} +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; + +namespace Sandbox.Factories +{ + internal class SqlServerDataSourceDashboards + { + internal static RdashDocument CreateDashboard() + { + var document = new RdashDocument("My Dashboard"); + + var sqlServerDataSourceItem = new DataSourceItemFactory().Create(DataSourceType.MicrosoftSqlServer, "Customers") + .Subtitle("SQL Server Data Source Item") + .Fields(new List + { + new TextField("ContactName"), + new TextField("ContactTitle"), + new TextField("City") + }) + .As() + .Host(@"Brian-Desktop\SQLEXPRESS") + .Database("Northwind") + .Table("Customers") + .Build(); + + document.Visualizations.Add(new GridVisualization("Customer List", sqlServerDataSourceItem).SetColumns("ContactName", "ContactTitle", "City")); + + return document; + } + } +} diff --git a/e2e/Sandbox/Helpers/DataSourceFactory.cs b/e2e/Sandbox/Helpers/DataSourceFactory.cs index ccc05b2..41d30b0 100644 --- a/e2e/Sandbox/Helpers/DataSourceFactory.cs +++ b/e2e/Sandbox/Helpers/DataSourceFactory.cs @@ -1,197 +1,214 @@ -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Visualizations; -using System; -using System.Collections.Generic; - -namespace Sandbox.Helpers -{ - internal class DataSourceFactory - { - internal static DataSourceItem GetMarketingDataSourceItem() - { - var excelDataSourceItem = new RestServiceBuilder("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .SetTitle("Excel Data Source") - .SetSubtitle("Marketing Sheet") - .UseExcel("Marketing") - .SetFields(GetMarketingDataSourceFields()) - .Build(); - - return excelDataSourceItem; - } - - internal static DataSourceItem GetHealthcareDataSourceItem() - { - var excelDataSourceItem = new RestServiceBuilder("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .SetTitle("Excel Data Source") - .SetSubtitle("Healthcare Sheet") - .UseExcel("Healthcare") - .SetFields(GetHealthcareDataSourceFields()) - .Build(); - - return excelDataSourceItem; - } - - internal static DataSourceItem GetManufacturingDataSourceItem() - { - var excelDataSourceItem = new RestServiceBuilder("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .SetTitle("Excel Data Source") - .SetSubtitle("Manufacturing Sheet") - .UseExcel("Manufacturing") - .SetFields(GetManufacturingDataSourceFields()) - .Build(); - - return excelDataSourceItem; - } - - internal static DataSourceItem GetSalesDataSourceItem() - { - var excelDataSourceItem = new RestServiceBuilder("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") - .SetTitle("Excel Data Source") - .SetSubtitle("Sales Sheet") - .UseExcel("Sales") - .SetFields(GetSalesDataSourceFields()) - .Build(); - - return excelDataSourceItem; - } - - internal static IEnumerable GetRevenueDataSourceFields() - { - return new List() - { - new DateField("Date"), - new TextField("State"), - new NumberField("Revenue"), - new NumberField("RevenueBudget"), - new NumberField("RevenueBudgetLY"), - new NumberField("GM"), - new NumberField("GrossMarginLY"), - new NumberField("GM%"), - new NumberField("GrossMargin%LY"), - new NumberField("RevenueperCompany"), - new TextField("Company"), - new TextField("Division") - }; - } - - internal static List GetHealthcareDataSourceFields() - { - return new List - { - new DateField("Date"), - new NumberField("Number of Inpatients"), - new NumberField("Number of Outpatients"), - new NumberField("Treatment Costs "), - new NumberField("ER Wait Time"), - new TextField("Divison"), - new TextField("Satisfaction"), - new NumberField("Length of Stay "), - new NumberField("Charges per MD"), - new NumberField("Current Paitents") - }; - } - - internal static List GetManufacturingDataSourceFields() - { - return new List - { - new DateField("Date"), - new NumberField("Units Lost"), - new NumberField("Overall Plant Productivity "), - new NumberField("Operators Available "), - new TextField("Operators by Function"), - new NumberField("Units Produced"), - new TextField("Product"), - new NumberField("Efficiency"), - new TextField("Line"), - new NumberField("Orders In"), - new NumberField("Orders Shipped "), - new NumberField("Cost of Labor "), - new NumberField("Revenue") - }; - } - - internal static List GetMarketingDataSourceFields() - { - return 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 %") - }; - } - - internal static List GetSalesDataSourceFields() - { - return new List - { - new TextField("Territory"), - new DateField("Date"), - new NumberField("Quota"), - new NumberField("Leads"), - new NumberField("Hot Leads"), - new NumberField("New Seats"), - new NumberField("New Sales"), - new NumberField("Renewal Seats"), - new NumberField("Renewal Sales "), - new TextField("Employee"), - new NumberField("Pipepline"), - new NumberField("Forecasted"), - new NumberField("Revenue"), - new NumberField("Total Opportunites"), - new TextField("Product") - }; - } - - internal static List GetSalesByCategoryFields() - { - return new List - { - new NumberField("CategoryID"), - new TextField("CategoryName"), - new TextField("ProductName"), - new NumberField("ProductSales"), - }; - } - - internal static List GetCsvDataSourceFields() - { - return new List - { - new TextField("the_geom"), - new NumberField("School_ID"), - new TextField("School_Nm"), - new TextField("Sch_Addr"), - new TextField("Grade_Cat"), - new TextField("Grades"), - new TextField("Sch_Type"), - new NumberField("X"), - new NumberField("Y"), - }; - } - - internal static IEnumerable GetOHLCDataSourceFields() - { - return new List - { - new DateField("Date"), - new NumberField("Open"), - new NumberField("High"), - new NumberField("Low"), - new NumberField("Close"), - new NumberField("Volume"), - }; - } - } -} +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; + +namespace Sandbox.Helpers +{ + internal class DataSourceFactory + { + static IDataSourceItemFactory _factory = new DataSourceItemFactory(); + static DataSource _excelDataSource = new DataSource() + { + Id = "RestExcel", + Title = "Excel Data Source", + Subtitle = "The Data Source for Excel via REST", + }; + + static string _restExcelUri = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; + + internal static DataSourceItem GetMarketingDataSourceItem() + { + var excelDataSourceItem = _factory.Create(DataSourceType.REST, _excelDataSource, "Marketing") + .Subtitle("Excel Data Source Item") + .Fields(GetMarketingDataSourceFields()) + .As() + .Uri(_restExcelUri) + .IsAnonymous(true) + .UseExcel("Marketing") + .Build(); + + return excelDataSourceItem; + } + + internal static DataSourceItem GetHealthcareDataSourceItem() + { + var excelDataSourceItem = _factory.Create(DataSourceType.REST, _excelDataSource, "Healthcare") + .Subtitle("Excel Data Source Item") + .Fields(GetHealthcareDataSourceFields()) + .As() + .Uri(_restExcelUri) + .IsAnonymous(true) + .UseExcel("Healthcare") + .Build(); + + return excelDataSourceItem; + } + + internal static DataSourceItem GetManufacturingDataSourceItem() + { + var excelDataSourceItem = _factory.Create(DataSourceType.REST, _excelDataSource, "Manufacturing") + .Subtitle("Excel Data Source Item") + .Fields(GetManufacturingDataSourceFields()) + .As() + .Uri(_restExcelUri) + .IsAnonymous(true) + .UseExcel("Manufacturing") + .Build(); + + return excelDataSourceItem; + } + + internal static DataSourceItem GetSalesDataSourceItem() + { + var excelDataSourceItem = _factory.Create(DataSourceType.REST, _excelDataSource, "Sales") + .Subtitle("Excel Data Source Item") + .Fields(GetSalesDataSourceFields()) + .As() + .Uri(_restExcelUri) + .IsAnonymous(true) + .UseExcel("Sales") + .Build(); + + return excelDataSourceItem; + } + + internal static IEnumerable GetRevenueDataSourceFields() + { + return new List() + { + new DateField("Date"), + new TextField("State"), + new NumberField("Revenue"), + new NumberField("RevenueBudget"), + new NumberField("RevenueBudgetLY"), + new NumberField("GM"), + new NumberField("GrossMarginLY"), + new NumberField("GM%"), + new NumberField("GrossMargin%LY"), + new NumberField("RevenueperCompany"), + new TextField("Company"), + new TextField("Division") + }; + } + + internal static List GetHealthcareDataSourceFields() + { + return new List + { + new DateField("Date"), + new NumberField("Number of Inpatients"), + new NumberField("Number of Outpatients"), + new NumberField("Treatment Costs "), + new NumberField("ER Wait Time"), + new TextField("Divison"), + new TextField("Satisfaction"), + new NumberField("Length of Stay "), + new NumberField("Charges per MD"), + new NumberField("Current Paitents") + }; + } + + internal static List GetManufacturingDataSourceFields() + { + return new List + { + new DateField("Date"), + new NumberField("Units Lost"), + new NumberField("Overall Plant Productivity "), + new NumberField("Operators Available "), + new TextField("Operators by Function"), + new NumberField("Units Produced"), + new TextField("Product"), + new NumberField("Efficiency"), + new TextField("Line"), + new NumberField("Orders In"), + new NumberField("Orders Shipped "), + new NumberField("Cost of Labor "), + new NumberField("Revenue") + }; + } + + internal static List GetMarketingDataSourceFields() + { + return 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 %") + }; + } + + internal static List GetSalesDataSourceFields() + { + return new List + { + new TextField("Territory"), + new DateField("Date"), + new NumberField("Quota"), + new NumberField("Leads"), + new NumberField("Hot Leads"), + new NumberField("New Seats"), + new NumberField("New Sales"), + new NumberField("Renewal Seats"), + new NumberField("Renewal Sales "), + new TextField("Employee"), + new NumberField("Pipepline"), + new NumberField("Forecasted"), + new NumberField("Revenue"), + new NumberField("Total Opportunites"), + new TextField("Product") + }; + } + + internal static List GetSalesByCategoryFields() + { + return new List + { + new NumberField("CategoryID"), + new TextField("CategoryName"), + new TextField("ProductName"), + new NumberField("ProductSales"), + }; + } + + internal static List GetCsvDataSourceFields() + { + return new List + { + new TextField("the_geom"), + new NumberField("School_ID"), + new TextField("School_Nm"), + new TextField("Sch_Addr"), + new TextField("Grade_Cat"), + new TextField("Grades"), + new TextField("Sch_Type"), + new NumberField("X"), + new NumberField("Y"), + }; + } + + internal static IEnumerable GetOHLCDataSourceFields() + { + return new List + { + new DateField("Date"), + new NumberField("Open"), + new NumberField("High"), + new NumberField("Low"), + new NumberField("Close"), + new NumberField("Volume"), + }; + } + } +} diff --git a/e2e/Sandbox/MainWindow.xaml.cs b/e2e/Sandbox/MainWindow.xaml.cs index e278278..43b2b94 100644 --- a/e2e/Sandbox/MainWindow.xaml.cs +++ b/e2e/Sandbox/MainWindow.xaml.cs @@ -1,15 +1,19 @@ using Reveal.Sdk; using Reveal.Sdk.Data; +using Reveal.Sdk.Data.Excel; 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 Sandbox.RevealSDK; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading.Tasks; using System.Windows; @@ -22,8 +26,7 @@ public partial class MainWindow : Window { static readonly string _dashboardFilePath = Path.Combine(Environment.CurrentDirectory, "Dashboards"); - //readonly string _readFilePath = Path.Combine(_dashboardFilePath, DashboardFileNames.Marketing); - readonly string _readFilePath = Path.Combine(_dashboardFilePath, "JB - New Infragistics Scorecard Test.rdash"); + readonly string _readFilePath = Path.Combine(_dashboardFilePath, DashboardFileNames.Marketing); readonly string _saveJsonToPath = Path.Combine(_dashboardFilePath, "MyDashboard.json"); readonly string _saveRdashToPath = Path.Combine(_dashboardFilePath, DashboardFileNames.MyDashboard); @@ -32,10 +35,9 @@ public MainWindow() { InitializeComponent(); - //RevealSdkSettings.EnableNewCharts = true; + RevealSdkSettings.DataSourceProvider = new Sandbox.RevealSDK.DataSourceProvider(); RevealSdkSettings.AuthenticationProvider = new AuthenticationProvider(); RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices(); - RevealSdkSettings.DataSourceProvider = new DataSourceProvider(); _revealView.LinkedDashboardProvider = (string dashboardId, string linkTitle) => { @@ -46,7 +48,7 @@ public MainWindow() return null; }; - _revealView.DataSourcesRequested += RevealView_DataSourcesRequested; + //_revealView.DataSourcesRequested += RevealView_DataSourcesRequested; _revealView.DashboardSelectorRequested += RevealView_DashboardSelectorRequested; } @@ -56,24 +58,91 @@ private void RevealView_DataSourcesRequested(object sender, DataSourcesRequested var ds = new List(); var dsi = new List(); - var restDS = new RVRESTDataSource(); - restDS.Title = "Excel to JSON"; - restDS.UseAnonymousAuthentication = true; - restDS.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; - ds.Add(restDS); - - var sqlDS = new RVSqlServerDataSource(); - sqlDS.Title = "SQL Server"; - sqlDS.Host = "Brian-Desktop\\SQLEXPRESS"; - ds.Add(sqlDS); - - var webDS = new RVWebResourceDataSource(); - webDS.UseAnonymousAuthentication = true; - webDS.Title = "Web Resource"; - webDS.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; - ds.Add(webDS); - - e.Callback(new RevealDataSources(ds, dsi, false)); + //REST + //var jsonRestDS = new RVRESTDataSource(); + //jsonRestDS.Title = "REST DS JSON"; + //jsonRestDS.Subtitle = "REST DS JSON Subtitle"; + //jsonRestDS.UseAnonymousAuthentication = true; + //jsonRestDS.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; + //ds.Add(jsonRestDS); + + //REST well defined + //var jsonRestDS = new RVRESTDataSource(); + //jsonRestDS.Title = "REST DS JSON"; + //jsonRestDS.Subtitle = "REST DS JSON Subtitle"; + //jsonRestDS.UseAnonymousAuthentication = true; + //jsonRestDS.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; + //ds.Add(jsonRestDS); + + //var jsonRestDSI = new RVRESTDataSourceItem(jsonRestDS); + //jsonRestDSI.Title = "REST DSI JSON"; + //jsonRestDSI.Subtitle = "REST JSON DSI Subtitle"; + + //var jsonDSI = new RVJsonDataSourceItem(jsonRestDSI); + //jsonDSI.Title = "JSON DSI"; + //jsonDSI.Subtitle = "JSON DSI Subtitle"; + //jsonDSI.Config = @" + //{ + // ""iterationDepth"": 0, + // ""columnsConfig"": [ + // { + // ""key"": ""CategoryID"", + // ""type"": 1 + // }, + // { + // ""key"": ""CategoryName"", + // ""type"": 0 + // }, + // { + // ""key"": ""ProductName"", + // ""type"": 0 + // }, + // { + // ""key"": ""ProductSales"", + // ""type"": 1 + // } + // ] + //}"; + //dsi.Add(jsonDSI); + + //REST Excel well defined + //var restExcelDS = new RVRESTDataSource(); + //restExcelDS.Title = "REST Excel"; + //restExcelDS.Subtitle = "Samples.xlsz"; + //restExcelDS.UseAnonymousAuthentication = true; + //restExcelDS.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; + //ds.Add(restExcelDS); + + //var restDSI = new RVRESTDataSourceItem(restExcelDS); + //restDSI.Title = "REST Data Source Item"; + //restDSI.Subtitle = "REST DSI Subtitle"; + + //var excelDSI = new RVExcelDataSourceItem(restDSI); + //excelDSI.Title = "Excel Data Source Item"; + //excelDSI.Subtitle = "Marketing Sheet"; + //excelDSI.Sheet = "Marketing"; + //dsi.Add(excelDSI); + + //var sqlDS = new RVSqlServerDataSource(); + //sqlDS.Title = "SQL Server Data Source"; + //sqlDS.Subtitle = "SQL Server DS Subtitle"; + //sqlDS.Host = "Brian-Desktop\\SQLEXPRESS"; + //sqlDS.Database = "Northwind"; //this is required + //ds.Add(sqlDS); + + //var sqlDSI = new RVSqlServerDataSourceItem(sqlDS); + //sqlDSI.Title = "SQL Server Data Source Item"; + //sqlDSI.Subtitle = "SQL Server DSI Subtitle"; + //sqlDSI.Table = "Customers"; + //dsi.Add(sqlDSI); + + //var webDS = new RVWebResourceDataSource(); + //webDS.UseAnonymousAuthentication = true; + //webDS.Title = "Web Resource"; + //webDS.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; + //ds.Add(webDS); + + e.Callback(new RevealDataSources(ds, dsi, true)); } private void RevealView_DashboardSelectorRequested(object sender, DashboardSelectorRequestedEventArgs e) @@ -119,37 +188,13 @@ private async void Create_Dashboard(object sender, RoutedEventArgs e) //var document = CampaignsDashboard.CreateDashboard(); //var document = HealthcareDashboard.CreateDashboard(); //var document = ManufacturingDashboard.CreateDashboard(); - //var document = CustomDashboard.CreateDashboard(); + var document = CustomDashboard.CreateDashboard(); //var document = RestDataSourceDashboards.CreateDashboard(); //var document = SqlServerDataSourceDashboards.CreateDashboard(); //var document = DashboardLinkingDashboard.CreateDashboard(); - //document.Save(_saveRdashToPath); - - var document = new RdashDocument() - { - Title = "My Dashboard", - Description = "I created" - }; - var json = document.ToJsonString(); - //json.Save(_saveJsonToPath); _revealView.Dashboard = await RVDashboard.LoadFromJsonAsync(json); } } - - public class DataSourceProvider : IRVDataSourceProvider - { - public Task ChangeDataSourceItemAsync(RVDataSourceItem dataSourceItem) - { - if (dataSourceItem is RVJsonDataSourceItem jsonDataSourceItem) - { - var restDataSourceItem = jsonDataSourceItem.ResourceItem as RVRESTDataSourceItem; - restDataSourceItem.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; - } - return Task.FromResult(dataSourceItem); - } - - - } } diff --git a/e2e/Sandbox/Reveal/AuthenticationProvider.cs b/e2e/Sandbox/Reveal/AuthenticationProvider.cs index 67de64c..07e9fce 100644 --- a/e2e/Sandbox/Reveal/AuthenticationProvider.cs +++ b/e2e/Sandbox/Reveal/AuthenticationProvider.cs @@ -1,24 +1,24 @@ -using Reveal.Sdk.Data; -using Reveal.Sdk.Data.Microsoft.AnalysisServices; -using Reveal.Sdk.Data.Microsoft.SqlServer; -using System.Threading.Tasks; - -namespace Sandbox.Helpers -{ - internal class AuthenticationProvider : IRVAuthenticationProvider - { - public Task ResolveCredentialsAsync(RVDashboardDataSource dataSource) - { - IRVDataSourceCredential userCredential = null; - if (dataSource is RVSqlServerDataSource) - { - userCredential = new RVUsernamePasswordDataSourceCredential("username", "password"); - } - else if (dataSource is RVNativeAnalysisServicesDataSource) - { - userCredential = new RVUsernamePasswordDataSourceCredential("username", "password", "domain"); - } - return Task.FromResult(userCredential); - } - } -} +using Reveal.Sdk.Data; +using Reveal.Sdk.Data.Microsoft.AnalysisServices; +using Reveal.Sdk.Data.Microsoft.SqlServer; +using System.Threading.Tasks; + +namespace Sandbox.RevealSDK +{ + internal class AuthenticationProvider : IRVAuthenticationProvider + { + public Task ResolveCredentialsAsync(RVDashboardDataSource dataSource) + { + IRVDataSourceCredential userCredential = null; + if (dataSource is RVSqlServerDataSource) + { + userCredential = new RVUsernamePasswordDataSourceCredential(); + } + else if (dataSource is RVNativeAnalysisServicesDataSource) + { + userCredential = new RVUsernamePasswordDataSourceCredential("username", "password", "domain"); + } + return Task.FromResult(userCredential); + } + } +} diff --git a/e2e/Sandbox/Reveal/DataSourceProvider.cs b/e2e/Sandbox/Reveal/DataSourceProvider.cs new file mode 100644 index 0000000..a75caa4 --- /dev/null +++ b/e2e/Sandbox/Reveal/DataSourceProvider.cs @@ -0,0 +1,65 @@ +using Reveal.Sdk.Data.Json; +using Reveal.Sdk.Data.Microsoft.SqlServer; +using Reveal.Sdk.Data.Rest; +using Reveal.Sdk.Data; +using System.Threading.Tasks; +using Reveal.Sdk.Data.Excel; + +namespace Sandbox.RevealSDK +{ + public class DataSourceProvider : IRVDataSourceProvider + { + public Task ChangeDataSourceItemAsync(RVDataSourceItem dataSourceItem) + { + //if (dataSourceItem is RVJsonDataSourceItem jsonDataSourceItem) + //{ + // var restDataSourceItem = jsonDataSourceItem.ResourceItem as RVRESTDataSourceItem; + // var ds = restDataSourceItem.DataSource as RVRESTDataSource; + // ds.UseAnonymousAuthentication = true; + // ds.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; + //} + + //if (dataSourceItem is RVExcelDataSourceItem excelDataSourceItem) + //{ + // if (excelDataSourceItem.Id == "MarketingID") + // { + // excelDataSourceItem.Sheet = "Marketing"; + // } + + // var restDataSourceItem = excelDataSourceItem.ResourceItem as RVRESTDataSourceItem; + // if (restDataSourceItem != null) + // { + // if (restDataSourceItem.Id == "MarketingID") + // { + // excelDataSourceItem.Sheet = "Marketing"; + // } + // var ds = restDataSourceItem.DataSource as RVRESTDataSource; + // ds.UseAnonymousAuthentication = true; + + // if (ds.Id == "RestExcel") + // { + // ds.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; + // } + // } + + // var webResourceItem = excelDataSourceItem.ResourceItem as RVWebResourceDataSourceItem; + // if (webResourceItem != null) + // { + // webResourceItem.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; + // } + //} + + //if (dataSourceItem is RVSqlServerDataSourceItem sqlServerDataSourceItem) + //{ + // sqlServerDataSourceItem.Table = "Customers"; + // sqlServerDataSourceItem.Database = "Northwind"; + + // var ds = sqlServerDataSourceItem.DataSource as RVSqlServerDataSource; + // ds.Host = "Brian-Desktop\\SQLEXPRESS"; + // ds.Database = "Northwind"; + //} + + return Task.FromResult(dataSourceItem); + } + } +} diff --git a/src/Reveal.Sdk.Dom.Tests/Core/Utilities/RdashDocumentValidatorFixture.cs b/src/Reveal.Sdk.Dom.Tests/Core/Utilities/RdashDocumentValidatorFixture.cs index f0265e0..e0e76ed 100644 --- a/src/Reveal.Sdk.Dom.Tests/Core/Utilities/RdashDocumentValidatorFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Core/Utilities/RdashDocumentValidatorFixture.cs @@ -1,70 +1,70 @@ -using Reveal.Sdk.Dom.Core.Utilities; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Visualizations; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Reveal.Sdk.Dom.Tests.Core.Utilities -{ - public class RdashDocumentValidatorFixture - { - [Fact] - public void DataSources_AddedToRdashDocument() - { - var dataSourceItem = new RestServiceBuilder("").SetFields(new List() { null }).Build(); - - var document = new RdashDocument(); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - - Assert.Empty(document.DataSources); - - RdashDocumentValidator.FixDocument(document); - - Assert.True(document.DataSources.Skip(1).Any()); - } - - [Fact] - public void DataSources_FromVisualizationsAreNotDuplicated() - { - var dataSourceItem = new RestServiceBuilder("").SetFields(new List() { null }).Build(); - - var document = new RdashDocument(); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - - Assert.Empty(document.DataSources); - - RdashDocumentValidator.FixDocument(document); - - var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON); - - Assert.Single(jsonDataSources); - } - - [Fact] - public void DataSources_FromVisualizations_AndDataSources_AreNotDuplicated() - { - var dataSourceItem = new RestServiceBuilder("").SetFields(new List() { null }).Build(); - var dataSource = dataSourceItem.DataSource; - - var document = new RdashDocument(); - document.DataSources.Add(dataSource); - - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); - - Assert.Single(document.DataSources); - - RdashDocumentValidator.FixDocument(document); - - var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON); - - Assert.Single(jsonDataSources); - } - } -} +using Reveal.Sdk.Dom.Core.Utilities; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Reveal.Sdk.Dom.Tests.Core.Utilities +{ + public class RdashDocumentValidatorFixture + { + [Fact] + public void DataSources_AddedToRdashDocument() + { + var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").Fields(new List() { null }).Build(); + + var document = new RdashDocument(); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + + Assert.Empty(document.DataSources); + + RdashDocumentValidator.FixDocument(document); + + Assert.True(document.DataSources.Skip(1).Any()); + } + + [Fact] + public void DataSources_FromVisualizationsAreNotDuplicated() + { + var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").Fields(new List() { null }).Build(); + + var document = new RdashDocument(); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + + Assert.Empty(document.DataSources); + + RdashDocumentValidator.FixDocument(document); + + var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON); + + Assert.Single(jsonDataSources); + } + + [Fact] + public void DataSources_FromVisualizations_AndDataSources_AreNotDuplicated() + { + var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").Fields(new List() { null }).Build(); + var dataSource = dataSourceItem.DataSource; + + var document = new RdashDocument(); + document.DataSources.Add(dataSource); + + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + + Assert.Single(document.DataSources); + + RdashDocumentValidator.FixDocument(document); + + var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON); + + Assert.Single(jsonDataSources); + } + } +} diff --git a/src/Reveal.Sdk.Dom.Tests/RdashDocumentFixture.cs b/src/Reveal.Sdk.Dom.Tests/RdashDocumentFixture.cs index acd60c7..8f237b8 100644 --- a/src/Reveal.Sdk.Dom.Tests/RdashDocumentFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/RdashDocumentFixture.cs @@ -1,202 +1,262 @@ -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Schema; -using Reveal.Sdk.Dom.Core.Constants; -using System; -using System.IO; -using Xunit; - -namespace Reveal.Sdk.Dom.Tests -{ - public class RdashDocumentFixture - { - [Fact] - public void NewDashboard_SetsTitle() - { - // Arrange - string title = "TestTitle"; - - // Act - RdashDocument document = new RdashDocument(title); - - //Assert - Assert.Equal(title, document.Title); - } - - [Fact] - public void NewDashboard_SetsDefaultValues() - { - var dashboard = new RdashDocument(); - - Assert.Equal("New Dashboard", dashboard.Title); - Assert.Equal(GlobalConstants.RdashDocument.CreatedWith, dashboard.CreatedWith); - Assert.Equal(string.Empty, dashboard.SavedWith); - Assert.Equal(Theme.Mountain, dashboard.Theme); - Assert.Null(dashboard.Tags); - Assert.Equal(6, dashboard.FormatVersion); - Assert.True(dashboard.UseAutoLayout); - - Assert.NotNull(dashboard.DataSources); - Assert.Empty(dashboard.DataSources); - - Assert.NotNull(dashboard.Filters); - Assert.Empty(dashboard.Filters); - - Assert.NotNull(dashboard.Visualizations); - Assert.Empty(dashboard.Visualizations); - } - - [Fact] - public void Load_SetsProperties() - { - var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "Sales.rdash"); - var document = RdashDocument.Load(filePath); - - Assert.NotNull(document); - - Assert.NotNull(document.Title); - Assert.NotEqual(GlobalConstants.RdashDocument.CreatedWith, document.CreatedWith); - Assert.NotEqual(string.Empty, document.SavedWith); - Assert.Equal(Theme.Mountain, document.Theme); - Assert.NotNull(document.Tags); - Assert.Equal(6, document.FormatVersion); - Assert.False(document.UseAutoLayout); - Assert.NotEmpty(document.DataSources); - Assert.NotEmpty(document.Filters); - Assert.NotEmpty(document.Visualizations); - } - - [Fact] - public void ToJsonString_IsValidSchema() - { - var schemaJson = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Schemas", "RdashDocument.json")); - var schema = JSchema.Parse(schemaJson); - - var dashboard = new RdashDocument() - { - Title = "New Dashboard", - Description = "This is a test dashboard", - Theme = Theme.Aurora, - Tags = "tag1,tag2,tag3" - }; - var json = dashboard.ToJsonString(); - - var jsonDocument = JObject.Parse(json); - - bool isValid = jsonDocument.IsValid(schema); - - Assert.True(isValid); - } - - [Fact] - public void Save_SavesFile() - { - var filePath = Path.Combine(Path.GetTempPath(), $"{Path.GetTempFileName()}.rdash"); - - try - { - var dashboard = new RdashDocument(); - - if (File.Exists(filePath)) - File.Delete(filePath); - - dashboard.Save(filePath); - - Assert.Equal("Reveal.Sdk.Dom", dashboard.SavedWith); - Assert.True(File.Exists(filePath)); - } - catch - { - throw; - } - finally - { - if (File.Exists(filePath)) - File.Delete(filePath); - } - } - - [Fact] - public void SettingDescription_SetsDescriptionValue() - { - // Arrange - var dashboard = new RdashDocument(); - var description = "This is a test description"; - - // Act - dashboard.Description = description; - - // Assert - Assert.Equal(description, dashboard.Description); - } - - [Fact] - public void SettingSavedWith_SetsSavedWithValue() - { - // Arrange - var dashboard = new RdashDocument(); - var savedWith = "Custom Test Version 1.0"; - - // Act - dashboard.SavedWith = savedWith; - - // Assert - Assert.Equal(savedWith, dashboard.SavedWith); - } - - [Fact] - public void SettingTheme_SetsThemeValue() - { - // Arrange - var dashboard = new RdashDocument(); - var theme = Theme.Ocean; - - // Act - dashboard.Theme = theme; - - // Assert - Assert.Equal(theme, dashboard.Theme); - } - - [Fact] - public void SettingTags_SetsTagsValue() - { - // Arrange - var dashboard = new RdashDocument(); - var tags = "tag1,tag2,tag3,tag4"; - - // Act - dashboard.Tags = tags; - - // Assert - Assert.Equal(tags, dashboard.Tags); - } - - [Fact] - public void SettingFormatVersion_SetsFormatVersionValue() - { - // Arrange - var dashboard = new RdashDocument(); - var formatVersion = 7; - - // Act - dashboard.FormatVersion = formatVersion; - - // Assert - Assert.Equal(formatVersion, dashboard.FormatVersion); - } - - [Fact] - public void SettingUseAutoLayout_SetsUseAutoLayoutValue() - { - // Arrange - var dashboard = new RdashDocument(); - var useAutoLayout = false; - - // Act - dashboard.UseAutoLayout = useAutoLayout; - - // Assert - Assert.Equal(useAutoLayout, dashboard.UseAutoLayout); - } - } -} +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Schema; +using Reveal.Sdk.Dom.Core.Constants; +using Reveal.Sdk.Dom.Core.Utilities; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; +using System.IO; +using Xunit; + +namespace Reveal.Sdk.Dom.Tests +{ + public class RdashDocumentFixture + { + [Fact] + public void RdashDocument_DefaultConstructor_ShouldSetDefaultValues() + { + // Arrange + var document = new RdashDocument(); + + // Act + + // Assert + Assert.Equal("New Dashboard", document.Title); + Assert.Null(document.Description); + Assert.Equal(Theme.Mountain, document.Theme); + Assert.Equal(GlobalConstants.RdashDocument.CreatedWith, document.CreatedWith); + Assert.Equal(string.Empty, document.SavedWith); + Assert.Equal(6, document.FormatVersion); + Assert.True(document.UseAutoLayout); + Assert.Null(document.Tags); + Assert.Empty(document.DataSources); + Assert.Empty(document.Filters); + Assert.Empty(document.GlobalVariables); + Assert.Empty(document.Visualizations); + } + + [Fact] + public void RdashDocument_TitleConstructor_ShouldSetTitle() + { + // Arrange + var title = "My Dashboard"; + + // Act + var document = new RdashDocument(title); + + // Assert + Assert.Equal(title, document.Title); + } + + [Fact] + public void RdashDocument_Import_ShouldImportVisualizations() + { + // Arrange + var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").Fields(new List() { null }).Build(); + + var sourceDocument = new RdashDocument(); + sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + + // Ensure data sources are added to the data sources collection + RdashDocumentValidator.FixDocument(sourceDocument); + + // Act + var document = new RdashDocument(); + document.Import(sourceDocument); + + // Assert + Assert.Equal(3, document.Visualizations.Count); + Assert.Contains(sourceDocument.Visualizations[0], document.Visualizations); + Assert.Contains(sourceDocument.Visualizations[1], document.Visualizations); + Assert.Contains(sourceDocument.Visualizations[2], document.Visualizations); + Assert.Equal(2, document.DataSources.Count); + } + + [Fact] + public void RdashDocument_Import_ShouldImportSingleVisualization() + { + // Arrange + var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "").Fields(new List() { null }).Build(); + + var sourceDocument = new RdashDocument(); + sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + sourceDocument.Visualizations.Add(new KpiTimeVisualization(dataSourceItem)); + + // Ensure data sources are added to the data sources collection + RdashDocumentValidator.FixDocument(sourceDocument); + + // Act + var document = new RdashDocument(); + document.Import(sourceDocument, sourceDocument.Visualizations[1].Id); + + // Assert + Assert.Single(document.Visualizations); + Assert.Equal(sourceDocument.Visualizations[1], document.Visualizations[0]); + Assert.Equal(2, document.DataSources.Count); + } + + [Fact] + public void RdashDocument_Import_WithNullDocument_ShouldThrowArgumentNullException() + { + // Arrange + var document = new RdashDocument(); + RdashDocument sourceDocument = null; + + // Act & Assert + Assert.Throws(() => document.Import(sourceDocument)); + } + + [Fact] + public void RdashDocument_Import_WithNullVisualizationId_ShouldThrowArgumentException() + { + // Arrange + var document = new RdashDocument(); + var sourceDocument = new RdashDocument(); + var visualizationId = string.Empty; + + // Act & Assert + Assert.Throws(() => document.Import(sourceDocument, visualizationId)); + } + + [Fact] + public void RdashDocument_Import_WithNullVisualization_ShouldThrowArgumentNullException() + { + // Arrange + var document = new RdashDocument(); + var sourceDocument = new RdashDocument(); + IVisualization visualization = null; + + // Act & Assert + Assert.Throws(() => document.Import(sourceDocument, visualization)); + } + + [Fact] + public void RdashDocument_Load_WithFilePath_ShouldLoadDocumentFromFile() + { + // Arrange + var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "Sales.rdash"); + + // Act + var document = RdashDocument.Load(filePath); + + // Assert + Assert.NotNull(document); + // Add more assertions based on the expected content of the loaded document + } + + [Fact] + public void RdashDocument_Load_WithStream_ShouldLoadDocumentFromStream() + { + // Arrange + var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "Sales.rdash"); + var stream = File.OpenRead(filePath); + + // Act + var document = RdashDocument.Load(stream); + + // Assert + Assert.NotNull(document); + // Add more assertions based on the expected content of the loaded document + } + + [Fact] + public void RdashDocument_LoadFromJson_ShouldLoadDocumentFromJsonString() + { + // Arrange + var json = "{\"Title\":\"My Dashboard\",\"ThemeName\":\"Mountain\"}"; + + // Act + var document = RdashDocument.LoadFromJson(json); + + // Assert + Assert.NotNull(document); + Assert.Equal("My Dashboard", document.Title); + Assert.Equal(Theme.Mountain, document.Theme); + // Add more assertions based on the expected content of the loaded document + } + + [Fact] + public void RdashDocument_Save_ShouldSaveDocumentToFile() + { + var filePath = Path.Combine(Path.GetTempPath(), $"{Path.GetTempFileName()}.rdash"); + + try + { + var dashboard = new RdashDocument(); + + if (File.Exists(filePath)) + File.Delete(filePath); + + dashboard.Save(filePath); + + Assert.Equal("Reveal.Sdk.Dom", dashboard.SavedWith); + Assert.True(File.Exists(filePath)); + } + catch + { + throw; + } + finally + { + if (File.Exists(filePath)) + File.Delete(filePath); + } + } + + [Fact] + public void RdashDocument_ToJsonString_ShouldReturnJsonStringRepresentation() + { + // Arrange + var document = new RdashDocument(); + string expectedJson = @" + { + ""Title"": ""New Dashboard"", + ""ThemeName"": ""rvDashboardMountainTheme"", + ""CreatedWith"": ""Reveal.Sdk.Dom"", + ""SavedWith"": """", + ""FormatVersion"": 6, + ""UseAutoLayout"": true, + ""DataSources"": [], + ""GlobalFilters"": [], + ""GlobalVariables"": [], + ""Widgets"": [] + }"; + + // Act + var jsonString = document.ToJsonString(); + + // Deserialize JSON strings to JObjects to make comparing them easier + var expectedJObject = JObject.Parse(expectedJson); + var actualJObject = JObject.Parse(jsonString); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } + + [Fact] + public void ToJsonString_IsValidSchema() + { + var schemaJson = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Schemas", "RdashDocument.json")); + var schema = JSchema.Parse(schemaJson); + + var dashboard = new RdashDocument() + { + Title = "New Dashboard", + Description = "This is a test dashboard", + Theme = Theme.Aurora, + Tags = "tag1,tag2,tag3" + }; + var json = dashboard.ToJsonString(); + + var jsonDocument = JObject.Parse(json); + + bool isValid = jsonDocument.IsValid(schema); + + Assert.True(isValid); + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/DataSourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceItemBuilder.cs new file mode 100644 index 0000000..6f83e14 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceItemBuilder.cs @@ -0,0 +1,90 @@ +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; + +namespace Reveal.Sdk.Dom.Data +{ + public abstract class DataSourceItemBuilder : IDataSourceItemBuilder + { + protected DataSource DataSource { get; set; } + protected DataSourceItem DataSourceItem { get; set; } + + public DataSourceItemBuilder(DataSourceProvider provider, string title) : + this(new DataSource(), provider, title) + { } + + public DataSourceItemBuilder(DataSource dataSource, DataSourceProvider provider, string title) + { + InitializeDataSource(dataSource, provider, title); + InitializeDataSourceItem(title); + } + + public virtual DataSourceItem Build() + { + //todo: need to revist to support xmla data sources + //fields is only used for tabular data sources + 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 virtual IDataSourceItemBuilder Id(string id) + { + DataSourceItem.Id = id; + return this; + } + + public virtual IDataSourceItemBuilder Fields(IEnumerable fields) + { + DataSourceItem.Fields.Clear(); + DataSourceItem.Fields.AddRange(fields); + return this; + } + + public virtual IDataSourceItemBuilder Fields(params IField[] fields) + { + return Fields((IEnumerable)fields); + } + + public virtual IDataSourceItemBuilder Subtitle(string subtitle) + { + DataSourceItem.Subtitle = subtitle; + if (string.IsNullOrEmpty(DataSource.Subtitle)) + DataSource.Subtitle = subtitle; + + return this; + } + + public virtual IDataSourceItemBuilder ConfigureDataSource(Action configureDataSource) + { + configureDataSource.Invoke(DataSource); + UpdateDataSourceId(DataSource.Id); + return this; + } + + protected void UpdateDataSourceId(string id) + { + DataSource.Id = id; + DataSourceItem.DataSourceId = id; + } + + private void InitializeDataSource(DataSource dataSource, DataSourceProvider provider, string title) + { + DataSource = dataSource ?? new DataSource(); + DataSource.Provider = provider; // //todo: maybe this shouldn't go here. Each specific builder should be responsible for setting the provider + if (string.IsNullOrEmpty(DataSource.Title)) + DataSource.Title = title; + } + + private void InitializeDataSourceItem(string title) + { + DataSourceItem = new DataSourceItem + { + DataSource = DataSource, + DataSourceId = DataSource.Id, + Title = title, + }; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/DataSourceResourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceResourceItemBuilder.cs new file mode 100644 index 0000000..765e0dd --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceResourceItemBuilder.cs @@ -0,0 +1,32 @@ +namespace Reveal.Sdk.Dom.Data +{ + public abstract class DataSourceResourceItemBuilder : DataSourceItemBuilder + { + protected DataSource ResourceItemDataSource { get; private set; } //resource item data source + protected DataSourceItem ResourceItem { get; private set; } //resource item that points to the data source + + public DataSourceResourceItemBuilder(DataSourceProvider dataSourceProvider, DataSourceProvider resourceItemDataSourceProvider, string title) : + this(new DataSource(), dataSourceProvider, resourceItemDataSourceProvider, title) + { } + + public DataSourceResourceItemBuilder(DataSource dataSource, DataSourceProvider dataSourceProvider, DataSourceProvider resourceItemDataSourceProvider, string title) : + base(dataSource, dataSourceProvider, title) + { + InitializeResourceItem(resourceItemDataSourceProvider, title); + } + + private void InitializeResourceItem(DataSourceProvider resourceItemDataSourceProvider, string title) + { + ResourceItemDataSource = new DataSource { Provider = resourceItemDataSourceProvider }; + ResourceItem = new DataSourceItem + { + DataSource = ResourceItemDataSource, + DataSourceId = ResourceItemDataSource.Id, + Title = title + }; + + DataSourceItem.ResourceItemDataSource = ResourceItemDataSource; + DataSourceItem.ResourceItem = ResourceItem; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs b/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs index cc9a067..92d8186 100644 --- a/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs +++ b/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs @@ -2,7 +2,6 @@ { public enum DataSourceType { - RemoteFile, REST, MicrosoftSqlServer } diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Extensions/IDataSourceBuilderExtensions.cs b/src/Reveal.Sdk.Dom/Data/Builders/Extensions/IDataSourceBuilderExtensions.cs new file mode 100644 index 0000000..c61d8cf --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Extensions/IDataSourceBuilderExtensions.cs @@ -0,0 +1,10 @@ +namespace Reveal.Sdk.Dom.Data +{ + public static class IDataSourceBuilderExtensions + { + public static T As(this IDataSourceItemBuilder builder) where T : class, IDataSourceItemBuilder + { + return builder as T; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceItemBuilder.cs new file mode 100644 index 0000000..2a8dbba --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceItemBuilder.cs @@ -0,0 +1,16 @@ +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; + +namespace Reveal.Sdk.Dom.Data +{ + public interface IDataSourceItemBuilder + { + IDataSourceItemBuilder Id(string id); + IDataSourceItemBuilder Fields(IEnumerable fields); + IDataSourceItemBuilder Fields(params IField[] fields); + IDataSourceItemBuilder Subtitle(string subtitle); + IDataSourceItemBuilder ConfigureDataSource(Action configureDataSource); + DataSourceItem Build(); + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestDataSourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestDataSourceItemBuilder.cs new file mode 100644 index 0000000..e8149c8 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestDataSourceItemBuilder.cs @@ -0,0 +1,11 @@ +namespace Reveal.Sdk.Dom.Data +{ + public interface IRestDataSourceItemBuilder : IDataSourceItemBuilder + { + IRestDataSourceItemBuilder AddHeader(HeaderType headerType, string value); + IRestDataSourceItemBuilder IsAnonymous(bool isAnonymous); + IRestDataSourceItemBuilder UseCsv(); + IRestDataSourceItemBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx); + IRestDataSourceItemBuilder Uri(string uri); + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/ISqlDataSourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/ISqlDataSourceItemBuilder.cs new file mode 100644 index 0000000..122ba32 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/ISqlDataSourceItemBuilder.cs @@ -0,0 +1,10 @@ +namespace Reveal.Sdk.Dom.Data +{ + public interface ISqlDataSourceItemBuilder : IDataSourceItemBuilder + { + ISqlDataSourceItemBuilder Database(string database); + ISqlDataSourceItemBuilder Host(string host); + ISqlDataSourceItemBuilder Schema(string schema); + ISqlDataSourceItemBuilder Table(string table); + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RestDataSourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RestDataSourceItemBuilder.cs new file mode 100644 index 0000000..5c7200d --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/RestDataSourceItemBuilder.cs @@ -0,0 +1,164 @@ +using Reveal.Sdk.Dom.Core.Constants; +using Reveal.Sdk.Dom.Core.Extensions; +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Reveal.Sdk.Dom.Data +{ + public class RestDataSourceItemBuilder : DataSourceResourceItemBuilder, IRestDataSourceItemBuilder + { + //bug: the url is required on the client or it won't work + + DataSource _dataSource; + + public RestDataSourceItemBuilder(string title) : + this(new DataSource(), title) + { } + + public RestDataSourceItemBuilder(DataSource dataSource, string title) : + base(null, DataSourceProvider.JSON, DataSourceProvider.REST, title) + { + _dataSource = dataSource ?? new DataSource(); + DataSource.Id = DataSourceIds.JSON; + DataSourceItem.DataSourceId = DataSource.Id; + UpdateResourceItemDataSource(_dataSource); + } + + public override IDataSourceItemBuilder Fields(IEnumerable fields) + { + DataSourceItem.Parameters.Add("config", BuildConfig(fields)); + return base.Fields(fields); + } + + public IRestDataSourceItemBuilder 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 IRestDataSourceItemBuilder IsAnonymous(bool isAnonymous) + { + ResourceItemDataSource.Properties.SetItem("_rpUseAnonymousAuthentication", isAnonymous); + return this; + } + + public IRestDataSourceItemBuilder UseCsv() + { + ClearJsonConfig(); + UpdateDataSourceId(DataSourceIds.CSV); + DataSource.Provider = DataSourceProvider.CSV; + ResourceItemDataSource.Properties.SetItem("Result-Type", ".csv"); + return this; + } + + public IRestDataSourceItemBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx) + { + ClearJsonConfig(); + UpdateDataSourceId(DataSourceIds.Excel); + DataSource.Provider = DataSourceProvider.MicrosoftExcel; + + var fileExt = fileType == ExcelFileType.Xlsx ? ".xlsx" : ".xls"; + ResourceItemDataSource.Properties.SetItem("Result-Type", fileExt); + + if (sheet != null) + DataSourceItem.Properties.SetItem("Sheet", sheet); + + return this; + } + + public IRestDataSourceItemBuilder Uri(string uri) + { + ResourceItem.Properties.SetItem("Url", uri); + ResourceItemDataSource.Properties.SetItem("Url", uri); + return this; + } + + public override IDataSourceItemBuilder Id(string id) + { + ResourceItem.Id = id; + return this; + } + + public override IDataSourceItemBuilder Subtitle(string subtitle) + { + base.Subtitle(subtitle); + ResourceItem.Subtitle = subtitle; + return this; + } + + public override IDataSourceItemBuilder ConfigureDataSource(Action configureDataSource) + { + configureDataSource.Invoke(_dataSource); + UpdateResourceItemDataSource(_dataSource); + return this; + } + + //todo: this may need to go on the base class. wait until more builders are created + private void UpdateResourceItemDataSource(DataSource dataSource) + { + ResourceItemDataSource.Id = dataSource.Id; + ResourceItemDataSource.Title = dataSource.Title ?? ResourceItem.Title; + ResourceItemDataSource.Subtitle = dataSource.Subtitle ?? ResourceItem.Subtitle; + ResourceItem.DataSourceId = ResourceItemDataSource.Id; + } + + 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; + } + + void ClearJsonConfig() + { + if (DataSourceItem.Parameters.ContainsKey("config")) + DataSourceItem.Parameters.Remove("config"); + } + + string AddDashesToEnumName(string name) + { + return string.Concat(name.Select(x => char.IsUpper(x) ? "-" + x : x.ToString())).TrimStart('-'); + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs deleted file mode 100644 index 833f7f9..0000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs +++ /dev/null @@ -1,174 +0,0 @@ -using Reveal.Sdk.Dom.Core.Constants; -using Reveal.Sdk.Dom.Visualizations; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Reveal.Sdk.Dom.Data -{ - public sealed class RestServiceBuilder - { - readonly DataSource _dataSource = new DataSource() { Id = DataSourceIds.JSON, Provider = DataSourceProvider.JSON }; //data source - readonly DataSourceItem _dataSourceItem = new DataSourceItem(); //data source item that points to the data source - 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 RestServiceBuilder(string uri) - { - _dataSourceItem.DataSource = _dataSource; - _dataSourceItem.DataSourceId = _dataSource.Id; - _dataSourceItem.HasTabularData = true; - - _resourceItemDataSource.Properties.Add("_rpUseAnonymousAuthentication", true); - _resourceItemDataSource.Properties.Add("Url", uri); - _resourceItemDataSource.Properties.Add("Method", "GET"); - _resourceItemDataSource.Properties.Add("Result-Type", ".json"); - - _dataSourceItem.ResourceItemDataSource = _resourceItemDataSource; - _resourceItem.DataSourceId = _resourceItemDataSource.Id; - - _resourceItem.Properties.Add("Url", uri); - _dataSourceItem.ResourceItem = _resourceItem; - } - - - public RestServiceBuilder IsAnonymous(bool isAnonymous) - { - _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; - return this; - } - - public RestServiceBuilder SetFields(IEnumerable fields) - { - _dataSourceItem.Fields.Clear(); - _dataSourceItem.Fields.AddRange(fields); - - _dataSourceItem.Parameters.Add("config", BuildConfig(fields)); - - return this; - } - - public RestServiceBuilder SetTitle(string title) - { - _dataSourceItem.Title = title; - _resourceItem.Title = title; - _resourceItemDataSource.Title = title; - return this; - } - - public RestServiceBuilder SetSubtitle(string subtitle) - { - _dataSourceItem.Subtitle = subtitle; - return this; - } - - 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 RestServiceBuilder 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 RestServiceBuilder UseCsv() - { - ClearJsonConfig(); - - _dataSource.Id = DataSourceIds.CSV; - _dataSource.Provider = DataSourceProvider.CSV; - _resourceItemDataSource.Properties["Result-Type"] = ".csv"; - - _dataSourceItem.DataSourceId = _dataSource.Id; - - return this; - } - - public RestServiceBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx) - { - ClearJsonConfig(); - - _dataSource.Id = DataSourceIds.Excel; - _dataSource.Provider = DataSourceProvider.MicrosoftExcel; - - var fileExt = fileType == ExcelFileType.Xlsx ? ".xlsx" : ".xls"; - _resourceItemDataSource.Properties["Result-Type"] = fileExt; - - 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; - } - - 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; - } - - void ClearJsonConfig() - { - if (_dataSourceItem.Parameters.ContainsKey("config")) - _dataSourceItem.Parameters.Remove("config"); - } - - string AddDashesToEnumName(string name) - { - return string.Concat(name.Select(x => char.IsUpper(x) ? "-" + x : x.ToString())).TrimStart('-'); - } - } -} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/SqlDataSourceItemBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/SqlDataSourceItemBuilder.cs new file mode 100644 index 0000000..a8ce4b3 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/SqlDataSourceItemBuilder.cs @@ -0,0 +1,44 @@ +using Reveal.Sdk.Dom.Core.Extensions; + +namespace Reveal.Sdk.Dom.Data +{ + public class SqlDataSourceItemBuilder : DataSourceItemBuilder, ISqlDataSourceItemBuilder + { + //bug: if the database is not provided, the DSI Title will not be shown in the UI + + //todo: support more sql based connectors + public SqlDataSourceItemBuilder(DataSource dataSource, string title) : + base(dataSource, DataSourceProvider.MicrosoftSqlServer, title) + { + Schema("dbo"); + DataSource.Properties.SetItem("ServerAggregationDefault", true); + DataSource.Properties.SetItem("ServerAggregationReadOnly", false); + DataSourceItem.Properties.SetItem("ServerAggregation", true); + } + + public ISqlDataSourceItemBuilder Database(string database) + { + DataSource.Properties.SetItem("Database", database); + DataSourceItem.Properties.SetItem("Database", database); + return this; + } + + public ISqlDataSourceItemBuilder Host(string host) + { + DataSource.Properties.SetItem("Host", host); + return this; + } + + public ISqlDataSourceItemBuilder Schema(string schema) + { + DataSourceItem.Properties.SetItem("Schema", schema); + return this; + } + + public ISqlDataSourceItemBuilder Table(string table) + { + DataSourceItem.Properties.SetItem("Table", table); + return this; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs deleted file mode 100644 index da2f1eb..0000000 --- a/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs +++ /dev/null @@ -1,79 +0,0 @@ -using Reveal.Sdk.Dom.Core.Constants; -using Reveal.Sdk.Dom.Core.Extensions; -using Reveal.Sdk.Dom.Visualizations; -using System; -using System.Collections.Generic; - -namespace Reveal.Sdk.Dom.Data -{ - public sealed class SqlServerBuilder - { - readonly DataSource _dataSource = new DataSource() { Provider = DataSourceProvider.MicrosoftSqlServer }; //data source - readonly DataSourceItem _dataSourceItem = new DataSourceItem(); //data source item that points to the data source - - public SqlServerBuilder(string host, string database, string table) - { - _dataSourceItem.DataSource = _dataSource; - _dataSourceItem.DataSourceId = _dataSource.Id; - - SetHost(host); - SetDatabase(database); - SetTable(table); - SetSchema("dbo"); - } - - public SqlServerBuilder SetDatabase(string database) - { - _dataSource.Properties.SetItem("Database", database); - _dataSourceItem.Properties.SetItem("Database", database); - return this; - } - - public SqlServerBuilder SetFields(IEnumerable fields) - { - _dataSourceItem.Fields.Clear(); - _dataSourceItem.Fields.AddRange(fields); - return this; - } - - public SqlServerBuilder SetHost(string host) - { - _dataSource.Properties.SetItem("Host", host); - return this; - } - - public SqlServerBuilder SetSchema(string schema) - { - _dataSourceItem.Properties.SetItem("Schema", schema); - return this; - } - - public SqlServerBuilder SetTable(string table) - { - _dataSourceItem.Properties.SetItem("Table", table); - return this; - } - - public SqlServerBuilder SetTitle(string title) - { - _dataSource.Title = title; - _dataSourceItem.Title = title; - return this; - } - - public SqlServerBuilder SetSubtitle(string subtitle) - { - _dataSource.Subtitle = subtitle; - _dataSourceItem.Subtitle = subtitle; - return this; - } - - 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; - } - } -} diff --git a/src/Reveal.Sdk.Dom/Data/DataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSource.cs index 4f1c609..22a8867 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSource.cs @@ -9,25 +9,30 @@ namespace Reveal.Sdk.Dom.Data { public sealed class DataSource : SchemaType, IEquatable { - public string Id { get; set; } = Guid.NewGuid().ToString(); + private string _id = Guid.NewGuid().ToString(); + + public DataSource() + { + SchemaTypeName = SchemaTypeNames.DataSourceType; + Properties = new Dictionary(); + } + + public string Id + { + get => _id; + set => _id = string.IsNullOrEmpty(value) ? Guid.NewGuid().ToString() : value; //do not allow a null Id + } [JsonProperty] [JsonConverter(typeof(StringEnumConverter))] - public DataSourceProvider Provider { get; internal set; } + public DataSourceProvider Provider { get; internal set; } //todo: can this be internal? [JsonProperty("Description")] public string Title { get; set; } public string Subtitle { get; set; } - - public Dictionary Properties { get; internal set; } - - public DataSource() - { - SchemaTypeName = SchemaTypeNames.DataSourceType; - Properties = new Dictionary(); - } + public Dictionary Properties { get; internal set; } //todo: can this be internal? public override bool Equals(object obj) { diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItem.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItem.cs index 6acc3b6..90c4e66 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSourceItem.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItem.cs @@ -9,15 +9,27 @@ namespace Reveal.Sdk.Dom.Data { public sealed class DataSourceItem : SchemaType { - public string Id { get; set; } = Guid.NewGuid().ToString(); + private string _id = Guid.NewGuid().ToString(); + + public DataSourceItem() + { + SchemaTypeName = SchemaTypeNames.DataSourceItemType; + } + + public string Id + { + get => _id; + set => _id = string.IsNullOrEmpty(value) ? Guid.NewGuid().ToString() : value; //do not allow a null Id + } + public string Title { get; set; } public string Subtitle { get; set; } - public string DataSourceId { get; set; } - public bool HasTabularData { get; set; } = true; - public bool HasAsset { get; set; } - public Dictionary Properties { get; set; } = new Dictionary(); - public Dictionary Parameters { get; set; } = new Dictionary(); - public DataSourceItem ResourceItem { get; set; } + public string DataSourceId { get; set; } //todo: can this be internal? + public bool HasTabularData { get; set; } = true; //todo: can this be internal? + public bool HasAsset { get; set; } //todo: can this be internal? + public Dictionary Properties { get; set; } = new Dictionary(); //todo: can this be internal? + public Dictionary Parameters { get; set; } = new Dictionary(); //todo: can this be internal? + public DataSourceItem ResourceItem { get; set; } //todo: can this be internal? [JsonIgnore] internal List Fields { get; set; } = new List(); @@ -35,10 +47,5 @@ public sealed class DataSourceItem : SchemaType /// [JsonIgnore] internal DataSource ResourceItemDataSource { get; set; } - - public DataSourceItem() - { - SchemaTypeName = SchemaTypeNames.DataSourceItemType; - } } } diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs b/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs new file mode 100644 index 0000000..342dc13 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/DataSourceItemFactory.cs @@ -0,0 +1,29 @@ +using System; + +namespace Reveal.Sdk.Dom.Data +{ + public interface IDataSourceItemFactory + { + IDataSourceItemBuilder Create(DataSourceType type, string title); + + IDataSourceItemBuilder Create(DataSourceType type, DataSource dataSource, string title); + } + + public class DataSourceItemFactory : IDataSourceItemFactory + { + public IDataSourceItemBuilder Create(DataSourceType type, string title) + { + return Create(type, new DataSource(), title); + } + + public IDataSourceItemBuilder Create(DataSourceType type, DataSource dataSource, string title) + { + return type switch + { + DataSourceType.MicrosoftSqlServer => new SqlDataSourceItemBuilder(dataSource, title), + DataSourceType.REST => new RestDataSourceItemBuilder(dataSource, title), + _ => throw new NotImplementedException($"No builder implemented for provider: {type}") + }; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Visualizations/TabularVisualizationBase.cs b/src/Reveal.Sdk.Dom/Visualizations/TabularVisualizationBase.cs deleted file mode 100644 index e3ed379..0000000 --- a/src/Reveal.Sdk.Dom/Visualizations/TabularVisualizationBase.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Newtonsoft.Json; -using Reveal.Sdk.Dom.Core; -using Reveal.Sdk.Dom.Core.Utilities; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Filters; -using Reveal.Sdk.Dom.Visualizations.Settings; -using System.Collections.Generic; -using System.Linq; - -namespace Reveal.Sdk.Dom.Visualizations -{ - //public abstract class TabularVisualizationBase : Visualization, ITabularVisualization - // where TSettings : VisualizationSettings, new() - //{ - // protected TabularVisualizationBase(string title, DataSourceItem dataSourceItem) : base(title) - // { - // DataDefinition = new TabularDataDefinition(); - // UpdateDataSourceItem(dataSourceItem); - // } - - // [JsonIgnore] - // public List Filters - // { - // get { return DataDefinition.QuickFilters; } - // } - - // /// - // /// Gets the data source item for the visualization. - // /// - // /// The - // public DataSourceItem GetDataSourceItem() - // { - // var dataSourceItem = DataDefinition.DataSourceItem; - // dataSourceItem.Fields = DataDefinition.Fields.Clone(); - - // IParentDocument viz = this; - // dataSourceItem.DataSource = viz.Document.DataSources.Where(x => x.Id == dataSourceItem.DataSourceId).First(); - // if (dataSourceItem.ResourceItem != null) - // dataSourceItem.ResourceItemDataSource = viz.Document.DataSources.Where(x => x.Id == dataSourceItem.ResourceItem.DataSourceId).First(); - - // return dataSourceItem; - // } - - // /// - // /// Updates the data source item and available fields for the visualization. - // /// - // /// The created with a data source builder. - // public void UpdateDataSourceItem(DataSourceItem dataSourceItem) - // { - // DataDefinition.DataSourceItem = dataSourceItem; - // DataDefinition.Fields = dataSourceItem?.Fields.Clone(); - // } - //} -} \ No newline at end of file