@@ -550,10 +550,23 @@ def save_new_widget(page, new_widgets): | |||
if widgets.card: | |||
original_page.build_links_table_from_card(widgets.card) | |||
# remove duplicate and unwanted widgets | |||
content = frappe.db.get_value("Internal Wiki Page", page, "content") | |||
for wid in ['shortcut']: | |||
widd = [x['data'][ wid + '_name'] for x in json.loads(content) if x['type'] == wid] | |||
original_page.set(wid+'s', [ele for ele in original_page.get(wid+'s') if ele.label in widd]) | |||
page_widgets = {} | |||
for wid in ['shortcut', 'card', 'chart']: | |||
# get list of widget's name from internal wiki page | |||
page_widgets[wid] = [x['data'][wid + '_name'] for x in json.loads(content) if x['type'] == wid] | |||
updated_widgets = [] | |||
original_page.get('shortcuts').reverse() | |||
for w in original_page.get('shortcuts'): | |||
if w.label in page_widgets['shortcut'] and w.label not in [x.label for x in updated_widgets]: | |||
updated_widgets.append(w) | |||
original_page.set('shortcuts', updated_widgets) | |||
for i, v in enumerate(original_page.links): | |||
if v.type == 'Card Break' and v.label not in page_widgets['card']: | |||
del original_page.links[ i : i+v.link_count+1] | |||
try: | |||
original_page.save(ignore_permissions=True) | |||
@@ -105,11 +105,18 @@ class Workspace(Document): | |||
for idx, card in enumerate(config): | |||
links = loads(card.get('links')) | |||
# remove duplicate before adding | |||
duplicate_links = [x for x in self.links if(x.label == card.get('label') and x.type == 'Card Break')] | |||
for v in duplicate_links: | |||
del self.links[ v.idx-1 : v.idx+v.link_count] | |||
self.append('links', { | |||
"label": card.get('label'), | |||
"type": "Card Break", | |||
"icon": card.get('icon'), | |||
"hidden": card.get('hidden') or False | |||
"hidden": card.get('hidden') or False, | |||
"link_count": card.get('link_count'), | |||
"idx": self.links[-1].idx + 1 | |||
}) | |||
for link in links: | |||
@@ -121,10 +128,10 @@ class Workspace(Document): | |||
"onboard": link.get('onboard'), | |||
"only_for": link.get('only_for'), | |||
"dependencies": link.get('dependencies'), | |||
"is_query_report": link.get('is_query_report') | |||
"is_query_report": link.get('is_query_report'), | |||
"idx": self.links[-1].idx + 1 | |||
}) | |||
def disable_saving_as_standard(): | |||
return frappe.flags.in_install or \ | |||
frappe.flags.in_patch or \ | |||
@@ -12,14 +12,18 @@ export default class LinksWidget extends Widget { | |||
return { | |||
name: this.name, | |||
links: JSON.stringify(this.links), | |||
link_count: this.links.length, | |||
label: this.label, | |||
hidden: this.hidden, | |||
}; | |||
} | |||
set_body() { | |||
this.options = {}; | |||
this.options.links = this.links; | |||
if (!this.options) { | |||
this.options = {}; | |||
this.options.links = this.links; | |||
} | |||
this.widget.addClass("links-widget-box"); | |||
const is_link_disabled = item => { | |||
return item.dependencies && item.incomplete_dependencies; | |||
@@ -74,7 +78,9 @@ export default class LinksWidget extends Widget { | |||
${get_link_for_item(item)} | |||
</a>`); | |||
}); | |||
if (this.in_customize_mode) { | |||
this.body.empty(); | |||
} | |||
this.link_list.forEach(link => link.appendTo(this.body)); | |||
} | |||
@@ -142,9 +142,9 @@ class CardDialog extends WidgetDialog { | |||
fieldtype: 'Table', | |||
label: __('Card Links'), | |||
editable_grid: 1, | |||
data: this.data || [], | |||
data: me.values ? JSON.parse(me.values.links) : [], | |||
get_data: () => { | |||
return this.data || []; | |||
return me.values ? JSON.parse(me.values.links) : []; | |||
}, | |||
fields: [ | |||
{ | |||
@@ -529,7 +529,7 @@ export default function get_dialog_constructor(type) { | |||
chart: ChartDialog, | |||
shortcut: ShortcutDialog, | |||
number_card: NumberCardDialog, | |||
card: CardDialog, | |||
links: CardDialog, | |||
}; | |||
return widget_map[type] || WidgetDialog; | |||
@@ -205,12 +205,12 @@ export class SingleWidgetGroup { | |||
widget_type: this.type, | |||
container: this.container, | |||
height: this.height || null, | |||
options: { | |||
...this.options, | |||
on_delete: () => this.on_delete(), | |||
on_edit: () => this.on_edit(widget_object) | |||
} | |||
}); | |||
widget_object.options = { | |||
...this.options, | |||
on_delete: () => this.on_delete(), | |||
on_edit: () => this.on_edit(widget_object) | |||
}; | |||
this.widgets_list.push(widget_object); | |||
this.widgets_dict[widget.name] = widget_object; | |||
@@ -11,9 +11,10 @@ export default class Card { | |||
return true; | |||
} | |||
constructor({data, api, config, readOnly}) { | |||
constructor({data, api, config, readOnly, block}) { | |||
this.data = data; | |||
this.api = api; | |||
this.block = block; | |||
this.config = config; | |||
this.readOnly = readOnly; | |||
this.sections = {}; | |||
@@ -28,7 +29,7 @@ export default class Card { | |||
allow_create: this.allow_customization, | |||
allow_delete: this.allow_customization, | |||
allow_hiding: false, | |||
allow_edit: false, | |||
allow_edit: true, | |||
}; | |||
} | |||
@@ -64,24 +65,25 @@ export default class Card { | |||
} | |||
_new_card() { | |||
const dialog_class = get_dialog_constructor('card'); | |||
const dialog_class = get_dialog_constructor('links'); | |||
this.dialog = new dialog_class({ | |||
label: this.label, | |||
type: 'card', | |||
primary_action: (widget) => { | |||
widget.in_customize_mode = 1; | |||
let wid = frappe.widget.make_widget({ | |||
this.card_widget = frappe.widget.make_widget({ | |||
...widget, | |||
widget_type: 'links', | |||
container: this.wrapper | |||
container: this.wrapper, | |||
options: { | |||
...this.options, | |||
on_delete: () => this.api.blocks.delete(), | |||
on_edit: () => this.on_edit(this.card_widget) | |||
} | |||
}); | |||
wid.options = { | |||
...this.options, | |||
on_delete: () => this.api.blocks.delete() | |||
}; | |||
wid.customize(this.options); | |||
this.wrapper.setAttribute("card_name", wid.label); | |||
this.new_card_widget = wid.get_config(); | |||
this.card_widget.customize(this.options); | |||
this.wrapper.setAttribute("card_name", this.card_widget.label); | |||
this.new_card_widget = this.card_widget.get_config(); | |||
}, | |||
}); | |||
@@ -156,22 +158,30 @@ export default class Card { | |||
this.card_field.make(); | |||
} | |||
on_edit(card_obj) { | |||
let card = card_obj.get_config(); | |||
this.card_widget.widgets = card; | |||
this.wrapper.setAttribute("card_name", card.label); | |||
this.new_card_widget = card_obj.get_config(); | |||
} | |||
_make_cards(card_name) { | |||
let card = this.config.page_data.cards.items.find(obj => { | |||
return obj.label == card_name; | |||
}); | |||
this.wrapper.innerHTML = ''; | |||
card.in_customize_mode = !this.readOnly; | |||
let card_widget = new frappe.widget.SingleWidgetGroup({ | |||
this.card_widget = new frappe.widget.SingleWidgetGroup({ | |||
container: this.wrapper, | |||
type: "links", | |||
options: this.options, | |||
widgets: card, | |||
api: this.api | |||
api: this.api, | |||
block: this.block | |||
}); | |||
this.wrapper.setAttribute("card_name", card_name); | |||
if (!this.readOnly) { | |||
card_widget.customize(); | |||
this.card_widget.customize(); | |||
} | |||
} | |||
} |
@@ -73,13 +73,13 @@ export default class Shortcut { | |||
this.shortcut_widget = frappe.widget.make_widget({ | |||
...widget, | |||
widget_type: 'shortcut', | |||
container: this.wrapper | |||
container: this.wrapper, | |||
options: { | |||
...this.options, | |||
on_delete: () => this.api.blocks.delete(), | |||
on_edit: () => this.on_edit(this.shortcut_widget) | |||
} | |||
}); | |||
this.shortcut_widget.options = { | |||
...this.options, | |||
on_delete: () => this.api.blocks.delete(), | |||
on_edit: () => this.on_edit(this.shortcut_widget) | |||
}; | |||
this.shortcut_widget.customize(this.options); | |||
this.wrapper.setAttribute("shortcut_name", this.shortcut_widget.label); | |||
this.new_shortcut_widget = this.shortcut_widget.get_config(); | |||