Skip to content

Commit

Permalink
[PM-254] Set PDF Attachments in Web to download, add success toast (#…
Browse files Browse the repository at this point in the history
…10757)

* add success toast to pdf attachment download in web

* update desktop attachments for toastService

* removed trailing comma

---------

Co-authored-by: gbubemismith <[email protected]>
Co-authored-by: SmithThe4th <[email protected]>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent 2cfbfcb commit 89751f4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 10 deletions.
3 changes: 3 additions & 0 deletions apps/browser/src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4308,6 +4308,9 @@
},
"enterprisePolicyRequirementsApplied": {
"message": "Enterprise policy requirements have been applied to this setting"
},
"fileSavedToDevice": {
"message": "File saved to device. Manage from your device downloads."
},
"showCharacterCount": {
"message": "Show character count"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

@Component({
selector: "app-vault-attachments",
Expand All @@ -38,6 +38,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
dialogService: DialogService,
billingAccountProfileStateService: BillingAccountProfileStateService,
accountService: AccountService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -52,6 +53,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
dialogService,
billingAccountProfileStateService,
accountService,
toastService,
);
}

Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3061,5 +3061,8 @@
},
"ssoError": {
"message": "No free ports could be found for the sso login."
},
"fileSavedToDevice": {
"message": "File saved to device. Manage from your device downloads."
}
}
4 changes: 3 additions & 1 deletion apps/desktop/src/vault/app/vault/attachments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

@Component({
selector: "app-vault-attachments",
Expand All @@ -30,6 +30,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
dialogService: DialogService,
billingAccountProfileStateService: BillingAccountProfileStateService,
accountService: AccountService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -44,6 +45,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
dialogService,
billingAccountProfileStateService,
accountService,
toastService,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

@Component({
selector: "emergency-access-attachments",
Expand All @@ -34,6 +34,7 @@ export class EmergencyAccessAttachmentsComponent extends BaseAttachmentsComponen
dialogService: DialogService,
billingAccountProfileStateService: BillingAccountProfileStateService,
accountService: AccountService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -48,6 +49,7 @@ export class EmergencyAccessAttachmentsComponent extends BaseAttachmentsComponen
dialogService,
billingAccountProfileStateService,
accountService,
toastService,
);
}

Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/app/core/web-file-download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ export class WebFileDownloadService implements FileDownloadService {
download(request: FileDownloadRequest): void {
const builder = new FileDownloadBuilder(request);
const a = window.document.createElement("a");
if (builder.downloadMethod === "save") {
a.download = request.fileName;
} else if (!this.platformUtilsService.isSafari()) {
if (!this.platformUtilsService.isSafari()) {
a.rel = "noreferrer";
a.target = "_blank";
}
a.href = URL.createObjectURL(builder.blob);
a.style.position = "fixed";
a.download = request.fileName;
window.document.body.appendChild(a);
a.click();
window.document.body.removeChild(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

@Component({
selector: "app-vault-attachments",
Expand All @@ -33,6 +33,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
dialogService: DialogService,
billingAccountProfileStateService: BillingAccountProfileStateService,
accountService: AccountService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -47,6 +48,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
dialogService,
billingAccountProfileStateService,
accountService,
toastService,
);
}

Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/app/vault/org-vault/attachments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.servi
import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data";
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

import { AttachmentsComponent as BaseAttachmentsComponent } from "../individual-vault/attachments.component";

Expand All @@ -39,6 +39,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
dialogService: DialogService,
billingAccountProfileStateService: BillingAccountProfileStateService,
accountService: AccountService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -52,6 +53,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
dialogService,
billingAccountProfileStateService,
accountService,
toastService,
);
}

Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9070,6 +9070,9 @@
"secretsManagerWithFreePasswordManagerInfo": {
"message": "Your complementary one year Password Manager subscription will upgrade to the selected plan. You will not be charged until the complimentary period is over."
},
"fileSavedToDevice": {
"message": "File saved to device. Manage from your device downloads."
},
"publicApi": {
"message": "Public API",
"description": "The text, 'API', is an acronymn and should not be translated."
Expand Down
8 changes: 7 additions & 1 deletion libs/angular/src/vault/components/attachments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.servi
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
import { AttachmentView } from "@bitwarden/common/vault/models/view/attachment.view";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

@Directive()
export class AttachmentsComponent implements OnInit {
Expand Down Expand Up @@ -49,6 +49,7 @@ export class AttachmentsComponent implements OnInit {
protected dialogService: DialogService,
protected billingAccountProfileStateService: BillingAccountProfileStateService,
protected accountService: AccountService,
protected toastService: ToastService,
) {}

async ngOnInit() {
Expand Down Expand Up @@ -182,6 +183,11 @@ export class AttachmentsComponent implements OnInit {
fileName: attachment.fileName,
blobData: decBuf,
});
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("fileSavedToDevice"),
});
} catch (e) {
this.platformUtilsService.showToast("error", null, this.i18nService.t("errorOccurred"));
}
Expand Down

0 comments on commit 89751f4

Please sign in to comment.