refactor: move desktop inside desk

This commit is contained in:
sokumon 2025-08-18 17:18:39 +05:30
parent a51218f511
commit 1e1455d373
9 changed files with 75 additions and 52 deletions

View file

View file

@ -0,0 +1,14 @@
<!-- jinja -->
<div class="container">
<div class="desktop-container">
<div class="icons">
{% for icon in icons %}
<div class="desktop-icon" data-icon="{{ icon.icon }}" data-type="{{ icon.type }}" data-route="{{ icon.route }}">
<div class="icon-container" data-color="{{ icon.color }}"> </div>
<div class="icon-label">{{ icon.label }}</div>
</div>
{% endfor %}
</div>
</div>
</div>

View file

@ -0,0 +1,34 @@
frappe.pages["desktop"].on_page_load = function (wrapper) {
var page = frappe.ui.make_app_page({
parent: wrapper,
title: "Desktop",
single_column: true,
});
page.page_head.hide();
$(frappe.render_template("desktop")).appendTo(page.body);
setup();
};
function setup() {
$(".desktop-icon").each((i, el) => {
let icon_name = $(el).attr("data-icon");
let icon_container = $(el.children[0]);
const svg = frappe.utils.icon(icon_name, "xl d-icon");
if (svg) {
icon_container.html(svg);
}
let color_name = icon_container.attr("data-color");
icon_container.css("background-color", color_name);
});
setup_click();
}
function setup_click() {
$(".desktop-icon").on("click", (ev) => {
let current = $(ev.currentTarget);
if (current.attr("data-type") == "workspace") {
window.location.href = window.location.origin + current.attr("data-route");
} else {
window.location.href = current.attr("data-route");
}
});
}

View file

@ -0,0 +1,24 @@
{
"content": null,
"creation": "2025-08-18 16:17:07.259326",
"docstatus": 0,
"doctype": "Page",
"icon": "",
"idx": 0,
"modified": "2025-08-18 16:17:19.559412",
"modified_by": "Administrator",
"module": "Desk",
"name": "desktop",
"owner": "Administrator",
"page_name": "desktop",
"roles": [
{
"role": "System Manager"
}
],
"script": null,
"standard": "Yes",
"style": null,
"system_page": 1,
"title": "Desktop"
}

View file

@ -7,4 +7,4 @@ def get_context(context):
frappe.local.flags.redirect_location = "/app"
raise frappe.Redirect
context.icons = get_desktop_icons()
return context
return {"icons": get_desktop_icons()}

View file

@ -60,7 +60,7 @@ website_route_rules = [
]
website_redirects = [
{"source": r"/desk", "target": r"/app\1"},
{"source": r"/desk(.*)", "target": r"/app\1"},
]
base_template = "templates/base.html"

View file

@ -136,7 +136,7 @@ frappe.ui.Page = class Page {
this.page_actions = this.wrapper.find(".page-actions");
this.filters = this.wrapper.find(".filters");
this.page_head = this.wrapper.find(".page-head");
this.btn_primary = this.page_actions.find(".primary-action");
this.btn_secondary = this.page_actions.find(".btn-secondary");

View file

@ -1,49 +0,0 @@
---
base_template: "templates/base.html"
no_cache: 1
---
{%- block navbar -%} {% from "frappe/templates/includes/avatar_macro.html" import avatar %} {%-
endblock -%} {%- block footer -%} {%- endblock -%} {% block content %}
<div class="container">
<div class="desktop-container">
<div class="icons">
{% for icon in icons %}
<div class="desktop-icon" data-icon="{{ icon.icon }}" data-type="{{ icon.type }}" data-route="{{ icon.route }}">
<div class="icon-container" data-color="{{ icon.color }}"> </div>
<div class="icon-label">{{ icon.label }}</div>
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock %} {% block script %}
<script>
frappe.ready(function(){
$(".desktop-icon").each((i, el)=> {
let icon_name = $(el).attr("data-icon");
let icon_container = $(el.children[0])
const svg = frappe.utils.icon(icon_name, "xl d-icon")
if (svg) {
icon_container.html(svg)
}
let color_name = icon_container.attr("data-color")
icon_container.css("background-color", color_name)
})
setup_click()
})
function setup_click(){
$(".desktop-icon").on("click",(ev)=> {
let current = $(ev.currentTarget)
if(current.attr("data-type") == "workspace"){
window.location.href = window.location.origin + current.attr("data-route")
}else{
window.location.href = current.attr("data-route")
}
})
}
</script>
{% endblock %}