refactor: common api to get apps with details
This commit is contained in:
parent
09ac7feb3a
commit
b3694b34cf
4 changed files with 34 additions and 40 deletions
|
|
@ -4,20 +4,36 @@
|
|||
import re
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_apps():
|
||||
apps = frappe.get_installed_apps()
|
||||
app_list = []
|
||||
app_list = [
|
||||
{
|
||||
"name": "frappe",
|
||||
"icon_url": "/assets/frappe/images/frappe-framework-logo.svg",
|
||||
"title": _("Admin"),
|
||||
"route": "/app",
|
||||
}
|
||||
]
|
||||
for app in apps:
|
||||
if app == "frappe":
|
||||
app_list.append(app)
|
||||
else:
|
||||
app_icon_url = frappe.get_hooks("app_icon_url", app_name=app)
|
||||
app_icon_route = frappe.get_hooks("app_icon_route", app_name=app)
|
||||
if app_icon_url and app_icon_route:
|
||||
app_list.append(app)
|
||||
continue
|
||||
app_icon_url = frappe.get_hooks("app_icon_url", app_name=app)
|
||||
app_icon_route = frappe.get_hooks("app_icon_route", app_name=app)
|
||||
if app_icon_url and app_icon_route:
|
||||
app_title = frappe.get_hooks("app_title", app_name=app)
|
||||
icon_title = frappe.get_hooks("app_icon_title", app_name=app)
|
||||
app_list.append(
|
||||
{
|
||||
"name": app,
|
||||
"icon_url": app_icon_url[0],
|
||||
"title": _(icon_title[0] if icon_title else app_title[0] if app_title else app),
|
||||
"route": app_icon_route[0],
|
||||
}
|
||||
)
|
||||
return app_list
|
||||
|
||||
|
||||
|
|
@ -30,9 +46,10 @@ def get_route(app_name):
|
|||
|
||||
def is_desk_apps(apps):
|
||||
for app in apps:
|
||||
route = frappe.get_hooks(app_name=app).get("app_icon_route")
|
||||
# check if route is /app or /app/* and not /app1 or /app1/*
|
||||
pattern = r"^/app(/.*)?$"
|
||||
if route and not re.match(pattern, route[0]):
|
||||
route = app.get("route")
|
||||
if route and not re.match(pattern, route):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -46,11 +63,9 @@ def get_default_path():
|
|||
return get_route(user_default_app)
|
||||
|
||||
apps = get_apps()
|
||||
_apps = [app for app in apps if app != "frappe"]
|
||||
_apps = [app for app in apps if app.get("name") != "frappe"]
|
||||
if len(_apps) == 1:
|
||||
first_app = _apps[0]
|
||||
if first_app:
|
||||
return get_route(first_app)
|
||||
return _apps[0].get("route") or "/apps"
|
||||
elif is_desk_apps(_apps):
|
||||
return "/app"
|
||||
return "/apps"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ frappe.ui.form.on("System Settings", {
|
|||
});
|
||||
|
||||
frappe.xcall("frappe.apps.get_apps").then((r) => {
|
||||
frm.set_df_property("default_app", "options", [" ", ...r]);
|
||||
let apps = r?.map((r) => r.name) || [];
|
||||
frm.set_df_property("default_app", "options", [" ", ...apps]);
|
||||
});
|
||||
|
||||
frm.trigger("set_rounding_method_options");
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ frappe.ui.form.on("User", {
|
|||
let doc = frm.doc;
|
||||
|
||||
frappe.xcall("frappe.apps.get_apps").then((r) => {
|
||||
frm.set_df_property("default_app", "options", [" ", ...r]);
|
||||
let apps = r?.map((r) => r.name) || [];
|
||||
frm.set_df_property("default_app", "options", [" ", ...apps]);
|
||||
});
|
||||
|
||||
if (frm.is_new()) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.website.utils import get_home_page
|
||||
from frappe.apps import get_apps
|
||||
|
||||
|
||||
def get_context():
|
||||
|
|
@ -13,27 +13,4 @@ def get_context():
|
|||
if frappe.session.data.user_type == "Website User":
|
||||
frappe.throw(_("You are not permitted to access this page."), frappe.PermissionError)
|
||||
|
||||
_apps = frappe.get_installed_apps()
|
||||
app_shortcuts = [
|
||||
{
|
||||
"name": "frappe",
|
||||
"icon_url": "/assets/frappe/images/frappe-framework-logo.svg",
|
||||
"title": _("Admin"),
|
||||
"route": "/app",
|
||||
}
|
||||
]
|
||||
for app in _apps:
|
||||
app_icon_url = frappe.get_hooks("app_icon_url", app_name=app)
|
||||
app_icon_route = frappe.get_hooks("app_icon_route", app_name=app)
|
||||
if app_icon_url and app_icon_route:
|
||||
app_title = frappe.get_hooks("app_title", app_name=app)
|
||||
icon_title = frappe.get_hooks("app_icon_title", app_name=app)
|
||||
app_shortcuts.append(
|
||||
{
|
||||
"name": app,
|
||||
"icon_url": app_icon_url[0],
|
||||
"title": _(icon_title[0] if icon_title else app_title[0] if app_title else app),
|
||||
"route": app_icon_route[0],
|
||||
}
|
||||
)
|
||||
return {"apps": app_shortcuts}
|
||||
return {"apps": get_apps()}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue