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";
|
2022-08-08 11:04:36 +02:00
|
|
|
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/sendView";
|
|
|
|
import { invokeMenu, RendererMenuItem } from "@bitwarden/electron/utils";
|
2021-02-03 22:24:49 +01:00
|
|
|
|
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,
|
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,
|
2021-12-15 23:32:00 +01:00
|
|
|
logService
|
|
|
|
);
|
|
|
|
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);
|
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) {
|
2021-04-07 20:25:15 +02:00
|
|
|
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
|
|
|
});
|
2021-04-07 20:25:15 +02: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
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-04-07 20:25:15 +02:00
|
|
|
invokeMenu(menu);
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2021-02-03 22:24:49 +01:00
|
|
|
}
|