1@using Escali.LicenseControl.Client.Pages
3@using Castle.Core.Internal
4@using Escali.LicenseControl.Client.ClientModels
5@using Escali.LicenseControl.Client.ViewModels
6@inject ModuleViewModel _moduleViewService
7@inject ProductViewModel _productViewService
8@inject PriceElementViewModel _priceElementViewService
9@inject StateService _stateService
10@implements IDisposable
12<ProductTableButtons FilterModules="FilterModules"/>
14@if (_moduleViewService.Modules != null)
16 <TableNested Items="_moduleViewService.Modules.Where(m => m.ProductSeq == _stateService.SelectedProductSeq.Value).Where(ModuleFilter).ToList()">
23 <td>@context.ModuleName</td>
26 <td class="table-col-last">
27 <Dropdown Options="CreateDropdownOptions(context)" />
31 @if (context.ModuleLevels != null && context.ModuleLevels.Any())
33 @foreach (var ml in context.ModuleLevels.Where(ModuleLevelFilter).ToList())
35 <tr class="table-data-third">
36 <td class="table-col-first"></td>
37 <td>@ml.ModuleLevelName</td>
38 <td>@ml.ModuleLevelRestriction</td>
40 @if (!_priceElementViewService.PriceElements.IsNullOrEmpty()
41 && _priceElementViewService.PriceElements.Any(pe => pe.ModuleLevelSeq == ml.ModuleLevelSeq && pe.PriceListSeq == _stateService.SelectedPriceListSeq.Value))
44 @_priceElementViewService.PriceElements?.First(pe => pe.ModuleLevelSeq == ml.ModuleLevelSeq && pe.PriceListSeq == _stateService.SelectedPriceListSeq.Value).Price
45 @_priceElementViewService.PriceElements?.FirstOrDefault(pe => pe.PriceListSeq == _stateService.SelectedPriceListSeq.Value && pe.ModuleLevelSeq == ml.ModuleLevelSeq)?.PriceList?.Currency.CurrencyName
53 <td class="table-col-last"></td>
65 private bool ShowInactiveModules { get; set; }
67 private Func<ModuleClientModel, bool> ModuleFilter => m => ShowInactiveModules || m.IsActive;
68 private Func<ModuleLevelClientModel, bool> ModuleLevelFilter => ml => ShowInactiveModules || ml.IsActive;
70 private void FilterModules(bool filter) => ShowInactiveModules = filter;
72 private (string, Action)[] CreateDropdownOptions(ModuleClientModel context)
74 return new (string, Action)[] {
75 ("Oppdater modul", () => _stateService.UpdateEditModule(context)),
79 protected override void OnInitialized()
81 _productViewService.DataChanged += StateHasChanged;
82 _moduleViewService.DataChanged += StateHasChanged;
83 _priceElementViewService.DataChanged += StateHasChanged;
85 _stateService.SelectedProductSeq.ValueChanged += StateHasChanged;
86 _stateService.SelectedPriceListSeq.ValueChanged += StateHasChanged;
89 void IDisposable.Dispose()
91 _productViewService.DataChanged -= StateHasChanged;
92 _moduleViewService.DataChanged -= StateHasChanged;
93 _priceElementViewService.DataChanged -= StateHasChanged;
95 _stateService.SelectedProductSeq.ValueChanged -= StateHasChanged;
96 _stateService.SelectedPriceListSeq.ValueChanged -= StateHasChanged;
99 private ModuleClientModel? _editModule;