Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ describe('AccountSettingsComponent', () => {

describe('Main form tests', () => {
it('initializes the form with default values', async () => {
component.ngOnInit();
fixture.detectChanges();

// Wait for async observable subscription and form patching to complete
await fixture.whenStable();

// Trigger change detection after async updates
fixture.detectChanges();

const formValue = component.form.getRawValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[dataSource]="dataSource"
[tableColumns]="tableColumns"
[contextMenuService]="contextMenuService"
(rowActionClicked)="rowActionClicked($event)"


[isFilterable]="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnInit, inject } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';

import { JChunk } from '@models/chunk.model';

import { ChunkActionsService } from '@services/actions/chunk-actions.service';
import { ChunkContextMenuService } from '@services/context-menu/chunk-menu.service';

import { ActionMenuEvent } from '@components/menus/action-menu/action-menu.model';
import { RowActionMenuAction } from '@components/menus/row-action-menu/row-action-menu.constants';
import { BaseTableComponent } from '@components/tables/base-table/base-table.component';
import { ChunksTableCol, ChunksTableColumnLabel } from '@components/tables/chunks-table/chunks-table.constants';
import { HTTableColumn } from '@components/tables/ht-table/ht-table.models';
Expand All @@ -29,6 +32,8 @@ export class ChunksTableComponent extends BaseTableComponent implements OnInit {
dataSource: ChunksDataSource;
selectedFilterColumn: string = 'all';

private readonly chunkActions = inject(ChunkActionsService);

ngOnInit(): void {
this.setColumnLabels(ChunksTableColumnLabel);
this.tableColumns = this.getColumns();
Expand Down Expand Up @@ -197,4 +202,17 @@ export class ChunksTableComponent extends BaseTableComponent implements OnInit {

return this.sanitize(`${chunk.solveTime}`);
}

rowActionClicked(event: ActionMenuEvent<JChunk>): void {
switch (event.menuItem.action) {
case RowActionMenuAction.RESET:
this.subscriptions.push(
this.chunkActions.resetChunk(event.data).subscribe(() => {
this.alertService.showSuccessMessage('Successfully reseted chunk!');
this.reload();
})
);
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { catchError } from 'rxjs';

import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges, inject } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';

import { JChunk } from '@models/chunk.model';

import { ChunkActionsService } from '@services/actions/chunk-actions.service';
import { ChunkContextMenuService } from '@services/context-menu/chunk-menu.service';
import { SERV } from '@services/main.config';

import { ActionMenuEvent } from '@components/menus/action-menu/action-menu.model';
import { RowActionMenuAction } from '@components/menus/row-action-menu/row-action-menu.constants';
Expand Down Expand Up @@ -42,6 +40,8 @@ export class TasksChunksTableComponent extends BaseTableComponent implements OnI
// Track initialization
private isInitialized = false;

private readonly chunkActions = inject(ChunkActionsService);

ngOnInit(): void {
this.setColumnLabels(TasksChunksTableColumnLabel);
this.tableColumns = this.getColumns();
Expand Down Expand Up @@ -221,36 +221,16 @@ export class TasksChunksTableComponent extends BaseTableComponent implements OnI
return this.sanitize(`${chunk.solveTime}`);
}

// --- Action functions ---
rowActionClicked(event: ActionMenuEvent<JChunk>): void {
switch (event.menuItem.action) {
case RowActionMenuAction.RESET:
this.rowActionReset(event.data);
this.subscriptions.push(
this.chunkActions.resetChunk(event.data).subscribe(() => {
this.alertService.showSuccessMessage('Successfully reseted chunk!');
this.reload();
})
);
break;
}
}

/**
* @todo Implement error handling.
*/
private rowActionReset(chunks: JChunk): void {
const path = chunks.state === 2 ? 'abortChunk' : 'resetChunk';
const payload = { chunkId: chunks.id };
this.subscriptions.push(
this.gs
.chelper(SERV.HELPER, path, payload)
.pipe(
catchError((error) => {
const errorMessage = 'Error during resetting';
console.error(errorMessage, error);
this.alertService.showErrorMessage(errorMessage);
return [];
})
)
.subscribe(() => {
this.alertService.showSuccessMessage('Successfully reseted chunk!');
this.reload();
})
);
}
}
42 changes: 42 additions & 0 deletions src/app/core/_services/actions/chunk-actions.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { EMPTY, Observable, catchError } from 'rxjs';

import { Injectable } from '@angular/core';

import { JChunk } from '@models/chunk.model';

import { SERV } from '@services/main.config';
import { GlobalService } from '@services/main.service';
import { AlertService } from '@services/shared/alert.service';

@Injectable({ providedIn: 'root' })
export class ChunkActionsService {
constructor(
private gs: GlobalService,
private alertService: AlertService
) {}

/**
* Resets or aborts a chunk based on its current state.
*
* If the chunk's state is `2` (in-progress), the request will abort it.
* Otherwise, the request will reset it to its initial state.
*
* @param chunk The chunk to reset or abort.
* @returns An Observable that completes when the operation finishes.
* Emits no value. Handles errors internally by logging and showing
* an error message via AlertService.
*/
resetChunk(chunk: JChunk): Observable<void> {
const path = chunk.state === 2 ? 'abortChunk' : 'resetChunk';
const payload = { chunkId: chunk.id };

return this.gs.chelper(SERV.HELPER, path, payload).pipe(
catchError((error) => {
const errorMessage = 'Error during resetting';
console.error(errorMessage, error);
this.alertService.showErrorMessage(errorMessage);
return EMPTY;
})
);
}
}