workspace_menu_entries.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding=utf-8
  2. import typing
  3. from copy import copy
  4. from tracim.models.applications import applications
  5. from tracim.models.data import Workspace
  6. class WorkspaceMenuEntry(object):
  7. """
  8. Application class with data needed for frontend
  9. """
  10. def __init__(
  11. self,
  12. label: str,
  13. slug: str,
  14. icon: str,
  15. hexcolor: str,
  16. route: str,
  17. ) -> None:
  18. self.slug = slug
  19. self.label = label
  20. self.route = route
  21. self.hexcolor = hexcolor
  22. self.icon = icon
  23. dashboard_menu_entry = WorkspaceMenuEntry(
  24. slug='dashboard',
  25. label='Dashboard',
  26. route='/#/workspaces/{workspace_id}/dashboard',
  27. hexcolor='#252525',
  28. icon="",
  29. )
  30. all_content_menu_entry = WorkspaceMenuEntry(
  31. slug="contents/all",
  32. label="All Contents",
  33. route="/#/workspaces/{workspace_id}/contents",
  34. hexcolor="#fdfdfd",
  35. icon="",
  36. )
  37. def default_workspace_menu_entry(
  38. workspace: Workspace,
  39. )-> typing.List[WorkspaceMenuEntry]:
  40. """
  41. Get default menu entry for a workspace
  42. """
  43. menu_entries = [
  44. copy(dashboard_menu_entry),
  45. copy(all_content_menu_entry),
  46. ]
  47. for app in applications:
  48. if app.main_route:
  49. new_entry = WorkspaceMenuEntry(
  50. slug=app.slug,
  51. label=app.label,
  52. hexcolor=app.hexcolor,
  53. icon=app.icon,
  54. route=app.main_route
  55. )
  56. menu_entries.append(new_entry)
  57. for entry in menu_entries:
  58. entry.route = entry.route.replace(
  59. '{workspace_id}',
  60. str(workspace.workspace_id)
  61. )
  62. return menu_entries