Skip to content

Commit

Permalink
feat(index): Expand index sidebar dialog to cancel download
Browse files Browse the repository at this point in the history
  • Loading branch information
castaway committed Feb 29, 2024
1 parent a9e5223 commit ad2e8b7
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 113 deletions.
2 changes: 1 addition & 1 deletion e2e/cypress/integration/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Login', () => {
function expectWebmail() {
cy.get('#sidenavGreeting').should('contain', '[email protected]');
cy.get('#offerLocalIndex').should('contain', 'Runbox 7');
cy.get('#offerLocalIndex mat-list-item button[mattooltip="Do not synchronize index"]').click().should(() => {
cy.get('#offerLocalIndex mat-list-item button[data-cy="cancel-button"]').click().should(() => {
expect(JSON.parse(localStorage.getItem('221:Desktop:localSearchPromptDisplayed'))).to.equal('true');
});
}
Expand Down
96 changes: 49 additions & 47 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@

<mat-divider></mat-divider>

<div id="offerLocalIndex" *ngIf="offerInitialLocalIndex">
<div style="display: flex;">
<p>
Runbox 7 can synchronize with your browser to give you an optimal webmail experience.
</p>
</div>
<mat-list-item>
<button mat-raised-button (click)="downloadIndexFromServer()" matTooltip="Synchronize index with your device" color="primary">
Download Search Index
</button>
<button mat-raised-button (click)="refuseLocalIndex()" matTooltip="Do not synchronize index" color="warn">
Cancel
</button>
</mat-list-item>
</div>

<mat-divider></mat-divider>

Expand Down Expand Up @@ -194,38 +179,55 @@ <h3 class="noMessageSelectedNotification">No Message Selected</h3>
</button>

<ng-container *ngIf="!hasChildRouterOutlet">
<mat-form-field id="searchField" floatLabel="auto"
*ngIf="searchService.downloadProgress===null">
<input matInput #searchInputField type="text"
(focus)="searchTextFieldFocus()"
(blur)="searchTextFieldBlur()" [placeholder]="dynamicSearchFieldPlaceHolder ? dynamicSearchFieldPlaceHolder: 'Start typing to search messages'"
[value]="searchText" (keyup)="searchFor($event.target.value)" matTooltip="Enter one or more search terms, or click the wrench to display the advanced search pane" />
<!-- <app-search-expression-builder
[searchInputField]="searchInputField"
[currentFolder]="selectedFolder"
matSuffix matTooltip="Show search options"></app-search-expression-builder> -->
<button *ngIf="searchText!==''"
mat-icon-button
matSuffix
(click)="showSaveSearchDialog()"
matTooltip="Save search">
<mat-icon svgIcon="content-save"></mat-icon>
</button>
<button *ngIf="!showMultipleSearchFields"
mat-icon-button
matSuffix
(click)="showMultipleSearchFields = true"
matTooltip="Show advanced search pane">
<mat-icon svgIcon="wrench"></mat-icon>
</button>
<button *ngIf="searchText!==''"
mat-icon-button
matSuffix
(click)="searchFor('')"
matTooltip="Clear search">
<mat-icon svgIcon="close"></mat-icon>
</button>
</mat-form-field>
<div id="offerLocalIndex" *ngIf="offerInitialLocalIndex; else searchBar" style="display: flex; flex-flow: row">
<p>
Runbox 7 can synchronize with your browser to give you an optimal webmail experience.<br> The data can be deleted at any time using the buttons under the folder list.
</p>
<mat-list>
<mat-list-item>
<button mat-raised-button (click)="downloadIndexFromServer()" matTooltip="Synchronize index with your device" color="primary" [disabled]="searchService.indexDownloadingInProgress">
Download
</button>
<button mat-raised-button (click)="cancelOrRefuseLocalIndex()" matTooltip="{{ searchService.indexDownloadingInProgress ? 'Cancel Download' : 'Do not synchronize index'}}" data-cy="cancel-button" color="warn">
Cancel
</button>
</mat-list-item>
</mat-list>
</div>
<ng-template #searchBar>
<mat-form-field id="searchField" floatLabel="auto"
*ngIf="searchService.downloadProgress===null">
<input matInput #searchInputField type="text"
(focus)="searchTextFieldFocus()"
(blur)="searchTextFieldBlur()" [placeholder]="dynamicSearchFieldPlaceHolder ? dynamicSearchFieldPlaceHolder: 'Start typing to search messages'"
[value]="searchText" (keyup)="searchFor($event.target.value)" matTooltip="Enter one or more search terms, or click the wrench to display the advanced search pane" />
<!-- <app-search-expression-builder
[searchInputField]="searchInputField"
[currentFolder]="selectedFolder"
matSuffix matTooltip="Show search options"></app-search-expression-builder> -->
<button *ngIf="searchText!==''"
mat-icon-button
matSuffix
(click)="showSaveSearchDialog()"
matTooltip="Save search">
<mat-icon svgIcon="content-save"></mat-icon>
</button>
<button *ngIf="!showMultipleSearchFields"
mat-icon-button
matSuffix
(click)="showMultipleSearchFields = true"
matTooltip="Show advanced search pane">
<mat-icon svgIcon="wrench"></mat-icon>
</button>
<button *ngIf="searchText!==''"
mat-icon-button
matSuffix
(click)="searchFor('')"
matTooltip="Clear search">
<mat-icon svgIcon="close"></mat-icon>
</button>
</mat-form-field>
</ng-template>

<button mat-icon-button (click)="updateViewMode('conversations')" *ngIf="!searchtextfieldfocused && viewmode==='singleconversation'"
matTooltip="Back to conversations list">
Expand Down
22 changes: 18 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,17 +997,31 @@ export class AppComponent implements OnInit, AfterViewInit, CanvasTableSelectLis
this.preferenceService.set(this.preferenceService.prefGroup, 'localSearchPromptDisplayed', 'true');
this.localSearchIndexPrompted = true;
this.searchService.downloadIndexFromServer().subscribe((res) => {
if (res) {
if (res && !this.searchService.stopIndexDownloadingInProgress) {
this.searchService.downloadPartitions().subscribe(() => {
// this.searchService.openDBOnWorker();
// only done prompting after all partitions fetched
if(this.searchService.stopIndexDownloadingInProgress) {
// decided to stop mid partition download
this.deleteLocalIndex();
}
this.searchService.indexDownloadingInProgress = false;
this.offerInitialLocalIndex = false;
});
} else {
console.log('Index download failed');
console.log('Index download cancelled or failed');
this.deleteLocalIndex();
this.searchService.indexDownloadingInProgress = false;
this.searchService.stopIndexDownloadingInProgress = false;
this.offerInitialLocalIndex = false;
}
});
}

public refuseLocalIndex() {
public cancelOrRefuseLocalIndex() {
// Downloading is in progress, pause it:
if (this.searchService.indexDownloadingInProgress) {
this.searchService.stopIndexDownloadingInProgress = true;
}
// User has had the initial prompt, stop asking
this.preferenceService.set(this.preferenceService.prefGroup, 'localSearchPromptDisplayed', 'true');
this.offerInitialLocalIndex = false;
Expand Down
10 changes: 9 additions & 1 deletion src/app/xapian/index.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,22 @@ class SearchIndexService {
}

public deleteLocalIndex(): Observable<any> {
if (!this.localSearchActivated) {
// called mid-index load and we hadnt loaded it anyway
// send indexDeleted so the progress dialog closes
console.log('Worker: Tried to delete local index when it is not present');
ctx.postMessage({'action': PostMessageAction.indexDeleted});
return of(null);
}

this.localSearchActivated = false;

return new Observable((observer) => {
console.log('Worker: Closing xapian database');
if (this.api) {
console.log('Worker: API exists?');
this.api.closeXapianDatabase();
}
this.api.closeXapianDatabase();

FS.readdir(XAPIAN_GLASS_WR).forEach((f) => {
if ( f !== '.' && f !== '..') {
Expand Down
Loading

0 comments on commit ad2e8b7

Please sign in to comment.