2021-02-12 23:28:31 +01:00
|
|
|
import { ChangeDetectorRef, Component, NgZone } from "@angular/core";
|
|
|
|
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
|
2021-10-14 23:58:59 +02:00
|
|
|
import { first } from "rxjs/operators";
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
import { Location } from "@angular/common";
|
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { SendView } from "jslib-common/models/view/sendView";
|
2021-02-12 23:28:31 +01:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { SendComponent as BaseSendComponent } from "jslib-angular/components/send/send.component";
|
2021-02-12 23:28:31 +01:00
|
|
|
|
2021-12-06 12:21:07 +01:00
|
|
|
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
|
2021-06-07 19:25:37 +02:00
|
|
|
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-10-21 11:10:46 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-06-07 19:25:37 +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";
|
2021-02-12 23:28:31 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
import { StateService } from "../../services/abstractions/state.service";
|
2021-02-12 23:28:31 +01:00
|
|
|
import { PopupUtilsService } from "../services/popup-utils.service";
|
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { SendType } from "jslib-common/enums/sendType";
|
2021-02-12 23:28:31 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
import { BrowserComponentState } from "../../models/browserComponentState";
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
const ComponentId = "SendTypeComponent";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-send-type",
|
|
|
|
templateUrl: "send-type.component.html",
|
|
|
|
})
|
|
|
|
export class SendTypeComponent extends BaseSendComponent {
|
|
|
|
groupingTitle: string;
|
|
|
|
// State Handling
|
2022-01-27 22:22:51 +01:00
|
|
|
state: BrowserComponentState;
|
2021-02-12 23:28:31 +01:00
|
|
|
private refreshTimeout: number;
|
|
|
|
private applySavedState = true;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
constructor(
|
|
|
|
sendService: SendService,
|
|
|
|
i18nService: I18nService,
|
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
environmentService: EnvironmentService,
|
|
|
|
ngZone: NgZone,
|
|
|
|
policyService: PolicyService,
|
|
|
|
searchService: SearchService,
|
|
|
|
private popupUtils: PopupUtilsService,
|
|
|
|
private stateService: StateService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private location: Location,
|
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
2021-10-21 11:10:46 +02:00
|
|
|
private broadcasterService: BroadcasterService,
|
|
|
|
private router: Router,
|
|
|
|
logService: LogService
|
|
|
|
) {
|
2021-02-12 23:28:31 +01:00
|
|
|
super(
|
|
|
|
sendService,
|
|
|
|
i18nService,
|
|
|
|
platformUtilsService,
|
|
|
|
environmentService,
|
|
|
|
ngZone,
|
|
|
|
searchService,
|
2021-10-21 11:10:46 +02:00
|
|
|
policyService,
|
|
|
|
logService
|
|
|
|
);
|
2021-02-12 23:28:31 +01:00
|
|
|
super.onSuccessfulLoad = async () => {
|
|
|
|
this.selectType(this.type);
|
|
|
|
};
|
|
|
|
this.applySavedState =
|
|
|
|
(window as any).previousPopupUrl != null &&
|
|
|
|
!(window as any).previousPopupUrl.startsWith("/send-type");
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
// Let super class finish
|
|
|
|
await super.ngOnInit();
|
2021-10-14 23:58:59 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (params) => {
|
2021-02-12 23:28:31 +01:00
|
|
|
if (this.applySavedState) {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.state = await this.stateService.getBrowserSendTypeComponentState();
|
|
|
|
if (this.state?.searchText != null) {
|
2021-02-12 23:28:31 +01:00
|
|
|
this.searchText = this.state.searchText;
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
if (params.type != null) {
|
|
|
|
this.type = parseInt(params.type, null);
|
|
|
|
switch (this.type) {
|
|
|
|
case SendType.Text:
|
|
|
|
this.groupingTitle = this.i18nService.t("sendTypeText");
|
|
|
|
break;
|
|
|
|
case SendType.File:
|
|
|
|
this.groupingTitle = this.i18nService.t("sendTypeFile");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
await this.load((s) => s.type === this.type);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
// Restore state and remove reference
|
|
|
|
if (this.applySavedState && this.state != null) {
|
2022-01-27 22:22:51 +01:00
|
|
|
window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state?.scrollY), 0);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
this.stateService.setBrowserSendTypeComponentState(null);
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
// Refresh Send list if sync completed in background
|
|
|
|
this.broadcasterService.subscribe(ComponentId, (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "syncCompleted":
|
|
|
|
if (message.successfully) {
|
|
|
|
this.refreshTimeout = window.setTimeout(() => {
|
|
|
|
this.refresh();
|
2021-12-21 15:43:35 +01:00
|
|
|
}, 500);
|
2021-02-12 23:28:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-23 22:37:55 +01:00
|
|
|
this.changeDetectorRef.detectChanges();
|
|
|
|
});
|
|
|
|
});
|
2021-02-12 23:28:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 23:03:44 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
// Remove timeout
|
|
|
|
if (this.refreshTimeout != null) {
|
|
|
|
window.clearTimeout(this.refreshTimeout);
|
|
|
|
}
|
2021-02-12 23:28:31 +01:00
|
|
|
// Save state
|
|
|
|
this.saveState();
|
|
|
|
// Unsubscribe
|
|
|
|
this.broadcasterService.unsubscribe(ComponentId);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
async selectSend(s: SendView) {
|
|
|
|
this.router.navigate(["/edit-send"], { queryParams: { sendId: s.id } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
async addSend() {
|
2021-02-24 23:03:44 +01:00
|
|
|
if (this.disableSend) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
2021-02-12 23:28:31 +01:00
|
|
|
}
|
2021-02-23 22:37:55 +01:00
|
|
|
this.router.navigate(["/add-send"], { queryParams: { type: this.type } });
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2021-02-12 23:28:31 +01:00
|
|
|
|
|
|
|
async removePassword(s: SendView): Promise<boolean> {
|
|
|
|
if (this.disableSend) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-24 23:03:44 +01:00
|
|
|
super.removePassword(s);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
back() {
|
2021-02-12 23:28:31 +01:00
|
|
|
(window as any).routeDirection = "b";
|
|
|
|
this.location.back();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
private async saveState() {
|
|
|
|
this.state = {
|
|
|
|
scrollY: this.popupUtils.getContentScrollY(window),
|
|
|
|
searchText: this.searchText,
|
2021-12-21 15:43:35 +01:00
|
|
|
};
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.stateService.setBrowserSendTypeComponentState(this.state);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2021-02-12 23:28:31 +01:00
|
|
|
}
|