Skip to content

Commit

Permalink
Create utils and add filename to backend requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sandratoh committed Mar 11, 2024
1 parent aab36e6 commit 2e1f124
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class ApplicationDocumentService {

async openFile(fileUuid: string) {
try {
return await firstValueFrom(this.httpClient.get<{ url: string }>(`${this.serviceUrl}/${fileUuid}/open`));
return await firstValueFrom(
// TODO: Make fileName mandatory when ready to update all other usage
this.httpClient.get<{ url: string; fileName?: string }>(`${this.serviceUrl}/${fileUuid}/open`)
);
} catch (e) {
console.error(e);
this.toastService.showErrorToast('Failed to open the document, please try again');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class NoticeOfIntentDocumentService {

async openFile(fileUuid: string) {
try {
return await firstValueFrom(this.httpClient.get<{ url: string }>(`${this.serviceUrl}/${fileUuid}/open`));
return await firstValueFrom(
// TODO: Make fileName mandatory when ready to update all other usage
this.httpClient.get<{ url: string; fileName?: string }>(`${this.serviceUrl}/${fileUuid}/open`)
);
} catch (e) {
console.error(e);
this.toastService.showErrorToast('Failed to open the document, please try again');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NoticeOfIntentOwnerService } from '../../../services/notice-of-intent-o
import { OWNER_TYPE } from '../../dto/owner.dto';
import { CrownOwnerDialogComponent } from '../crown-owner-dialog/crown-owner-dialog.component';
import { OwnerDialogComponent } from '../owner-dialog/owner-dialog.component';
import { openFileIframe } from '../../utils/file';

@Component({
selector: 'app-parcel-owners[owners][fileId][submissionUuid][ownerService]',
Expand Down Expand Up @@ -107,7 +108,8 @@ export class ParcelOwnersComponent {
async onOpenFile(uuid: string) {
const res = await this.documentService.openFile(uuid);
if (res) {
window.open(res.url, '_blank');
const { fileName, url } = res;
openFileIframe(fileName || 'browser title', url);
}
}
}
20 changes: 20 additions & 0 deletions portal-frontend/src/app/shared/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,23 @@ export const openPdfFile = (fileName: string, data: any) => {
}
downloadLink.click();
};

export const openFileIframe = (fileName: string, url: string) => {
const newWindow = window.open('', '_blank');
if (newWindow) {
newWindow.document.title = fileName;

const iframe = newWindow.document.createElement('iframe');
iframe.src = url;
iframe.style.borderWidth = '0';
iframe.style.width = '100%';
iframe.style.height = '100%';

newWindow.document.body.appendChild(iframe);
newWindow.document.body.style.backgroundColor = 'rgb(82, 86, 89)';
newWindow.document.body.style.height = '100%';
newWindow.document.body.style.width = '100%';
newWindow.document.body.style.margin = '0';
newWindow.document.body.style.overflow = 'hidden';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class ApplicationDocumentController {

if (canAccessDocument) {
const url = await this.applicationDocumentService.getInlineUrl(document);
return { url };
// TODO: Same thing for other document controllers
const { fileName } = document.document;
return { url, fileName };
}

throw new NotFoundException('Failed to find document');
Expand Down

0 comments on commit 2e1f124

Please sign in to comment.