2021-02-12 23:28:31 +01:00
|
|
|
import {
|
|
|
|
ChangeDetectorRef,
|
|
|
|
Component,
|
|
|
|
NgZone,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
2021-02-23 22:37:55 +01:00
|
|
|
Router,
|
2021-02-12 23:28:31 +01:00
|
|
|
} 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-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';
|
|
|
|
import { StateService } from 'jslib-common/abstractions/state.service';
|
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
2021-02-12 23:28:31 +01:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { BroadcasterService } from 'jslib-angular/services/broadcaster.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
|
|
|
|
|
|
|
const ComponentId = 'SendTypeComponent';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-send-type',
|
|
|
|
templateUrl: 'send-type.component.html',
|
|
|
|
})
|
|
|
|
export class SendTypeComponent extends BaseSendComponent {
|
|
|
|
groupingTitle: string;
|
|
|
|
// State Handling
|
|
|
|
state: any;
|
|
|
|
private refreshTimeout: number;
|
|
|
|
private applySavedState = true;
|
|
|
|
|
|
|
|
constructor(sendService: SendService, i18nService: I18nService,
|
|
|
|
platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService, ngZone: NgZone,
|
|
|
|
policyService: PolicyService, userService: UserService, 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, userService, 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');
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
this.state = (await this.stateService.get<any>(ComponentId)) || {};
|
|
|
|
if (this.state.searchText != null) {
|
|
|
|
this.searchText = this.state.searchText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore state and remove reference
|
|
|
|
if (this.applySavedState && this.state != null) {
|
|
|
|
window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY), 0);
|
|
|
|
}
|
|
|
|
this.stateService.remove(ComponentId);
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.changeDetectorRef.detectChanges();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
// Remove timeout
|
|
|
|
if (this.refreshTimeout != null) {
|
|
|
|
window.clearTimeout(this.refreshTimeout);
|
|
|
|
}
|
|
|
|
// Save state
|
|
|
|
this.saveState();
|
|
|
|
// Unsubscribe
|
|
|
|
this.broadcasterService.unsubscribe(ComponentId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async selectSend(s: SendView) {
|
2021-02-23 22:37:55 +01:00
|
|
|
this.router.navigate(['/edit-send'], { queryParams: { sendId: s.id } });
|
2021-02-12 23:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async addSend() {
|
2021-02-24 23:03:44 +01:00
|
|
|
if (this.disableSend) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-23 22:37:55 +01:00
|
|
|
this.router.navigate(['/add-send'], { queryParams: { type: this.type } });
|
2021-02-12 23:28:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 23:03:44 +01:00
|
|
|
async removePassword(s: SendView): Promise<boolean> {
|
|
|
|
if (this.disableSend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.removePassword(s);
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:28:31 +01:00
|
|
|
back() {
|
|
|
|
(window as any).routeDirection = 'b';
|
|
|
|
this.location.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async saveState() {
|
|
|
|
this.state = {
|
|
|
|
scrollY: this.popupUtils.getContentScrollY(window),
|
|
|
|
searchText: this.searchText,
|
|
|
|
};
|
|
|
|
await this.stateService.save(ComponentId, this.state);
|
|
|
|
}
|
|
|
|
}
|