PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NavMenu.razor 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. @using cwebplusApp.Shared.Services;
  2. @using cwebplusApp.Components;
  3. @inject AppState AppState;
  4. @inject NavigationManager NavigationManager;
  5. @inject IStringLocalizer<Resources> I18n
  6. @inject IJSRuntime JSRuntime;
  7. @inject PageHistoryManager PageHistoryManager;
  8. @implements IDisposable;
  9. @if (HandleAppBarContainer()) {
  10. <div class="sidebar">
  11. <MatAppBarContainer>
  12. <MatAppBar Fixed="true">
  13. <MatAppBarRow>
  14. <MatAppBarSection>
  15. <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
  16. @if (PageHistoryManager.CanGoBack()) {
  17. <MatIconButton Icon="@MatIconNames.Keyboard_backspace" OnClick="@((e) => ButtonBackClicked())" Disabled="@BackButtonDisabled()"></MatIconButton>
  18. }
  19. <MatAppBarTitle Class="navBar-title">@LocationUrl</MatAppBarTitle>
  20. </MatAppBarSection>
  21. <MatAppBarSection align="@MatAppBarSectionAlign.End" Style="max-width:min-content">
  22. <NavLink rel="noopener" target="_blank" class="text-white small" href="https://www.caritas.ch" align="@MatAppBarSectionAlign.End" style="padding-right:1em">@I18n["Learnmore"]</NavLink>
  23. </MatAppBarSection>
  24. </MatAppBarRow>
  25. </MatAppBar>
  26. <MatAppBarContent>
  27. <MatDrawerContainer>
  28. <MatDrawer @bind-Opened="@opened" Mode="@MatDrawerMode.Modal">
  29. <MatList>
  30. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  31. <MatListItem Class="@((index == 1) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  32. Href="caritas_services"
  33. @onclick="@((e) => ButtonClicked(1))">
  34. <MatIcon Icon="@MatIconNames.Apps"></MatIcon>
  35. <MatListItemText Style="padding-left:0.5em">@I18n["CaritasServices"]</MatListItemText>
  36. </MatListItem>
  37. </MatRipple>
  38. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  39. <MatListItem Class="@((index == 2) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  40. Href="account"
  41. @onclick="@((e) => ButtonClicked(2))">
  42. <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon>
  43. <MatListItemText Style="padding-left:0.5em">@I18n["account"]</MatListItemText>
  44. </MatListItem>
  45. </MatRipple>
  46. <MatNavMenu @ref="extrasNavMenu">
  47. <MatNavSubMenu @bind-Expanded="@navSubMenuOpen">
  48. <MatNavSubMenuHeader Title=@I18n["Extras"]>
  49. <MatNavItem AllowSelection="false">
  50. <MatIcon Icon="@MatIconNames.View_quilt" />&nbsp; @I18n["Extras"]
  51. </MatNavItem>
  52. </MatNavSubMenuHeader>
  53. <MatNavSubMenuList>
  54. <MatNavSubMenu>
  55. <MatNavSubMenuHeader>
  56. <MatNavItem AllowSelection="false">
  57. <MatIcon Icon="@MatIconNames.Directions_bike" />&nbsp; @I18n["fundvelo/lost_found"]
  58. </MatNavItem>
  59. </MatNavSubMenuHeader>
  60. <MatNavSubMenuList>
  61. <MatNavItem Href="fundvelo/history_found" AllowSelection="true" Class="@((index == 3)? "selected": "")" @onclick="@((e) => ButtonClicked(3))">
  62. <MatIcon Icon="@MatIconNames.History" />&nbsp; @I18n["HistoryFound"]
  63. </MatNavItem>
  64. <MatNavItem Href="fundvelo/history_missing" AllowSelection="true" Class="@((index == 4)? "selected": "")" @onclick="@((e) => ButtonClicked(4))">
  65. <MatIcon Icon="@MatIconNames.History" />&nbsp; @I18n["HistoryMissing"]
  66. </MatNavItem>
  67. <MatNavItem Href="fundvelo/links" AllowSelection="true" Class="@((index == 5)? "selected": "")" @onclick="@((e) => ButtonClicked(5))">
  68. <MatIcon Icon="@MatIconNames.Link" />&nbsp; @I18n["FundveloLinks"]
  69. </MatNavItem>
  70. </MatNavSubMenuList>
  71. </MatNavSubMenu>
  72. </MatNavSubMenuList>
  73. </MatNavSubMenu>
  74. </MatNavMenu>
  75. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  76. <MatListItem Class="@((index == 5) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  77. Href="info"
  78. @onclick="@((e) => ButtonClicked(5))">
  79. <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
  80. <MatListItemText Style="padding-left:0.5em">@I18n["info"]</MatListItemText>
  81. </MatListItem>
  82. </MatRipple>
  83. </MatList>
  84. </MatDrawer>
  85. </MatDrawerContainer>
  86. </MatAppBarContent>
  87. </MatAppBarContainer>
  88. </div>
  89. <OnlineStatusIndicator />
  90. }
  91. @code {
  92. private MatNavMenu extrasNavMenu;
  93. private bool navSubMenuOpen = false;
  94. private bool opened = false;
  95. private int index = 1;
  96. private string locUrl;
  97. private string LocationUrl {
  98. get => locUrl;
  99. set {
  100. locUrl = value;
  101. StateHasChanged();
  102. }
  103. }
  104. public void Dispose() {
  105. AppState.OnChange -= StateHasChanged;
  106. NavigationManager.LocationChanged -= LocationChanged;
  107. }
  108. protected override void OnInitialized() {
  109. base.OnInitialized();
  110. AppState.OnChange += StateHasChanged;
  111. NavigationManager.LocationChanged += LocationChanged;
  112. locUrl = I18n.GetString(NavigationManager.Uri.Replace(NavigationManager.BaseUri, ""));
  113. StateHasChanged();
  114. }
  115. private void ButtonClicked() {
  116. opened = !opened;
  117. }
  118. private void ButtonClicked(int _Index) {
  119. index = _Index;
  120. navSubMenuOpen = (index == 3 || index == 4 || index == 5);
  121. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  122. StateHasChanged();
  123. ButtonClicked();
  124. }
  125. private void ButtonBackClicked() {
  126. PageHistoryManager.NavigateBack();
  127. }
  128. private void LocationChanged(object sender, LocationChangedEventArgs e) {
  129. locUrl = I18n.GetString(e.Location.Replace(NavigationManager.BaseUri, ""));
  130. if (IsInServicesUrl(e.Location)) {
  131. index = 1;
  132. } else if (e.Location.Contains("account")) {
  133. index = 2;
  134. } else if (e.Location.Contains("history_found")) {
  135. index = 3;
  136. } else if (e.Location.Contains("history_missing")) {
  137. index = 4;
  138. } else if (e.Location.Contains("info")) {
  139. index = 5;
  140. } else {
  141. index = 0;
  142. }
  143. StateHasChanged();
  144. }
  145. private bool IsInServicesUrl(string location) {
  146. return (location.Contains("caritas_services") || location.Contains("lost_found") || location.Contains("keydata")
  147. || location.Contains("account/") || location.Contains("conclusion_"));
  148. }
  149. private bool HandleAppBarContainer() {
  150. string uri = NavigationManager.Uri;
  151. string baseUri = NavigationManager.BaseUri;
  152. string delta = uri.Replace(baseUri, "");
  153. if (delta == null || delta.Equals("")) {
  154. return false;
  155. } else {
  156. if (IsInServicesUrl(delta)) {
  157. index = 1;
  158. } else if (delta.Equals("account")) {
  159. index = 2;
  160. } else if (delta.Equals("fundvelo/history_found")) {
  161. index = 3;
  162. } else if (delta.Equals("fundvelo/history_missing")) {
  163. index = 4;
  164. } else if (delta.Equals("info")) {
  165. index = 5;
  166. } else {
  167. index = 0;
  168. }
  169. return true;
  170. }
  171. }
  172. private bool BackButtonDisabled() {
  173. return !PageHistoryManager.CanGoBack();
  174. }
  175. }