mirror of
https://github.com/frappe/books.git
synced 2024-11-14 01:14:03 +00:00
fix: use toast for Save as PDF
- DRY for export toast
This commit is contained in:
parent
8e62272d08
commit
81c6812e2f
@ -1,10 +1,5 @@
|
|||||||
import frappe from 'frappejs';
|
import frappe from 'frappejs';
|
||||||
import {
|
import { getSavePath, saveData, showExportInFolder } from '../src/utils';
|
||||||
getSavePath,
|
|
||||||
saveData,
|
|
||||||
showItemInFolder,
|
|
||||||
showToast,
|
|
||||||
} from '../src/utils';
|
|
||||||
|
|
||||||
function templateToInnerText(innerHTML) {
|
function templateToInnerText(innerHTML) {
|
||||||
const temp = document.createElement('template');
|
const temp = document.createElement('template');
|
||||||
@ -106,11 +101,5 @@ export default function getCommonExportActions(reportName) {
|
|||||||
|
|
||||||
export async function saveExportData(data, filePath) {
|
export async function saveExportData(data, filePath) {
|
||||||
await saveData(data, filePath);
|
await saveData(data, filePath);
|
||||||
showToast({
|
showExportInFolder(frappe._('Export Successful'), filePath);
|
||||||
message: frappe._('Export Successful'),
|
|
||||||
actionText: frappe._('Open Folder'),
|
|
||||||
action: async () => {
|
|
||||||
await showItemInFolder(filePath);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import fs from 'fs';
|
import { BrowserWindow } from 'electron';
|
||||||
import { sleep } from 'frappejs/utils';
|
import fs from 'fs/promises';
|
||||||
import { shell, BrowserWindow } from 'electron';
|
|
||||||
|
|
||||||
const PRINT_OPTIONS = {
|
const PRINT_OPTIONS = {
|
||||||
marginsType: 1, // no margin
|
marginsType: 1, // no margin
|
||||||
@ -17,14 +16,16 @@ export default async function makePDF(html, savePath) {
|
|||||||
document.body.innerHTML = \`${html}\`;
|
document.body.innerHTML = \`${html}\`;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
return await new Promise((resolve) => {
|
||||||
printWindow.webContents.on('did-finish-load', async () => {
|
printWindow.webContents.on('did-finish-load', async () => {
|
||||||
await sleep(1); // Required else pdf'll be blank.
|
await sleep(1); // Required else pdf'll be blank.
|
||||||
printWindow.webContents.printToPDF(PRINT_OPTIONS).then((data) => {
|
|
||||||
// printWindow.destroy();
|
const data = await printWindow.webContents.printToPDF(PRINT_OPTIONS);
|
||||||
fs.writeFile(savePath, data, (error) => {
|
await fs.writeFile(savePath, data, (error) => {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
return shell.openPath(savePath);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
11
src/utils.js
11
src/utils.js
@ -174,6 +174,17 @@ export function handleErrorWithDialog(e, doc) {
|
|||||||
|
|
||||||
export async function makePDF(html, savePath) {
|
export async function makePDF(html, savePath) {
|
||||||
await ipcRenderer.invoke(IPC_ACTIONS.SAVE_HTML_AS_PDF, html, savePath);
|
await ipcRenderer.invoke(IPC_ACTIONS.SAVE_HTML_AS_PDF, html, savePath);
|
||||||
|
showExportInFolder(frappe._('Save as PDF Successful'), savePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showExportInFolder(message, filePath) {
|
||||||
|
showToast({
|
||||||
|
message,
|
||||||
|
actionText: frappe._('Open Folder'),
|
||||||
|
action: async () => {
|
||||||
|
await showItemInFolder(filePath);
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveData(data, savePath) {
|
export async function saveData(data, savePath) {
|
||||||
|
Loading…
Reference in New Issue
Block a user