Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WhatsApp Card in the Integrations Workspace #93

Closed
wants to merge 11 commits into from
Closed
6 changes: 3 additions & 3 deletions frappe_whatsapp/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
# Installation
# ------------

# before_install = "frappe_whatsapp.install.before_install"
# after_install = "frappe_whatsapp.install.after_install"
# before_install = "frappe_whatsapp.install.before_install
after_install = "frappe_whatsapp.setup.install.create_integrations_card"

# Uninstallation
# ------------

# before_uninstall = "frappe_whatsapp.uninstall.before_uninstall"
before_uninstall = "frappe_whatsapp.setup.uninstall.remove_integrations_card"
# after_uninstall = "frappe_whatsapp.uninstall.after_uninstall"

# Desk Notifications
Expand Down
61 changes: 61 additions & 0 deletions frappe_whatsapp/setup/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import frappe

def create_integrations_card():
try:
# Fetch the Integrations workspace document
workspace = frappe.get_doc('Workspace', 'Integrations')
except frappe.DoesNotExistError:
frappe.throw("The Integrations workspace does not exist.")
buff0k marked this conversation as resolved.
Show resolved Hide resolved

# Check if the card break already exists to avoid duplicating it
card_exists = any(d.label == "WhatsApp" for d in workspace.links)

if not card_exists:
# Define the card break with the title "WhatsApp Integrations"
card_break = {
"type": "Card Break",
"label": "WhatsApp",
}

# Define the links to be added under this card break
links = [
{
"type": "Link",
"label": "WhatsApp Templates",
"link_type": "DocType",
"link_to": "WhatsApp Templates"
},
{
"type": "Link",
"label": "WhatsApp Notification",
"link_type": "DocType",
"link_to": "WhatsApp Notification"
},
{
"type": "Link",
"label": "WhatsApp Message",
"link_type": "DocType",
"link_to": "WhatsApp Message"
},
{
"type": "Link",
"label": "WhatsApp Notification Log",
"link_type": "DocType",
"link_to": "WhatsApp Notification Log"
},
{
"type": "Link",
"label": "WhatsApp Settings",
"link_type": "DocType",
"link_to": "WhatsApp Settings"
}
]

# Append the card break and links
workspace.append('links', card_break)
for link in links:
workspace.append('links', link)

# Save the updated workspace
workspace.save()
frappe.db.commit()
27 changes: 27 additions & 0 deletions frappe_whatsapp/setup/uninstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import frappe

def remove_integrations_card():
try:
# Fetch the Integrations workspace document
workspace = frappe.get_doc('Workspace', 'Integrations')
except frappe.DoesNotExistError:
frappe.log_error("The Integrations workspace does not exist.")
return

# Find the index of the card break with the label "WhatsApp Integrations"
card_break_index = next((index for (index, d) in enumerate(workspace.links) if d.type == "Card Break" and d.label == "WhatsApp"), None)

if card_break_index is not None:
# Remove the card break and all links after it until the next card break or the end of the list
workspace.links.pop(card_break_index)

# Remove subsequent links associated with the "WhatsApp Integrations" card
while card_break_index < len(workspace.links) and workspace.links[card_break_index].type == "Link":
workspace.links.pop(card_break_index)

# Save the updated workspace
workspace.save()
frappe.db.commit()
frappe.log_error("WhatsApp Integrations card and links removed successfully.")
else:
frappe.log_error("WhatsApp Integrations card not found in the workspace.")
Loading