From 1d4749b19421928d9b0c6ef7b56aa15015301afc Mon Sep 17 00:00:00 2001 From: Christian Anetzberger Date: Sat, 24 Oct 2026 13:31:54 +0000 Subject: [PATCH] Exported Custom HTML Blocks --- manufacturing_utilities/fixtures/custom_html_block.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manufacturing_utilities/fixtures/custom_html_block.json b/manufacturing_utilities/fixtures/custom_html_block.json index c207d1f..6b7d074 100644 --- a/manufacturing_utilities/fixtures/custom_html_block.json +++ b/manufacturing_utilities/fixtures/custom_html_block.json @@ -2,12 +2,12 @@ { "docstatus": 0, "doctype": "Custom HTML Block", - "html": "

Hello from the frontend

\n
\n Loading...\n
\n
", - "modified": "2026-10-17 14:58:45.689239", + "html": "
\n
\n Loading...\n
\n
", + "modified": "2026-10-24 15:30:08.275864", "name": "Manufacturing Overview", "private": 0, "roles": [], - "script": "frappe.call({\n method: \"manufacturing_utilities.manufacturing_overview.api.hello_world\",\n type: \"GET\"\n}).then((r) => {\n const container = root_element.querySelector(\n \".manufacturing-overview-content\"\n );\n\n container.textContent = r.message;\n});", - "style": null + "script": "const OVERVIEW_METHOD =\n \"manufacturing_utilities.manufacturing_overview.api.get_manufacturing_overview\";\n\nconst REALTIME_EVENT = \"manufacturing_overview_updated\";\nconst REFRESH_INTERVAL = 60 * 1000;\n\nconst container = root_element.querySelector(\n \".manufacturing-overview-list\"\n);\n\nlet isLoading = false;\n\n\n/*\n * --------------------------------------------------------------------------\n * Helpers\n * --------------------------------------------------------------------------\n */\n\nfunction formatQty(value) {\n const number = Number(value || 0);\n\n return Number.isInteger(number)\n ? number.toString()\n : number.toLocaleString(undefined, {\n maximumFractionDigits: 3,\n });\n}\n\n\nfunction formatDate(value) {\n if (!value) {\n return \"\";\n }\n\n return frappe.datetime.str_to_user(value);\n}\n\n\nfunction getDeliveryDateClass(value) {\n if (!value) {\n return \"\";\n }\n\n const deliveryDate =\n frappe.datetime.str_to_obj(value);\n\n const today =\n frappe.datetime.str_to_obj(\n frappe.datetime.get_today()\n );\n\n deliveryDate.setHours(0, 0, 0, 0);\n today.setHours(0, 0, 0, 0);\n\n if (deliveryDate < today) {\n return \"mo-date-overdue\";\n }\n\n if (\n deliveryDate.getTime() ===\n today.getTime()\n ) {\n return \"mo-date-today\";\n }\n\n return \"\";\n}\n\n\nfunction getDateGroup(value) {\n if (!value) {\n return \"upcoming\";\n }\n\n const deliveryDate =\n frappe.datetime.str_to_obj(value);\n\n const today =\n frappe.datetime.str_to_obj(\n frappe.datetime.get_today()\n );\n\n deliveryDate.setHours(0, 0, 0, 0);\n today.setHours(0, 0, 0, 0);\n\n if (deliveryDate < today) {\n return \"behind_schedule\";\n }\n\n if (\n deliveryDate.getTime() ===\n today.getTime()\n ) {\n return \"today\";\n }\n\n return \"upcoming\";\n}\n\n\nfunction escape(value) {\n return frappe.utils.escape_html(\n value == null ? \"\" : String(value)\n );\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Manufacturing card\n * --------------------------------------------------------------------------\n */\n\nfunction renderManufacturingCard(item) {\n const status =\n item.status || \"unknown\";\n\n const statusLabels = {\n partially_delivered:\n \"Partially Delivered\",\n in_warehouse:\n \"In Warehouse\",\n to_produce:\n \"To Produce\",\n no_work_order:\n \"No Work Order\",\n };\n\n let statusLabel =\n statusLabels[status] || status;\n\n if (\n status ===\n \"partially_delivered\"\n ) {\n statusLabel +=\n ` (${formatQty(item.delivered_qty)}/${formatQty(item.qty)})`;\n }\n\n const salesOrder =\n escape(item.sales_order);\n\n const workOrder =\n escape(item.work_order);\n\n const itemCode =\n escape(item.item_code);\n\n const itemName =\n escape(item.item_name);\n\n const customer =\n escape(item.customer);\n\n const deliveryDate =\n escape(\n formatDate(\n item.delivery_date\n )\n );\n\n const deliveryDateClass =\n getDeliveryDateClass(\n item.delivery_date\n );\n\n return `\n \n \n\n
\n\n
\n\n
\n\n \n ${formatQty(item.remaining_qty)} ×\n \n\n \n ${itemName}\n \n\n
\n\n \n ${deliveryDate}\n
\n\n
\n\n
\n\n \n ${customer}\n \n\n \n •\n \n\n \n ${itemCode}\n \n\n
\n\n
\n\n \n ${salesOrder}\n \n\n \n ${escape(statusLabel)}\n \n\n
\n\n \n \n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Subcontracting card\n * --------------------------------------------------------------------------\n */\n\nfunction renderSubcontractingCard(\n subcontracting\n) {\n const purchaseOrder =\n escape(\n subcontracting.purchase_order\n );\n\n const supplier =\n escape(\n subcontracting.supplier\n );\n\n const process =\n escape(\n subcontracting.process\n );\n\n const status =\n escape(\n subcontracting.status\n );\n\n const deliveryDate =\n escape(\n formatDate(\n subcontracting.delivery_date\n )\n );\n\n const deliveryDateClass =\n getDeliveryDateClass(\n subcontracting.delivery_date\n );\n\n const targetDoctype =\n subcontracting.subcontracting_order\n ? \"Subcontracting Order\"\n : \"Purchase Order\";\n\n const targetName =\n subcontracting.subcontracting_order\n || subcontracting.purchase_order\n || \"\";\n\n return `\n \n \n\n
\n\n
\n\n
\n\n \n ${formatQty(subcontracting.qty)} ×\n \n\n \n ${process}\n \n\n
\n\n \n ${deliveryDate}\n
\n\n
\n\n
\n\n \n ${supplier}\n \n\n
\n\n
\n\n \n ${purchaseOrder}\n \n\n \n ${status}\n \n\n
\n\n \n \n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * One complete manufacturing row\n * --------------------------------------------------------------------------\n */\n\nfunction renderOverviewEntry(item) {\n const subcontracting =\n item.subcontracting || [];\n\n const subcontractingCards =\n subcontracting.length\n ? `\n
\n ${subcontracting\n .map(\n renderSubcontractingCard\n )\n .join(\"\")}\n
\n `\n : \"\";\n\n return `\n
\n\n
\n ${renderManufacturingCard(item)}\n
\n\n
\n ${subcontractingCards}\n
\n\n
\n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Complete overview\n * --------------------------------------------------------------------------\n */\n\nfunction renderManufacturingOverview(\n items\n) {\n if (!container) {\n console.error(\n \"Manufacturing Overview container not found.\"\n );\n\n return;\n }\n\n if (!items.length) {\n container.innerHTML = `\n
\n No manufacturing items found.\n
\n `;\n\n return;\n }\n\n const groups = {\n behind_schedule: [],\n today: [],\n upcoming: [],\n };\n\n items.forEach((item) => {\n const group =\n getDateGroup(\n item.delivery_date\n );\n\n groups[group].push(item);\n });\n\n const sectionOrder = [\n \"behind_schedule\",\n \"today\",\n \"upcoming\",\n ];\n\n const sectionLabels = {\n behind_schedule:\n \"Behind schedule\",\n today:\n \"Today\",\n upcoming:\n \"Upcoming\",\n };\n\n container.innerHTML =\n sectionOrder\n .filter(\n (key) =>\n groups[key].length\n )\n .map((key) => `\n
\n\n
\n ${sectionLabels[key]}\n
\n\n
\n ${groups[key]\n .map(\n renderOverviewEntry\n )\n .join(\"\")}\n
\n\n
\n `)\n .join(\"\");\n\n bindCardNavigation();\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Navigation\n * --------------------------------------------------------------------------\n */\n\nfunction bindCardNavigation() {\n\n /*\n * Manufacturing card\n * → Work Order\n */\n container\n .querySelectorAll(\n \".mo-manufacturing-card.mo-row-clickable\"\n )\n .forEach((row) => {\n\n row.addEventListener(\n \"click\",\n (event) => {\n\n if (\n event.target.closest(\"a\")\n ) {\n return;\n }\n\n const workOrder =\n row.dataset.workOrder;\n\n if (!workOrder) {\n return;\n }\n\n frappe.set_route(\n \"Form\",\n \"Work Order\",\n workOrder\n );\n }\n );\n });\n\n\n /*\n * Subcontracting card\n */\n container\n .querySelectorAll(\n \".mo-subcontracting-card.mo-row-clickable\"\n )\n .forEach((row) => {\n\n row.addEventListener(\n \"click\",\n (event) => {\n\n if (\n event.target.closest(\"a\")\n ) {\n return;\n }\n\n const doctype =\n row.dataset.targetDoctype;\n\n const name =\n row.dataset.targetName;\n\n if (\n !doctype ||\n !name\n ) {\n return;\n }\n\n frappe.set_route(\n \"Form\",\n doctype,\n name\n );\n }\n );\n });\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Data loading\n * --------------------------------------------------------------------------\n */\n\nasync function loadManufacturingOverview() {\n if (isLoading) {\n return;\n }\n\n isLoading = true;\n\n try {\n\n const response =\n await frappe.call({\n method:\n OVERVIEW_METHOD,\n type:\n \"GET\",\n });\n\n renderManufacturingOverview(\n response.message?.items || []\n );\n\n } catch (error) {\n\n console.error(\n \"Failed to load Manufacturing Overview:\",\n error\n );\n\n if (container) {\n container.innerHTML = `\n
\n Failed to load Manufacturing Overview.\n
\n `;\n }\n\n } finally {\n isLoading = false;\n }\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Cleanup old block instance\n * --------------------------------------------------------------------------\n */\n\nif (\n root_element\n ._manufacturingOverviewCleanup\n) {\n root_element\n ._manufacturingOverviewCleanup();\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Realtime refresh\n * --------------------------------------------------------------------------\n */\n\nconst realtimeHandler = () => {\n loadManufacturingOverview();\n};\n\nfrappe.realtime.on(\n REALTIME_EVENT,\n realtimeHandler\n);\n\n\n/*\n * --------------------------------------------------------------------------\n * Safety refresh\n * --------------------------------------------------------------------------\n */\n\nconst refreshTimer =\n setInterval(\n loadManufacturingOverview,\n REFRESH_INTERVAL\n );\n\n\n/*\n * --------------------------------------------------------------------------\n * Cleanup\n * --------------------------------------------------------------------------\n */\n\nroot_element\n ._manufacturingOverviewCleanup =\n () => {\n\n clearInterval(\n refreshTimer\n );\n\n if (\n frappe.realtime.off\n ) {\n frappe.realtime.off(\n REALTIME_EVENT,\n realtimeHandler\n );\n }\n };\n\n\n/*\n * --------------------------------------------------------------------------\n * Initial load\n * --------------------------------------------------------------------------\n */\n\nloadManufacturingOverview();", + "style": ".manufacturing-overview {\n width: 100%;\n}\n\n.manufacturing-overview-list {\n display: flex;\n flex-direction: column;\n}\n\n\n/* -------------------------------------------------------------------------\n * Sections\n * ---------------------------------------------------------------------- */\n\n.mo-section {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.mo-section + .mo-section {\n margin-top: 28px;\n}\n\n.mo-section-header {\n padding:\n 0 2px 6px;\n\n font-size:\n var(--text-sm);\n\n font-weight: 600;\n\n color:\n var(--text-muted);\n\n border-bottom:\n 1px solid\n var(--border-color);\n}\n\n.mo-section-list {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n\n/* -------------------------------------------------------------------------\n * Two-column overview layout\n * ---------------------------------------------------------------------- */\n\n.mo-overview-entry {\n display: grid;\n\n grid-template-columns:\n minmax(0, 1fr)\n minmax(0, 1fr);\n\n gap: 10px;\n\n align-items: start;\n}\n\n.mo-manufacturing-column,\n.mo-subcontracting-column {\n min-width: 0;\n}\n\n.mo-subcontracting-list {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n\n/* -------------------------------------------------------------------------\n * Base card\n * ---------------------------------------------------------------------- */\n\n.mo-row {\n display: flex;\n gap: 12px;\n\n padding:\n 12px 14px;\n\n border:\n 1px solid\n var(--border-color);\n\n border-radius:\n 12px;\n\n background:\n var(--card-bg);\n\n box-shadow:\n none;\n\n transition:\n background 0.15s ease,\n border-color 0.15s ease,\n box-shadow 0.15s ease,\n transform 0.15s ease;\n}\n\n.mo-row-clickable {\n cursor: pointer;\n}\n\n.mo-row-clickable:hover {\n background:\n var(--control-bg);\n\n border-color:\n var(--gray-300);\n\n box-shadow:\n 0 1px 2px\n rgba(0, 0, 0, 0.06),\n 0 3px 8px\n rgba(0, 0, 0, 0.05);\n}\n\n.mo-row-clickable:active {\n transform:\n translateY(1px);\n\n box-shadow:\n 0 1px 2px\n rgba(0, 0, 0, 0.08);\n}\n\n\n/* -------------------------------------------------------------------------\n * Status bars\n * ---------------------------------------------------------------------- */\n\n.mo-status {\n width: 6px;\n min-width: 6px;\n\n border-radius:\n 999px;\n\n background:\n var(--gray-400);\n}\n\n.mo-status-in_warehouse {\n background:\n var(--green-500);\n}\n\n.mo-status-to_produce {\n background:\n var(--yellow-500);\n}\n\n.mo-status-no_work_order {\n background:\n var(--red-500);\n}\n\n.mo-status-partially_delivered {\n background:\n var(--blue-500);\n}\n\n.mo-status-subcontracting {\n background:\n var(--purple-500);\n}\n\n\n/* -------------------------------------------------------------------------\n * Card content\n * ---------------------------------------------------------------------- */\n\n.mo-main {\n flex: 1;\n min-width: 0;\n}\n\n.mo-title-row {\n display: flex;\n\n justify-content:\n space-between;\n\n align-items:\n flex-start;\n\n gap: 16px;\n}\n\n.mo-title {\n min-width: 0;\n\n font-size:\n var(--text-base);\n\n font-weight: 600;\n\n color:\n var(--text-color);\n}\n\n.mo-qty {\n margin-right:\n 4px;\n\n color:\n var(--text-muted);\n}\n\n.mo-item-link {\n font-weight: 600;\n}\n\n\n/* -------------------------------------------------------------------------\n * Delivery date\n * ---------------------------------------------------------------------- */\n\n.mo-date {\n white-space: nowrap;\n\n font-size:\n var(--text-sm);\n\n color:\n var(--text-muted);\n}\n\n.mo-date-today {\n font-weight: 700;\n\n color:\n var(--text-color);\n}\n\n.mo-date-overdue {\n font-weight: 700;\n\n color:\n var(--red-600);\n}\n\n\n/* -------------------------------------------------------------------------\n * Meta / footer\n * ---------------------------------------------------------------------- */\n\n.mo-meta,\n.mo-footer {\n display: flex;\n\n align-items: center;\n\n gap: 6px;\n\n margin-top: 4px;\n\n font-size:\n var(--text-sm);\n\n color:\n var(--text-muted);\n}\n\n.mo-footer {\n justify-content:\n space-between;\n}\n\n.mo-separator {\n opacity: 0.5;\n}\n\n.mo-status-label {\n font-size:\n var(--text-xs);\n\n font-weight: 500;\n}\n\n\n/* -------------------------------------------------------------------------\n * Links\n * ---------------------------------------------------------------------- */\n\n.mo-link {\n color: inherit;\n\n text-decoration: none;\n}\n\n.mo-link:hover {\n color:\n var(--text-color);\n\n text-decoration:\n underline;\n}\n\n\n/* -------------------------------------------------------------------------\n * Subcontracting card\n * ---------------------------------------------------------------------- */\n\n.mo-subcontracting-card {\n position: relative;\n}\n\n.mo-subcontracting-card:hover {\n background:\n var(--control-bg);\n}\n\n\n/* -------------------------------------------------------------------------\n * Empty / error states\n * ---------------------------------------------------------------------- */\n\n.mo-empty {\n padding: 24px;\n\n text-align: center;\n}\n\n.mo-error {\n padding: 16px;\n\n color:\n var(--red-600);\n}\n\n\n/* -------------------------------------------------------------------------\n * Responsive\n * ---------------------------------------------------------------------- */\n\n@media (max-width: 900px) {\n\n .mo-overview-entry {\n grid-template-columns:\n minmax(0, 1fr);\n }\n\n}" } ] \ No newline at end of file