fix: backend to create workspace custom block and update workspace
This commit is contained in:
parent
45c05be9a3
commit
001425f71b
1 changed files with 25 additions and 3 deletions
|
|
@ -165,6 +165,7 @@ class Workspace:
|
|||
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)
|
||||
|
|
@ -346,6 +347,22 @@ class Workspace:
|
|||
|
||||
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()
|
||||
|
|
@ -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")
|
||||
|
|
@ -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")
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue