workspace_menu_entries.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding=utf-8
  2. import typing
  3. from copy import copy
  4. from tracim_backend.models.applications import applications
  5. from tracim_backend.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. fa_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.fa_icon = fa_icon
  23. dashboard_menu_entry = WorkspaceMenuEntry(
  24. slug='dashboard',
  25. label='Dashboard',
  26. route='/#/workspaces/{workspace_id}/dashboard',
  27. hexcolor='#252525',
  28. fa_icon="signal",
  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. fa_icon="th",
  36. )
  37. # TODO - G.M - 08-06-2018 - This is hardcoded default menu entry,
  38. # of app, make this dynamic (and loaded from application system)
  39. def default_workspace_menu_entry(
  40. workspace: Workspace,
  41. )-> typing.List[WorkspaceMenuEntry]:
  42. """
  43. Get default menu entry for a workspace
  44. """
  45. menu_entries = [
  46. copy(dashboard_menu_entry),
  47. copy(all_content_menu_entry),
  48. ]
  49. for app in applications:
  50. if app.main_route:
  51. new_entry = WorkspaceMenuEntry(
  52. slug=app.slug,
  53. label=app.label,
  54. hexcolor=app.hexcolor,
  55. fa_icon=app.fa_icon,
  56. route=app.main_route
  57. )
  58. menu_entries.append(new_entry)
  59. for entry in menu_entries:
  60. entry.route = entry.route.replace(
  61. '{workspace_id}',
  62. str(workspace.workspace_id)
  63. )
  64. return menu_entries