2021-02-18 19:03:20 +01:00
|
|
|
import { remote } from 'electron';
|
|
|
|
|
2021-02-03 22:24:49 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
NgZone,
|
2021-02-16 17:52:23 +01:00
|
|
|
OnDestroy,
|
2021-02-03 22:24:49 +01:00
|
|
|
OnInit,
|
2021-02-09 21:57:10 +01:00
|
|
|
ViewChild,
|
2021-02-03 22:24:49 +01:00
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2021-02-09 21:57:10 +01:00
|
|
|
import { PolicyService } from 'jslib/abstractions/policy.service';
|
2021-02-03 22:24:49 +01:00
|
|
|
import { SearchService } from 'jslib/abstractions/search.service';
|
|
|
|
import { SendService } from 'jslib/abstractions/send.service';
|
2021-02-09 21:57:10 +01:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2021-02-03 22:24:49 +01:00
|
|
|
|
|
|
|
import { SendComponent as BaseSendComponent } from 'jslib/angular/components/send/send.component';
|
|
|
|
|
|
|
|
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
|
|
|
|
|
|
|
|
import { SendView } from 'jslib/models/view/sendView';
|
|
|
|
|
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-02-03 22:24:49 +01:00
|
|
|
sendId: string;
|
|
|
|
action: Action = Action.None;
|
|
|
|
|
|
|
|
constructor(sendService: SendService, i18nService: I18nService,
|
|
|
|
platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService,
|
2021-02-16 17:52:23 +01:00
|
|
|
private broadcasterService: BroadcasterService, ngZone: NgZone,
|
2021-02-09 21:57:10 +01:00
|
|
|
searchService: SearchService, policyService: PolicyService,
|
|
|
|
userService: UserService) {
|
2021-02-03 22:24:49 +01:00
|
|
|
super(sendService, i18nService, platformUtilsService,
|
2021-02-16 17:52:23 +01:00
|
|
|
environmentService, ngZone, searchService,
|
2021-02-09 21:57:10 +01:00
|
|
|
policyService, userService);
|
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
super.ngOnInit();
|
2021-02-16 17:52:23 +01:00
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case 'syncCompleted':
|
|
|
|
await this.load();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-02-09 21:57:10 +01:00
|
|
|
await this.load();
|
2021-02-03 22:24:49 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 17:52:23 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
|
|
|
|
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-02-16 17:52:23 +01:00
|
|
|
cancel(s: SendView) {
|
|
|
|
this.action = Action.None;
|
|
|
|
this.sendId = null;
|
|
|
|
}
|
|
|
|
|
2021-02-16 19:11:14 +01:00
|
|
|
async deletedSend(s: SendView) {
|
|
|
|
await this.refresh();
|
|
|
|
this.action = Action.None;
|
|
|
|
this.sendId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
async savedSend(s: SendView) {
|
|
|
|
await this.refresh();
|
|
|
|
this.selectSend(s.id);
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:57:10 +01:00
|
|
|
async selectSend(sendId: string) {
|
2021-02-16 19:11:14 +01:00
|
|
|
if (sendId === this.sendId && this.action === Action.Edit) {
|
2021-02-16 17:52:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-02-04 05:50:41 +01:00
|
|
|
this.action = Action.Edit;
|
2021-02-16 17:52:23 +01:00
|
|
|
this.sendId = sendId;
|
2021-02-09 21:57:10 +01:00
|
|
|
if (this.addEditComponent != null) {
|
2021-02-16 17:52:23 +01:00
|
|
|
this.addEditComponent.sendId = sendId;
|
2021-02-09 21:57:10 +01:00
|
|
|
await this.addEditComponent.refresh();
|
|
|
|
}
|
2021-02-03 22:24:49 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 05:50:41 +01:00
|
|
|
get selectedSendType() {
|
2021-02-10 20:15:10 +01:00
|
|
|
return this.sends.find(s => s.id === this.sendId)?.type;
|
2021-02-03 22:24:49 +01:00
|
|
|
}
|
2021-02-18 19:03:20 +01:00
|
|
|
|
|
|
|
viewSendMenu(send: SendView) {
|
|
|
|
const menu = new remote.Menu();
|
|
|
|
menu.append(new remote.MenuItem({
|
|
|
|
label: this.i18nService.t('copyLink'),
|
2021-02-18 19:06:21 +01:00
|
|
|
click: () => this.copy(send),
|
2021-02-18 19:03:20 +01:00
|
|
|
}));
|
|
|
|
menu.append(new remote.MenuItem({
|
|
|
|
label: this.i18nService.t('delete'),
|
|
|
|
click: async () => {
|
|
|
|
await this.delete(send);
|
|
|
|
await this.deletedSend(send);
|
2021-02-18 19:06:21 +01:00
|
|
|
},
|
2021-02-18 19:03:20 +01:00
|
|
|
}));
|
|
|
|
menu.popup({ window: remote.getCurrentWindow() });
|
|
|
|
}
|
2021-02-03 22:24:49 +01:00
|
|
|
}
|