mirror of
https://github.com/bitwarden/browser
synced 2025-12-31 07:33:23 +00:00
Replace toaster library (#1183)
This commit is contained in:
@@ -1,10 +1,3 @@
|
||||
import {
|
||||
BodyOutputType,
|
||||
Toast,
|
||||
ToasterConfig,
|
||||
ToasterService,
|
||||
} from 'angular2-toaster';
|
||||
|
||||
import {
|
||||
Component,
|
||||
NgZone,
|
||||
@@ -16,6 +9,10 @@ import {
|
||||
} from '@angular/core';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { Router } from '@angular/router';
|
||||
import {
|
||||
IndividualConfig,
|
||||
ToastrService,
|
||||
} from 'ngx-toastr';
|
||||
|
||||
import { PremiumComponent } from './accounts/premium.component';
|
||||
import { SettingsComponent } from './accounts/settings.component';
|
||||
@@ -64,7 +61,6 @@ const SyncInterval = 6 * 60 * 60 * 1000; // 6 hours
|
||||
selector: 'app-root',
|
||||
styles: [],
|
||||
template: `
|
||||
<toaster-container [toasterconfig]="toasterConfig" aria-live="polite"></toaster-container>
|
||||
<ng-template #settings></ng-template>
|
||||
<ng-template #premium></ng-template>
|
||||
<ng-template #passwordHistory></ng-template>
|
||||
@@ -83,13 +79,6 @@ export class AppComponent implements OnInit {
|
||||
@ViewChild('appPasswordGenerator', { read: ViewContainerRef, static: true })
|
||||
passwordGeneratorModalRef: ViewContainerRef;
|
||||
|
||||
toasterConfig: ToasterConfig = new ToasterConfig({
|
||||
showCloseButton: true,
|
||||
mouseoverTimerStop: true,
|
||||
animation: 'flyRight',
|
||||
limit: 5,
|
||||
});
|
||||
|
||||
private lastActivity: number = null;
|
||||
private modal: ModalRef = null;
|
||||
private idleTimer: number = null;
|
||||
@@ -100,7 +89,7 @@ export class AppComponent implements OnInit {
|
||||
private settingsService: SettingsService, private syncService: SyncService,
|
||||
private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService,
|
||||
private authService: AuthService, private router: Router,
|
||||
private toasterService: ToasterService, private i18nService: I18nService,
|
||||
private toastrService: ToastrService, private i18nService: I18nService,
|
||||
private sanitizer: DomSanitizer, private ngZone: NgZone,
|
||||
private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService,
|
||||
private cryptoService: CryptoService, private logService: LogService,
|
||||
@@ -224,9 +213,9 @@ export class AppComponent implements OnInit {
|
||||
case 'syncVault':
|
||||
try {
|
||||
await this.syncService.fullSync(true, true);
|
||||
this.toasterService.popAsync('success', null, this.i18nService.t('syncingComplete'));
|
||||
this.platformUtilsService.showToast('success', null, this.i18nService.t('syncingComplete'));
|
||||
} catch {
|
||||
this.toasterService.popAsync('error', null, this.i18nService.t('syncingFailed'));
|
||||
this.platformUtilsService.showToast('error', null, this.i18nService.t('syncingFailed'));
|
||||
}
|
||||
break;
|
||||
case 'checkSyncVault':
|
||||
@@ -374,7 +363,7 @@ export class AppComponent implements OnInit {
|
||||
this.searchService.clearIndex();
|
||||
this.authService.logOut(async () => {
|
||||
if (expired) {
|
||||
this.toasterService.popAsync('warning', this.i18nService.t('loggedOut'),
|
||||
this.platformUtilsService.showToast('warning', this.i18nService.t('loggedOut'),
|
||||
this.i18nService.t('loginExpired'));
|
||||
}
|
||||
this.router.navigate(['login']);
|
||||
@@ -428,30 +417,29 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
private showToast(msg: any) {
|
||||
const toast: Toast = {
|
||||
type: msg.type,
|
||||
title: msg.title,
|
||||
};
|
||||
let message = '';
|
||||
|
||||
const options: Partial<IndividualConfig> = {};
|
||||
|
||||
if (typeof (msg.text) === 'string') {
|
||||
toast.body = msg.text;
|
||||
message = msg.text;
|
||||
} else if (msg.text.length === 1) {
|
||||
toast.body = msg.text[0];
|
||||
message = msg.text[0];
|
||||
} else {
|
||||
let message = '';
|
||||
msg.text.forEach((t: string) =>
|
||||
message += ('<p>' + this.sanitizer.sanitize(SecurityContext.HTML, t) + '</p>'));
|
||||
toast.body = message;
|
||||
toast.bodyOutputType = BodyOutputType.TrustedHtml;
|
||||
options.enableHtml = true;
|
||||
}
|
||||
if (msg.options != null) {
|
||||
if (msg.options.trustedHtml === true) {
|
||||
toast.bodyOutputType = BodyOutputType.TrustedHtml;
|
||||
options.enableHtml = true;
|
||||
}
|
||||
if (msg.options.timeout != null && msg.options.timeout > 0) {
|
||||
toast.timeout = msg.options.timeout;
|
||||
options.timeOut = msg.options.timeout;
|
||||
}
|
||||
}
|
||||
this.toasterService.popAsync(toast);
|
||||
|
||||
this.toastrService.show(message, msg.title, options, 'toast-' + msg.type);
|
||||
}
|
||||
|
||||
private routeToVault(action: string, cipherType: CipherType) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'zone.js/dist/zone';
|
||||
|
||||
import { ToasterModule } from 'angular2-toaster';
|
||||
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { ServicesModule } from './services.module';
|
||||
|
||||
@@ -33,6 +31,7 @@ import { VaultTimeoutInputComponent } from './accounts/vault-timeout-input.compo
|
||||
|
||||
import { CalloutComponent } from 'jslib-angular/components/callout.component';
|
||||
import { IconComponent } from 'jslib-angular/components/icon.component';
|
||||
import { BitwardenToastModule } from 'jslib-angular/components/toastr.component';
|
||||
|
||||
import { A11yTitleDirective } from 'jslib-angular/directives/a11y-title.directive';
|
||||
import { ApiActionDirective } from 'jslib-angular/directives/api-action.directive';
|
||||
@@ -177,7 +176,11 @@ registerLocaleData(localeZhTw, 'zh-TW');
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
ServicesModule,
|
||||
ToasterModule.forRoot(),
|
||||
BitwardenToastModule.forRoot({
|
||||
maxOpened: 5,
|
||||
autoDismiss: true,
|
||||
closeButton: true,
|
||||
}),
|
||||
ScrollingModule,
|
||||
A11yModule,
|
||||
],
|
||||
|
||||
@@ -14,8 +14,6 @@ import {
|
||||
|
||||
import { first } from 'rxjs/operators';
|
||||
|
||||
import { ToasterService } from 'angular2-toaster';
|
||||
|
||||
import { AddEditComponent } from './add-edit.component';
|
||||
import { AttachmentsComponent } from './attachments.component';
|
||||
import { CiphersComponent } from './ciphers.component';
|
||||
@@ -86,7 +84,7 @@ export class VaultComponent implements OnInit, OnDestroy {
|
||||
private i18nService: I18nService, private modalService: ModalService,
|
||||
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
|
||||
private ngZone: NgZone, private syncService: SyncService,
|
||||
private toasterService: ToasterService, private messagingService: MessagingService,
|
||||
private messagingService: MessagingService,
|
||||
private platformUtilsService: PlatformUtilsService, private eventService: EventService,
|
||||
private totpService: TotpService, private userService: UserService,
|
||||
private passwordRepromptService: PasswordRepromptService) { }
|
||||
@@ -651,7 +649,7 @@ export class VaultComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
this.platformUtilsService.copyToClipboard(value);
|
||||
this.toasterService.popAsync('info', null,
|
||||
this.platformUtilsService.showToast('info', null,
|
||||
this.i18nService.t('valueCopied', this.i18nService.t(labelI18nKey)));
|
||||
if (this.action === 'view') {
|
||||
this.messagingService.send('minimizeOnCopy');
|
||||
|
||||
Reference in New Issue
Block a user