-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathSkillTable.razor
96 lines (87 loc) · 3.2 KB
/
SkillTable.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@using LinkDotNet.Blog.Domain
@using LinkDotNet.Blog.Infrastructure.Persistence
@inject IRepository<Skill> Repository
<div>
@if (ShowAdminActions)
{
<button type="button" class="btn btn-primary" @onclick="() => AddSkillDialog.Open()">
<i class="plus"></i>Add skill</button>
<AddSkillDialog @ref="AddSkillDialog" SkillAdded="@AddSkill"></AddSkillDialog>
}
</div>
<div class="aboutme-table-container">
<table class="aboutme-skill-table" id="aboutme-skill-table">
<tbody>
<tr>
<th>Capability</th>
<th>Familiar with</th>
<th>Proficient</th>
<th>Expert</th>
</tr>
@foreach (var skillCapabilityGroup in skills.GroupBy(s => s.Capability))
{
<tr ondragover="event.preventDefault();">
<td>@skillCapabilityGroup.Key</td>
@foreach (var skillLevel in ProficiencyLevel.All)
{
<td @ondrop="@(() => HandleDrop(skillLevel))" class="proficiency-level">
@foreach (var skill in skillCapabilityGroup.Where(s => s.ProficiencyLevel == skillLevel))
{
@if (ShowAdminActions)
{
<div draggable="true" @ondrag="@(() => currentDragItem = skill)" style="cursor: grab"
class="skill-tag">
<SkillTag Skill="@skill"
ShowAdminActions="@true"
DeleteSkill="@(() => DeleteSkill(skill))"/>
</div>
}
else
{
<div>
<SkillTag Skill="@skill"/>
</div>
}
}
</td>
}
</tr>
}
</tbody>
</table>
@if (ShowAdminActions)
{
<small for="aboutme-skill-table">You can drag and drop your skills from one proficiency to another</small>
}
</div>
@code {
[Parameter]
public bool ShowAdminActions { get; set; }
private AddSkillDialog AddSkillDialog { get; set; } = default!;
private List<Skill> skills = [];
private Skill? currentDragItem;
protected override async Task OnInitializedAsync()
{
skills = (await Repository.GetAllAsync()).ToList();
}
private async Task AddSkill(Skill skillToAdd)
{
skills.Add(skillToAdd);
await Repository.StoreAsync(skillToAdd);
}
private async Task DeleteSkill(Skill skill)
{
skills.Remove(skill);
await Repository.DeleteAsync(skill.Id);
}
private async Task HandleDrop(ProficiencyLevel proficiencyLevel)
{
if (currentDragItem is null || currentDragItem.ProficiencyLevel == proficiencyLevel)
{
return;
}
currentDragItem.SetProficiencyLevel(proficiencyLevel);
await Repository.StoreAsync(currentDragItem);
currentDragItem = null;
}
}