Escali License control 1
AddModuleModal.razor
Gå til dokumentasjonen til denne filen.
1@using Escali.LicenseControl.Client.ViewModels
2@using Escali.LicenseControl.Client.ClientModels
3@using AutoMapper
4@inject ModuleViewModel _moduleViewService
5@inject IMapper _mapper
6@inject StateService _stateService
7
8<EditForm Model="Module" OnValidSubmit="AddModule" OnInvalidSubmit="EventCallback.Empty">
9 <StandardModal Header="Ny modul" SubmitButtonName="Opprett modul" @ref="Modal" OnModalClosed="() => Module = new()">
10
11 <div class="create-modal-container">
12 <ObjectGraphDataAnnotationsValidator />
13
14 <div class="input-container form-floating mb-3">
15 <InputText @bind-Value="Module.ModuleName" type="text" class="form-control input-text" id="floatingInput" placeholder="Modulnavn" />
16 <label for="floatingInput">Modulnavn</label>
17 </div>
18
19 <div class="module-level-modal-list">
20
21 <h6 class="modal-header-second">Modulnivå</h6>
22
23 @foreach (var ml in Module.ModuleLevels)
24 {
25 <InputModuleLevel NewModuleLevel="ml" OnChange="OnModuleLevelChange" ChildConentAtLeft="false">
26 <RightContent>
27 <button @onclick="() => Module.ModuleLevels.Remove(ml)" type="button" class="delete-module-level-button">
28 <img class="" src="Icons/add-icon.svg" alt=""/>
29 </button>
30 </RightContent>
31 </InputModuleLevel>
32
33 }
34
35 <button class="add-module-level-button" type="button" @onclick="() => Module.ModuleLevels.Add(new ModuleLevelClientModel())">
36 <img class="" src="Icons/add-icon-black.svg" alt=""/>
37 </button>
38
39 </div>
40 </div>
41
42 </StandardModal>
43</EditForm>
44
45
46<button class="btn btn-primary button-with-icon" @onclick="() => Modal.OpenModal()">
47 Ny modul
48 <img class="button-icon" src="Icons/add-icon.svg" alt=""/>
49</button>
50
51@code {
52
53 private StandardModal Modal;
54
55 private ModuleClientModel? Module
56 {
57 get => _module;
58 set
59 {
60 _module = _mapper.Map<ModuleClientModel>(value);
61 _module.ModuleLevels = _mapper.Map<List<ModuleLevelClientModel>>(value?.ModuleLevels);
62 }
63 }
64
65 private EventCallback<ChangeEventArgs> OnModuleLevelChange { get; set; }
66
67 private async Task AddModule()
68 {
69 Module!.ProductSeq = _stateService.SelectedProductSeq.Value;
70 var createdModule = await _moduleViewService.CreateModule(Module);
71 if (createdModule != null)
72 {
73 Module = new();
74 Modal.HideModal();
75 }
76 }
77
78 private ModuleClientModel? _module = new();
79
80}