diff --git a/CS/Directory.Packages.props b/CS/Directory.Packages.props index 47836c5c..52c47d2b 100644 --- a/CS/Directory.Packages.props +++ b/CS/Directory.Packages.props @@ -3,57 +3,57 @@ true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CS/OutlookInspired.Blazor.Server/Charts/OpportunityPieChart.razor b/CS/OutlookInspired.Blazor.Server/Charts/OpportunityPieChart.razor new file mode 100644 index 00000000..d7b38f61 --- /dev/null +++ b/CS/OutlookInspired.Blazor.Server/Charts/OpportunityPieChart.razor @@ -0,0 +1,40 @@ +@using System.Linq.Expressions +@using DevExpress.ExpressApp.Blazor.Editors +@using DevExpress.ExpressApp.Blazor.Editors.Models +@using DevExpress.ExpressApp.Utils +@using OutlookInspired.Module.BusinessObjects +@using System.Drawing + + + + + + + + + @context.Point.Argument + Sales: @($"${context.Point.Value:#,0.}") + + + + +@code { + [CascadingParameter] public DxChartListEditor ChartEditor { get; set; } + + protected override void OnParametersSet() + { + base.OnParametersSet(); + if (ChartEditor.ChartModel is DxPieChartModel pieChart) + { + pieChart.SetAttribute("style", "margin-top:100px"); + pieChart.Diameter = 1; + pieChart.InnerDiameter = 0.5; + pieChart.StartAngle = 0; + pieChart.SegmentDirection = PieChartSegmentDirection.Clockwise; + pieChart.CustomizeSeriesPoint = e + => e.PointAppearance.Color = ColorTranslator.FromHtml(e.Point.DataItems.Cast().First().Stage.Color()); + } + } +} diff --git a/CS/OutlookInspired.Blazor.Server/Charts/SalesCustomerChart.razor b/CS/OutlookInspired.Blazor.Server/Charts/SalesCustomerChart.razor new file mode 100644 index 00000000..f46ff5da --- /dev/null +++ b/CS/OutlookInspired.Blazor.Server/Charts/SalesCustomerChart.razor @@ -0,0 +1,13 @@ +@using OutlookInspired.Module.BusinessObjects + + + + + + @context.Point.SeriesName: @($"{(decimal)context.Point.Value:$0,.#K}") + + diff --git a/CS/OutlookInspired.Blazor.Server/Charts/SalesProductChart.razor b/CS/OutlookInspired.Blazor.Server/Charts/SalesProductChart.razor new file mode 100644 index 00000000..086671e2 --- /dev/null +++ b/CS/OutlookInspired.Blazor.Server/Charts/SalesProductChart.razor @@ -0,0 +1,13 @@ +@using OutlookInspired.Module.BusinessObjects + + + + + + @context.Point.SeriesName: @($"{(decimal)context.Point.Value:$0,.#K}") + + diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/DxChartListEditor.cs b/CS/OutlookInspired.Blazor.Server/Editors/Charts/DxChartListEditor.cs deleted file mode 100644 index 8347e10c..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/DxChartListEditor.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Collections; -using System.ComponentModel; -using DevExpress.ExpressApp; -using DevExpress.ExpressApp.Blazor; -using DevExpress.ExpressApp.Blazor.Components; -using DevExpress.ExpressApp.Blazor.Components.Models; -using DevExpress.ExpressApp.Editors; -using DevExpress.ExpressApp.Model; -using Microsoft.AspNetCore.Components; - -namespace OutlookInspired.Blazor.Server.Editors.Charts { - [ListEditor(typeof(object))] - public class DxChartListEditor(IModelListView info) :ListEditor(info), IComponentContentHolder,IComplexListEditor{ - private RenderFragment _componentContent; - private CollectionSourceBase _collectionSource; - protected override object CreateControlsCore() => new DxChartModel(); - public new DxChartModel Control => (DxChartModel)base.Control; - protected override void AssignDataSourceToControl(object dataSource) { - if(Control == null||dataSource==null) return; - if (dataSource is IBindingList bindingList){ - bindingList.ListChanged -= BindingList_ListChanged; - } - Control.Data = ((IEnumerable)dataSource).Cast(); - if (dataSource is IBindingList newBindingList){ - newBindingList.ListChanged += BindingList_ListChanged; - } - } - - private void BindingList_ListChanged(object sender, ListChangedEventArgs e) => Refresh(); - - public override void Refresh() => _collectionSource.ResetCollection(); - - - public override IList GetSelectedObjects() => Array.Empty(); - public override SelectionType SelectionType => SelectionType.None; - - RenderFragment IComponentContentHolder.ComponentContent - => _componentContent ??= ComponentModelObserver.Create(Control, Control.GetComponentContent()); - - public void Setup(CollectionSourceBase collectionSource, XafApplication application) => _collectionSource = collectionSource; - } -} \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/DxChartPieListEditor.cs b/CS/OutlookInspired.Blazor.Server/Editors/Charts/DxChartPieListEditor.cs deleted file mode 100644 index e84d3948..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/DxChartPieListEditor.cs +++ /dev/null @@ -1,11 +0,0 @@ -using DevExpress.ExpressApp.Editors; -using DevExpress.ExpressApp.Model; - -namespace OutlookInspired.Blazor.Server.Editors.Charts{ - [ListEditor(typeof(object))] - public class DxChartPieListEditor(IModelListView info) :DxChartListEditor(info){ - protected override object CreateControlsCore() => new DxChartPieModel(); - - public new DxChartPieModel Control => (DxChartPieModel)base.Control; - } -} \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxChart.razor b/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxChart.razor deleted file mode 100644 index 2e1d199c..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxChart.razor +++ /dev/null @@ -1,37 +0,0 @@ -@using System.Linq.Expressions - - - - - - - @context.Point.SeriesName: @($"{(decimal)context.Point.Value:$0,.#K}") - - - -@code { - [Parameter][EditorRequired] - public IEnumerable Data { get; set; } - [Parameter][EditorRequired] - public Expression> ArgumentField { get; set; } - [Parameter][EditorRequired] - public Expression> ValueField { get; set; } - [Parameter][EditorRequired] - public Expression> NameField { get; set; } - [Parameter][EditorRequired] - public Func, decimal> SummaryMethod { get; set; } - [Parameter][EditorRequired] - public Action CustomizeSeriesPoint { get; set; } - [Parameter] - public string Height { get; set; } = "70vh"; - [Parameter][EditorRequired] - public ChartSeriesType SeriesType{ get; set; } - [Parameter] public string Style{ get; set; } - - public DxChart Chart; - protected override void OnAfterRender(bool firstRender){ - base.OnAfterRender(firstRender); - Chart.RefreshData(); - } -} \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxChart.razor.cs b/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxChart.razor.cs deleted file mode 100644 index eaa2b84c..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxChart.razor.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Linq.Expressions; -using DevExpress.Blazor; - -namespace OutlookInspired.Blazor.Server.Editors.Charts; - -public class DxChartModel : DevExpress.ExpressApp.Blazor.Components.Models.ComponentModelBase { - public ChartSeriesType SeriesType{ - get => GetPropertyValue(); - set => SetPropertyValue(value); - } - - public IEnumerable Data { - get => GetPropertyValue>(); - set => SetPropertyValue(value); - } - public string Style { - get => GetPropertyValue(); - set => SetPropertyValue(value); - } - public Expression> ArgumentField { - get => GetPropertyValue>>(); - set => SetPropertyValue(value); - } - public Expression> ValueField { - get => GetPropertyValue>>(); - set => SetPropertyValue(value); - } - public Expression> NameField { - get => GetPropertyValue>>(); - set => SetPropertyValue(value); - } - public Func, decimal> SummaryMethod { - get => GetPropertyValue, decimal>>(); - set => SetPropertyValue(value); - } - - public Action CustomizeSeriesPoint{ - get => GetPropertyValue>(); - set => SetPropertyValue(value); - } - - public string Height { - get => GetPropertyValue("70vh"); - set => SetPropertyValue(value); - } - - public override Type ComponentType => typeof(MyDxChart); -} - diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor b/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor deleted file mode 100644 index 4f1661b3..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor +++ /dev/null @@ -1,50 +0,0 @@ -@inject IJSRuntime JSRuntime -@implements IAsyncDisposable; -@using System.Linq.Expressions - - - - - - - - - - - - @context.Point.Argument - Sales: @($"${context.Point.Value:#,0.}") - - - - - - -@code { - private ElementReference _pieChartDiv; - private IJSObjectReference _module; - [Parameter] public IEnumerable Data { get; set; } - [Parameter] public Expression> ArgumentField { get; set; } - [Parameter] public Expression> ValueField { get; set; } - [Parameter] public Expression> NameField { get; set; } - [Parameter] public Func, decimal> SummaryMethod { get; set; } - [Parameter] public bool Stick { get; set; } - [Parameter] public Action CustomizeSeriesPoint { get; set; } - [Parameter] public string Style{ get; set; } - - - protected override async Task OnAfterRenderAsync(bool firstRender){ - if (!firstRender||!Stick)return; - _module = await JSRuntime.InvokeAsync("import", "./Editors/Charts/MyDxPieChart.razor.js"); - await _module.InvokeVoidAsync("moveElementOnScroll", _pieChartDiv); - } - - - public async ValueTask DisposeAsync(){ - if (_module == null) return; - await _module.DisposeAsync(); - } - -} diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor.cs b/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor.cs deleted file mode 100644 index b7013828..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace OutlookInspired.Blazor.Server.Editors.Charts; - -public class DxChartPieModel : DxChartModel{ - - public override Type ComponentType => typeof(MyDxPieChart); - - public bool Stick{ - get => GetPropertyValue(); - set => SetPropertyValue(value); - } -} \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor.js b/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor.js deleted file mode 100644 index 490b5674..00000000 --- a/CS/OutlookInspired.Blazor.Server/Editors/Charts/MyDxPieChart.razor.js +++ /dev/null @@ -1,12 +0,0 @@ - -export function moveElementOnScroll(element) { - const mainContent = document.getElementsByClassName('main-content')[0]; - if (mainContent) { - mainContent.addEventListener('scroll', function() { - element.style.transform = `translateY(${mainContent.scrollTop}px)`; - }); - } else { - setTimeout(moveElementOnScroll, 100); - } - -} \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Features/Maps/SalesMapItemDxChartListEditorController.cs b/CS/OutlookInspired.Blazor.Server/Features/Maps/SalesMapItemDxChartListEditorController.cs index fae3878e..c34b8c51 100644 --- a/CS/OutlookInspired.Blazor.Server/Features/Maps/SalesMapItemDxChartListEditorController.cs +++ b/CS/OutlookInspired.Blazor.Server/Features/Maps/SalesMapItemDxChartListEditorController.cs @@ -1,61 +1,58 @@ using System.Drawing; using DevExpress.Blazor; using DevExpress.ExpressApp; +using DevExpress.ExpressApp.Blazor.Editors; using DevExpress.ExpressApp.Editors; -using OutlookInspired.Blazor.Server.Editors.Charts; +using OutlookInspired.Blazor.Server.Charts; using OutlookInspired.Blazor.Server.Editors.Maps; using OutlookInspired.Module.BusinessObjects; using OutlookInspired.Module.Features.Maps; -namespace OutlookInspired.Blazor.Server.Features.Maps{ - public class SalesMapItemDxChartListEditorController:ObjectViewController{ - private DxChartListEditor _chartListEditor; - - protected override void OnActivated(){ - base.OnActivated(); - View.CustomizeViewItemControl(this,listPropertyEditor => { - if (listPropertyEditor.ListView.Editor is not DxChartListEditor mapItemDxChartListEditor) return; - _chartListEditor = mapItemDxChartListEditor; - _chartListEditor.ControlsCreated+=ChartListEditorOnControlsCreated; - }); - } - - protected override void OnDeactivated(){ - base.OnDeactivated(); - if (_chartListEditor == null) return; - _chartListEditor.ControlsCreated -= ChartListEditorOnControlsCreated; - } - - private void ChartListEditorOnControlsCreated(object sender, EventArgs args){ - var model = _chartListEditor.Control; - model.SeriesType=ChartSeriesType.Bar; - model.ArgumentField = model.NameField=item - => IsCustomer? ((MapItem)item).ProductName:((MapItem)item).CustomerName; - model.SummaryMethod = items => items.Sum(); - model.ValueField = item => ((MapItem)item).Total; - model.CustomizeSeriesPoint=e => e.PointAppearance.Color = ColorTranslator.FromHtml(e.Point.DataItems.Cast().First().Color); - var mapItemListEditor = View.GetItems() - .Select(editor => editor.ListView?.Editor).OfType().First(); - mapItemListEditor.SelectionChanged+=MapItemListEditorOnSelectionChanged; - var mapItems = ((ProxyCollection)mapItemListEditor.DataSource).Cast().ToArray(); - mapItemListEditor.ApplyColors( mapItems,item => IsCustomer?item.ProductName:item.CustomerName); - _chartListEditor.DataSource = mapItems; - } - - private bool IsCustomer => View.ObjectTypeInfo.Type == typeof(Customer); - private void MapItemListEditorOnSelectionChanged(object sender, EventArgs e){ - var city = ((MapItemListEditor)sender).GetSelectedObjects().Cast().FirstOrDefault()?.City; - if (city==null)return; - var mapItemListEditor = View.GetItems() - .Select(editor => editor.ListView?.Editor).OfType().First(); - var dataSource = MapItems(mapItemListEditor) - .Where(item => item.City == city) - .ToArray(); - mapItemListEditor.ApplyColors( dataSource,item => IsCustomer?item.ProductName:item.CustomerName ); - _chartListEditor.DataSource = dataSource; - } - - private static MapItem[] MapItems(MapItemListEditor mapItemListEditor) => ((ProxyCollection)mapItemListEditor.DataSource).Cast().ToArray(); +namespace OutlookInspired.Blazor.Server.Features.Maps; +public class SalesMapItemDxChartListEditorController : ObjectViewController { + private DxChartListEditor _chartListEditor; + + protected override void OnActivated() { + base.OnActivated(); + View.CustomizeViewItemControl(this, listPropertyEditor => { + if(listPropertyEditor.ListView.Editor is not DxChartListEditor mapItemDxChartListEditor) { return; } + _chartListEditor = mapItemDxChartListEditor; + _chartListEditor.ControlsCreated += ChartListEditorOnControlsCreated; + }); + } + + protected override void OnDeactivated() { + base.OnDeactivated(); + if(_chartListEditor == null) { return; } + _chartListEditor.ControlsCreated -= ChartListEditorOnControlsCreated; } + + private void ChartListEditorOnControlsCreated(object sender, EventArgs args) { + _chartListEditor.ChartModel.CustomizeSeriesPoint = e + => e.PointAppearance.Color = ColorTranslator.FromHtml(e.Point.DataItems.Cast().First().Color); + _chartListEditor.SettingsType = IsCustomer ? typeof(SalesProductChart) : typeof(SalesCustomerChart); + + var mapItemListEditor = View.GetItems() + .Select(editor => editor.ListView?.Editor).OfType().First(); + mapItemListEditor.SelectionChanged += MapItemListEditorOnSelectionChanged; + var mapItems = ((ProxyCollection)mapItemListEditor.DataSource).Cast().ToArray(); + mapItemListEditor.ApplyColors(mapItems, item => IsCustomer ? item.ProductName : item.CustomerName); + _chartListEditor.DataSource = mapItems; + } + + private bool IsCustomer => View.ObjectTypeInfo.Type == typeof(Customer); + private void MapItemListEditorOnSelectionChanged(object sender, EventArgs e) { + var city = ((MapItemListEditor)sender).GetSelectedObjects().Cast().FirstOrDefault()?.City; + if(city == null) { return; } + var mapItemListEditor = View.GetItems() + .Select(editor => editor.ListView?.Editor).OfType().First(); + var dataSource = MapItems(mapItemListEditor) + .Where(item => item.City == city) + .ToArray(); + mapItemListEditor.ApplyColors(dataSource, item => IsCustomer ? item.ProductName : item.CustomerName); + _chartListEditor.DataSource = dataSource; + } + + private static MapItem[] MapItems(MapItemListEditor mapItemListEditor) => ((ProxyCollection)mapItemListEditor.DataSource).Cast().ToArray(); } \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Features/Quotes/BlazorOpportunitiesChartListViewController.cs b/CS/OutlookInspired.Blazor.Server/Features/Quotes/BlazorOpportunitiesChartListViewController.cs deleted file mode 100644 index bbf9041f..00000000 --- a/CS/OutlookInspired.Blazor.Server/Features/Quotes/BlazorOpportunitiesChartListViewController.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Drawing; -using DevExpress.ExpressApp; -using OutlookInspired.Blazor.Server.Editors.Charts; -using OutlookInspired.Module.BusinessObjects; - - -namespace OutlookInspired.Blazor.Server.Features.Quotes { - public class BlazorOpportunitiesChartListViewController : ObjectViewController { - protected override void OnViewControlsCreated() { - base.OnViewControlsCreated(); - if(View.Editor is DxChartPieListEditor editor) { - var chartModel = editor.Control; - chartModel.ArgumentField = item => ((Opportunity)item).Stage.ToString(); - chartModel.ValueField = item => ((Opportunity)item).Value; - chartModel.SummaryMethod = items => items.Sum(); - chartModel.CustomizeSeriesPoint = e - => e.PointAppearance.Color = ColorTranslator.FromHtml(e.Point.DataItems.Cast().First().Stage.Color()); - chartModel.Stick = true; - chartModel.Style = "margin-top:100px"; - } - } - } -} \ No newline at end of file diff --git a/CS/OutlookInspired.Blazor.Server/Model.xafml b/CS/OutlookInspired.Blazor.Server/Model.xafml index f7007c15..938252bf 100644 --- a/CS/OutlookInspired.Blazor.Server/Model.xafml +++ b/CS/OutlookInspired.Blazor.Server/Model.xafml @@ -22,7 +22,7 @@ - + @@ -332,7 +332,7 @@ - + @@ -460,7 +460,7 @@ - + diff --git a/CS/OutlookInspired.Blazor.Server/OutlookInspired.Blazor.Server.csproj b/CS/OutlookInspired.Blazor.Server/OutlookInspired.Blazor.Server.csproj index 2274ada6..39ce71a6 100644 --- a/CS/OutlookInspired.Blazor.Server/OutlookInspired.Blazor.Server.csproj +++ b/CS/OutlookInspired.Blazor.Server/OutlookInspired.Blazor.Server.csproj @@ -1,4 +1,4 @@ - + net9.0 false @@ -36,7 +36,6 @@ Always -