| | 1 | | @namespace Syki.Front.Features.Teacher.CreateClassActivity |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2" DefaultFocus="DefaultFocus.None"> |
| | 4 | | <TitleContent> |
| | 5 | | <SykiDialogTitle Text="Nova Atividade" /> |
| | 6 | | </TitleContent> |
| | 7 | | <DialogContent> |
| 0 | 8 | | <MudForm @ref="@_form" Class="pt-1" Spacing="0"> |
| 0 | 9 | | <MudGrid Spacing="2"> |
| 0 | 10 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| 0 | 11 | | <SykiTextField Label="Título" AutoFocus="true" @bind-Value="@_title" MaxLength="50" /> |
| 0 | 12 | | </MudItem> |
| 0 | 13 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | 14 | | <SykiTextField Label="Descrição" @bind-Value="@_description" AutoGrow="true" Lines="8" MaxLines="20" |
| | 15 | | </MudItem> |
| | 16 | |
|
| | 17 | | <MudItem xs="12" sm="4" md="4" lg="4"> |
| | 18 | | <MudSelect |
| | 19 | | Dense="true" |
| | 20 | | Margin="Margin.Dense" |
| | 21 | | Variant="Variant.Outlined" |
| | 22 | | T="ClassActivityType" |
| | 23 | | @bind-Value="@_type" |
| | 24 | | Label="Tipo" |
| | 25 | | Required="true" |
| | 26 | | RequiredError="Informe!" |
| | 27 | | AdornmentColor="Color.Primary" |
| | 28 | | > |
| 0 | 29 | | @foreach (ClassActivityType type in Enum.GetValues<ClassActivityType>()) |
| | 30 | | { |
| 0 | 31 | | <MudSelectItem Value="@type">@type.GetDescription()</MudSelectItem> |
| | 32 | | } |
| | 33 | | </MudSelect> |
| | 34 | | </MudItem> |
| | 35 | |
|
| | 36 | | <MudItem xs="12" sm="4" md="4" lg="4"> |
| | 37 | | <MudSelect |
| | 38 | | Dense="true" |
| | 39 | | Margin="Margin.Dense" |
| | 40 | | Variant="Variant.Outlined" |
| | 41 | | T="ClassNoteType" |
| | 42 | | Value="@_note" |
| 0 | 43 | | ValueChanged="x => HandleNoteChanged(x)" |
| | 44 | | Label="Nota" |
| | 45 | | Required="true" |
| | 46 | | RequiredError="Informe!" |
| | 47 | | AdornmentColor="Color.Primary" |
| | 48 | | > |
| 0 | 49 | | @foreach (ClassNoteType type in Enum.GetValues<ClassNoteType>()) |
| | 50 | | { |
| 0 | 51 | | <MudSelectItem Value="@type">@type.GetDescription()</MudSelectItem> |
| | 52 | | } |
| | 53 | | </MudSelect> |
| | 54 | | </MudItem> |
| | 55 | |
|
| | 56 | | <MudItem xs="12" sm="4" md="4" lg="4"> |
| | 57 | | <MudNumericField |
| | 58 | | T="int" |
| | 59 | | @bind-Value="@_weight" |
| | 60 | | Max="@_maxWeight" |
| | 61 | | MaxLength="@(GetWeightMaxWidth())" |
| | 62 | | Min="0" |
| | 63 | | HideSpinButtons="true" |
| | 64 | | Variant="Variant.Outlined" |
| | 65 | | Margin="Margin.Dense" |
| | 66 | | HelperText="@($"Máx: {_maxWeight}")" |
| | 67 | | Required="true" |
| | 68 | | Label="Peso (%)" |
| | 69 | | RequiredError="Informe!" |
| | 70 | | /> |
| | 71 | | </MudItem> |
| | 72 | |
|
| | 73 | | <MudItem xs="12" sm="6" md="6" lg="6"> |
| | 74 | | <SykiDatePicker Label="Data de entrega" @bind-Date="@_dueDate" Editable="false" /> |
| | 75 | | </MudItem> |
| | 76 | | <MudItem xs="12" sm="6" md="6" lg="6"> |
| | 77 | | <MudSelect |
| | 78 | | Dense="true" |
| | 79 | | Margin="Margin.Dense" |
| | 80 | | Variant="Variant.Outlined" |
| | 81 | | T="Hour" |
| | 82 | | @bind-Value="@_dueHour" |
| | 83 | | Label="Hora de entrega" |
| | 84 | | Required="true" |
| | 85 | | RequiredError="Informe!" |
| | 86 | | AdornmentColor="Color.Primary" |
| | 87 | | > |
| 0 | 88 | | @foreach (Hour hour in Enum.GetValues<Hour>().Where(x => (int)x % 100 == 0)) |
| | 89 | | { |
| 0 | 90 | | <MudSelectItem Value="@hour">@hour.GetDescription()</MudSelectItem> |
| | 91 | | } |
| | 92 | | </MudSelect> |
| | 93 | | </MudItem> |
| | 94 | | </MudGrid> |
| | 95 | | </MudForm> |
| | 96 | | </DialogContent> |
| | 97 | | <DialogActions> |
| | 98 | | <DialogCancelButton OnClick="@Close" /> |
| | 99 | | <SykiProgressCircular Loading="@_loading" /> |
| | 100 | | <DialogSaveButton OnClick="@Submit" /> |
| | 101 | | </DialogActions> |
| | 102 | | </MudDialog> |
| | 103 | |
|
| | 104 | | @inject ISnackbar Snackbar |
| | 105 | | @inject CreateClassActivityClient Client |
| | 106 | | @inject IBrowserViewportService BrowserViewportService |
| | 107 | | @inject GetClassNotesRemainingWeightsClient GetClassNotesRemainingWeightsClient |
| | 108 | |
|
| | 109 | | @code |
| | 110 | | { |
| | 111 | | [CascadingParameter] |
| 0 | 112 | | IMudDialogInstance MudDialog { get; set; } |
| | 113 | |
|
| | 114 | | [Parameter] |
| 0 | 115 | | public Guid ClassId { get; set; } |
| | 116 | |
|
| | 117 | | [Parameter] |
| 0 | 118 | | public EventCallback AfterSubmit { get; set; } |
| | 119 | |
|
| | 120 | | private MudForm _form; |
| | 121 | | private bool _loading; |
| | 122 | |
|
| 0 | 123 | | private List<ClassNoteRemainingWeightsOut> _remainingWeights = []; |
| | 124 | |
|
| | 125 | | private ClassNoteType _note = ClassNoteType.N1; |
| | 126 | | private string _title; |
| | 127 | | private string _description; |
| | 128 | | private ClassActivityType _type = ClassActivityType.Exam; |
| | 129 | | private int _weight; |
| | 130 | | private int _maxWeight; |
| 0 | 131 | | private DateTime? _dueDate = DateTime.UtcNow.AddDays(7); |
| 0 | 132 | | private Hour _dueHour = Hour.H12_00; |
| | 133 | |
|
| | 134 | | protected override async Task OnInitializedAsync() |
| | 135 | | { |
| 0 | 136 | | await base.OnInitializedAsync(); |
| | 137 | |
|
| 0 | 138 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 139 | | var options = MudDialog.Options with |
| 0 | 140 | | { |
| 0 | 141 | | FullWidth = true, |
| 0 | 142 | | CloseButton = true, |
| 0 | 143 | | BackdropClick = false, |
| 0 | 144 | | MaxWidth = MaxWidth.Medium, |
| 0 | 145 | | FullScreen = breakpoint == Breakpoint.Xs |
| 0 | 146 | | }; |
| 0 | 147 | | await MudDialog.SetOptionsAsync(options); |
| | 148 | |
|
| 0 | 149 | | await Setup(); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | private async Task Setup() |
| | 153 | | { |
| 0 | 154 | | Reset(); |
| 0 | 155 | | var response = await GetClassNotesRemainingWeightsClient.Get(ClassId); |
| 0 | 156 | | if (response.IsSuccess) |
| | 157 | | { |
| 0 | 158 | | _remainingWeights = response.Success; |
| | 159 | | } |
| 0 | 160 | | _maxWeight = _remainingWeights.Where(x => x.Note == _note).Select(x => x.Weight).First(); |
| 0 | 161 | | } |
| | 162 | |
|
| | 163 | | private void Reset() |
| | 164 | | { |
| 0 | 165 | | _note = ClassNoteType.N1; |
| 0 | 166 | | _title = string.Empty; |
| 0 | 167 | | _description = string.Empty; |
| 0 | 168 | | _type = ClassActivityType.Work; |
| 0 | 169 | | _weight = 0; |
| 0 | 170 | | _dueDate = DateTime.UtcNow.AddDays(7); |
| 0 | 171 | | _dueHour = Hour.H12_00; |
| 0 | 172 | | } |
| | 173 | |
|
| | 174 | | private void Close() |
| | 175 | | { |
| 0 | 176 | | Reset(); |
| 0 | 177 | | MudDialog.Cancel(); |
| 0 | 178 | | } |
| | 179 | |
|
| | 180 | | private async Task Submit() |
| | 181 | | { |
| 0 | 182 | | if (_loading) return; |
| | 183 | |
|
| 0 | 184 | | await _form.Validate(); |
| 0 | 185 | | if (!_form.IsValid) return; |
| | 186 | |
|
| 0 | 187 | | _loading = true; |
| | 188 | |
|
| 0 | 189 | | var response = await Client.Create(ClassId, _note, _title, _description, _type, _weight, _dueDate!.Value.ToDateO |
| 0 | 190 | | if (response.IsSuccess) |
| | 191 | | { |
| 0 | 192 | | await AfterSubmit.InvokeAsync(); |
| 0 | 193 | | Close(); |
| 0 | 194 | | Snackbar.Add("Atividade criada com sucesso!", Severity.Success); |
| | 195 | | } |
| | 196 | | else |
| | 197 | | { |
| 0 | 198 | | Snackbar.Add(response.Error.Message, Severity.Error); |
| | 199 | | } |
| | 200 | |
|
| 0 | 201 | | _loading = false; |
| 0 | 202 | | } |
| | 203 | |
|
| | 204 | | private void HandleNoteChanged(ClassNoteType newValue) |
| | 205 | | { |
| 0 | 206 | | _note = newValue; |
| 0 | 207 | | _maxWeight = _remainingWeights.Where(x => x.Note == _note).Select(x => x.Weight).First(); |
| 0 | 208 | | } |
| | 209 | |
|
| | 210 | | private int GetWeightMaxWidth() |
| | 211 | | { |
| 0 | 212 | | if (_maxWeight == 100) return 3; |
| 0 | 213 | | if (_maxWeight > 9) return 2; |
| 0 | 214 | | if (_maxWeight > 0 && _maxWeight <= 9) return 1; |
| | 215 | |
|
| 0 | 216 | | return 0; |
| | 217 | | } |
| | 218 | | } |