Fix #4025: add user setting to keep the view mode.
This commit is contained in:
parent
854f3b5257
commit
7b67c9aa8d
@ -2,6 +2,7 @@
|
|||||||
@inherits ThemeControlBase
|
@inherits ThemeControlBase
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject IPageService PageService
|
@inject IPageService PageService
|
||||||
|
@inject ISettingService SettingService
|
||||||
|
|
||||||
@if (ShowLanguageSwitcher)
|
@if (ShowLanguageSwitcher)
|
||||||
{
|
{
|
||||||
@ -99,7 +100,7 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ToggleEditMode(bool EditMode)
|
private async Task ToggleEditMode(bool editMode)
|
||||||
{
|
{
|
||||||
Page page = null;
|
Page page = null;
|
||||||
if (PageState.Page.IsPersonalizable && PageState.User != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Registered))
|
if (PageState.Page.IsPersonalizable && PageState.User != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Registered))
|
||||||
@ -109,13 +110,18 @@
|
|||||||
|
|
||||||
if (_showEditMode)
|
if (_showEditMode)
|
||||||
{
|
{
|
||||||
if (EditMode)
|
PageState.EditMode = !editMode;
|
||||||
|
|
||||||
|
if(PageState.User != null) //keep edit mode for authenticated users.
|
||||||
{
|
{
|
||||||
PageState.EditMode = false;
|
|
||||||
}
|
var viewMode = PageState.EditMode ? ViewMode.Edit.ToString() : ViewMode.View.ToString();
|
||||||
else
|
var userSettings = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
PageState.EditMode = true;
|
{ UserSetting.ViewMode, viewMode }
|
||||||
|
};
|
||||||
|
|
||||||
|
await SettingService.UpdateUserSettingsAsync(userSettings, PageState.User.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// preserve other querystring parameters
|
// preserve other querystring parameters
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
@using System.Diagnostics.CodeAnalysis
|
@using System.Diagnostics.CodeAnalysis
|
||||||
@using System.Net
|
@using System.Net
|
||||||
|
@using Microsoft.AspNetCore.Http
|
||||||
@namespace Oqtane.UI
|
@namespace Oqtane.UI
|
||||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||||
@inject SiteState SiteState
|
@inject SiteState SiteState
|
||||||
@ -11,7 +12,9 @@
|
|||||||
@inject IUserService UserService
|
@inject IUserService UserService
|
||||||
@inject IUrlMappingService UrlMappingService
|
@inject IUrlMappingService UrlMappingService
|
||||||
@inject ILogService LogService
|
@inject ILogService LogService
|
||||||
|
@inject ISettingService SettingService
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
@implements IHandleAfterRender
|
@implements IHandleAfterRender
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
|
|
||||||
@ -28,6 +31,7 @@
|
|||||||
private bool _navigationInterceptionEnabled;
|
private bool _navigationInterceptionEnabled;
|
||||||
private PageState _pagestate;
|
private PageState _pagestate;
|
||||||
private string _error = "";
|
private string _error = "";
|
||||||
|
private bool _pageChanged;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string RenderMode { get; set; }
|
public string RenderMode { get; set; }
|
||||||
@ -58,6 +62,17 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var route = new Route(_absoluteUri, SiteState.Alias.Path);
|
||||||
|
var lastViewPage = HttpContextAccessor.HttpContext.Request.Cookies[UserSetting.LastViewPage] ?? string.Empty;
|
||||||
|
if (lastViewPage != route.PagePath)
|
||||||
|
{
|
||||||
|
HttpContextAccessor.HttpContext.Response.Cookies.Append(UserSetting.LastViewPage, route.PagePath);
|
||||||
|
_pageChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
NavigationManager.LocationChanged -= LocationChanged;
|
NavigationManager.LocationChanged -= LocationChanged;
|
||||||
@ -142,21 +157,6 @@
|
|||||||
refresh = true;
|
refresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PageState != null)
|
|
||||||
{
|
|
||||||
editmode = PageState.EditMode;
|
|
||||||
lastsyncdate = PageState.LastSyncDate;
|
|
||||||
visitorId = PageState.VisitorId;
|
|
||||||
}
|
|
||||||
if (PageState?.Page.Path != route.PagePath)
|
|
||||||
{
|
|
||||||
editmode = false; // reset edit mode when navigating to different page
|
|
||||||
}
|
|
||||||
if (querystring.ContainsKey("edit") && querystring["edit"] == "true")
|
|
||||||
{
|
|
||||||
editmode = true; // querystring can set edit mode
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify user is authenticated for current site
|
// verify user is authenticated for current site
|
||||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (authState.User.Identity.IsAuthenticated && authState.User.Claims.Any(item => item.Type == "sitekey" && item.Value == SiteState.Alias.SiteKey))
|
if (authState.User.Identity.IsAuthenticated && authState.User.Claims.Any(item => item.Type == "sitekey" && item.Value == SiteState.Alias.SiteKey))
|
||||||
@ -176,6 +176,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PageState != null)
|
||||||
|
{
|
||||||
|
editmode = PageState.EditMode;
|
||||||
|
lastsyncdate = PageState.LastSyncDate;
|
||||||
|
visitorId = PageState.VisitorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (PageState?.Page.Path != route.PagePath || _pageChanged)
|
||||||
|
{
|
||||||
|
editmode = false; // reset edit mode when navigating to different page
|
||||||
|
|
||||||
|
if (user != null) //keep edit mode for authenticated users.
|
||||||
|
{
|
||||||
|
var userSettings = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ UserSetting.ViewMode, ViewMode.View.ToString() }
|
||||||
|
};
|
||||||
|
|
||||||
|
await SettingService.UpdateUserSettingsAsync(userSettings, user.UserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (querystring.ContainsKey("edit") && querystring["edit"] == "true")
|
||||||
|
{
|
||||||
|
editmode = true; // querystring can set edit mode
|
||||||
|
}
|
||||||
|
|
||||||
|
//check edit mode for authenticated users.
|
||||||
|
if (!editmode && user != null)
|
||||||
|
{
|
||||||
|
Enum.TryParse<ViewMode>(user.Settings.GetValueOrDefault(UserSetting.ViewMode, ViewMode.View.ToString()), true, out ViewMode viewMode);
|
||||||
|
if (viewMode == ViewMode.Edit)
|
||||||
|
{
|
||||||
|
editmode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// process any sync events
|
// process any sync events
|
||||||
var sync = await SyncService.GetSyncEventsAsync(lastsyncdate);
|
var sync = await SyncService.GetSyncEventsAsync(lastsyncdate);
|
||||||
lastsyncdate = sync.SyncDate;
|
lastsyncdate = sync.SyncDate;
|
||||||
|
14
Oqtane.Shared/Enums/ViewMode.cs
Normal file
14
Oqtane.Shared/Enums/ViewMode.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Oqtane.Enums
|
||||||
|
{
|
||||||
|
public enum ViewMode
|
||||||
|
{
|
||||||
|
View,
|
||||||
|
Edit
|
||||||
|
}
|
||||||
|
}
|
15
Oqtane.Shared/Models/UserSetting.cs
Normal file
15
Oqtane.Shared/Models/UserSetting.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Oqtane.Models
|
||||||
|
{
|
||||||
|
public class UserSetting
|
||||||
|
{
|
||||||
|
public const string ViewMode = "Page:ViewMode";
|
||||||
|
|
||||||
|
public const string LastViewPage = "LastViewed";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user