Escali License control 1
ProductTable.razor
Gå til dokumentasjonen til denne filen.
1@using Escali.LicenseControl.Client.Pages
2@using System.Linq
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
11
12<ProductTableButtons FilterModules="FilterModules"/>
13
14@if (_moduleViewService.Modules != null)
15{
16 <TableNested Items="_moduleViewService.Modules.Where(m => m.ProductSeq == _stateService.SelectedProductSeq.Value).Where(ModuleFilter).ToList()">
17 <TableHeader>
18 <td>Navn</td>
19 <td>Begrensning</td>
20 <td>Pris</td>
21 </TableHeader>
22 <RowTemplate>
23 <td>@context.ModuleName</td>
24 <td></td>
25 <td></td>
26 <td class="table-col-last">
27 <Dropdown Options="CreateDropdownOptions(context)" />
28 </td>
29 </RowTemplate>
30 <ChildRowTemplate>
31 @if (context.ModuleLevels != null && context.ModuleLevels.Any())
32 {
33 @foreach (var ml in context.ModuleLevels.Where(ModuleLevelFilter).ToList())
34 {
35 <tr class="table-data-third">
36 <td class="table-col-first"></td>
37 <td>@ml.ModuleLevelName</td>
38 <td>@ml.ModuleLevelRestriction</td>
39
40 @if (!_priceElementViewService.PriceElements.IsNullOrEmpty()
41 && _priceElementViewService.PriceElements.Any(pe => pe.ModuleLevelSeq == ml.ModuleLevelSeq && pe.PriceListSeq == _stateService.SelectedPriceListSeq.Value))
42 {
43 <td>
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
46 </td>
47 }
48 else
49 {
50 <td>Ingen pris</td>
51 }
52
53 <td class="table-col-last"></td>
54 </tr>
55 }
56 }
57 </ChildRowTemplate>
58 </TableNested>
59
60 <EditModuleModal />
61}
62
63@code {
64
65 private bool ShowInactiveModules { get; set; }
66
67 private Func<ModuleClientModel, bool> ModuleFilter => m => ShowInactiveModules || m.IsActive;
68 private Func<ModuleLevelClientModel, bool> ModuleLevelFilter => ml => ShowInactiveModules || ml.IsActive;
69
70 private void FilterModules(bool filter) => ShowInactiveModules = filter;
71
72 private (string, Action)[] CreateDropdownOptions(ModuleClientModel context)
73 {
74 return new (string, Action)[] {
75 ("Oppdater modul", () => _stateService.UpdateEditModule(context)),
76 };
77 }
78
79 protected override void OnInitialized()
80 {
81 _productViewService.DataChanged += StateHasChanged;
82 _moduleViewService.DataChanged += StateHasChanged;
83 _priceElementViewService.DataChanged += StateHasChanged;
84
85 _stateService.SelectedProductSeq.ValueChanged += StateHasChanged;
86 _stateService.SelectedPriceListSeq.ValueChanged += StateHasChanged;
87 }
88
89 void IDisposable.Dispose()
90 {
91 _productViewService.DataChanged -= StateHasChanged;
92 _moduleViewService.DataChanged -= StateHasChanged;
93 _priceElementViewService.DataChanged -= StateHasChanged;
94
95 _stateService.SelectedProductSeq.ValueChanged -= StateHasChanged;
96 _stateService.SelectedPriceListSeq.ValueChanged -= StateHasChanged;
97 }
98
99 private ModuleClientModel? _editModule;
100}