Skip to content

Commit

Permalink
SF-1873 Add messages to sync progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebuss committed Nov 5, 2024
1 parent e75b87f commit 5642825
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
[bufferValue]="1"
color="accent"
></mat-progress-bar>
<div class="sync-status" *transloco="let t; read: 'sync'">
@if ((syncPhase === 0 && syncProgress > 0) || (syncPhase === 8 && syncProgress === 80)) {
{{ t(syncStatus, { projectType: projectType }) }}
} @else if (syncPhase === 0 || syncPhase === 4 || syncPhase === 8) {
{{ t(syncStatus) }}
} @else if (syncStatus != null) {
{{ t(syncStatus, { progressPercent: stagePercentage }) }}
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('SyncProgressComponent', () => {
env.updateSyncProgress(0.5, 'testProject01');
expect(env.host.inProgress).toBe(true);
expect(await env.getPercent()).toEqual(50);
expect(env.syncStatus).not.toBeNull();
env.emitSyncComplete(true, 'testProject01');
expect(env.host.inProgress).toBe(false);
}));
Expand All @@ -84,6 +85,7 @@ describe('SyncProgressComponent', () => {
// Simulate sync in progress
env.updateSyncProgress(0.5, 'testProject01');
expect(await env.getMode()).toBe('determinate');
expect(env.syncStatus).not.toBeNull();
// Simulate sync completed
env.emitSyncComplete(true, 'testProject01');
tick();
Expand All @@ -97,6 +99,7 @@ describe('SyncProgressComponent', () => {
});
env.setupProjectDoc();
env.checkCombinedProgress();
expect(env.syncStatus).not.toBeNull();
tick();
}));

Expand All @@ -108,6 +111,7 @@ describe('SyncProgressComponent', () => {
});
env.setupProjectDoc();
env.checkCombinedProgress();
expect(env.syncStatus).not.toBeNull();
tick();
}));

Expand All @@ -120,6 +124,7 @@ describe('SyncProgressComponent', () => {
env.emitSyncComplete(true, 'sourceProject02');
env.updateSyncProgress(0.5, 'testProject01');
expect(await env.getPercent()).toEqual(50);
expect(env.syncStatus).not.toBeNull();
env.emitSyncComplete(true, 'testProject01');
}));

Expand All @@ -131,6 +136,7 @@ describe('SyncProgressComponent', () => {
verify(mockedProjectService.get('sourceProject02')).never();
verify(mockedErrorReportingService.silentError(anything(), anything())).once();
expect(env.progressBar).not.toBeNull();
expect(env.syncStatus).not.toBeNull();
}));
});

Expand Down Expand Up @@ -227,6 +233,10 @@ class TestEnvironment {
return this.fixture.nativeElement.querySelector('mat-progress-bar');
}

get syncStatus(): HTMLElement | null {
return this.fixture.nativeElement.querySelector('.sync-status');
}

set onlineStatus(isOnline: boolean) {
this.testOnlineStatusService.setIsOnline(isOnline);
tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ import { SFProjectService } from '../../core/sf-project.service';
export class ProgressState {
constructor(
public progressValue: number,
public progressString?: string
public progressString?: string,
public syncPhase?: number,
public syncProgress?: number
) {}
}

@Component({
selector: 'app-sync-progress',
templateUrl: './sync-progress.component.html'
templateUrl: './sync-progress.component.html',
styleUrl: '../sync.component.scss'
})
export class SyncProgressComponent extends SubscriptionDisposable {
@Output() inProgress: EventEmitter<boolean> = new EventEmitter<boolean>();

private progressPercent$ = new BehaviorSubject<number>(0);
syncPhase: number = 0;
syncProgress: number | undefined;
stagePercentage: string = '0.0';
projectType: string = '';

/** The progress as a percent between 0 and 100 for the target project and the source project, if one exists. */
syncProgressPercent$: Observable<number> = this.progressPercent$.pipe(map(p => p * 100));
Expand Down Expand Up @@ -57,6 +64,10 @@ export class SyncProgressComponent extends SubscriptionDisposable {
});
}

get syncStatus(): string {
return `stage_${this.syncPhase}_${this.syncProgress ?? 0}`;
}

