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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. </MatNavSubMenuList>
  68. </MatNavSubMenu>
  69. </MatNavSubMenuList>
  70. </MatNavSubMenu>
  71. </MatNavMenu>
  72. <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
  73. <MatListItem Class="@((index == 5) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
  74. Href="info"
  75. @onclick="@((e) => ButtonClicked(5))">
  76. <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
  77. <MatListItemText Style="padding-left:0.5em">@I18n["info"]</MatListItemText>
  78. </MatListItem>
  79. </MatRipple>
  80. </MatList>
  81. </MatDrawer>
  82. </MatDrawerContainer>
  83. </MatAppBarContent>
  84. </MatAppBarContainer>
  85. </div>
  86. <OnlineStatusIndicator />
  87. }
  88. @code {
  89. private MatNavMenu extrasNavMenu;
  90. private bool navSubMenuOpen = false;
  91. private bool opened = false;
  92. private int index = 1;
  93. private string locUrl;
  94. private string LocationUrl {
  95. get => locUrl;
  96. set {
  97. locUrl = value;
  98. StateHasChanged();
  99. }
  100. }
  101. public void Dispose() {
  102. AppState.OnChange -= StateHasChanged;
  103. NavigationManager.LocationChanged -= LocationChanged;
  104. }
  105. protected override void OnInitialized() {
  106. base.OnInitialized();
  107. AppState.OnChange += StateHasChanged;
  108. NavigationManager.LocationChanged += LocationChanged;
  109. locUrl = I18n.GetString(NavigationManager.Uri.Replace(NavigationManager.BaseUri, ""));
  110. StateHasChanged();
  111. }
  112. private void ButtonClicked() {
  113. opened = !opened;
  114. }
  115. private void ButtonClicked(int _Index) {
  116. index = _Index;
  117. navSubMenuOpen = (index == 3 || index == 4 || index == 5);
  118. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  119. StateHasChanged();
  120. ButtonClicked();
  121. }
  122. private void ButtonBackClicked() {
  123. PageHistoryManager.NavigateBack();
  124. }
  125. private void LocationChanged(object sender, LocationChangedEventArgs e) {
  126. locUrl = I18n.GetString(e.Location.Replace(NavigationManager.BaseUri, ""));
  127. if (IsInServicesUrl(e.Location)) {
  128. index = 1;
  129. } else if (e.Location.Contains("account")) {
  130. index = 2;
  131. } else if (e.Location.Contains("history_found")) {
  132. index = 3;
  133. } else if (e.Location.Contains("history_missing")) {
  134. index = 4;
  135. } else if (e.Location.Contains("info")) {
  136. index = 5;
  137. } else {
  138. index = 0;
  139. }
  140. StateHasChanged();
  141. }
  142. private bool IsInServicesUrl(string location) {
  143. return (location.Contains("caritas_services") || location.Contains("lost_found") || location.Contains("keydata")
  144. || location.Contains("account/") || location.Contains("conclusion_"));
  145. }
  146. private bool HandleAppBarContainer() {
  147. string uri = NavigationManager.Uri;
  148. string baseUri = NavigationManager.BaseUri;
  149. string delta = uri.Replace(baseUri, "");
  150. if (delta == null || delta.Equals("")) {
  151. return false;
  152. } else {
  153. if (IsInServicesUrl(delta)) {
  154. index = 1;
  155. } else if (delta.Equals("account")) {
  156. index = 2;
  157. } else if (delta.Equals("fundvelo/history_found")) {
  158. index = 3;
  159. } else if (delta.Equals("fundvelo/history_missing")) {
  160. index = 4;
  161. } else if (delta.Equals("info")) {
  162. index = 5;
  163. } else {
  164. index = 0;
  165. }
  166. return true;
  167. }
  168. }
  169. private bool BackButtonDisabled() {
  170. return !PageHistoryManager.CanGoBack();
  171. }
  172. }