app
This commit is contained in:
parent
c5e27c0f70
commit
309925c191
28 changed files with 1757 additions and 4 deletions
40
custom_ui/commands.py
Normal file
40
custom_ui/commands.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import click
|
||||
import os
|
||||
import subprocess
|
||||
import frappe
|
||||
from custom_ui.utils import create_module
|
||||
|
||||
@click.command("build-frontend")
|
||||
def build_frontend():
|
||||
app_package_path = frappe.get_app_path("custom_ui")
|
||||
app_root = os.path.dirname(app_package_path)
|
||||
|
||||
candidates = [
|
||||
os.path.join(app_root, 'frontend'),
|
||||
os.path.join(app_package_path, 'frontend')
|
||||
]
|
||||
|
||||
frontend_path = None
|
||||
for p in candidates:
|
||||
if os.path.exists(p):
|
||||
frontend_path = p
|
||||
break
|
||||
|
||||
if frontend_path:
|
||||
click.echo("\n📦 Building frontend for custom_ui...\n")
|
||||
try:
|
||||
subprocess.check_call(["npm", "install"], cwd=frontend_path)
|
||||
subprocess.check_call(["npm", "run", "build"], cwd=frontend_path)
|
||||
click.echo("\n✅ Frontend build completed successfully.\n")
|
||||
except subprocess.CalledProcessError as e:
|
||||
click.echo(f"\n❌ Frontend build failed: {e}\n")
|
||||
else:
|
||||
frappe.log_error(message="No frontend directory found for custom_ui", title="Frontend Build Skipped")
|
||||
click.echo(f"\n⚠️ Frontend directory does not exist. Skipping build. Path was {frontend_path}\n")
|
||||
|
||||
@click.command("create-module")
|
||||
def create_module_command():
|
||||
create_module()
|
||||
click.echo("✅ Custom UI module created or already exists.")
|
||||
|
||||
commands = [build_frontend, create_module_command]
|
||||
8
custom_ui/config/desktop.py
Normal file
8
custom_ui/config/desktop.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from frappe import _
|
||||
|
||||
def get_data():
|
||||
return [{
|
||||
"module_name": "Custom UI",
|
||||
"type": "module",
|
||||
"label": _("Custom UI")
|
||||
}]
|
||||
0
custom_ui/custom_ui/page/__init__.py
Normal file
0
custom_ui/custom_ui/page/__init__.py
Normal file
0
custom_ui/custom_ui/page/custom_ui/__init__.py
Normal file
0
custom_ui/custom_ui/page/custom_ui/__init__.py
Normal file
6
custom_ui/custom_ui/page/custom_ui/custom_ui.html
Normal file
6
custom_ui/custom_ui/page/custom_ui/custom_ui.html
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<div id="custom-ui-app"></div>
|
||||
{% if bundle_path %}
|
||||
<script type="module" src="{{ bundle_path }}"></script>
|
||||
{% else %}
|
||||
<p style="color: red">Bundle path is not available.</p>
|
||||
{% endif %}
|
||||
11
custom_ui/custom_ui/page/custom_ui/custom_ui.js
Normal file
11
custom_ui/custom_ui/page/custom_ui/custom_ui.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
frappe.pages["custom_ui"].on_page_load = function (wrapper) {
|
||||
$(wrapper).html('<div id="custom-ui-app"></div>');
|
||||
console.log("App root div created");
|
||||
|
||||
const script = document.createElement("script");
|
||||
|
||||
script.src = "/assets/custom_ui/dist/assets/custom_ui.bundle.js";
|
||||
script.type = "module";
|
||||
document.body.appendChild(script);
|
||||
console.log("Custom UI script loaded:", script.src);
|
||||
};
|
||||
10
custom_ui/custom_ui/page/custom_ui/custom_ui.json
Normal file
10
custom_ui/custom_ui/page/custom_ui/custom_ui.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "custom_ui",
|
||||
"title": "Custom UI",
|
||||
"doctype": "Page",
|
||||
"module": "Custom UI",
|
||||
"standard": "Yes",
|
||||
"type": "Single",
|
||||
"content": "",
|
||||
"icon": "octicon octicon-screen-full"
|
||||
}
|
||||
17
custom_ui/custom_ui/page/custom_ui/custom_ui.py
Normal file
17
custom_ui/custom_ui/page/custom_ui/custom_ui.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import frappe
|
||||
from custom_ui.utils import get_manifest
|
||||
|
||||
def get_context(context):
|
||||
frappe.throw("Loading custom_ui context...")
|
||||
print("Loading custom_ui context with manifest...")
|
||||
manifest = get_manifest()
|
||||
|
||||
context.template = "custom_ui/custom_ui/page/custom_ui/custom_ui.html"
|
||||
print("Manifest:", manifest)
|
||||
if manifest:
|
||||
js_file = manifest["src/main.js"]["file"]
|
||||
context.bundle_path = f"/assets/custom_ui/dist/{js_file}"
|
||||
else:
|
||||
print("ERROR: Manifest is missing or invalid.")
|
||||
frappe.log_error(message="Manifest file is missing or invalid for custom_ui", title="Context Load Failed")
|
||||
context.bundle_path = ""
|
||||
|
|
@ -1,10 +1,31 @@
|
|||
from . import commands
|
||||
|
||||
app_name = "custom_ui"
|
||||
app_title = "Custom Ui"
|
||||
app_title = "Custom UI"
|
||||
app_publisher = "Shiloh Code LLC"
|
||||
app_description = "Custom UI"
|
||||
app_email = "casey@shilohcode.com"
|
||||
app_license = "mit"
|
||||
|
||||
after_install = "custom_ui.install.after_install"
|
||||
after_migrate = "custom_ui.install.after_migrate"
|
||||
# on_session_creation = "custom_ui.utils.on_login_redirect"
|
||||
# on_login = "custom_ui.utils.on_login_redirect"
|
||||
# page_js = {
|
||||
# "custom_ui": "custom_ui/custom_ui/page/custom_ui/custom_ui.js"
|
||||
# }
|
||||
|
||||
# app_include_js = ["/assets/custom_ui/dist/assets/main.js"]
|
||||
|
||||
add_to_apps_screen = [
|
||||
{
|
||||
"name": "custom_ui",
|
||||
"logo": "/assets/custom_ui/logo.png",
|
||||
"title": "Custom UI",
|
||||
"route": "/app/custom_ui",
|
||||
# "has_permission": "custom_ui.api.permission.has_app_permission"
|
||||
}
|
||||
]
|
||||
# Apps
|
||||
# ------------------
|
||||
|
||||
|
|
|
|||
46
custom_ui/install.py
Normal file
46
custom_ui/install.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import os
|
||||
import subprocess
|
||||
import frappe
|
||||
from .utils import create_module
|
||||
|
||||
def after_install():
|
||||
create_module()
|
||||
build_frontend()
|
||||
|
||||
def after_migrate():
|
||||
build_frontend()
|
||||
|
||||
def build_frontend():
|
||||
app_package_path = frappe.get_app_path("custom_ui")
|
||||
app_root = os.path.dirname(app_package_path)
|
||||
candidates = [
|
||||
os.path.join(app_root, "frontend"),
|
||||
os.path.join(app_package_path, "frontend")
|
||||
]
|
||||
|
||||
frontend_path = None
|
||||
for p in candidates:
|
||||
if os.path.exists(p):
|
||||
frontend_path = p
|
||||
break
|
||||
|
||||
if not frontend_path:
|
||||
frappe.log_error(message="No frontend directory found for custom_ui", title="Frontend Build Skipped")
|
||||
print(f"⚠️ Frontend directory does not exist. Skipping build. Path was {frontend_path}")
|
||||
return
|
||||
|
||||
dist_path = os.path.join(app_root, "custom_ui", "public", "dist")
|
||||
should_build = True
|
||||
if os.path.exists(dist_path) and os.listdir(dist_path):
|
||||
print("ℹ️ Frontend already built. Skipping rebuild.")
|
||||
should_build = False
|
||||
|
||||
if should_build:
|
||||
print("\n📦 Building frontend for custom_ui...\n")
|
||||
try:
|
||||
subprocess.check_call(["npm", "install"], cwd=frontend_path)
|
||||
subprocess.check_call(["npm", "run", "build"], cwd=frontend_path)
|
||||
print("\n✅ Frontend build completed successfully.\n")
|
||||
except subprocess.CalledProcessError as e:
|
||||
frappe.log_error(message=str(e), title="Frontend Build Failed")
|
||||
print(f"\n❌ Frontend build failed: {e}\n")
|
||||
|
|
@ -1 +1 @@
|
|||
Custom Ui
|
||||
Custom UI
|
||||
20
custom_ui/public/js/custom_ui_loader.js
Normal file
20
custom_ui/public/js/custom_ui_loader.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
frappe.pages["custom-ui"].on_page_load = async (wrapper) => {
|
||||
const page = frappe.ui.make_app_page({
|
||||
parent: wrapper,
|
||||
title: "Custom UI",
|
||||
single_column: true,
|
||||
});
|
||||
|
||||
const $main = $(wrapper).find(".layout-main-section");
|
||||
$main.empty();
|
||||
|
||||
const manifestUrl = "/assets/custom_ui/dist/.vite/manifest.json";
|
||||
const manifest = await (await fetch(manifestUrl)).json();
|
||||
|
||||
const mainJs = `/assets/custom_ui/dist/${manifest["src/main.js"]["file"]}`;
|
||||
|
||||
const script = document.createElement("script");
|
||||
script.type = "module";
|
||||
script.src = mainJs;
|
||||
document.body.appendChild(script);
|
||||
};
|
||||
37
custom_ui/utils.py
Normal file
37
custom_ui/utils.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import frappe, os, json
|
||||
|
||||
def get_manifest():
|
||||
app_path = frappe.get_app_path("custom_ui")
|
||||
manifest_path = os.path.join(app_path, "custom_ui","public", "dist", ".vite", "manifest.json")
|
||||
if not os.path.exists(manifest_path):
|
||||
frappe.log_error(message="Manifest file not found for custom_ui", title="Manifest Load Failed")
|
||||
return {}
|
||||
with open(manifest_path) as f:
|
||||
return json.load(f)
|
||||
|
||||
def create_module():
|
||||
print("Creating Custom UI module if it does not exist...")
|
||||
|
||||
mod_name = "Custom UI"
|
||||
if frappe.db.exists("Module Def", mod_name):
|
||||
mod = frappe.get_doc("Module Def", mod_name)
|
||||
mod.show_in_sidebar = 1 # make sure it’s visible
|
||||
mod.save(ignore_permissions=True)
|
||||
print(f"Module '{mod_name}' updated with show_in_sidebar=1")
|
||||
else:
|
||||
frappe.get_doc({
|
||||
"doctype": "Module Def",
|
||||
"module_name": mod_name,
|
||||
"app_name": "custom_ui",
|
||||
"color": "#1976d2",
|
||||
"icon": "octicon octicon-code",
|
||||
"show_in_sidebar": 1
|
||||
}).insert(ignore_permissions=True)
|
||||
print(f"Module '{mod_name}' created")
|
||||
|
||||
frappe.db.commit()
|
||||
print("Custom UI module creation process completed.")
|
||||
|
||||
def on_login_redirect(login_manager):
|
||||
frappe.local.response["type"] = "redirect"
|
||||
frappe.local.response["location"] = "/app/custom-ui"
|
||||
0
custom_ui/www/__init__.py
Normal file
0
custom_ui/www/__init__.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue