| | 1 | | @using Syki.Front.Components.Agenda |
| | 2 | | @using Syki.Front.Features.Academic.CreateClass |
| | 3 | |
|
| | 4 | | @namespace Syki.Front.Features.Academic.BuildClassroomAssignment |
| | 5 | |
|
| | 6 | | <MudDialog Class="pb-2" DefaultFocus="DefaultFocus.None"> |
| | 7 | | <TitleContent> |
| | 8 | | <SykiDialogTitle Icon="@Icons.Material.Filled.VideoLabel" Text="@($"{Classroom.Name} ({Classroom.Capacity} vagas |
| | 9 | | </TitleContent> |
| | 10 | | <DialogContent> |
| | 11 | | <MudGrid Spacing="2"> |
| | 12 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | 13 | | <MudSelect |
| | 14 | | Dense |
| | 15 | | Margin="Margin.Dense" |
| | 16 | | Variant="Variant.Outlined" |
| | 17 | | @bind-Value="@_class" |
| | 18 | | Label="Turma" |
| | 19 | | Required |
| | 20 | | RequiredError="Informe!" |
| | 21 | | AdornmentColor="Color.Primary" |
| | 22 | | > |
| 0 | 23 | | @foreach (GetCampusClassesOut? item in Classes) |
| | 24 | | { |
| 0 | 25 | | <MudSelectItem Value="@item">@item.Discipline ● @item.Teacher</MudSelectItem> |
| | 26 | | } |
| | 27 | | </MudSelect> |
| | 28 | | </MudItem> |
| | 29 | |
|
| | 30 | | <MudItem xs="12" sm="4" md="4" lg="4"> |
| | 31 | | <MudSelect |
| | 32 | | Dense |
| | 33 | | Margin="Margin.Dense" |
| | 34 | | Variant="Variant.Outlined" |
| | 35 | | T="Day?" |
| | 36 | | @bind-Value="@_schedule.Day" |
| | 37 | | Label="Dia" |
| | 38 | | Required |
| | 39 | | RequiredError="Informe!" |
| | 40 | | AdornmentColor="Color.Primary" |
| | 41 | | > |
| 0 | 42 | | @foreach (Day? day in Enum.GetValues<Day>()) |
| | 43 | | { |
| 0 | 44 | | <MudSelectItem Value="@day">@day.GetDescription()</MudSelectItem> |
| | 45 | | } |
| | 46 | | </MudSelect> |
| | 47 | | </MudItem> |
| | 48 | | <MudItem xs="12" sm="3" md="3" lg="3"> |
| | 49 | | <MudSelect |
| | 50 | | Dense |
| | 51 | | Margin="Margin.Dense" |
| | 52 | | Variant="Variant.Outlined" |
| | 53 | | T="Hour?" |
| | 54 | | @bind-Value="@_schedule.Start" |
| | 55 | | Label="Início" |
| | 56 | | Required |
| | 57 | | RequiredError="Informe!" |
| | 58 | | AdornmentColor="Color.Primary" |
| | 59 | | > |
| 0 | 60 | | @foreach (Hour? hour in Enum.GetValues<Hour>()) |
| | 61 | | { |
| 0 | 62 | | <MudSelectItem Value="@hour">@hour.GetDescription()</MudSelectItem> |
| | 63 | | } |
| | 64 | | </MudSelect> |
| | 65 | | </MudItem> |
| | 66 | | <MudItem xs="12" sm="3" md="3" lg="3"> |
| | 67 | | <MudSelect |
| | 68 | | Dense |
| | 69 | | Margin="Margin.Dense" |
| | 70 | | Variant="Variant.Outlined" |
| | 71 | | T="Hour?" |
| | 72 | | @bind-Value="@_schedule.End" |
| | 73 | | Label="Fim" |
| | 74 | | Required |
| | 75 | | RequiredError="Informe!" |
| | 76 | | AdornmentColor="Color.Primary" |
| | 77 | | > |
| 0 | 78 | | @foreach (Hour? hour in Enum.GetValues<Hour>()) |
| | 79 | | { |
| 0 | 80 | | if (_schedule.Start == null || hour <= _schedule.Start) continue; |
| 0 | 81 | | <MudSelectItem Value="@hour">@hour.GetDescription()</MudSelectItem> |
| | 82 | | } |
| | 83 | | </MudSelect> |
| | 84 | | </MudItem> |
| | 85 | |
|
| | 86 | | <MudItem xs="12" sm="2" md="2" lg="2" Class="d-flex align-center justify-center"> |
| | 87 | | <MudButton |
| | 88 | | StartIcon="@Icons.Material.Outlined.Add" |
| | 89 | | IconSize="Size.Medium" |
| | 90 | | Variant="Variant.Filled" |
| | 91 | | Size="Size.Medium" |
| | 92 | | Color="Color.Primary" |
| | 93 | | OnClick="@AddNewSchedule" |
| | 94 | | Disabled="@(_class == null || _schedule == null || _schedule.Day == null || _schedule.Start == null |
| | 95 | | > |
| | 96 | | Horário |
| | 97 | | </MudButton> |
| | 98 | | </MudItem> |
| | 99 | | </MudGrid> |
| | 100 | |
|
| | 101 | | <CascadingValue Name="Days" Value="@_agenda"> |
| | 102 | | <WeeklyAgenda Class="px-0 pt-4 pb-2" /> |
| | 103 | | </CascadingValue> |
| | 104 | | </DialogContent> |
| | 105 | | </MudDialog> |
| | 106 | |
|
| | 107 | | @inject ISnackbar Snackbar |
| | 108 | | @inject GetClassroomAgendaClient GetClassroomAgendaClient |
| | 109 | | @inject AssignClassToClassroomClient AssignClassToClassroomClient |
| | 110 | |
|
| | 111 | | @code |
| | 112 | | { |
| | 113 | | [CascadingParameter] |
| 0 | 114 | | IMudDialogInstance MudDialog { get; set; } |
| | 115 | |
|
| | 116 | | [Parameter] |
| 0 | 117 | | public GetClassroomsOut Classroom { get; set; } = new(); |
| | 118 | |
|
| | 119 | | [Parameter] |
| 0 | 120 | | public List<GetCampusClassesOut> Classes { get; set; } = []; |
| | 121 | |
|
| | 122 | | private bool _loading; |
| 0 | 123 | | private ScheduleInFillable? _schedule = new(); |
| | 124 | | private GetCampusClassesOut? _class; |
| 0 | 125 | | private List<AgendaDayOut> _agenda = []; |
| | 126 | |
|
| | 127 | | protected override async Task OnInitializedAsync() |
| | 128 | | { |
| 0 | 129 | | _agenda = await GetClassroomAgendaClient.Get(Classroom.Id); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | private async Task AddNewSchedule() |
| | 133 | | { |
| 0 | 134 | | if (_schedule == null) return; |
| 0 | 135 | | if (_schedule.Day == null) return; |
| 0 | 136 | | if (_schedule.Start == null) return; |
| 0 | 137 | | if (_schedule.End == null) return; |
| | 138 | |
|
| 0 | 139 | | var @class = Classes.FirstOrDefault(x => x.Id == _class?.Id); |
| 0 | 140 | | if (@class == null) return; |
| | 141 | |
|
| 0 | 142 | | if (_loading) return; |
| 0 | 143 | | _loading = true; |
| | 144 | |
|
| 0 | 145 | | var schedules = new List<ScheduleIn>(); |
| 0 | 146 | | foreach (var agenda in _agenda) |
| | 147 | | { |
| 0 | 148 | | foreach (var d in agenda.Disciplines.Where(d => d.ClassId == _class.Id)) |
| | 149 | | { |
| 0 | 150 | | schedules.Add(new ScheduleIn(agenda.Day, d.Start, d.End)); |
| | 151 | | } |
| | 152 | | } |
| 0 | 153 | | schedules.Add(new ScheduleIn(_schedule.Day!.Value, _schedule.Start!.Value, _schedule.End!.Value)); |
| | 154 | |
|
| 0 | 155 | | var response = await AssignClassToClassroomClient.Assign(Classroom.Id, _class.Id, schedules); |
| 0 | 156 | | if (response.IsSuccess) |
| | 157 | | { |
| 0 | 158 | | Snackbar.Add("Horário salvo com sucesso!", Severity.Success); |
| 0 | 159 | | _class = null; |
| 0 | 160 | | _schedule = new(); |
| 0 | 161 | | _agenda = await GetClassroomAgendaClient.Get(Classroom.Id); |
| | 162 | | } |
| | 163 | | else |
| | 164 | | { |
| 0 | 165 | | Snackbar.Add(response.Error.Message, Severity.Error); |
| | 166 | | } |
| 0 | 167 | | _loading = false; |
| 0 | 168 | | } |
| | 169 | |
|
| 0 | 170 | | void Cancel() => MudDialog.Cancel(); |
| | 171 | | } |