HomeEntrypoint.vala 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Statum;
  2. using Invercargill;
  3. using Invercargill.DataStructures;
  4. namespace Example {
  5. // Typed slot models — GObject properties mapped to/from Properties via
  6. // GObjectMapping. ActionDto fields round-trip as nested JSON.
  7. public class CounterPrivate : Object {
  8. public int delta { get; set; }
  9. }
  10. public class CounterPublic : Object {
  11. public int value { get; set; }
  12. public Model.ActionDto bump { get; set; }
  13. }
  14. public class PagePublic : Object {
  15. public Model.ActionDto login { get; set; }
  16. }
  17. public class AuthPublic : Object {
  18. public string name { get; set; }
  19. public string role { get; set; }
  20. public Model.ActionDto logout { get; set; }
  21. public Model.ActionDto update_announcement { get; set; }
  22. }
  23. public class AuthPrivate : Object {
  24. public bool is_admin { get; set; }
  25. }
  26. /** Global broadcast model — a simple announcement string. */
  27. public class AnnouncementPublic : Object {
  28. public string text { get; set; }
  29. }
  30. /**
  31. * Entrypoint for the home page: hydrates counter + page slots with typed
  32. * models, embedding action references as fields.
  33. */
  34. public class HomeEntrypoint : StatumEntrypoint {
  35. public override async DirectiveBuilder handle() throws GLib.Error {
  36. var bump_private = new CounterPrivate();
  37. bump_private.delta = 1;
  38. var bump_ref = action_registry.author_private<BumpCounterAction, CounterPrivate>(bump_private);
  39. var counter = new CounterPublic();
  40. counter.value = 0;
  41. counter.bump = bump_ref;
  42. var page = new PagePublic();
  43. page.login = action_registry.author<LoginAction>();
  44. return directives()
  45. .set_global("announcement")
  46. .subscribe_global("announcement")
  47. .set_typed<CounterPublic>("counter", Scope.PAGE, counter)
  48. .set_typed<PagePublic>("page", Scope.PAGE, page);
  49. }
  50. }
  51. /**
  52. * Entrypoint for the guarded dashboard page.
  53. */
  54. public class DashboardEntrypoint : StatumEntrypoint {
  55. public override async DirectiveBuilder handle() throws GLib.Error {
  56. return directives()
  57. .set_global("announcement")
  58. .notify("info", "Welcome to your dashboard");
  59. }
  60. }
  61. }