diff --git a/src/app/send/add-edit.component.html b/src/app/send/add-edit.component.html index 3f254ef3a7..3a052531e1 100644 --- a/src/app/send/add-edit.component.html +++ b/src/app/send/add-edit.component.html @@ -52,22 +52,45 @@ -

{{'options' | i18n}}

+

{{'options' | i18n}}

- +
+ + +
+
+ +
- + {{'clear' | i18n}}
- +
+ + +
+
+ +
diff --git a/src/app/send/add-edit.component.ts b/src/app/send/add-edit.component.ts index 5e08ac395f..cce9e747da 100644 --- a/src/app/send/add-edit.component.ts +++ b/src/app/send/add-edit.component.ts @@ -48,14 +48,30 @@ export class AddEditComponent { deletePromise: Promise; sendType = SendType; typeOptions: any[]; + deletionDateOptions: any[]; + expirationDateOptions: any[]; + deletionDateSelect = 168; + expirationDateSelect: number = null; constructor(private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private apiService: ApiService, private environmentService: EnvironmentService, - private datePipe: DatePipe, private sendService: SendService) { + private environmentService: EnvironmentService, private datePipe: DatePipe, + private sendService: SendService) { this.typeOptions = [ { name: i18nService.t('sendTypeFile'), value: SendType.File }, { name: i18nService.t('sendTypeText'), value: SendType.Text }, ]; + this.deletionDateOptions = this.expirationDateOptions = [ + { name: i18nService.t('oneHour'), value: 1 }, + { name: i18nService.t('oneDay'), value: 24 }, + { name: i18nService.t('days', '2'), value: 48 }, + { name: i18nService.t('days', '3'), value: 72 }, + { name: i18nService.t('days', '7'), value: 168 }, + { name: i18nService.t('days', '30'), value: 720 }, + { name: i18nService.t('custom'), value: 0 }, + ]; + this.expirationDateOptions = [ + { name: i18nService.t('never'), value: null } + ].concat([...this.deletionDateOptions]); } async ngOnInit() { @@ -88,10 +104,8 @@ export class AddEditComponent { this.hasPassword = this.send.password != null && this.send.password.trim() !== ''; // Parse dates - this.deletionDate = this.send.deletionDate == null ? null : - this.datePipe.transform(this.send.deletionDate, 'yyyy-MM-ddTHH:mm'); - this.expirationDate = this.send.expirationDate == null ? null : - this.datePipe.transform(this.send.expirationDate, 'yyyy-MM-ddTHH:mm'); + this.deletionDate = this.dateToString(this.send.deletionDate); + this.expirationDate = this.dateToString(this.send.expirationDate); if (this.editMode) { let webVaultUrl = this.environmentService.getWebVaultUrl(); @@ -127,6 +141,20 @@ export class AddEditComponent { } } + if (!this.editMode) { + const now = new Date(); + if (this.deletionDateSelect > 0) { + const d = new Date(); + d.setHours(now.getHours() + this.deletionDateSelect); + this.deletionDate = this.dateToString(d); + } + if (this.expirationDateSelect != null && this.expirationDateSelect > 0) { + const d = new Date(); + d.setHours(now.getHours() + this.expirationDateSelect); + this.expirationDate = this.dateToString(d); + } + } + const encSend = await this.encryptSend(file); try { this.formPromise = this.sendService.saveWithServer(encSend); @@ -158,7 +186,7 @@ export class AddEditComponent { } try { - this.deletePromise = this.apiService.deleteSend(this.send.id); + this.deletePromise = this.sendService.deleteWithServer(this.send.id); await this.deletePromise; this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedSend')); await this.load(); @@ -167,9 +195,7 @@ export class AddEditComponent { } protected async loadSend(): Promise { - const response = await this.apiService.getSend(this.sendId); - const data = new SendData(response); - return new Send(data); + return this.sendService.get(this.sendId); } protected async encryptSend(file: File): Promise<[Send, ArrayBuffer]> { @@ -189,4 +215,8 @@ export class AddEditComponent { return sendData; } + + protected dateToString(d: Date) { + return d == null ? null : this.datePipe.transform(d, 'yyyy-MM-ddTHH:mm'); + } } diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 7fe48c12ee..03a03a2500 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -3443,10 +3443,10 @@ "message": "Time required before automatically granting access." }, "oneDay": { - "message": "1 Day" + "message": "1 day" }, "days": { - "message": "$DAYS$ Days", + "message": "$DAYS$ days", "placeholders": { "days": { "content": "$1", @@ -3559,5 +3559,8 @@ }, "disableRequireSsoError": { "message": "You must manually disable the Single Sign-On Authentication policy before this policy can be disabled." + }, + "custom": { + "message": "Custom" } }