mirror of
https://github.com/bitwarden/browser.git
synced 2025-02-01 23:01:28 +01:00
Add import error dialog
This commit is contained in:
parent
fbf67a819f
commit
518211dae0
@ -0,0 +1,29 @@
|
|||||||
|
<bit-dialog>
|
||||||
|
<span bitDialogTitle>
|
||||||
|
{{ "importError" | i18n }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span bitDialogContent>
|
||||||
|
<div>{{ "resolveTheErrorsBelowAndTryAgain" | i18n }}</div>
|
||||||
|
<bit-table [dataSource]="dataSource">
|
||||||
|
<ng-container header>
|
||||||
|
<tr>
|
||||||
|
<th bitCell>{{ "name" | i18n }}</th>
|
||||||
|
<th bitCell>{{ "description" | i18n }}</th>
|
||||||
|
</tr>
|
||||||
|
</ng-container>
|
||||||
|
<ng-template body let-rows$>
|
||||||
|
<tr bitRow *ngFor="let r of rows$ | async">
|
||||||
|
<td bitCell>{{ r.type }}</td>
|
||||||
|
<td bitCell>{{ r.message }}</td>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
</bit-table>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div bitDialogFooter>
|
||||||
|
<button bitButton bitDialogClose buttonType="primary" type="button">
|
||||||
|
{{ "ok" | i18n }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</bit-dialog>
|
@ -0,0 +1,33 @@
|
|||||||
|
import { DialogRef, DIALOG_DATA } from "@angular/cdk/dialog";
|
||||||
|
import { Component, Inject, OnInit } from "@angular/core";
|
||||||
|
|
||||||
|
import { TableDataSource } from "@bitwarden/components";
|
||||||
|
|
||||||
|
export interface ErrorList {
|
||||||
|
type: string;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: "app-import-error-dialog",
|
||||||
|
templateUrl: "./import-error-dialog.component.html",
|
||||||
|
})
|
||||||
|
export class ImportErrorDialogComponent implements OnInit {
|
||||||
|
protected dataSource = new TableDataSource<ErrorList>();
|
||||||
|
|
||||||
|
constructor(public dialogRef: DialogRef, @Inject(DIALOG_DATA) public data: Error) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
const split = this.data.message.split("\n\n");
|
||||||
|
if (split.length == 1) {
|
||||||
|
this.dataSource.data = [{ type: "", message: this.data.message }];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: ErrorList[] = [];
|
||||||
|
split.forEach((line) => {
|
||||||
|
data.push({ type: "", message: line });
|
||||||
|
});
|
||||||
|
this.dataSource.data = data;
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
|
export * from "./import-error-dialog.component";
|
||||||
export * from "./import-success-dialog.component";
|
export * from "./import-success-dialog.component";
|
||||||
export * from "./file-password-prompt.component";
|
export * from "./file-password-prompt.component";
|
||||||
|
@ -15,7 +15,11 @@ import {
|
|||||||
|
|
||||||
import { LooseComponentsModule, SharedModule } from "../../shared";
|
import { LooseComponentsModule, SharedModule } from "../../shared";
|
||||||
|
|
||||||
import { ImportSuccessDialogComponent, FilePasswordPromptComponent } from "./dialog";
|
import {
|
||||||
|
ImportErrorDialogComponent,
|
||||||
|
ImportSuccessDialogComponent,
|
||||||
|
FilePasswordPromptComponent,
|
||||||
|
} from "./dialog";
|
||||||
import { ExportComponent } from "./export.component";
|
import { ExportComponent } from "./export.component";
|
||||||
import { ImportExportRoutingModule } from "./import-export-routing.module";
|
import { ImportExportRoutingModule } from "./import-export-routing.module";
|
||||||
import { ImportComponent } from "./import.component";
|
import { ImportComponent } from "./import.component";
|
||||||
@ -26,6 +30,7 @@ import { ImportComponent } from "./import.component";
|
|||||||
ImportComponent,
|
ImportComponent,
|
||||||
ExportComponent,
|
ExportComponent,
|
||||||
FilePasswordPromptComponent,
|
FilePasswordPromptComponent,
|
||||||
|
ImportErrorDialogComponent,
|
||||||
ImportSuccessDialogComponent,
|
ImportSuccessDialogComponent,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -3,7 +3,6 @@ import { Router } from "@angular/router";
|
|||||||
import * as JSZip from "jszip";
|
import * as JSZip from "jszip";
|
||||||
import { Subject, lastValueFrom } from "rxjs";
|
import { Subject, lastValueFrom } from "rxjs";
|
||||||
import { takeUntil } from "rxjs/operators";
|
import { takeUntil } from "rxjs/operators";
|
||||||
import Swal, { SweetAlertIcon } from "sweetalert2";
|
|
||||||
|
|
||||||
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
|
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
|
||||||
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
||||||
@ -20,7 +19,11 @@ import {
|
|||||||
ImportType,
|
ImportType,
|
||||||
} from "@bitwarden/importer";
|
} from "@bitwarden/importer";
|
||||||
|
|
||||||
import { FilePasswordPromptComponent, ImportSuccessDialogComponent } from "./dialog";
|
import {
|
||||||
|
FilePasswordPromptComponent,
|
||||||
|
ImportErrorDialogComponent,
|
||||||
|
ImportSuccessDialogComponent,
|
||||||
|
} from "./dialog";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-import",
|
selector: "app-import",
|
||||||
@ -152,7 +155,9 @@ export class ImportComponent implements OnInit, OnDestroy {
|
|||||||
this.syncService.fullSync(true);
|
this.syncService.fullSync(true);
|
||||||
await this.onSuccessfulImport();
|
await this.onSuccessfulImport();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.error(e);
|
this.dialogService.open<unknown, Error>(ImportErrorDialogComponent, {
|
||||||
|
data: e,
|
||||||
|
});
|
||||||
this.logService.error(e);
|
this.logService.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,27 +208,6 @@ export class ImportComponent implements OnInit, OnDestroy {
|
|||||||
this.fileSelected = fileInputEl.files.length > 0 ? fileInputEl.files[0] : null;
|
this.fileSelected = fileInputEl.files.length > 0 ? fileInputEl.files[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async error(error: Error) {
|
|
||||||
await Swal.fire({
|
|
||||||
heightAuto: false,
|
|
||||||
buttonsStyling: false,
|
|
||||||
icon: "error" as SweetAlertIcon,
|
|
||||||
iconHtml: `<i class="swal-custom-icon bwi bwi-error text-danger"></i>`,
|
|
||||||
input: "textarea",
|
|
||||||
inputValue: error.message,
|
|
||||||
inputAttributes: {
|
|
||||||
readonly: "true",
|
|
||||||
},
|
|
||||||
titleText: this.i18nService.t("importError"),
|
|
||||||
text: this.i18nService.t("importErrorDesc"),
|
|
||||||
showConfirmButton: true,
|
|
||||||
confirmButtonText: this.i18nService.t("ok"),
|
|
||||||
onOpen: (popupEl) => {
|
|
||||||
popupEl.querySelector(".swal2-textarea").scrollTo(0, 0);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFileContents(file: File): Promise<string> {
|
private getFileContents(file: File): Promise<string> {
|
||||||
if (this.format === "1password1pux") {
|
if (this.format === "1password1pux") {
|
||||||
return this.extract1PuxContent(file);
|
return this.extract1PuxContent(file);
|
||||||
|
Loading…
Reference in New Issue
Block a user