Skip to content

Commit

Permalink
feat(status): add 'pending tasks' info
Browse files Browse the repository at this point in the history
Adds information on the number of pending deletions.
  • Loading branch information
zaldih committed May 25, 2024
1 parent 38c8513 commit 32fcf02
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/constants/main.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const UI_POSITIONS: IUiPosition = {
SPACE_RELEASED: { x: 50, y: 4 },
STATUS: { x: 50, y: 5 },
STATUS_BAR: { x: 50, y: 6 },
PENDING_TASKS: { x: 50, y: 7 }, //Starting position. It will then be replaced.
TOTAL_SPACE: { x: 50, y: 3 },
ERRORS_COUNT: { x: 50, y: 2 },
TUTORIAL_TIP: { x: 1, y: 7 },
Expand Down
12 changes: 8 additions & 4 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,8 @@ export class Controller {
return;
}
const parentFolder = path.join(nodeFolder.path, '../');
const result = await this.fileService.getRecentModificationInDir(
parentFolder,
);
const result =
await this.fileService.getRecentModificationInDir(parentFolder);
nodeFolder.modificationTime = result;
this.logger.info(`Last mod. of ${nodeFolder.path}: ${result}`);
}),
Expand Down Expand Up @@ -527,18 +526,23 @@ export class Controller {

this.logger.info(`Deleting ${folder.path}`);
folder.status = 'deleting';
this.searchStatus.pendingDeletions++;
this.uiStatus.render();
this.printFoldersSection();

this.fileService
.deleteDir(folder.path)
.then(() => {
folder.status = 'deleted';
this.uiStats.render();
this.searchStatus.pendingDeletions--;
this.uiStatus.render();
this.printFoldersSection();
this.logger.info(`Deleted ${folder.path}`);
})
.catch((e) => {
folder.status = 'error-deleting';
this.searchStatus.pendingDeletions--;
this.uiStatus.render();
this.printFoldersSection();
this.newError(e.message);
});
Expand Down
1 change: 1 addition & 0 deletions src/models/search-state.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class SearchStatus {
public pendingStatsCalculation = 0;
public completedStatsCalculation = 0;
public resultsFound = 0;
public pendingDeletions = 0;
public workerStatus: WorkerStatus = 'stopped';
public workersJobs;

Expand Down
39 changes: 38 additions & 1 deletion src/ui/components/header/status.ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class StatusUi extends BaseUi {
private text = '';
private barNormalizedWidth = 0;
private barClosing = false;
private showProgressBar = true;
private pendingTasksPosition = { ...UI_POSITIONS.PENDING_TASKS };
private readonly searchEnd$ = new Subject();
private readonly SEARCH_STATES = {
stopped: () => this.startingSearch(),
Expand Down Expand Up @@ -53,7 +55,31 @@ export class StatusUi extends BaseUi {

render(): void {
this.printAt(this.text, UI_POSITIONS.STATUS);
this.renderProgressBar();

if (this.showProgressBar) {
this.renderProgressBar();
}

this.renderPendingTasks();
}

private renderPendingTasks(): void {
this.clearPendingTasks();
if (this.searchStatus.pendingDeletions === 0) {
return;
}

const { pendingDeletions } = this.searchStatus;
const text = pendingDeletions > 1 ? 'pending tasks' : 'pending task ';
this.printAt(
colors.yellow(`${pendingDeletions} ${text}`),
this.pendingTasksPosition,
);
}

private clearPendingTasks(): void {
const PENDING_TASK_LENGHT = 15;
this.printAt(' '.repeat(PENDING_TASK_LENGHT), this.pendingTasksPosition);
}

private renderProgressBar(): void {
Expand Down Expand Up @@ -128,6 +154,9 @@ export class StatusUi extends BaseUi {
this.barClosing = true;
if (this.barNormalizedWidth < 0) {
this.barNormalizedWidth = 0;
this.showProgressBar = false;

this.movePendingTaskToTop();
return;
}
this.barNormalizedWidth -= 0.05;
Expand All @@ -136,6 +165,14 @@ export class StatusUi extends BaseUi {
setTimeout(() => this.animateClose(), SPINNER_INTERVAL);
}

/** When the progress bar disappears, "pending tasks" will move up one
position. */
private movePendingTaskToTop(): void {
this.clearPendingTasks();
this.pendingTasksPosition = { ...UI_POSITIONS.STATUS_BAR };
this.renderPendingTasks();
}

private printProgressBar(progressBar: string): void {
if (this.barClosing) {
const postX =
Expand Down

0 comments on commit 32fcf02

Please sign in to comment.