diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/base-table/base-table.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/base-table/base-table.component.ts index aa3ef7b..3562a11 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/base-table/base-table.component.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/base-table/base-table.component.ts @@ -127,7 +127,7 @@ export class BaseTableComponent> return this.mainGrid.api; } - set source(data: TModel[]) { + set source(data: any[]) { this.api.setSource(data) } diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/group-table/group-table.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/group-table/group-table.component.ts index 3a84629..99992ba 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/group-table/group-table.component.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/tables/group-table/group-table.component.ts @@ -7,6 +7,7 @@ import { ColorModeService } from '../../../services/color-mode.service'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { env } from '../../../../environments/environment'; +import { GroupOfUserService } from '../../../services/group-of-user.service'; @Component({ standalone: true, @@ -16,8 +17,14 @@ import { env } from '../../../../environments/environment'; styleUrl: './group-table.component.css' }) export class GroupTableComponent extends BaseTableComponent { - constructor( - service: GroupService, cModeService: ColorModeService) { + constructor(service: GroupService, cModeService: ColorModeService, private gouService: GroupOfUserService) { super(service, env.columnNames.group.complete, cModeService) } + + fetchDataByUsername(username: string) { + console.log(username) + this.gouService.getByUsername(username) + .then(gos_list => gos_list.map(gos => gos.group)) + .then(groups => this.source = groups) + } } \ No newline at end of file diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.html b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.html index 96f9d0b..e481724 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.html +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.html @@ -1 +1,26 @@ - \ No newline at end of file +
+
+
+ + + + + +
+
+ + + + + +
+
+ + + + + +
+
+
\ No newline at end of file diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.ts index f316c62..5e2e2e6 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/components/user/user.component.ts @@ -1,16 +1,21 @@ import { AfterViewInit, Component, ViewChild } from '@angular/core'; -import { GuiCellEdit } from '@generic-ui/ngx-grid'; +import { GuiCellEdit, GuiSelectedRow } from '@generic-ui/ngx-grid'; import { UserTableComponent } from '../tables/user-table/user-table.component'; import { RefreshService } from '../../services/refresh.service'; +import { MatTabsModule } from '@angular/material/tabs'; +import { GroupTableComponent } from '../../components/tables/group-table/group-table.component'; +import { ModuleTableComponent } from '../../components/tables/module-table/module-table.component'; @Component({ standalone: true, - imports: [UserTableComponent], + imports: [UserTableComponent, MatTabsModule, GroupTableComponent, ModuleTableComponent], selector: 'app-user', templateUrl: './user.component.html', styleUrl: './user.component.css' }) export class UserComponent implements AfterViewInit { + initWithoutData = () => { } + cellEditing: GuiCellEdit = { enabled: true, rowEdit: (value: any, item: any, index: number) => { @@ -21,6 +26,8 @@ export class UserComponent implements AfterViewInit { } } + private sUsername = null; + constructor(private refreshService: RefreshService) { } ngAfterViewInit(): void { @@ -31,4 +38,15 @@ export class UserComponent implements AfterViewInit { } @ViewChild("userTable") userTable!: UserTableComponent + @ViewChild("groupTable") groupTable!: GroupTableComponent; + @ViewChild("moduleTable") moduleTable!: ModuleTableComponent; + + usersOnSelectedRows = (rows: GuiSelectedRow[]) => { + if (rows.length > 0) { + this.sUsername = rows[0].source.username; + + if (this.sUsername != null) + this.groupTable.fetchDataByUsername(this.sUsername); + } + } } \ No newline at end of file diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/group-of-user.service.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/group-of-user.service.ts index 7669dbf..ade2161 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/group-of-user.service.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/group-of-user.service.ts @@ -2,14 +2,14 @@ import { Injectable, Inject } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { GroupOfUser } from '../models/user-management.api.models'; import { ApiService } from './user-management.api.service'; -import { Observable } from 'rxjs'; +import { Observable, firstValueFrom } from 'rxjs'; import { UrlService } from './url.service'; @Injectable({ providedIn: 'root' }) export class GroupOfUserService extends ApiService { - constructor(http: HttpClient, urlService : UrlService) { + constructor(http: HttpClient, urlService: UrlService) { super(http, urlService.apiRoute.groupOfUser); } @@ -29,4 +29,9 @@ export class GroupOfUserService extends ApiService { return this.http.get(this.baseUrl, { params, withCredentials: true }); } + + async getByUsername(username: string): Promise { + const url = `${this.baseUrl}?username=${username}`; + return await firstValueFrom(this.http.get(url, { withCredentials: true })); + } } \ No newline at end of file diff --git a/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs b/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs index 7b9a447..5f7a0c5 100644 --- a/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs +++ b/DigitalData.UserManager.API/Controllers/GroupOfUserController.cs @@ -37,10 +37,17 @@ namespace DigitalData.UserManager.API.Controllers public override Task GetAll() => base.GetAll(); [HttpGet] - public async Task GetAll([FromQuery]bool withUser = false, [FromQuery]bool withGroup = false) + public async Task GetAll([FromQuery]bool withUser = false, [FromQuery]bool withGroup = false, [FromQuery] string? username = null) { try { + if (username is not null) + return await _service.ReadByUsernameAsync(username).ThenAsync(Ok, IActionResult (m, n) => + { + _logger.LogNotice(n); + return NotFound(); + }); + return await _service.ReadAllAsyncWith(withUser, withGroup).ThenAsync(Ok, IActionResult (m, n) => { _logger.LogNotice(n); diff --git a/DigitalData.UserManager.Application/Contracts/IGroupOfUserService.cs b/DigitalData.UserManager.Application/Contracts/IGroupOfUserService.cs index aa48951..856a295 100644 --- a/DigitalData.UserManager.Application/Contracts/IGroupOfUserService.cs +++ b/DigitalData.UserManager.Application/Contracts/IGroupOfUserService.cs @@ -12,5 +12,7 @@ namespace DigitalData.UserManager.Application.Contracts Task>> ReadAllAsyncWith(bool user, bool group); Task HasGroup(string username, string groupname, bool caseSensitive = true); + + Task>> ReadByUsernameAsync(string username); } } \ No newline at end of file diff --git a/DigitalData.UserManager.Application/Services/GroupOfUserService.cs b/DigitalData.UserManager.Application/Services/GroupOfUserService.cs index dd67d39..0602455 100644 --- a/DigitalData.UserManager.Application/Services/GroupOfUserService.cs +++ b/DigitalData.UserManager.Application/Services/GroupOfUserService.cs @@ -5,7 +5,6 @@ using DigitalData.UserManager.Application.Contracts; using DigitalData.UserManager.Application.DTOs.GroupOfUser; using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Infrastructure.Contracts; -using Microsoft.Extensions.Localization; namespace DigitalData.UserManager.Application.Services { @@ -63,5 +62,12 @@ namespace DigitalData.UserManager.Application.Services return gous.Any() ? Result.Success() : Result.Fail(); } + + public async Task>> ReadByUsernameAsync(string username) + { + var groups = await _repository.ReadByUsernameAsync(username); + var groupDtos = _mapper.MapOrThrow>(groups); + return Result.Success(groupDtos); + } } } \ No newline at end of file diff --git a/DigitalData.UserManager.Infrastructure/Contracts/IGroupOfUserRepository.cs b/DigitalData.UserManager.Infrastructure/Contracts/IGroupOfUserRepository.cs index 886d6ab..c47f06e 100644 --- a/DigitalData.UserManager.Infrastructure/Contracts/IGroupOfUserRepository.cs +++ b/DigitalData.UserManager.Infrastructure/Contracts/IGroupOfUserRepository.cs @@ -14,5 +14,7 @@ namespace DigitalData.UserManager.Infrastructure.Contracts Task> ReadAllAsyncWithUser(); Task> ReadAllAsyncWithGroupAndUser(); + + Task> ReadByUsernameAsync(string username); } } \ No newline at end of file diff --git a/DigitalData.UserManager.Infrastructure/Repositories/GroupOfUserRepository.cs b/DigitalData.UserManager.Infrastructure/Repositories/GroupOfUserRepository.cs index 8b92ead..87e9ebd 100644 --- a/DigitalData.UserManager.Infrastructure/Repositories/GroupOfUserRepository.cs +++ b/DigitalData.UserManager.Infrastructure/Repositories/GroupOfUserRepository.cs @@ -12,9 +12,15 @@ namespace DigitalData.UserManager.Infrastructure.Repositories { } + //TODO: making it public and having it in the interface is against Clean Architecture. Make it private public IQueryable ReadByGroupId(int groupId) { - return _dbSet.Where(mou => mou.GroupId == groupId); + return _dbSet.Where(mou => mou.GroupId == groupId); + } + + private IQueryable ReadByUsername(string userName) + { + return _dbSet.Where(gou => gou.User!.Username == userName).Include(gou => gou.Group); } public async Task> ReadByGroupUserIdAsync(int groupId, int userId) @@ -26,6 +32,8 @@ namespace DigitalData.UserManager.Infrastructure.Repositories public async Task> ReadAllAsyncWithUser() => await _dbSet.Include(gou => gou.User).ToListAsync(); - public async Task> ReadAllAsyncWithGroupAndUser() => await _dbSet.Include(gou => gou.Group).Include(gou => gou.User).ToListAsync(); + public async Task> ReadAllAsyncWithGroupAndUser() => await _dbSet.Include(gou => gou.Group).Include(gou => gou.User).ToListAsync(); + + public async Task> ReadByUsernameAsync(string username) => await ReadByUsername(username).ToListAsync(); } } \ No newline at end of file