Skip to content

Commit

Permalink
feat: resolved dto changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gzozo committed Oct 8, 2024
1 parent 0ab88a9 commit 5c9ce41
Show file tree
Hide file tree
Showing 23 changed files with 1,633 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<TemplateColumn Title="Actions" T="TItem">
<CellTemplate>
<MudStack Row>
@if (AddEdit)
@if (ShowEdit)
{
<MudIconButton Icon="@Icons.Material.Filled.Edit" Color="Color.Primary" Size="Size.Small" OnClick="@(() => StartEditing(context))"/>
}
@if (AddDelete)
@if (ShowDelete)
{
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Size="Size.Small" OnClick="@(() => DeleteItem(context.Item))"/>
}
Expand All @@ -19,8 +19,8 @@

[Parameter] public Func<CellContext<TItem>, Task>? OnEditItem { get; set; }
[Parameter] public Func<TItem, Task>? OnDeleteItem { get; set; }
[Parameter] public bool AddEdit { get; set; } = true;
[Parameter] public bool AddDelete { get; set; } = true;
[Parameter] public bool ShowEdit { get; set; } = true;
[Parameter] public bool ShowDelete { get; set; } = true;


private async Task StartEditing(CellContext<TItem> context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
@inject ExerciseClient ExerciseClient

<MudDataGrid T="Exercise2" Items="Values" EditMode="DataGridEditMode.Form" ReadOnly="false" CommittedItemChanges="@CommittedItemChanges" Style="width: 100%">
<MudDataGrid T="ExerciseResponse" Items="Values" EditMode="DataGridEditMode.Form" ReadOnly="false" CommittedItemChanges="@CommittedItemChanges" Style="width: 100%">
<Columns>
<PropertyColumn Property="x => x.Id" Title="Id" Editable="false"/>
<PropertyColumn Property="x => x.Name" Title="Name"/>
<PropertyColumn Property="x => x.GithubPrefix" Title="Github Prefix"/>
<PropertyColumn Property="x => x.DueDate" Title="Due Date"/>
<PropertyColumn Property="x => JoinScoreTypes(x)" Title="Score Types"/>
<DataGridActions TItem="Exercise2" OnEditItem="@StartEditing" OnDeleteItem="@DeleteItem"/>
<DataGridActions TItem="ExerciseResponse" OnEditItem="@StartEditing" OnDeleteItem="@DeleteItem"/>
</Columns>
</MudDataGrid>


@code {
[Parameter] public ICollection<Exercise2> Values { get; set; }
[Parameter] public ICollection<ExerciseResponse> Values { get; set; }

private string JoinScoreTypes(Exercise2 item) => string.Join(", ", item.ScoreTypes.Select(x => $"{x.Key}: {x.Value}"));
private string JoinScoreTypes(ExerciseResponse item) => string.Join(", ", item.ScoreTypes.Select(x => $"{x.Key}: {x.Value}"));

private async Task StartEditing(CellContext<Exercise2?> context)
private async Task StartEditing(CellContext<ExerciseResponse?> context)
{
await context.Actions.StartEditingItemAsync();
StateHasChanged();
}

private async Task CommittedItemChanges(Exercise2 items)
private async Task CommittedItemChanges(ExerciseResponse items)
{
await ExerciseClient.UpdateAsync(items.Id, items);
await ExerciseClient.UpdateAsync(items.Id, items.ToRequest());
}

private async Task DeleteItem(Exercise2 item)
private async Task DeleteItem(ExerciseResponse item)
{
Values.Remove(item);
await ExerciseClient.DeleteAsync(item.Id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
@inject CrudSnackbarService SnackbarService
@inject GroupClient GroupClient

<MudDataGrid T="Group2" Items="Values" EditMode="DataGridEditMode.Form" ReadOnly="false" CommittedItemChanges="@CommittedItemChanges" Style="width: 100%">
<MudDataGrid T="GroupResponse" Items="Values" EditMode="DataGridEditMode.Form" ReadOnly="false" CommittedItemChanges="@CommittedItemChanges" Style="width: 100%">
<Columns>
<PropertyColumn Property="x => x.Id" Title="Id" Editable="false"/>
<PropertyColumn Property="x => x.Name" Title="Name"/>
<DataGridActions TItem="Group2" OnEditItem="@StartEditing" OnDeleteItem="@DeleteItem"/>
<DataGridActions TItem="GroupResponse" OnEditItem="@StartEditing" OnDeleteItem="@DeleteItem"/>
</Columns>
</MudDataGrid>


@code {
[Parameter] public ICollection<Group2> Values { get; set; }
[Parameter] public ICollection<GroupResponse> Values { get; set; }

private async Task StartEditing(CellContext<Group2?> context)
private async Task StartEditing(CellContext<GroupResponse?> context)
{
await context.Actions.StartEditingItemAsync();
StateHasChanged();
}

private async Task CommittedItemChanges(Group2 items)
private async Task CommittedItemChanges(GroupResponse items)
{
await GroupClient.UpdateAsync(items.Id, items);
await GroupClient.UpdateAsync(items.Id, items.ToRequest());
SnackbarService.ShowEditSuccess();
StateHasChanged();
}

private async Task DeleteItem(Group2 item)
private async Task DeleteItem(GroupResponse item)
{
Values.Remove(item);
await GroupClient.DeleteAsync(item.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
</style>

<MudSelect T="Subject" Value="@Value"
ValueChanged="@((Subject value) => { Value = value; ValueChanged.InvokeAsync(value); })"
<MudSelect T="SubjectResponse" Value="@Value"
ValueChanged="@((SubjectResponse value) => { Value = value; ValueChanged.InvokeAsync(value); })"
ToStringFunc="@subjectToString" Label="Subject" Class="white-select" Dense="true" Variant="Variant.Outlined"
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
@foreach (var semester in PossibleValues)
{
<MudSelectItem Value="@semester"/>
<MudSelectItem Value="@semester"/>
}
</MudSelect>

@code {
[Parameter] public Subject Value { get; set; }
[Parameter] public List<Subject> PossibleValues { get; set; }
[Parameter] public EventCallback<Subject> ValueChanged { get; set; }
[Parameter] public SubjectResponse Value { get; set; }
[Parameter] public List<SubjectResponse> PossibleValues { get; set; }
[Parameter] public EventCallback<SubjectResponse> ValueChanged { get; set; }

private Func<Subject, string> subjectToString = p => p.Name;
private Func<SubjectResponse, string> subjectToString = p => p.Name;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,83 @@ namespace GradeManagement.Client.Components.Helpers;

public static class Extensions
{
public static Subject2 ToSubject2(this Subject subject, ICollection<User>? teachers = null)
public static SubjectRequest ToRequest(this SubjectResponse subject, ICollection<User>? teachers = null)
{
return new Subject2
return new SubjectRequest
{
Id = subject.Id,
Name = subject.Name,
NeptunCode = subject.NeptunCode,
GitHubOrgName = subject.GitHubOrgName,
Teachers = teachers
Teachers = teachers,
};
}

public static Subject ToSubject(this Subject2 subject)
public static SubjectResponse ToResponse(this SubjectRequest subject)
{
return new Subject
return new SubjectResponse
{
Id = subject.Id,
Name = subject.Name,
NeptunCode = subject.NeptunCode,
GitHubOrgName = subject.GitHubOrgName
GitHubOrgName = subject.GitHubOrgName,
};
}

public static Group2 ToGroup2(this Group group, ICollection<User>? teachers = null)
public static GroupRequest ToRequest(this GroupResponse group, ICollection<User>? teachers = null)
{
return new GroupRequest { Id = group.Id, Name = group.Name, CourseId = group.CourseId, Teachers = teachers };
}

public static GroupResponse ToResponse(this GroupRequest group)
{
return new GroupResponse { Id = group.Id, Name = group.Name, CourseId = group.CourseId };
}

public static ExerciseRequest ToRequest(this ExerciseResponse exercise)
{
return new Group2 { Id = group.Id, Name = group.Name, CourseId = group.CourseId, Teachers = teachers };
return new ExerciseRequest
{
Id = exercise.Id,
CourseId = exercise.CourseId,
Name = exercise.Name,
DueDate = exercise.DueDate,
GithubPrefix = exercise.GithubPrefix,
ScoreTypes = exercise.ScoreTypes
};
}

public static Group ToGroup(this Group2 group)
public static ExerciseResponse ToResponse(this ExerciseRequest exercise)
{
return new Group { Id = group.Id, Name = group.Name, CourseId = group.CourseId };
return new ExerciseResponse
{
Id = exercise.Id,
CourseId = exercise.CourseId,
Name = exercise.Name,
DueDate = exercise.DueDate,
GithubPrefix = exercise.GithubPrefix,
ScoreTypes = exercise.ScoreTypes
};
}

public static Student2 ToStudent2(this Student student, ICollection<long>? groupIds = null)

public static StudentRequest ToRequest(this StudentResponse student, ICollection<long>? groupIds = null)
{
return new Student2
return new StudentRequest
{
Id = student.Id,
Name = student.Name,
NeptunCode = student.NeptunCode,
GithubId = student.GithubId,
GroupIds = groupIds
GroupIds = groupIds,
};
}

public static Student ToStudent(this Student2 student)
public static StudentResponse ToResponse(this StudentRequest student)
{
return new Student
return new StudentResponse
{
Id = student.Id, Name = student.Name, NeptunCode = student.NeptunCode, GithubId = student.GithubId
Id = student.Id, Name = student.Name, NeptunCode = student.NeptunCode, GithubId = student.GithubId,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
}
}

public Exercise2 value = new();
public ExerciseRequest value = new();

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
_availableUsers = await UserClient.GetAllAsync();
}

public Group2 value = new();
public GroupRequest value = new();
private ICollection<User> _availableUsers = new List<User>();
private IEnumerable<User> _selectedUsers = new List<User>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
}

public Student2 value = new()
public StudentRequest value = new()
{
GroupIds = []
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
}

public Subject2 value = new()
public SubjectRequest value = new()
{
Teachers = new List<User>() //TODO: add current user
};
Expand Down
Loading

0 comments on commit 5c9ce41

Please sign in to comment.