Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Join API #60

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions e2e/Sandbox/Factories/SqlServerDataSourceDashboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,50 @@ internal static RdashDocument CreateDashboard()
Database = "Northwind",
};

var document = new RdashDocument("My Dashboard");

var customersDsi = new MicrosoftSqlServerDataSourceItem("Customers Table", "Customers", sqlServerDS)
var customers = new MicrosoftSqlServerDataSourceItem("Customers Table", "Customers", sqlServerDS)
{
Subtitle = "SQL Server Data Source Item",
Fields = new List<IField>
{
new TextField("ContactName"),
new TextField("ContactTitle"),
new TextField("City")
new TextField("CustomerID"),
new TextField("ContactName") { FieldLabel = "Customer Name" },
new TextField("ContactTitle") { FieldLabel = "Customer Title" },
new TextField("City") { FieldLabel = "Customer City" }
}
};
document.Visualizations.Add(new GridVisualization("Customer List", customersDsi).SetColumns("ContactName", "ContactTitle", "City"));

var employeesDsi = new MicrosoftSqlServerDataSourceItem("Employees Table", sqlServerDS)
var employees = new MicrosoftSqlServerDataSourceItem("Employees Table", sqlServerDS)
{
Subtitle = "SQL Server Data Source Item",
Table = "Employees",
Fields = new List<IField>
{
new TextField("FirstName"),
new TextField("LastName"),
new NumberField("EmployeeID"),
new TextField("FirstName") { FieldLabel = "Employee First Name" },
new TextField("LastName") { FieldLabel = "Employee Last Name" },
}
};
document.Visualizations.Add(new GridVisualization("Employee List", employeesDsi).SetColumns("FirstName", "LastName"));

var orders = new MicrosoftSqlServerDataSourceItem("Orders Table", "Orders", sqlServerDS)
{
Fields = new List<IField>
{
new TextField("CustomerID"),
new NumberField("EmployeeID") { FieldLabel = "Order Employee ID" },
new DateField("OrderDate") { FieldLabel = "Oder Date" },
new TextField("ShipName") { FieldLabel = "Order Ship Name" },
},
};

customers.Join("A", "CustomerID", "CustomerID", orders);
customers.Join("B", "A.EmployeeID", "EmployeeID", employees);

var document = new RdashDocument("My Dashboard");

document.Visualizations.Add(new GridVisualization("Customer List", customers).SetColumns("ContactName", "ContactTitle", "City"));
document.Visualizations.Add(new GridVisualization("Employee List", employees).SetColumns("FirstName", "LastName"));
document.Visualizations.Add(new GridVisualization("Joined Tables", customers).SetColumns("ContactName", "ContactTitle", "City",
"A.EmployeeID", "A.OrderDate", "A.ShipName", "B.FirstName", "B.LastName"));

return document;
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/Sandbox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Button Click="Clear_Dashboard">Clear Dashboard</Button>
</StackPanel>

<rv:RevealView Grid.Row="1" x:Name="_revealView"
<rv:RevealView Grid.Row="1" x:Name="_revealView" ShowEditDataSource="True" ShowDataBlending="True"
SaveDashboard="RevealView_SaveDashboard"/>
</Grid>

Expand Down
24 changes: 20 additions & 4 deletions e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Windows.Management.Deployment;

namespace Sandbox
{
Expand All @@ -43,7 +44,8 @@ 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, DashboardFileNames.Marketing);
readonly string _readFilePath = Path.Combine(_dashboardFilePath, "My Dashboard.rdash");

readonly string _saveJsonToPath = Path.Combine(_dashboardFilePath, "MyDashboard.json");
readonly string _saveRdashToPath = Path.Combine(_dashboardFilePath, DashboardFileNames.MyDashboard);
Expand Down Expand Up @@ -159,6 +161,19 @@ private void RevealView_DataSourcesRequested(object sender, DataSourcesRequested
//webDS.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx";
//ds.Add(webDS);

//var http = new RVHttpAnalysisServicesDataSource();
//http.Title = "HTTP Analysis Services";
//http.Subtitle = "HTTP Analysis Services Subtitle";
//http.Url = "http://revealdb01.infragistics.local/OLAP/msmdpump.dll";
//http.Catalog = "Adventure Works DW 2008R2";
//ds.Add(http);

//var httpItem = new RVAnalysisServicesDataSourceItem(http);
//httpItem.Title = "HTTP Analysis Services Item";
//httpItem.Subtitle = "HTTP Analysis Services Item Subtitle";
//httpItem.Cube = "Adventure Works";
//dsi.Add(httpItem);

e.Callback(new RevealDataSources(ds, dsi, true));
}

Expand Down Expand Up @@ -206,11 +221,12 @@ private async void Create_Dashboard(object sender, RoutedEventArgs e)
//var document = HealthcareDashboard.CreateDashboard();
//var document = ManufacturingDashboard.CreateDashboard();
//var document = CustomDashboard.CreateDashboard();
var document = RestDataSourceDashboards.CreateDashboard();
//var document = SqlServerDataSourceDashboards.CreateDashboard();
//var document = DashboardLinkingDashboard.CreateDashboard();
//var document = RestDataSourceDashboards.CreateDashboard();
var document = SqlServerDataSourceDashboards.CreateDashboard();
//var document = DashboardLinkingDashboard.CreateDashboard();

var json = document.ToJsonString();

_revealView.Dashboard = await RVDashboard.LoadFromJsonAsync(json);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Reveal.Sdk.Dom.Core.Utilities;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
Expand All @@ -12,22 +13,22 @@ public class RdashDocumentValidatorFixture
[Fact]
public void DataSources_AddedToRdashDocument()
{
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { new TextField("Test") });

var document = new RdashDocument();
document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem));

