bitwarden-estensione-browser/apps/desktop/src/app/send/send.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
4.1 KiB
TypeScript
Raw Normal View History

2021-02-03 22:24:49 +01:00
import { Component, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
2022-06-14 17:10:53 +02:00
import { SendComponent as BaseSendComponent } from "@bitwarden/angular/components/send/send.component";
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
2022-06-14 17:10:53 +02:00
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendView } from "@bitwarden/common/models/view/send.view";
2021-02-03 22:24:49 +01:00
import { invokeMenu, RendererMenuItem } from "../../utils";
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
import { SearchBarService } from "../layout/search/search-bar.service";
2022-02-24 20:50:19 +01:00
2021-02-09 21:57:10 +01:00
import { AddEditComponent } from "./add-edit.component";
2021-02-03 22:24:49 +01:00
enum Action {
None = "",
Add = "add",
Edit = "edit",
}
2021-02-16 17:52:23 +01:00
const BroadcasterSubscriptionId = "SendComponent";
2021-02-03 22:24:49 +01:00
@Component({
selector: "app-send",
templateUrl: "send.component.html",
})
2021-02-16 17:52:23 +01:00
export class SendComponent extends BaseSendComponent implements OnInit, OnDestroy {
2021-02-09 21:57:10 +01:00
@ViewChild(AddEditComponent) addEditComponent: AddEditComponent;
2021-12-20 15:47:17 +01:00
2021-02-03 22:24:49 +01:00
sendId: string;
action: Action = Action.None;
2021-12-20 15:47:17 +01:00
2021-02-03 22:24:49 +01:00
constructor(
sendService: SendService,
i18nService: I18nService,
platformUtilsService: PlatformUtilsService,
environmentService: EnvironmentService,
2021-02-16 17:52:23 +01:00
private broadcasterService: BroadcasterService,
ngZone: NgZone,
searchService: SearchService,
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
policyService: PolicyService,
private searchBarService: SearchBarService,
2021-02-16 17:52:23 +01:00
logService: LogService
) {
super(
2021-02-03 22:24:49 +01:00
sendService,
i18nService,
2021-02-16 17:52:23 +01:00
platformUtilsService,
environmentService,
2021-12-20 15:47:17 +01:00
ngZone,
2021-02-16 17:52:23 +01:00
searchService,
policyService,
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
logService
);
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
this.searchBarService.searchText$.subscribe((searchText) => {
2021-02-16 17:52:23 +01:00
this.searchText = searchText;
this.searchTextChanged();
});
}
2021-12-20 15:47:17 +01:00
2021-02-16 19:11:14 +01:00
async ngOnInit() {
this.searchBarService.setEnabled(true);
this.searchBarService.setPlaceholderText(this.i18nService.t("searchSends"));
2021-12-20 15:47:17 +01:00
2021-02-09 21:57:10 +01:00
super.ngOnInit();
2021-02-16 19:11:14 +01:00
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
2021-02-09 21:57:10 +01:00
this.ngZone.run(async () => {
2021-02-16 17:52:23 +01:00
switch (message.command) {
2021-02-09 21:57:10 +01:00
case "syncCompleted":
await this.load();
break;
}
2021-12-20 15:47:17 +01:00
});
});
2021-02-09 21:57:10 +01:00
await this.load();
2021-12-20 15:47:17 +01:00
}
2021-02-16 17:52:23 +01:00
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
this.searchBarService.setEnabled(false);
2021-12-20 15:47:17 +01:00
}
2021-02-03 22:24:49 +01:00
addSend() {
2021-02-04 05:50:41 +01:00
this.action = Action.Add;
2021-02-16 17:52:23 +01:00
if (this.addEditComponent != null) {
this.addEditComponent.sendId = null;
this.addEditComponent.send = null;
this.addEditComponent.load();
2021-02-03 22:24:49 +01:00
}
2021-12-20 15:47:17 +01:00
}
2021-02-16 17:52:23 +01:00
cancel(s: SendView) {
2021-02-04 05:50:41 +01:00
this.action = Action.None;
2021-02-16 17:52:23 +01:00
this.sendId = null;
2021-12-20 15:47:17 +01:00
}
2021-02-04 05:50:41 +01:00
async deletedSend(s: SendView) {
await this.refresh();
2021-02-10 20:15:10 +01:00
this.action = Action.None;
2021-02-16 17:52:23 +01:00
this.sendId = null;
2021-12-20 15:47:17 +01:00
}
2021-02-10 20:15:10 +01:00
async savedSend(s: SendView) {
await this.refresh();
this.selectSend(s.id);
2021-12-20 15:47:17 +01:00
}
2021-02-10 20:15:10 +01:00
async selectSend(sendId: string) {
if (sendId === this.sendId && this.action === Action.Edit) {
return;
2021-02-03 22:24:49 +01:00
}
2021-02-18 19:03:20 +01:00
this.action = Action.Edit;
this.sendId = sendId;
if (this.addEditComponent != null) {
this.addEditComponent.sendId = sendId;
await this.addEditComponent.refresh();
}
2021-12-20 15:47:17 +01:00
}
2021-02-09 21:57:10 +01:00
get selectedSendType() {
2021-02-16 17:52:23 +01:00
return this.sends.find((s) => s.id === this.sendId)?.type;
2021-12-20 15:47:17 +01:00
}
2021-02-18 19:03:20 +01:00
viewSendMenu(send: SendView) {
const menu: RendererMenuItem[] = [];
menu.push({
2021-02-18 19:03:20 +01:00
label: this.i18nService.t("copyLink"),
2021-02-18 19:06:21 +01:00
click: () => this.copy(send),
2021-12-20 15:47:17 +01:00
});
menu.push({
2021-02-18 19:03:20 +01:00
label: this.i18nService.t("delete"),
click: async () => {
2021-02-16 19:11:14 +01:00
await this.delete(send);
await this.deletedSend(send);
2021-12-20 15:47:17 +01:00
},
});
invokeMenu(menu);
2021-12-20 15:47:17 +01:00
}
2021-02-03 22:24:49 +01:00
}