fix: make the desktop page functional
This commit is contained in:
parent
2af99c6009
commit
2a47687690
7 changed files with 93 additions and 13 deletions
|
|
@ -3,4 +3,29 @@
|
|||
|
||||
frappe.ui.form.on("Desktop Icon", {
|
||||
refresh: function (frm) {},
|
||||
before_save: function (frm) {
|
||||
if (frm.doc.type == "workspace") {
|
||||
frappe.call({
|
||||
method: "frappe.client.get",
|
||||
args: {
|
||||
doctype: "Workspace", // e.g., "User"
|
||||
name: frm.doc.workspace,
|
||||
},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
// Access attributes like r.message.another_field
|
||||
let doc = r.message;
|
||||
let url = `/app/${
|
||||
doc.public
|
||||
? frappe.router.slug(doc.title)
|
||||
: "private/" + frappe.router.slug(doc.title)
|
||||
}`;
|
||||
frm.doc.route = url;
|
||||
}
|
||||
},
|
||||
});
|
||||
} else if (frm.doc.type == "link") {
|
||||
frm.doc.route = frm.doc.link;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
"label",
|
||||
"standard",
|
||||
"custom",
|
||||
"type",
|
||||
"workspace",
|
||||
"route",
|
||||
"column_break_3",
|
||||
"app",
|
||||
"description",
|
||||
|
|
@ -16,7 +19,6 @@
|
|||
"blocked",
|
||||
"force_show",
|
||||
"section_break_7",
|
||||
"type",
|
||||
"_doctype",
|
||||
"_report",
|
||||
"link",
|
||||
|
|
@ -100,7 +102,7 @@
|
|||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Type",
|
||||
"options": "module\nlist\nlink\npage\nquery-report"
|
||||
"options": "module\nlist\nlink\npage\nquery-report\nworkspace"
|
||||
},
|
||||
{
|
||||
"fieldname": "_doctype",
|
||||
|
|
@ -143,10 +145,22 @@
|
|||
"fieldname": "idx",
|
||||
"fieldtype": "Int",
|
||||
"label": "Idx"
|
||||
},
|
||||
{
|
||||
"fieldname": "workspace",
|
||||
"fieldtype": "Link",
|
||||
"label": "Workspace",
|
||||
"options": "Workspace"
|
||||
},
|
||||
{
|
||||
"fieldname": "route",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"label": "Route"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2025-08-07 13:11:45.701693",
|
||||
"modified": "2025-08-08 02:36:28.942332",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "Desktop Icon",
|
||||
|
|
|
|||
|
|
@ -34,8 +34,10 @@ class DesktopIcon(Document):
|
|||
link: DF.SmallText | None
|
||||
module_name: DF.Data | None
|
||||
reverse: DF.Check
|
||||
route: DF.Data | None
|
||||
standard: DF.Check
|
||||
type: DF.Literal["module", "list", "link", "page", "query-report"]
|
||||
type: DF.Literal["module", "list", "link", "page", "query-report", "workspace"]
|
||||
workspace: DF.Link | None
|
||||
# end: auto-generated types
|
||||
|
||||
def validate(self):
|
||||
|
|
@ -45,6 +47,9 @@ class DesktopIcon(Document):
|
|||
def on_trash(self):
|
||||
clear_desktop_icons_cache()
|
||||
|
||||
def after_insert(self):
|
||||
clear_desktop_icons_cache()
|
||||
|
||||
|
||||
def after_doctype_insert():
|
||||
frappe.db.add_unique("Desktop Icon", ("module_name", "owner", "standard"))
|
||||
|
|
@ -76,6 +81,8 @@ def get_desktop_icons(user=None):
|
|||
"custom",
|
||||
"standard",
|
||||
"blocked",
|
||||
"workspace",
|
||||
"route",
|
||||
]
|
||||
|
||||
active_domains = frappe.get_active_domains()
|
||||
|
|
@ -569,3 +576,25 @@ def hide(name, user=None):
|
|||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def create_desktop_icons_from_workspace():
|
||||
all_workspaces = frappe.get_all("Workspace", filters={"public": 1}, pluck="name")
|
||||
for w in all_workspaces:
|
||||
icon = frappe.new_doc("Desktop Icon")
|
||||
icon.type = "workspace"
|
||||
icon.workspace = w
|
||||
icon.route = "/app/" + w.lower()
|
||||
icon.label = w
|
||||
icon.color = generate_color()
|
||||
icon.icon = frappe.db.get_value("Workspace", w, "icon")
|
||||
icon.insert(ignore_if_duplicate=True)
|
||||
|
||||
|
||||
def generate_color():
|
||||
import random
|
||||
|
||||
def hex():
|
||||
return random.randint(0, 255)
|
||||
|
||||
return "#%02X%02X%02X" % (hex(), hex(), hex())
|
||||
|
|
|
|||
|
|
@ -384,7 +384,6 @@ export default class GridRow {
|
|||
|
||||
add_column_configure_button() {
|
||||
if (this.grid.df.in_place_edit && !this.frm) return;
|
||||
|
||||
if (this.configure_columns && this.frm) {
|
||||
this.configure_columns_button = $(`
|
||||
<div class="col grid-static-col pointer">
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
.desktop-container{
|
||||
max-width: 100px;
|
||||
}
|
||||
.icons{
|
||||
gap: 30px;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
margin-top: 50px;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
}
|
||||
.d-icon{
|
||||
stroke: white;
|
||||
|
|
@ -21,8 +18,14 @@
|
|||
.icon-container{
|
||||
padding: 10px;
|
||||
border: black solid 0px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.icon-container:hover{
|
||||
transform: scale(1.05);
|
||||
transition: transform 0.1s;
|
||||
}
|
||||
.icon-label{
|
||||
text-align: center;
|
||||
text-wrap: nowrap;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ endblock -%} {%- block footer -%} {%- endblock -%} {% block content %}
|
|||
<div class="desktop-container">
|
||||
<div class="icons">
|
||||
{% for icon in icons %}
|
||||
<div class="desktop-icon" data-icon="{{ icon.icon }}">
|
||||
<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>
|
||||
{{ icon.label }}
|
||||
<div class="icon-label">{{ icon.label }}</div>
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
|
|
@ -21,7 +21,6 @@ endblock -%} {%- block footer -%} {%- endblock -%} {% block content %}
|
|||
</div>
|
||||
{% endblock %} {% block script %}
|
||||
<script>
|
||||
console.log('Desktop is back')
|
||||
frappe.ready(function(){
|
||||
$(".desktop-icon").each((i, el)=> {
|
||||
let icon_name = $(el).attr("data-icon");
|
||||
|
|
@ -33,6 +32,18 @@ endblock -%} {%- block footer -%} {%- endblock -%} {% block content %}
|
|||
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 %}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,5 @@ def get_context(context):
|
|||
if frappe.session.user == "Guest":
|
||||
frappe.local.flags.redirect_location = "/app"
|
||||
raise frappe.Redirect
|
||||
|
||||
context.icons = get_desktop_icons()
|
||||
return context
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue