From 3ae049894b0eb9a1898dc65813d0a1155a923eb0 Mon Sep 17 00:00:00 2001 From: cv5ch <176032962+cv5ch@users.noreply.github.com> Date: Thu, 3 Jul 2025 14:11:00 +0200 Subject: [PATCH] - Refactored service injection in base datasource so that not all child classes have to pass the injected services again - Inject permissionService in base datasource so that datasources kann make permission Checks --- .../access-groups-agents-table.component.ts | 2 +- .../access-groups-table.component.ts | 2 +- .../access-groups-users-table.component.ts | 2 +- ...-permission-groups-user-table.component.ts | 2 +- ...permission-groups-users-table.component.ts | 2 +- .../agent-binaries-table.component.ts | 2 +- .../agent-error-table.component.ts | 2 +- .../agents-status-table.component.ts | 2 +- .../agents-table/agents-table.component.ts | 2 +- .../tables/base-table/base-table.component.ts | 3 +- .../chunks-table/chunks-table.component.ts | 2 +- .../crackers-table.component.ts | 2 +- .../cracks-table/cracks-table.component.ts | 2 +- .../files-attack-table.component.ts | 2 +- .../files-table/files-table.component.ts | 2 +- .../hashes-table/hashes-table.component.ts | 2 +- .../hashlists-table.component.ts | 2 +- .../hashtypes-table.component.ts | 2 +- .../health-check-agents-table.component.ts | 2 +- .../health-checks-table.component.ts | 2 +- .../tables/logs-table/logs-table.component.ts | 2 +- .../notifications-table.component.ts | 2 +- .../permissions-table.component.ts | 2 +- .../preprocessors-table.component.ts | 2 +- .../pretasks-table.component.ts | 2 +- .../search-hash-table.component.ts | 2 +- .../super-hashlists-table.component.ts | 2 +- .../supertasks-pretasks-table.component.ts | 2 +- .../supertasks-table.component.ts | 2 +- .../tasks-chunks-table.component.ts | 2 +- .../tasks-supertasks-table.component.ts | 2 +- .../tasks-table/tasks-table.component.ts | 2 +- .../users-table/users-table.component.ts | 2 +- .../vouchers-table.component.ts | 2 +- .../core/_datasources/agents.datasource.ts | 35 +++++++------------ src/app/core/_datasources/base.datasource.ts | 19 ++++++---- 36 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/app/core/_components/tables/access-groups-agents-table/access-groups-agents-table.component.ts b/src/app/core/_components/tables/access-groups-agents-table/access-groups-agents-table.component.ts index 9e1bd7650..c061e2bc8 100644 --- a/src/app/core/_components/tables/access-groups-agents-table/access-groups-agents-table.component.ts +++ b/src/app/core/_components/tables/access-groups-agents-table/access-groups-agents-table.component.ts @@ -36,7 +36,7 @@ export class AccessGroupsAgentsTableComponent extends BaseTableComponent impleme ngOnInit(): void { this.setColumnLabels(AccessGroupsAgentsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AccessGroupsExpandDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AccessGroupsExpandDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.accessgroupId) { this.dataSource.setAccessGroupId(this.accessgroupId); diff --git a/src/app/core/_components/tables/access-groups-table/access-groups-table.component.ts b/src/app/core/_components/tables/access-groups-table/access-groups-table.component.ts index 4cc7efa7a..f6972ccb6 100644 --- a/src/app/core/_components/tables/access-groups-table/access-groups-table.component.ts +++ b/src/app/core/_components/tables/access-groups-table/access-groups-table.component.ts @@ -34,7 +34,7 @@ export class AccessGroupsTableComponent extends BaseTableComponent implements On ngOnInit(): void { this.setColumnLabels(AccessGroupsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AccessGroupsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AccessGroupsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new AccessGroupsContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/access-groups-users-table/access-groups-users-table.component.ts b/src/app/core/_components/tables/access-groups-users-table/access-groups-users-table.component.ts index 0558fe59a..c7f942229 100644 --- a/src/app/core/_components/tables/access-groups-users-table/access-groups-users-table.component.ts +++ b/src/app/core/_components/tables/access-groups-users-table/access-groups-users-table.component.ts @@ -40,7 +40,7 @@ export class AccessGroupsUserTableComponent extends BaseTableComponent implement ngOnInit(): void { this.setColumnLabels(AccessGroupsUsersTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AccessGroupsExpandDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AccessGroupsExpandDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.accessgroupId) { this.dataSource.setAccessGroupId(this.accessgroupId); diff --git a/src/app/core/_components/tables/access-permission-groups-user-table/access-permission-groups-user-table.component.ts b/src/app/core/_components/tables/access-permission-groups-user-table/access-permission-groups-user-table.component.ts index 716239f5f..b2d30e00a 100644 --- a/src/app/core/_components/tables/access-permission-groups-user-table/access-permission-groups-user-table.component.ts +++ b/src/app/core/_components/tables/access-permission-groups-user-table/access-permission-groups-user-table.component.ts @@ -34,7 +34,7 @@ export class AccessPermissionGroupsUserTableComponent extends BaseTableComponent ngOnInit(): void { this.setColumnLabels(AccessPermissionGroupsUserTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AccessPermissionGroupsExpandDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AccessPermissionGroupsExpandDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.accesspermgroupId) { this.dataSource.setAccessPermGroupId(this.accesspermgroupId); diff --git a/src/app/core/_components/tables/access-permission-groups-users-table/access-permission-groups-users-table.component.ts b/src/app/core/_components/tables/access-permission-groups-users-table/access-permission-groups-users-table.component.ts index 0a8c11574..3781b59e7 100644 --- a/src/app/core/_components/tables/access-permission-groups-users-table/access-permission-groups-users-table.component.ts +++ b/src/app/core/_components/tables/access-permission-groups-users-table/access-permission-groups-users-table.component.ts @@ -32,7 +32,7 @@ export class AccessPermissionGroupsUsersTableComponent extends BaseTableComponen ngOnInit(): void { this.setColumnLabels(AccessPermissionGroupsUsersTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AccessPermissionGroupsExpandDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AccessPermissionGroupsExpandDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.accesspermgroupId) { this.dataSource.setAccessPermGroupId(this.accesspermgroupId); diff --git a/src/app/core/_components/tables/agent-binaries-table/agent-binaries-table.component.ts b/src/app/core/_components/tables/agent-binaries-table/agent-binaries-table.component.ts index a2118f78f..0e9439654 100644 --- a/src/app/core/_components/tables/agent-binaries-table/agent-binaries-table.component.ts +++ b/src/app/core/_components/tables/agent-binaries-table/agent-binaries-table.component.ts @@ -37,7 +37,7 @@ export class AgentBinariesTableComponent extends BaseTableComponent implements O ngOnInit(): void { this.setColumnLabels(AgentBinariesTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AgentBinariesDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AgentBinariesDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new AgentBinariesMenuServiceContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/agent-error-table/agent-error-table.component.ts b/src/app/core/_components/tables/agent-error-table/agent-error-table.component.ts index 88092776e..76ab0840c 100644 --- a/src/app/core/_components/tables/agent-error-table/agent-error-table.component.ts +++ b/src/app/core/_components/tables/agent-error-table/agent-error-table.component.ts @@ -40,7 +40,7 @@ export class AgentErrorTableComponent extends BaseTableComponent implements OnIn ngOnInit(): void { this.setColumnLabels(AgentErrorTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AgentErrorDatasource(this.cdr, this.gs, this.uiService); + this.dataSource = new AgentErrorDatasource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.agentId) { diff --git a/src/app/core/_components/tables/agents-status-table/agents-status-table.component.ts b/src/app/core/_components/tables/agents-status-table/agents-status-table.component.ts index c9fa07a68..d88aa057d 100644 --- a/src/app/core/_components/tables/agents-status-table/agents-status-table.component.ts +++ b/src/app/core/_components/tables/agents-status-table/agents-status-table.component.ts @@ -52,7 +52,7 @@ export class AgentsStatusTableComponent extends BaseTableComponent implements On ngOnInit(): void { this.setColumnLabels(AgentsStatusTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AgentsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AgentsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new AgentMenuService(this.permissionService).addContextMenu(); this.dataSource.reload(); diff --git a/src/app/core/_components/tables/agents-table/agents-table.component.ts b/src/app/core/_components/tables/agents-table/agents-table.component.ts index e305a240f..4bf4a9cb6 100644 --- a/src/app/core/_components/tables/agents-table/agents-table.component.ts +++ b/src/app/core/_components/tables/agents-table/agents-table.component.ts @@ -56,7 +56,7 @@ export class AgentsTableComponent extends BaseTableComponent implements OnInit, ngOnInit(): void { this.setColumnLabels(AgentsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new AgentsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new AgentsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.taskId) { this.dataSource.setTaskId(this.taskId); diff --git a/src/app/core/_components/tables/base-table/base-table.component.ts b/src/app/core/_components/tables/base-table/base-table.component.ts index 1dfcf5d47..cb0a1b3f9 100644 --- a/src/app/core/_components/tables/base-table/base-table.component.ts +++ b/src/app/core/_components/tables/base-table/base-table.component.ts @@ -2,7 +2,7 @@ import { faKey, faShieldHalved } from '@fortawesome/free-solid-svg-icons'; import { Observable, Subscription, of } from 'rxjs'; import { Clipboard } from '@angular/cdk/clipboard'; -import { ChangeDetectorRef, Component, Input, ViewChild } from '@angular/core'; +import { ChangeDetectorRef, Component, Injector, Input, ViewChild } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { Router } from '@angular/router'; @@ -57,6 +57,7 @@ export class BaseTableComponent { protected contextMenuService: ContextMenuService; constructor( + protected injector: Injector, protected gs: GlobalService, protected cs: ConfigService, public clipboard: Clipboard, diff --git a/src/app/core/_components/tables/chunks-table/chunks-table.component.ts b/src/app/core/_components/tables/chunks-table/chunks-table.component.ts index 13579c740..bee193ffa 100644 --- a/src/app/core/_components/tables/chunks-table/chunks-table.component.ts +++ b/src/app/core/_components/tables/chunks-table/chunks-table.component.ts @@ -32,7 +32,7 @@ export class ChunksTableComponent extends BaseTableComponent implements OnInit { ngOnInit(): void { this.setColumnLabels(ChunksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new ChunksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new ChunksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.agentId) { this.dataSource.setAgentId(this.agentId); diff --git a/src/app/core/_components/tables/crackers-table/crackers-table.component.ts b/src/app/core/_components/tables/crackers-table/crackers-table.component.ts index 83c36738f..0ced0861d 100644 --- a/src/app/core/_components/tables/crackers-table/crackers-table.component.ts +++ b/src/app/core/_components/tables/crackers-table/crackers-table.component.ts @@ -31,7 +31,7 @@ export class CrackersTableComponent extends BaseTableComponent implements OnInit ngOnInit(): void { this.setColumnLabels(CrackersTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new CrackersDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new CrackersDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new CrackersContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/cracks-table/cracks-table.component.ts b/src/app/core/_components/tables/cracks-table/cracks-table.component.ts index 8d2d013fd..81184aaea 100644 --- a/src/app/core/_components/tables/cracks-table/cracks-table.component.ts +++ b/src/app/core/_components/tables/cracks-table/cracks-table.component.ts @@ -28,7 +28,7 @@ export class CracksTableComponent extends BaseTableComponent implements OnInit, ngOnInit(): void { this.setColumnLabels(CracksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new CracksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new CracksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.loadAll().then(() => {}); } diff --git a/src/app/core/_components/tables/files-attack-table/files-attack-table.component.ts b/src/app/core/_components/tables/files-attack-table/files-attack-table.component.ts index 24c0b9041..d06f3fedb 100644 --- a/src/app/core/_components/tables/files-attack-table/files-attack-table.component.ts +++ b/src/app/core/_components/tables/files-attack-table/files-attack-table.component.ts @@ -36,7 +36,7 @@ export class FilesAttackTableComponent extends BaseTableComponent implements OnI ngOnInit(): void { this.setColumnLabels(FilesAttackTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new FilesDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new FilesDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.setFileType(this.fileType); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/files-table/files-table.component.ts b/src/app/core/_components/tables/files-table/files-table.component.ts index 1c7f67ce5..4c9039065 100644 --- a/src/app/core/_components/tables/files-table/files-table.component.ts +++ b/src/app/core/_components/tables/files-table/files-table.component.ts @@ -61,7 +61,7 @@ export class FilesTableComponent extends BaseTableComponent implements OnInit, O if (this.name !== 'filesTableInPreTasks') { this.contextMenuService = new FilesContextMenuService(this.permissionService).addContextMenu(); } - this.dataSource = new FilesDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new FilesDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.setFileType(this.fileType); if (this.editIndex) { diff --git a/src/app/core/_components/tables/hashes-table/hashes-table.component.ts b/src/app/core/_components/tables/hashes-table/hashes-table.component.ts index e29541c7a..da24e651e 100644 --- a/src/app/core/_components/tables/hashes-table/hashes-table.component.ts +++ b/src/app/core/_components/tables/hashes-table/hashes-table.component.ts @@ -28,7 +28,7 @@ export class HashesTableComponent extends BaseTableComponent implements OnInit, ngOnInit(): void { this.setColumnLabels(HashesTableColColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new HashesDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new HashesDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.id) { this.dataSource.setId(this.id); diff --git a/src/app/core/_components/tables/hashlists-table/hashlists-table.component.ts b/src/app/core/_components/tables/hashlists-table/hashlists-table.component.ts index af067a2d5..60eb90ec6 100644 --- a/src/app/core/_components/tables/hashlists-table/hashlists-table.component.ts +++ b/src/app/core/_components/tables/hashlists-table/hashlists-table.component.ts @@ -37,7 +37,7 @@ export class HashlistsTableComponent extends BaseTableComponent implements OnIni ngOnInit(): void { this.setColumnLabels(HashlistsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new HashlistsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new HashlistsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.setIsArchived(this.isArchived); this.contextMenuService = new HashListContextMenuService(this.permissionService).addContextMenu(); diff --git a/src/app/core/_components/tables/hashtypes-table/hashtypes-table.component.ts b/src/app/core/_components/tables/hashtypes-table/hashtypes-table.component.ts index 763696591..2a105922a 100644 --- a/src/app/core/_components/tables/hashtypes-table/hashtypes-table.component.ts +++ b/src/app/core/_components/tables/hashtypes-table/hashtypes-table.component.ts @@ -34,7 +34,7 @@ export class HashtypesTableComponent extends BaseTableComponent implements OnIni ngOnInit(): void { this.setColumnLabels(HashtypesTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new HashtypesDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new HashtypesDataSource(this.injector); this.contextMenuService = new HashTypesContextMenuService(this.permissionService).addContextMenu(); this.dataSource.setColumns(this.tableColumns); } diff --git a/src/app/core/_components/tables/health-check-agents-table/health-check-agents-table.component.ts b/src/app/core/_components/tables/health-check-agents-table/health-check-agents-table.component.ts index a7463adfa..3a9b5e53e 100644 --- a/src/app/core/_components/tables/health-check-agents-table/health-check-agents-table.component.ts +++ b/src/app/core/_components/tables/health-check-agents-table/health-check-agents-table.component.ts @@ -31,7 +31,7 @@ export class HealthCheckAgentsTableComponent extends BaseTableComponent implemen ngOnInit(): void { this.setColumnLabels(HealthCheckAgentsTableColColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new HealthCheckAgentsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new HealthCheckAgentsDataSource(this.injector); if (this.healthCheckId) { this.dataSource.setHealthCheckId(this.healthCheckId); } diff --git a/src/app/core/_components/tables/health-checks-table/health-checks-table.component.ts b/src/app/core/_components/tables/health-checks-table/health-checks-table.component.ts index 967a8999a..b838b6a48 100644 --- a/src/app/core/_components/tables/health-checks-table/health-checks-table.component.ts +++ b/src/app/core/_components/tables/health-checks-table/health-checks-table.component.ts @@ -38,7 +38,7 @@ export class HealthChecksTableComponent extends BaseTableComponent implements On ngOnInit(): void { this.setColumnLabels(HealthChecksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new HealthChecksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new HealthChecksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new HealthCheckContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/logs-table/logs-table.component.ts b/src/app/core/_components/tables/logs-table/logs-table.component.ts index d8094371c..70fe003e6 100644 --- a/src/app/core/_components/tables/logs-table/logs-table.component.ts +++ b/src/app/core/_components/tables/logs-table/logs-table.component.ts @@ -23,7 +23,7 @@ export class LogsTableComponent extends BaseTableComponent implements OnInit, On ngOnInit(): void { this.setColumnLabels(LogsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new LogsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new LogsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.loadAll(); } diff --git a/src/app/core/_components/tables/notifications-table/notifications-table.component.ts b/src/app/core/_components/tables/notifications-table/notifications-table.component.ts index ca3344a9e..9cba48f4e 100644 --- a/src/app/core/_components/tables/notifications-table/notifications-table.component.ts +++ b/src/app/core/_components/tables/notifications-table/notifications-table.component.ts @@ -36,7 +36,7 @@ export class NotificationsTableComponent extends BaseTableComponent implements O ngOnInit(): void { this.setColumnLabels(NotificationsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new NotificationsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new NotificationsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new NotificationsContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/permissions-table/permissions-table.component.ts b/src/app/core/_components/tables/permissions-table/permissions-table.component.ts index 764775448..aeb167416 100644 --- a/src/app/core/_components/tables/permissions-table/permissions-table.component.ts +++ b/src/app/core/_components/tables/permissions-table/permissions-table.component.ts @@ -34,7 +34,7 @@ export class PermissionsTableComponent extends BaseTableComponent implements OnI ngOnInit(): void { this.setColumnLabels(PermissionsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new PermissionsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new PermissionsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new PermissionsContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/preprocessors-table/preprocessors-table.component.ts b/src/app/core/_components/tables/preprocessors-table/preprocessors-table.component.ts index abf96baf9..9ed09deed 100644 --- a/src/app/core/_components/tables/preprocessors-table/preprocessors-table.component.ts +++ b/src/app/core/_components/tables/preprocessors-table/preprocessors-table.component.ts @@ -33,7 +33,7 @@ export class PreprocessorsTableComponent extends BaseTableComponent implements O ngOnInit(): void { this.setColumnLabels(PreprocessorsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new PreprocessorsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new PreprocessorsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new PreProContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/pretasks-table/pretasks-table.component.ts b/src/app/core/_components/tables/pretasks-table/pretasks-table.component.ts index cfd7f0eb2..25ca9bd4b 100644 --- a/src/app/core/_components/tables/pretasks-table/pretasks-table.component.ts +++ b/src/app/core/_components/tables/pretasks-table/pretasks-table.component.ts @@ -62,7 +62,7 @@ export class PretasksTableComponent extends BaseTableComponent implements OnInit ngOnInit(): void { this.setColumnLabels(PretasksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new PreTasksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new PreTasksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.supertTaskId) { this.dataSource.setSuperTaskId(this.supertTaskId); diff --git a/src/app/core/_components/tables/search-hash-table/search-hash-table.component.ts b/src/app/core/_components/tables/search-hash-table/search-hash-table.component.ts index 64255ee78..13886e14b 100644 --- a/src/app/core/_components/tables/search-hash-table/search-hash-table.component.ts +++ b/src/app/core/_components/tables/search-hash-table/search-hash-table.component.ts @@ -29,7 +29,7 @@ export class SearchHashTableComponent extends BaseTableComponent implements OnIn ngOnInit(): void { this.setColumnLabels(SearchHashTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new SearchHashDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new SearchHashDataSource(this.injector); if (this.search) { this.dataSource.setSearch(this.search); } diff --git a/src/app/core/_components/tables/super-hashlists-table/super-hashlists-table.component.ts b/src/app/core/_components/tables/super-hashlists-table/super-hashlists-table.component.ts index 3e8bd9911..4748a697e 100644 --- a/src/app/core/_components/tables/super-hashlists-table/super-hashlists-table.component.ts +++ b/src/app/core/_components/tables/super-hashlists-table/super-hashlists-table.component.ts @@ -35,7 +35,7 @@ export class SuperHashlistsTableComponent extends BaseTableComponent implements ngOnInit(): void { this.setColumnLabels(SuperHashlistsTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new SuperHashlistsDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new SuperHashlistsDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.setIsArchived(this.isArchived); this.contextMenuService = new SuperHashListContextMenuService(this.permissionService).addContextMenu(); diff --git a/src/app/core/_components/tables/supertasks-pretasks-table/supertasks-pretasks-table.component.ts b/src/app/core/_components/tables/supertasks-pretasks-table/supertasks-pretasks-table.component.ts index cb6ba969c..92ca3ee38 100644 --- a/src/app/core/_components/tables/supertasks-pretasks-table/supertasks-pretasks-table.component.ts +++ b/src/app/core/_components/tables/supertasks-pretasks-table/supertasks-pretasks-table.component.ts @@ -36,7 +36,7 @@ export class SuperTasksPretasksTableComponent extends BaseTableComponent impleme ngOnInit(): void { this.setColumnLabels(SupertasksPretasksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new SuperTasksPretasksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new SuperTasksPretasksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.supertaskId) { this.dataSource.setSuperTaskId(this.supertaskId); diff --git a/src/app/core/_components/tables/supertasks-table/supertasks-table.component.ts b/src/app/core/_components/tables/supertasks-table/supertasks-table.component.ts index f44331b88..d92418407 100644 --- a/src/app/core/_components/tables/supertasks-table/supertasks-table.component.ts +++ b/src/app/core/_components/tables/supertasks-table/supertasks-table.component.ts @@ -36,7 +36,7 @@ export class SuperTasksTableComponent extends BaseTableComponent implements OnIn ngOnInit(): void { this.setColumnLabels(SupertasksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new SuperTasksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new SuperTasksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new SuperTaskContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/tasks-chunks-table/tasks-chunks-table.component.ts b/src/app/core/_components/tables/tasks-chunks-table/tasks-chunks-table.component.ts index 244b0261e..206ee3bac 100644 --- a/src/app/core/_components/tables/tasks-chunks-table/tasks-chunks-table.component.ts +++ b/src/app/core/_components/tables/tasks-chunks-table/tasks-chunks-table.component.ts @@ -45,7 +45,7 @@ export class TasksChunksTableComponent extends BaseTableComponent implements OnI ngOnInit(): void { this.setColumnLabels(TasksChunksTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new TasksChunksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new TasksChunksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new ChunkContextMenuService(this.permissionService).addContextMenu(); // Do NOT load yet diff --git a/src/app/core/_components/tables/tasks-supertasks-table/tasks-supertasks-table.component.ts b/src/app/core/_components/tables/tasks-supertasks-table/tasks-supertasks-table.component.ts index 9c114a9eb..dafeb81d2 100644 --- a/src/app/core/_components/tables/tasks-supertasks-table/tasks-supertasks-table.component.ts +++ b/src/app/core/_components/tables/tasks-supertasks-table/tasks-supertasks-table.component.ts @@ -40,7 +40,7 @@ export class TasksSupertasksTableComponent extends BaseTableComponent implements ngOnInit(): void { this.setColumnLabels(TasksSupertasksDataSourceTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new TasksSupertasksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new TasksSupertasksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); if (this.supertaskId) { this.dataSource.setSuperTaskId(this.supertaskId); diff --git a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts index 1a11fe7ef..ea1ac71f9 100644 --- a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts +++ b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts @@ -64,7 +64,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O ngOnInit(): void { this.setColumnLabels(TaskTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new TasksDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new TasksDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.dataSource.setIsArchived(this.isArchived); this.contextMenuService = new TaskContextMenuService(this.permissionService).addContextMenu(); diff --git a/src/app/core/_components/tables/users-table/users-table.component.ts b/src/app/core/_components/tables/users-table/users-table.component.ts index 97e52869f..3da2b405c 100644 --- a/src/app/core/_components/tables/users-table/users-table.component.ts +++ b/src/app/core/_components/tables/users-table/users-table.component.ts @@ -37,7 +37,7 @@ export class UsersTableComponent extends BaseTableComponent implements OnInit, O ngOnInit(): void { this.setColumnLabels(UsersTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new UsersDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new UsersDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new UsersContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_components/tables/vouchers-table/vouchers-table.component.ts b/src/app/core/_components/tables/vouchers-table/vouchers-table.component.ts index 06d299faa..e4724534a 100644 --- a/src/app/core/_components/tables/vouchers-table/vouchers-table.component.ts +++ b/src/app/core/_components/tables/vouchers-table/vouchers-table.component.ts @@ -32,7 +32,7 @@ export class VouchersTableComponent extends BaseTableComponent implements OnInit ngOnInit(): void { this.setColumnLabels(VouchersTableColumnLabel); this.tableColumns = this.getColumns(); - this.dataSource = new VouchersDataSource(this.cdr, this.gs, this.uiService); + this.dataSource = new VouchersDataSource(this.injector); this.dataSource.setColumns(this.tableColumns); this.contextMenuService = new VoucherContextMenuService(this.permissionService).addContextMenu(); this.dataSource.loadAll(); diff --git a/src/app/core/_datasources/agents.datasource.ts b/src/app/core/_datasources/agents.datasource.ts index ad10f82e5..9917f959f 100644 --- a/src/app/core/_datasources/agents.datasource.ts +++ b/src/app/core/_datasources/agents.datasource.ts @@ -1,21 +1,24 @@ -import { ChunkState, chunkStates } from '@src/app/core/_constants/chunks.config'; /** * Contains data source for agents resource * @module */ import { catchError, finalize, firstValueFrom, of } from 'rxjs'; -import { BaseDataSource } from '@datasources/base.datasource'; -import { FilterType } from '@models/request-params.model'; -import { IParamBuilder } from '@services/params/builder-types.service'; -import { JAgent } from '@models/agent.model'; import { JAgentAssignment } from '@models/agent-assignment.model'; +import { JAgent } from '@models/agent.model'; import { JChunk } from '@models/chunk.model'; +import { FilterType } from '@models/request-params.model'; +import { ResponseWrapper } from '@models/response.model'; import { JUser } from '@models/user.model'; + import { JsonAPISerializer } from '@services/api/serializer-service'; -import { RequestParamBuilder } from '@services/params/builder-implementation.service'; -import { ResponseWrapper } from '@models/response.model'; import { SERV } from '@services/main.config'; +import { RequestParamBuilder } from '@services/params/builder-implementation.service'; +import { IParamBuilder } from '@services/params/builder-types.service'; + +import { BaseDataSource } from '@datasources/base.datasource'; + +import { ChunkState, chunkStates } from '@src/app/core/_constants/chunks.config'; export class AgentsDataSource extends BaseDataSource { private chunktime = this.uiService.getUIsettings('chunktime').value; @@ -75,15 +78,9 @@ export class AgentsDataSource extends BaseDataSource { } }); } - const length = response.meta.page.total_elements; + const length = response.meta.page.total_elements; - this.setPaginationConfig( - this.pageSize, - length, - this.pageAfter, - this.pageBefore, - this.index - ); + this.setPaginationConfig(this.pageSize, length, this.pageAfter, this.pageBefore, this.index); this.setData(agents); }); } @@ -147,13 +144,7 @@ export class AgentsDataSource extends BaseDataSource { const length = response.meta.page.total_elements; - this.setPaginationConfig( - this.pageSize, - length, - this.pageAfter, - this.pageBefore, - this.index - ); + this.setPaginationConfig(this.pageSize, length, this.pageAfter, this.pageBefore, this.index); this.setData(agents); } }); diff --git a/src/app/core/_datasources/base.datasource.ts b/src/app/core/_datasources/base.datasource.ts index c93c08924..090e80a87 100644 --- a/src/app/core/_datasources/base.datasource.ts +++ b/src/app/core/_datasources/base.datasource.ts @@ -1,7 +1,7 @@ import { BehaviorSubject, Observable, Subscription } from 'rxjs'; import { CollectionViewer, DataSource, SelectionModel } from '@angular/cdk/collections'; -import { ChangeDetectorRef } from '@angular/core'; +import { ChangeDetectorRef, Injectable, Injector } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort, SortDirection } from '@angular/material/sort'; @@ -9,6 +9,7 @@ import { ChunkData, JChunk } from '@models/chunk.model'; import { JsonAPISerializer } from '@services/api/serializer-service'; import { GlobalService } from '@services/main.service'; +import { PermissionService } from '@services/permission/permission.service'; import { UIConfigService } from '@services/shared/storage.service'; import { HTTableColumn } from '@components/tables/ht-table/ht-table.models'; @@ -23,6 +24,7 @@ import { environment } from '@src/environments/environment'; * @template T - The type of data that the data source holds. * @template P - The type of paginator, extending MatTableDataSourcePaginator. */ +@Injectable() export abstract class BaseDataSource implements DataSource { public pageSize = 10; public currentPage = 0; @@ -75,11 +77,16 @@ export abstract class BaseDataSource i private readonly chunkTime: number = 600; - constructor( - protected cdr: ChangeDetectorRef, - protected service: GlobalService, - protected uiService: UIConfigService - ) { + protected cdr: ChangeDetectorRef; + protected service: GlobalService; + protected uiService: UIConfigService; + protected permissionService: PermissionService; + + constructor(protected injector: Injector) { + this.cdr = injector.get(ChangeDetectorRef); + this.service = injector.get(GlobalService); + this.uiService = injector.get(UIConfigService); + this.permissionService = injector.get(PermissionService); this.serializer = new JsonAPISerializer(); const chunktimeSetting: string = this.uiService.getUIsettings('chunktime').value; if (chunktimeSetting) {