Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/app/core/_datasources/agent-error.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class AgentErrorDatasource extends BaseDataSource<JAgentErrors> {

// Use stored filter if no new filter is provided
const activeFilter = query || this._currentFilter;
let agentParams = new RequestParamBuilder().addInitial(this).addInclude('task');
let agentParams = new RequestParamBuilder().addInitial(this).addInclude('task').addAggregate({
field: 'task',
values: []
});

if (this._agentId) {
agentParams.addFilter({ field: 'agentId', operator: FilterType.EQUAL, value: this._agentId });
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/core/_datasources/agents.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export class AgentsDataSource extends BaseDataSource<JAgent> {
.addInclude('accessGroups')
.addInclude('tasks')
.addInclude('assignments')
.addInclude('user');
.addInclude('user')
.addAggregate({
field: 'task',
values: []
});
if (this.agentStatsRequired) {
agentParams = agentParams.addInclude('agentStats');
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/core/_datasources/chunks.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export class ChunksDataSource extends BaseDataSource<JChunk> {

// Use stored filter if no new filter is provided
const activeFilter = query || this._currentFilter;
let params = new RequestParamBuilder().addInitial(this).addInclude('task').addInclude('agent');
let params = new RequestParamBuilder().addInitial(this).addInclude('agent').addInclude('task').addAggregate({
field: 'task',
values: []
});

if (this._agentId) {
params.addFilter({ field: 'agentId', operator: FilterType.EQUAL, value: this._agentId });
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/core/_datasources/files.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ export class FilesDataSource extends BaseDataSource<JFile> {

if (this.editIndex !== undefined) {
if (this.editType === 0) {
files$ = this.service.get(SERV.TASKS, this.editIndex, paramsBuilder.addInclude('files').create(), httpOptions);
files$ = this.service.get(
SERV.TASKS,
this.editIndex,
paramsBuilder.addInclude('files').addAggregate({ field: 'task', values: [] }).create(),
httpOptions
);
} else if (this.editType === 1) {
files$ = this.service.get(
SERV.PRETASKS,
this.editIndex,
paramsBuilder.addInclude('pretaskFiles').create(),
paramsBuilder.addInclude('pretaskFiles').addAggregate({ field: 'pretask', values: [] }).create(),
httpOptions
);
}
Expand Down
9 changes: 7 additions & 2 deletions src/app/core/_datasources/tasks-chunks.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TasksChunksDataSource extends BaseDataSource<JChunk> {

const activeFilter = query || this._currentFilter;

let chunkParams = new RequestParamBuilder().addInitial(this).addInclude('task').addInclude('agent').addFilter({
let chunkParams = new RequestParamBuilder().addInitial(this).addInclude('agent').addFilter({
field: 'taskId',
operator: FilterType.EQUAL,
value: this._taskId
Expand All @@ -46,8 +46,13 @@ export class TasksChunksDataSource extends BaseDataSource<JChunk> {
if (this._taskId) {
const httpOptions = { headers: new HttpHeaders({ 'X-Skip-Error-Dialog': 'true' }) };
try {
const taskParams = new RequestParamBuilder().addAggregate({
field: 'task',
values: []
});

const response = await firstValueFrom<ResponseWrapper>(
this.service.get(SERV.TASKS, this._taskId, undefined, httpOptions).pipe(
this.service.get(SERV.TASKS, this._taskId, taskParams.create(), httpOptions).pipe(
catchError((error) => {
this.handleFilterError(error);
throw error;
Expand Down
12 changes: 12 additions & 0 deletions src/app/core/_models/request-params.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export interface Filter {
parent?: string;
}

/**
* Interface definition for aggregate fieldsets
* @prop field Aggregate field name
* @prop values Values to aggregate for the field
*/
export interface Aggregate {
field: string;
values: string[];
}

/**
* Interface definition for request params
*/
Expand All @@ -46,6 +56,8 @@ interface IRequestParams {
include?: Array<string>;
// Array of Filter objects that have to be performed
filter?: Array<Filter>;
//array of aggregated fields to include ex. [active agents for tasks]
aggregate?: Array<Aggregate>;
//array of attributes to sort on where '-' implies descending order on ex. [id, -name]
sort?: Array<string>;
//Parameter for count endpoints to also include the count without filters
Expand Down
8 changes: 8 additions & 0 deletions src/app/core/_services/buildparams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export function setParameter(params: RequestParams): HttpParams {
});
}

// Handle aggregate array
const aggregate = params.aggregate;
if (Array.isArray(aggregate) && aggregate.length > 0) {
aggregate.forEach((aggregate) => {
httpParams = httpParams.set(`aggregate[${aggregate.field}]`, aggregate.values.join(','));
});
}

// Handle ordering parameter
const sort = params.sort;
if (Array.isArray(sort) && sort.length > 0) {
Expand Down
13 changes: 12 additions & 1 deletion src/app/core/_services/params/builder-implementation.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SortingColumn } from '@components/tables/ht-table/ht-table.models';

import { BaseDataSource } from '@src/app/core/_datasources/base.datasource';
import { Filter, type RequestParams } from '@src/app/core/_models/request-params.model';
import { Aggregate, Filter, type RequestParams } from '@src/app/core/_models/request-params.model';
import { IParamBuilder, RequestParamsIntermediate } from '@src/app/core/_services/params/builder-types.service';

/**
Expand Down Expand Up @@ -98,6 +98,16 @@ export class RequestParamBuilder implements IParamBuilder {
return this;
}

/**
* Adds a new value to the aggregate fieldsets array
* @param include new include value
* @returns object instance
*/
addAggregate(aggregate: Aggregate): IParamBuilder {
this.params.aggregate = this.addToArray<Aggregate>(this.params.aggregate, aggregate);
return this;
}

/**
* Adds a new value from the given column to the sort array
* @param sortingColumn column to get sort values from
Expand Down Expand Up @@ -131,6 +141,7 @@ export class RequestParamBuilder implements IParamBuilder {
if (this.params.sortOrder) requestParams.sort = this.params.sortOrder;
if (this.params.filters) requestParams.filter = this.params.filters;
if (this.params.includeTotal !== undefined) requestParams.include_total = this.params.includeTotal;
if (this.params.aggregate !== undefined) requestParams.aggregate = this.params.aggregate;
return requestParams;
}

Expand Down
5 changes: 4 additions & 1 deletion src/app/core/_services/params/builder-types.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SortingColumn } from '@components/tables/ht-table/ht-table.models';

import { BaseDataSource } from '@datasources/base.datasource';

import { Filter, type RequestParams } from '@src/app/core/_models/request-params.model';
import { Aggregate, Filter, type RequestParams } from '@src/app/core/_models/request-params.model';

/**
* Intermediate class to build RequestParams from using a builder interface implementation
Expand All @@ -20,6 +20,7 @@ export class RequestParamsIntermediate {
public filters?: Array<Filter>;
public sortOrder?: Array<string>;
public includeTotal?: boolean;
public aggregate?: Array<Aggregate>;
}

/**
Expand All @@ -40,6 +41,8 @@ export interface IParamBuilder {

addIncludeTotal(includeTotal: boolean): IParamBuilder;

addAggregate(aggregate: Aggregate): IParamBuilder;

addInitial(datasource: BaseDataSource<MatPaginator>): IParamBuilder;

create(): RequestParams;
Expand Down
Loading