mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 02:33:46 +00:00
Apply Prettier (#1202)
This commit is contained in:
@@ -1,22 +1,50 @@
|
||||
<a class="account-switcher" (click)="toggle()" cdkOverlayOrigin #trigger="cdkOverlayOrigin" [hidden]="!showSwitcher">
|
||||
<app-avatar [data]="activeAccountEmail" size="25" [circle]="true" [fontSize]="14" [dynamic]="true" *ngIf="activeAccountEmail != null"></app-avatar>
|
||||
<span>{{activeAccountEmail}}</span>
|
||||
<i class="fa" aria-hidden="true" [ngClass]="{'fa-chevron-down': !isOpen, 'fa-chevron-up': isOpen}"></i>
|
||||
<a
|
||||
class="account-switcher"
|
||||
(click)="toggle()"
|
||||
cdkOverlayOrigin
|
||||
#trigger="cdkOverlayOrigin"
|
||||
[hidden]="!showSwitcher"
|
||||
>
|
||||
<app-avatar
|
||||
[data]="activeAccountEmail"
|
||||
size="25"
|
||||
[circle]="true"
|
||||
[fontSize]="14"
|
||||
[dynamic]="true"
|
||||
*ngIf="activeAccountEmail != null"
|
||||
></app-avatar>
|
||||
<span>{{ activeAccountEmail }}</span>
|
||||
<i
|
||||
class="fa"
|
||||
aria-hidden="true"
|
||||
[ngClass]="{ 'fa-chevron-down': !isOpen, 'fa-chevron-up': isOpen }"
|
||||
></i>
|
||||
</a>
|
||||
|
||||
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="isOpen" cdkConnectedOverlayMinWidth="250px">
|
||||
<div class="account-switcher-dropdown" [@transformPanel]="'open'">
|
||||
<div class="accounts">
|
||||
<a *ngFor="let a of accounts | keyvalue" class="account" [ngClass]="{'active': a.value.profile.authenticationStatus == 'active'}"
|
||||
href="#" appStopClick (click)="switch(a.key)">
|
||||
<span class="email">{{a.value.profile.email}}</span>
|
||||
<span class="server">{{a.value.settings.environmentUrls.server}}</span>
|
||||
<span class="status">{{a.value.profile.authenticationStatus}}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="border"></div>
|
||||
<a class="add" routerLink="/login" (click)="toggle()">
|
||||
<i class="fa fa-plus" aria-hidden="true"></i> {{'addAccount' | i18n}}
|
||||
</a>
|
||||
<ng-template
|
||||
cdkConnectedOverlay
|
||||
[cdkConnectedOverlayOrigin]="trigger"
|
||||
[cdkConnectedOverlayOpen]="isOpen"
|
||||
cdkConnectedOverlayMinWidth="250px"
|
||||
>
|
||||
<div class="account-switcher-dropdown" [@transformPanel]="'open'">
|
||||
<div class="accounts">
|
||||
<a
|
||||
*ngFor="let a of accounts | keyvalue"
|
||||
class="account"
|
||||
[ngClass]="{ active: a.value.profile.authenticationStatus == 'active' }"
|
||||
href="#"
|
||||
appStopClick
|
||||
(click)="switch(a.key)"
|
||||
>
|
||||
<span class="email">{{ a.value.profile.email }}</span>
|
||||
<span class="server">{{ a.value.settings.environmentUrls.server }}</span>
|
||||
<span class="status">{{ a.value.profile.authenticationStatus }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="border"></div>
|
||||
<a class="add" routerLink="/login" (click)="toggle()">
|
||||
<i class="fa fa-plus" aria-hidden="true"></i> {{ "addAccount" | i18n }}
|
||||
</a>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -1,78 +1,87 @@
|
||||
import {
|
||||
animate,
|
||||
state,
|
||||
style,
|
||||
transition,
|
||||
trigger,
|
||||
} from '@angular/animations';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { animate, state, style, transition, trigger } from "@angular/animations";
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
|
||||
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
||||
import { StateService } from 'jslib-common/abstractions/state.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
import { VaultTimeoutService } from "jslib-common/abstractions/vaultTimeout.service";
|
||||
|
||||
import { AuthenticationStatus } from 'jslib-common/enums/authenticationStatus';
|
||||
import { AuthenticationStatus } from "jslib-common/enums/authenticationStatus";
|
||||
|
||||
import { Account } from 'jslib-common/models/domain/account';
|
||||
import { Account } from "jslib-common/models/domain/account";
|
||||
|
||||
@Component({
|
||||
selector: 'app-account-switcher',
|
||||
templateUrl: 'account-switcher.component.html',
|
||||
animations: [
|
||||
trigger('transformPanel', [
|
||||
state('void', style({
|
||||
opacity: 0,
|
||||
})),
|
||||
transition('void => open', animate('100ms linear', style({
|
||||
opacity: 1,
|
||||
}))),
|
||||
transition('* => void', animate('100ms linear', style({opacity: 0}))),
|
||||
]),
|
||||
],
|
||||
selector: "app-account-switcher",
|
||||
templateUrl: "account-switcher.component.html",
|
||||
animations: [
|
||||
trigger("transformPanel", [
|
||||
state(
|
||||
"void",
|
||||
style({
|
||||
opacity: 0,
|
||||
})
|
||||
),
|
||||
transition(
|
||||
"void => open",
|
||||
animate(
|
||||
"100ms linear",
|
||||
style({
|
||||
opacity: 1,
|
||||
})
|
||||
)
|
||||
),
|
||||
transition("* => void", animate("100ms linear", style({ opacity: 0 }))),
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class AccountSwitcherComponent implements OnInit {
|
||||
isOpen: boolean = false;
|
||||
accounts: { [userId: string]: Account } = {};
|
||||
activeAccountEmail: string;
|
||||
isOpen: boolean = false;
|
||||
accounts: { [userId: string]: Account } = {};
|
||||
activeAccountEmail: string;
|
||||
|
||||
get showSwitcher() {
|
||||
return this.accounts != null && Object.keys(this.accounts).length > 0;
|
||||
}
|
||||
get showSwitcher() {
|
||||
return this.accounts != null && Object.keys(this.accounts).length > 0;
|
||||
}
|
||||
|
||||
constructor(private stateService: StateService, private vaultTimeoutService: VaultTimeoutService,
|
||||
private messagingService: MessagingService, private router: Router) {}
|
||||
constructor(
|
||||
private stateService: StateService,
|
||||
private vaultTimeoutService: VaultTimeoutService,
|
||||
private messagingService: MessagingService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.stateService.accounts.subscribe(async accounts => {
|
||||
for (const userId in accounts) {
|
||||
if (userId === await this.stateService.getUserId()) {
|
||||
accounts[userId].profile.authenticationStatus = AuthenticationStatus.Active;
|
||||
} else {
|
||||
accounts[userId].profile.authenticationStatus = await this.vaultTimeoutService.isLocked(userId) ?
|
||||
AuthenticationStatus.Locked :
|
||||
AuthenticationStatus.Unlocked;
|
||||
}
|
||||
}
|
||||
|
||||
this.accounts = accounts;
|
||||
this.activeAccountEmail = await this.stateService.getEmail();
|
||||
});
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.isOpen = !this.isOpen;
|
||||
}
|
||||
|
||||
async switch(userId: string) {
|
||||
await this.stateService.setActiveUser(userId);
|
||||
const locked = await this.vaultTimeoutService.isLocked(userId);
|
||||
if (locked) {
|
||||
this.messagingService.send('locked', { userId: userId });
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.stateService.accounts.subscribe(async (accounts) => {
|
||||
for (const userId in accounts) {
|
||||
if (userId === (await this.stateService.getUserId())) {
|
||||
accounts[userId].profile.authenticationStatus = AuthenticationStatus.Active;
|
||||
} else {
|
||||
this.messagingService.send('unlocked');
|
||||
this.messagingService.send('syncVault');
|
||||
this.router.navigate(['vault']);
|
||||
accounts[userId].profile.authenticationStatus = (await this.vaultTimeoutService.isLocked(
|
||||
userId
|
||||
))
|
||||
? AuthenticationStatus.Locked
|
||||
: AuthenticationStatus.Unlocked;
|
||||
}
|
||||
}
|
||||
|
||||
this.accounts = accounts;
|
||||
this.activeAccountEmail = await this.stateService.getEmail();
|
||||
});
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.isOpen = !this.isOpen;
|
||||
}
|
||||
|
||||
async switch(userId: string) {
|
||||
await this.stateService.setActiveUser(userId);
|
||||
const locked = await this.vaultTimeoutService.isLocked(userId);
|
||||
if (locked) {
|
||||
this.messagingService.send("locked", { userId: userId });
|
||||
} else {
|
||||
this.messagingService.send("unlocked");
|
||||
this.messagingService.send("syncVault");
|
||||
this.router.navigate(["vault"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="header">
|
||||
<app-search></app-search>
|
||||
<app-account-switcher></app-account-switcher>
|
||||
<app-search></app-search>
|
||||
<app-account-switcher></app-account-switcher>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component } from "@angular/core";
|
||||
|
||||
@Component({
|
||||
selector: 'app-header',
|
||||
templateUrl: 'header.component.html',
|
||||
selector: "app-header",
|
||||
templateUrl: "header.component.html",
|
||||
})
|
||||
export class HeaderComponent {
|
||||
}
|
||||
export class HeaderComponent {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<ng-container *ngFor="let item of items">
|
||||
<a [routerLink]="item.link" class="btn primary" routerLinkActive="active" [title]="item.label">
|
||||
<i class="fa" [ngClass]="item.icon"></i>{{ item.label }}
|
||||
</a>
|
||||
<a [routerLink]="item.link" class="btn primary" routerLinkActive="active" [title]="item.label">
|
||||
<i class="fa" [ngClass]="item.icon"></i>{{ item.label }}
|
||||
</a>
|
||||
</ng-container>
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
||||
import { Component } from "@angular/core";
|
||||
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-nav',
|
||||
templateUrl: 'nav.component.html',
|
||||
selector: "app-nav",
|
||||
templateUrl: "nav.component.html",
|
||||
})
|
||||
export class NavComponent {
|
||||
items: any[] = [
|
||||
{
|
||||
link: '/vault',
|
||||
icon: 'fa-lock',
|
||||
label: this.i18nService.translate('myVault'),
|
||||
},
|
||||
{
|
||||
link: '/send',
|
||||
icon: 'fa-paper-plane',
|
||||
label: 'Send',
|
||||
},
|
||||
];
|
||||
items: any[] = [
|
||||
{
|
||||
link: "/vault",
|
||||
icon: "fa-lock",
|
||||
label: this.i18nService.translate("myVault"),
|
||||
},
|
||||
{
|
||||
link: "/send",
|
||||
icon: "fa-paper-plane",
|
||||
label: "Send",
|
||||
},
|
||||
];
|
||||
|
||||
constructor(private i18nService: I18nService) {}
|
||||
constructor(private i18nService: I18nService) {}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Injectable } from "@angular/core";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
export type SearchBarState = {
|
||||
enabled: boolean;
|
||||
placeholderText: string;
|
||||
enabled: boolean;
|
||||
placeholderText: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class SearchBarService {
|
||||
searchText = new BehaviorSubject<string>(null);
|
||||
|
||||
searchText = new BehaviorSubject<string>(null);
|
||||
private _state = {
|
||||
enabled: false,
|
||||
placeholderText: "",
|
||||
};
|
||||
|
||||
private _state = {
|
||||
enabled: false,
|
||||
placeholderText: '',
|
||||
};
|
||||
// tslint:disable-next-line:member-ordering
|
||||
state = new BehaviorSubject<SearchBarState>(this._state);
|
||||
|
||||
// tslint:disable-next-line:member-ordering
|
||||
state = new BehaviorSubject<SearchBarState>(this._state);
|
||||
setEnabled(enabled: boolean) {
|
||||
this._state.enabled = enabled;
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
setEnabled(enabled: boolean) {
|
||||
this._state.enabled = enabled;
|
||||
this.updateState();
|
||||
}
|
||||
setPlaceholderText(placeholderText: string) {
|
||||
this._state.placeholderText = placeholderText;
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
setPlaceholderText(placeholderText: string) {
|
||||
this._state.placeholderText = placeholderText;
|
||||
this.updateState();
|
||||
}
|
||||
setSearchText(value: string) {
|
||||
this.searchText.next(value);
|
||||
}
|
||||
|
||||
setSearchText(value: string) {
|
||||
this.searchText.next(value);
|
||||
}
|
||||
|
||||
private updateState() {
|
||||
this.state.next(this._state);
|
||||
}
|
||||
private updateState() {
|
||||
this.state.next(this._state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
<div class="search" *ngIf="state.enabled">
|
||||
<input type="search" [placeholder]="state.placeholderText" id="search" autocomplete="off" [formControl]="searchText" appAutofocus>
|
||||
<i class="fa fa-search" aria-hidden="true"></i>
|
||||
<input
|
||||
type="search"
|
||||
[placeholder]="state.placeholderText"
|
||||
id="search"
|
||||
autocomplete="off"
|
||||
[formControl]="searchText"
|
||||
appAutofocus
|
||||
/>
|
||||
<i class="fa fa-search" aria-hidden="true"></i>
|
||||
</div>
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { Component } from "@angular/core";
|
||||
import { FormControl } from "@angular/forms";
|
||||
|
||||
import { SearchBarService, SearchBarState } from './search-bar.service';
|
||||
import { SearchBarService, SearchBarState } from "./search-bar.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
templateUrl: 'search.component.html',
|
||||
selector: "app-search",
|
||||
templateUrl: "search.component.html",
|
||||
})
|
||||
export class SearchComponent {
|
||||
state: SearchBarState;
|
||||
searchText: FormControl = new FormControl(null);
|
||||
|
||||
state: SearchBarState;
|
||||
searchText: FormControl = new FormControl(null);
|
||||
constructor(private searchBarService: SearchBarService) {
|
||||
this.searchBarService.state.subscribe((state) => {
|
||||
this.state = state;
|
||||
});
|
||||
|
||||
constructor(private searchBarService: SearchBarService) {
|
||||
this.searchBarService.state.subscribe(state => {
|
||||
this.state = state;
|
||||
});
|
||||
|
||||
this.searchText.valueChanges.subscribe(value => {
|
||||
this.searchBarService.setSearchText(value);
|
||||
});
|
||||
}
|
||||
this.searchText.valueChanges.subscribe((value) => {
|
||||
this.searchBarService.setSearchText(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user