| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- @using cwebplusApp.Shared.Services;
- @inject AppState AppState;
- @inject NavigationManager NavigationManager;
- @inject IStringLocalizer<Resources> i18n
- @inject IJSRuntime jsRuntime;
- @inject PageHistoryManager PageHistoryManager;
- @implements IDisposable;
-
-
- @if (HandleAppBarContainer()) {
- <div class="sidebar">
- <MatAppBarContainer>
- <MatAppBar Fixed="true">
- <MatAppBarRow>
- <MatAppBarSection>
- <MatIconButton Icon="menu" OnClick="@((e) => ButtonClicked())"></MatIconButton>
- @if (PageHistoryManager.CanGoBack()) {
- <MatIconButton Icon="keyboard_backspace" OnClick="@((e) => ButtonBackClicked())" Disabled="@BackButtonDisabled()"></MatIconButton>
- }
- <MatAppBarTitle Class="navBar-title">@LocationUrl</MatAppBarTitle>
- </MatAppBarSection>
- <MatAppBarSection align="@MatAppBarSectionAlign.End" Style="max-width:min-content">
- <NavLink rel="noopener" target="_blank" class="text-white small" href="https://www.caritas.ch" align="@MatAppBarSectionAlign.End" style="padding-right:1em">@i18n["Learnmore"]</NavLink>
- </MatAppBarSection>
- </MatAppBarRow>
- </MatAppBar>
- <MatAppBarContent>
- <MatDrawerContainer>
- <MatDrawer @bind-Opened="@Opened" Mode="@MatDrawerMode.Modal">
- <MatList>
- <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
- <MatListItem Class="@((Index == 1) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
- Href="caritas_services"
- @onclick="@((e) => ButtonClicked(1))">
- <MatIcon Icon="@MatIconNames.Apps"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">@i18n["CaritasServices"]</MatListItemText>
- </MatListItem>
- </MatRipple>
- <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
- <MatListItem Class="@((Index == 2) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
- Href="account"
- @onclick="@((e) => ButtonClicked(2))">
- <MatIcon Icon="@MatIconNames.Person_outline"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">@i18n["account"]</MatListItemText>
- </MatListItem>
- </MatRipple>
- <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
- <MatListItem Class="@((Index == 3) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
- Href="info"
- @onclick="@((e) => ButtonClicked(3))">
- <MatIcon Icon="@MatIconNames.Error_outline" Style="transform: rotate(180deg)"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">@i18n["info"]</MatListItemText>
- </MatListItem>
- </MatRipple>
- <MatRipple Class="navmenu-mat-ripple" Color="@MatRippleColor.Default">
- <MatListItem Class="@((Index == 4) ? "bg-primary-color text-white" : "")" Style="margin-left:0;margin-right:0"
- href=""
- Match="NavLinkMatch.All"
- @onclick="@((e) => ButtonClicked(4))">
- <MatIcon Icon="@MatIconNames.Exit_to_app"></MatIcon>
- <MatListItemText Style="padding-left:0.5em">@i18n["Logout"]</MatListItemText>
- </MatListItem>
- </MatRipple>
- </MatList>
- </MatDrawer>
- </MatDrawerContainer>
-
- </MatAppBarContent>
- </MatAppBarContainer>
- </div>
- }
-
-
- @code {
-
- private bool Opened = false;
-
- private static int Index = 1;
-
- private string locUrl;
- private string LocationUrl {
- get => locUrl;
- set {
- locUrl = value;
- StateHasChanged();
- }
- }
-
- public void Dispose() {
- AppState.OnChange -= StateHasChanged;
- NavigationManager.LocationChanged -= LocationChanged;
- }
-
- protected override void OnInitialized() {
- AppState.OnChange += StateHasChanged;
- NavigationManager.LocationChanged += LocationChanged;
- PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
- base.OnInitialized();
- }
-
- private void ButtonClicked() {
- Opened = !Opened;
- }
-
- private void ButtonClicked(int _Index) {
- Index = _Index;
- ButtonClicked();
- if (_Index == 4) {
- AppState.LoggedIn = false;
- }
- }
-
- private void ButtonBackClicked() {
- NavigationManager.NavigateTo(PageHistoryManager.GetPreviousPage());
- }
-
-
- private void LocationChanged(object sender, LocationChangedEventArgs e) {
- locUrl = i18n.GetString(e.Location.Replace(NavigationManager.BaseUri, ""));
- if (IsInServicesUrl(e)) {
- Index = 1;
- } else if (e.Location.Contains("account")) {
- Index = 2;
- } else if (e.Location.Contains("info")) {
- Index = 3;
- } else {
- Index = 4;
- }
- StateHasChanged();
- }
-
- private bool IsInServicesUrl(LocationChangedEventArgs e) {
- return (e.Location.Contains("caritas_services") || e.Location.Contains("lost_found") || e.Location.Contains("keydata")
- || e.Location.Contains("account/") || e.Location.Contains("conclusion_"));
- }
-
- private bool HandleAppBarContainer() {
- string uri = NavigationManager.Uri;
- string baseUri = NavigationManager.BaseUri;
- string delta = uri.Replace(baseUri, "");
-
- if (delta == null || delta.Equals("")) {
- Index = 4;
- return false;
- } else {
- if (delta.Equals("caritas_services")) {
- Index = 1;
- } else if (delta.Equals("account")) {
- Index = 2;
- } else if (delta.Equals("info")) {
- Index = 3;
- }
- return true;
- }
- }
-
- private bool BackButtonDisabled() {
- return !PageHistoryManager.CanGoBack();
- }
-
- }
|