get appOnline(): boolean {
return this.onlineStatus.isOnline && this.onlineStatus.isBrowserOnline;
}
Expand Down Expand Up @@ -115,11 +126,18 @@ export class SyncProgressComponent extends SubscriptionDisposable {

public updateProgressState(projectId: string, progressState: ProgressState): void {
const hasSourceProject = this.sourceProjectDoc?.data != null;
this.syncPhase = progressState.syncPhase ?? 0;
this.syncProgress = progressState.syncProgress != null ? Math.floor(progressState.syncProgress) : 0;
this.stagePercentage =
progressState.syncProgress != null ? ((progressState.syncProgress - this.syncProgress) * 100).toFixed(2) : '0.00';

if (projectId === this._projectDoc?.id) {
this.projectType = 'target';
this.progressPercent$.next(
hasSourceProject ? 0.5 + progressState.progressValue * 0.5 : progressState.progressValue
);
} else if (hasSourceProject && projectId === this.sourceProjectDoc?.id) {
this.projectType = 'source';
this.progressPercent$.next(progressState.progressValue * 0.5);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
.sync-card {
padding: 0;
max-width: 37rem;
min-width: 18rem;
min-width: 25rem;
}

.sync-status {
display: flex;
padding: 1rem;
align-content: center;
justify-content: center;
}

.card-content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,35 @@
"supported_back_translation_languages_dialog_header": "Supported Back Translation Languages"
},
"sync": {
"stage_0_0": "Connecting to server",
"stage_0_30": "Connecting to {{projectType}} project",
"stage_0_60": "Connection complete for {{projectType}} project",
"stage_0_90": "Beginning {{projectType}} sync",
"stage_1_0": "Updating changes for Books and Notes {{progressPercent}}%",
"stage_1_1": "Updating changes for Books and Notes 100%",
"stage_2_0": "Getting Paratext biblical terms",
"stage_2_25": "Getting SF biblical terms",
"stage_2_50": "Checking Paratext updates to biblical terms {{progressPercent}}%",
"stage_2_75": "Saving Paratext biblical terms to SF",
"stage_3_0": "Finalizing biblical terms updates {{progressPercent}}%",
"stage_3_1": "Biblical terms updated",
"stage_4_0": "Starting Paratext Send/Receive",
"stage_4_30": "Checking for any removed books...",
"stage_4_60": "Checking user permissions...",
"stage_4_90": "Checking resources...",
"stage_5_0": "Updating removed Books and Notes {{progressPercent}}%",
"stage_5_1": "Updating removed Books and Notes 100%",
"stage_6_0": "Updating SF docs {{progressPercent}}%",
"stage_6_1": "Updating SF docs 100%",
"stage_7_0": "Checking SF updates to biblical terms {{progressPercent}}%",
"stage_7_25": "Getting updated SF biblical terms",
"stage_7_50": "Getting Paratext biblical terms",
"stage_7_75": "Saving SF biblical terms to Paratext",
"stage_7_1": "Paratext Send/Receive complete",
"stage_8_20": "Updating resources and permissions",
"stage_8_40": "We're almost done, just finishing up a few things",
"stage_8_60": "Validating sync is complete...",
"stage_8_80": "Finalizing {{projectType}} sync",
"cancel": "Cancel",
"connect_network_to_synchronize": "Please connect to the internet to synchronize this project",
"last_synced_time_stamp": "Last synced on {{ timeStamp }}",
Expand Down
2 changes: 2 additions & 0 deletions src/SIL.XForge.Scripture/Models/ProgressState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public class ProgressState
public static readonly ProgressState NotStarted = new ProgressState { ProgressValue = 0.0 };
public string? ProgressString { get; set; }
public double ProgressValue { get; set; }
public int SyncPhase { get; set; }
public double SyncProgress { get; set; }
}
8 changes: 5 additions & 3 deletions src/SIL.XForge.Scripture/Services/ParatextSyncRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ CancellationToken token
}

ReportRepoRevs();
await NotifySyncProgress(SyncPhase.Phase1, 50.0);
await NotifySyncProgress(SyncPhase.Phase1, 90.0);

if (_paratextService.IsResource(targetParatextId))
{
Expand Down Expand Up @@ -1019,7 +1019,7 @@ CancellationToken token
return false;
}

await NotifySyncProgress(SyncPhase.Phase1, 10.0);
await NotifySyncProgress(SyncPhase.Phase1, 30.0);

if (!(await _projectSecrets.TryGetAsync(projectSFId)).TryResult(out _projectSecret))
{
Expand Down Expand Up @@ -1057,7 +1057,7 @@ await _projectDoc.SubmitJson0OpAsync(op =>

_notesMapper.Init(_userSecret, _paratextUsers);

await NotifySyncProgress(SyncPhase.Phase1, 20.0);
await NotifySyncProgress(SyncPhase.Phase1, 60.0);
return true;
}

Expand Down Expand Up @@ -2128,6 +2128,8 @@ await _hubContext.NotifySyncProgress(
ProgressValue =
1.0 / _numberOfPhases * (double)syncPhase
+ (progress > 1.0 ? progress / 100.0 : progress) * 1.0 / _numberOfPhases,
SyncPhase = (int)syncPhase,
SyncProgress = progress
}
);
}
Expand Down

0 comments on commit 5642825

Please sign in to comment.