Assert.Empty(document.DataSources);

RdashDocumentValidator.FixDocument(document);
document.Validate();

Assert.True(document.DataSources.Skip(1).Any());
}

[Fact]
public void DataSources_FromVisualizationsAreNotDuplicated()
{
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { new TextField("Test") });

var document = new RdashDocument();
document.Visualizations.Add(new KpiTimeVisualization(dataSourceItem));
Expand All @@ -37,7 +38,7 @@ public void DataSources_FromVisualizationsAreNotDuplicated()

Assert.Empty(document.DataSources);

RdashDocumentValidator.FixDocument(document);
document.Validate();

var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON);

Expand All @@ -47,7 +48,7 @@ public void DataSources_FromVisualizationsAreNotDuplicated()
[Fact]
public void DataSources_FromVisualizations_AndDataSources_AreNotDuplicated()
{
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { null });
var dataSourceItem = new DataSourceItemFactory().Create(DataSourceType.REST, "", "").SetFields(new List<IField>() { new TextField("Test") });
var dataSource = dataSourceItem.DataSource;

var document = new RdashDocument();
Expand All @@ -60,11 +61,88 @@ public void DataSources_FromVisualizations_AndDataSources_AreNotDuplicated()

Assert.Single(document.DataSources);

RdashDocumentValidator.FixDocument(document);
document.Validate();

var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON);

Assert.Single(jsonDataSources);
}

[Fact]
public void Validate_ThrowsException_WhenDataSourceItemIsNull()
{
// Arrange
var viz = new GridVisualization("TEST", null)
{
Title = "Test Visualization",
DataDefinition = new TabularDataDefinition()
};
var document = new RdashDocument("Test");
document.Visualizations.Add(viz);

// Act & Assert
Assert.Throws<Exception>(() => RdashDocumentValidator.Validate(document));
}

[Fact]
public void Validate_ThrowsException_WhenFieldIsNull()
{
// Arrange
var dataSourceItem = new DataSourceItem()
{
Fields = new List<IField> { null }
};

var viz = new GridVisualization("TEST", dataSourceItem)
{
Title = "Test Visualization",
DataDefinition = new TabularDataDefinition()
};

var document = new RdashDocument("Test");
document.Visualizations.Add(viz);

// Act & Assert
Assert.Throws<Exception>(() => RdashDocumentValidator.Validate(document));
}

[Fact]
public void Validate_ThrowsException_WhenFieldsAreNullOrEmpty()
{
var dataSourceItem = new DataSourceItem()
{
Fields = new List<IField> { null }
};

var viz = new GridVisualization("TEST", dataSourceItem)
{
Title = "Test Visualization",
DataDefinition = new TabularDataDefinition()
};

var document = new RdashDocument("Test");
document.Visualizations.Add(viz);

// Act & Assert
Assert.Throws<Exception>(() => RdashDocumentValidator.Validate(document));

// Arrange
var dataSourceItem2 = new DataSourceItem()
{
Fields = new List<IField>()
};

var viz2 = new GridVisualization("TEST", dataSourceItem2)
{
Title = "Test Visualization",
DataDefinition = new TabularDataDefinition()
};

var document2 = new RdashDocument("Test");
document2.Visualizations.Add(viz2);

// Act & Assert
Assert.Throws<Exception>(() => RdashDocumentValidator.Validate(document2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Data
namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
{
public class DataSourceItemFactoryFixture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Data
namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
{
public class ExcelFileDataSourceItemFixture
{
Expand Down Expand Up @@ -132,12 +132,12 @@ public void Constructor_WithTitle_Should_Add_TwoDataSources()
{
// Arrange
var document = new RdashDocument("Test");
var dataSourceItem = new ExcelFileDataSourceItem("Test").SetFields(new List<IField>() { null });
var dataSourceItem = new ExcelFileDataSourceItem("Test").SetFields(new List<IField>() { new TextField("Test") });

document.Visualizations.Add(new GridVisualization(dataSourceItem));

// Ensure data sources are added to the data sources collection
RdashDocumentValidator.FixDocument(document);
document.Validate();

// Assert
Assert.Equal(2, document.DataSources.Count);
Expand All @@ -150,12 +150,12 @@ public void Constructor_WithTitleAndPath_Should_Add_TwoDataSources()
{
// Arrange
var document = new RdashDocument("Test");
var dataSourceItem = new ExcelFileDataSourceItem("Test", "Path").SetFields(new List<IField>() { null });
var dataSourceItem = new ExcelFileDataSourceItem("Test", "Path").SetFields(new List<IField>() { new TextField("Test") });

document.Visualizations.Add(new GridVisualization(dataSourceItem));

// Ensure data sources are added to the data sources collection
RdashDocumentValidator.FixDocument(document);
document.Validate();

// Assert
Assert.Equal(2, document.DataSources.Count);
Expand All @@ -168,12 +168,12 @@ public void Constructor_WithTitleAndPathAndSheet_Should_Add_TwoDataSources()
{
// Arrange
var document = new RdashDocument("Test");
var dataSourceItem = new ExcelFileDataSourceItem("Test", "Path", "Sheet").SetFields(new List<IField>() { null });
var dataSourceItem = new ExcelFileDataSourceItem("Test", "Path", "Sheet").SetFields(new List<IField>() { new TextField("Test") });

document.Visualizations.Add(new GridVisualization(dataSourceItem));

// Ensure data sources are added to the data sources collection
RdashDocumentValidator.FixDocument(document);
document.Validate();

// Assert
Assert.Equal(2, document.DataSources.Count);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Reveal.Sdk.Dom.Data;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Data
namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
{
public class MicrosoftSqlServerDataSourceItemFixture
{
Expand Down
Loading
Loading