2020-11-04 20:49:08 +01:00
|
|
|
import { Component, NgZone, ViewChild, ViewContainerRef } from "@angular/core";
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { SendComponent as BaseSendComponent } from "jslib-angular/components/send/send.component";
|
2022-02-24 12:10:07 +01:00
|
|
|
import { ModalService } from "jslib-angular/services/modal.service";
|
2021-12-07 23:16:47 +01:00
|
|
|
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { PolicyService } from "jslib-common/abstractions/policy.service";
|
|
|
|
import { SearchService } from "jslib-common/abstractions/search.service";
|
|
|
|
import { SendService } from "jslib-common/abstractions/send.service";
|
2022-02-24 12:10:07 +01:00
|
|
|
import { SendView } from "jslib-common/models/view/sendView";
|
2020-11-04 20:49:08 +01:00
|
|
|
|
2022-02-24 12:10:07 +01:00
|
|
|
import { AddEditComponent } from "./add-edit.component";
|
2021-01-22 23:03:55 +01:00
|
|
|
|
2021-02-12 17:38:55 +01:00
|
|
|
const BroadcasterSubscriptionId = "SendComponent";
|
|
|
|
|
2020-11-04 20:49:08 +01:00
|
|
|
@Component({
|
|
|
|
selector: "app-send",
|
|
|
|
templateUrl: "send.component.html",
|
|
|
|
})
|
2021-02-01 17:30:27 +01:00
|
|
|
export class SendComponent extends BaseSendComponent {
|
2020-11-04 20:49:08 +01:00
|
|
|
@ViewChild("sendAddEdit", { read: ViewContainerRef, static: true })
|
|
|
|
sendAddEditModalRef: ViewContainerRef;
|
|
|
|
|
2021-02-01 17:30:27 +01:00
|
|
|
constructor(
|
|
|
|
sendService: SendService,
|
|
|
|
i18nService: I18nService,
|
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
environmentService: EnvironmentService,
|
2021-12-14 17:10:26 +01:00
|
|
|
ngZone: NgZone,
|
|
|
|
searchService: SearchService,
|
|
|
|
policyService: PolicyService,
|
|
|
|
private modalService: ModalService,
|
|
|
|
private broadcasterService: BroadcasterService,
|
|
|
|
logService: LogService
|
|
|
|
) {
|
2021-02-12 17:38:55 +01:00
|
|
|
super(
|
|
|
|
sendService,
|
2021-12-14 17:10:26 +01:00
|
|
|
i18nService,
|
2021-02-12 17:38:55 +01:00
|
|
|
platformUtilsService,
|
|
|
|
environmentService,
|
|
|
|
ngZone,
|
|
|
|
searchService,
|
2021-12-14 17:10:26 +01:00
|
|
|
policyService,
|
2021-02-12 17:38:55 +01:00
|
|
|
logService
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
|
|
|
await this.load();
|
2021-02-08 23:53:48 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
// Broadcaster subscription - load if sync completes in the background
|
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
2021-02-04 20:08:16 +01:00
|
|
|
switch (message.command) {
|
|
|
|
case "syncCompleted":
|
|
|
|
if (message.successfully) {
|
|
|
|
await this.load();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-02-04 20:08:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2021-02-12 17:38:55 +01:00
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-02-04 20:08:16 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async addSend() {
|
|
|
|
if (this.disableSend) {
|
2020-11-04 20:49:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
const component = await this.editSend(null);
|
2020-11-04 20:49:08 +01:00
|
|
|
component.type = this.type;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async editSend(send: SendView) {
|
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
|
|
|
AddEditComponent,
|
|
|
|
this.sendAddEditModalRef,
|
|
|
|
(comp) => {
|
2021-08-31 16:42:43 +02:00
|
|
|
comp.sendId = send == null ? null : send.id;
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onSavedSend.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
|
|
|
await this.load();
|
2020-11-04 20:49:08 +01:00
|
|
|
});
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onDeletedSend.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
|
|
|
await this.load();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2020-11-04 20:49:08 +01:00
|
|
|
|
|
|
|
return childComponent;
|
|
|
|
}
|
|
|
|
}
|