Skip to content

Commit 4382492

Browse files
Can remove API resource
1 parent f5cb020 commit 4382492

15 files changed

Lines changed: 261 additions & 157 deletions

File tree

src/IdServer/SimpleIdServer.IdServer.Store/ApiResourceRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface IApiResourceRepository
99
{
1010
IQueryable<ApiResource> Query();
1111
void Add(ApiResource apiResource);
12+
void Delete(ApiResource apiResource);
1213
Task<int> SaveChanges(CancellationToken cancellationToken);
1314
}
1415

@@ -23,6 +24,8 @@ public ApiResourceRepository(StoreDbContext dbContext)
2324

2425
public void Add(ApiResource apiResource) => _dbContext.ApiResources.Add(apiResource);
2526

27+
public void Delete(ApiResource apiResource) => _dbContext.ApiResources.Remove(apiResource);
28+
2629
public IQueryable<ApiResource> Query() => _dbContext.ApiResources;
2730

2831
public Task<int> SaveChanges(CancellationToken cancellationToken) => _dbContext.SaveChangesAsync(cancellationToken);

src/IdServer/SimpleIdServer.IdServer.Website/Pages/ScopeResources.razor

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<RadzenDataGridColumn TItem="SelectableApiResource" Property="Value.Name" Title="Resource" Filterable="false" Sortable="false" Width="80px" />
4747
<RadzenDataGridColumn TItem="SelectableApiResource" Property="Value.Audience" Title="Audience" Filterable="false" Sortable="false" Width="80px" />
4848
<RadzenDataGridColumn TItem="SelectableApiResource" Property="Value.UpdateDateTime" Filterable="false" Sortable="true" FormatString="{0:dd/M/yyyy HH:mm:ss}" SortOrder="SortOrder.Descending" Title="Update datetime" Width="80px" />
49+
<RadzenDataGridColumn TItem="SelectableApiResource" Filterable="false" Sortable="false" Width="80px" TextAlign="TextAlign.Center">
50+
<Template Context="data">
51+
<RadzenButton Icon="more_vert" Click="@(args => ShowMoreContextMenu(data, args))" />
52+
</Template>
53+
</RadzenDataGridColumn>
4954
</Columns>
5055
</RadzenDataGrid>
5156

@@ -66,6 +71,11 @@
6671
notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Success, Summary = Global.ScopeResourcesUpdated });
6772
StateHasChanged();
6873
});
74+
SubscribeToAction<RemoveSelectedApiResourcesSuccessAction>((act) =>
75+
{
76+
notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Success, Summary = Global.ScopeResourcesRemoved });
77+
StateHasChanged();
78+
});
6979
grid.Reload();
7080
}
7181
}
@@ -93,6 +103,24 @@
93103
row.Attributes.Remove(className);
94104
}
95105

106+
void ShowMoreContextMenu(SelectableApiResource resource, MouseEventArgs args)
107+
{
108+
contextMenuService.Open(args, new List<ContextMenuItem>
109+
{
110+
new ContextMenuItem { Text = "Delete", Value = 1 }
111+
}, (a) =>
112+
{
113+
if (a.Value.Equals(1))
114+
{
115+
var resourceIds = searchApiResourcesState.Value.ApiResources.Where(s => s.IsSelected).Select(s => s.Value.Id).ToList();
116+
if (!resourceIds.Contains(resource.Value.Id)) resourceIds.Add(resource.Value.Id);
117+
var act = new RemoveSelectedApiResourcesAction { ResourceIds = resourceIds };
118+
dispatcher.Dispatch(act);
119+
contextMenuService.Close();
120+
}
121+
});
122+
}
123+
96124
void LoadData(LoadDataArgs args)
97125
{
98126
var act = new SearchApiResourcesAction { Filter = args.Filter, OrderBy = args.OrderBy, Skip = args.Skip, Take = args.Top, ScopeName = Scope.Name };
@@ -110,7 +138,7 @@
110138
});
111139
}
112140

113-
async void UpdateResource()
141+
void UpdateResource()
114142
{
115143
var selectedApiResources = searchApiResourcesState.Value.ApiResources.Where(r => r.IsSelected).Select(r => r.Value.Name);
116144
dispatcher.Dispatch(new UpdateApiScopeResourcesAction { Name = Scope.Name, Resources = selectedApiResources });

0 commit comments

Comments
 (0)