Skip to content

Commit

Permalink
fix: backend to create workspace custom block and update workspace
Browse files Browse the repository at this point in the history
(cherry picked from commit 001425f)
  • Loading branch information
shariquerik authored and mergify[bot] committed May 18, 2023
1 parent d08401d commit 3583490
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions frappe/desk/desktop.py
Expand Up @@ -165,6 +165,7 @@ def build_workspace(self):
self.onboardings = {"items": self.get_onboardings()}
self.quick_lists = {"items": self.get_quick_lists()}
self.number_cards = {"items": self.get_number_cards()}
self.custom_blocks = {"items": self.get_custom_blocks()}

def _doctype_contains_a_record(self, name):
exists = self.table_counts.get(name, False)
Expand Down Expand Up @@ -346,6 +347,22 @@ def get_number_cards(self):

return all_number_cards

@handle_not_exist
def get_custom_blocks(self):
all_custom_blocks = []
if frappe.has_permission("Custom HTML Block", throw=False):
custom_blocks = self.doc.custom_blocks

for custom_block in custom_blocks:
if frappe.has_permission("Custom HTML Block", doc=custom_block.custom_block_name):
# Translate label
custom_block.label = (
_(custom_block.label) if custom_block.label else _(custom_block.custom_block_name)
)
all_custom_blocks.append(custom_block)

return all_custom_blocks


@frappe.whitelist()
@frappe.read_only()
Expand All @@ -369,6 +386,7 @@ def get_desktop_page(page):
"onboardings": workspace.onboardings,
"quick_lists": workspace.quick_lists,
"number_cards": workspace.number_cards,
"custom_blocks": workspace.custom_blocks,
}
except DoesNotExistError:
frappe.log_error("Workspace Missing")
Expand Down Expand Up @@ -497,6 +515,10 @@ def save_new_widget(doc, page, blocks, new_widgets):
doc.shortcuts.extend(new_widget(widgets.shortcut, "Workspace Shortcut", "shortcuts"))
if widgets.quick_list:
doc.quick_lists.extend(new_widget(widgets.quick_list, "Workspace Quick List", "quick_lists"))
if widgets.custom_block:
doc.custom_blocks.extend(
new_widget(widgets.custom_block, "Workspace Custom Block", "custom_blocks")
)
if widgets.number_card:
doc.number_cards.extend(
new_widget(widgets.number_card, "Workspace Number Card", "number_cards")
Expand Down Expand Up @@ -530,12 +552,12 @@ def save_new_widget(doc, page, blocks, new_widgets):
def clean_up(original_page, blocks):
page_widgets = {}

for wid in ["shortcut", "card", "chart", "quick_list", "number_card"]:
for wid in ["shortcut", "card", "chart", "quick_list", "number_card", "custom_block"]:
# get list of widget's name from blocks
page_widgets[wid] = [x["data"][wid + "_name"] for x in loads(blocks) if x["type"] == wid]

# shortcut, chart, quick_list & number_card cleanup
for wid in ["shortcut", "chart", "quick_list", "number_card"]:
# shortcut, chart, quick_list, number_card & custom_block cleanup
for wid in ["shortcut", "chart", "quick_list", "number_card", "custom_block"]:
updated_widgets = []
original_page.get(wid + "s").reverse()

Expand Down

0 comments on commit 3583490

Please sign in to comment.