HomeEntrypoint.vala 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }
  22. public class AuthPrivate : Object {
  23. public bool is_admin { get; set; }
  24. }
  25. /**
  26. * Entrypoint for the home page: hydrates counter + page slots with typed
  27. * models, embedding action references as fields.
  28. */
  29. public class HomeEntrypoint : StatumEntrypoint {
  30. public override async DirectiveBuilder handle() throws GLib.Error {
  31. var bump_private = new CounterPrivate();
  32. bump_private.delta = 1;
  33. var bump_ref = action_registry.author_private<BumpCounterAction, CounterPrivate>(bump_private);
  34. var counter = new CounterPublic();
  35. counter.value = 0;
  36. counter.bump = bump_ref;
  37. var page = new PagePublic();
  38. page.login = action_registry.author<LoginAction>();
  39. return directives()
  40. .set_typed<CounterPublic>("counter", Scope.PAGE, counter)
  41. .set_typed<PagePublic>("page", Scope.PAGE, page);
  42. }
  43. }
  44. /**
  45. * Entrypoint for the guarded dashboard page.
  46. */
  47. public class DashboardEntrypoint : StatumEntrypoint {
  48. public override async DirectiveBuilder handle() throws GLib.Error {
  49. return directives().notify("info", "Welcome to your dashboard");
  50. }
  51. }
  52. }