rework returnUrl - created parser - invalid if contain protocol ref

This commit is contained in:
Frede Hundewadt 2022-12-22 16:36:59 +01:00
parent 6a246b1dc5
commit e85f1c909e
6 changed files with 56 additions and 25 deletions

View file

@ -21,6 +21,19 @@ namespace Wonky.Client.Helpers;
public static class Utils
{
public static Dictionary<string, string> ParseQueryString(string query)
{
if (string.IsNullOrWhiteSpace(query) || query.Contains("://"))
return new Dictionary<string, string>();
var elements = query.Split("&");
return elements.Select(
data
=> data.Split("="))
.ToDictionary(element => element[0], element => element[1]);
}
public static bool IsValidEmail(string email)
{
var trimmedEmail = email.Trim();

View file

@ -16,9 +16,7 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterfaces;
using Wonky.Client.HttpRepository;
using Wonky.Client.Models;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
@ -31,28 +29,38 @@ public partial class CrmReportViewPage
[Inject] public ILocalStorageService Storage { get; set; }
private ReportView Report { get; set; } = new();
private List<ReportItemView> Items { get; set; } = new ();
private bool Working { get; set; } = true;
private UserInfoView UserInfo { get; set; } = new();
private string ReturnUrl { get; set; } = "";
protected override async Task OnInitializedAsync()
{
UserInfo = await Storage.GetItemAsync<UserInfoView>("_xu");
if (!string.IsNullOrWhiteSpace(ReportDate))
{
await GetReport(ReportDate);
}
Working = false;
}
private async Task Print(PTarget target)
private void Print(PTarget target)
{
var ux = await Storage.GetItemAsync<UserInfoView>("_ux");
if (target == PTarget.Order)
var returnUrl = new Uri(Navigator.Uri).AbsolutePath;
switch (target)
{
Navigator.NavigateTo($"/print/orders/{ux.CountryCode}/{ux.Id}/{ReportDate}");
return;
case PTarget.Order:
Navigator.NavigateTo($"/print/orders/{UserInfo.CountryCode.ToLower()}/{UserInfo.Id}/{ReportDate}?returnUrl={returnUrl}");
break;
case PTarget.Report:
Navigator.NavigateTo($"/print/report/{UserInfo.CountryCode.ToLower()}/{UserInfo.Id}/{ReportDate}?returnUrl={returnUrl}");
break;
case PTarget.None:
break;
case PTarget.All:
break;
default:
throw new ArgumentOutOfRangeException(nameof(target), target, null);
}
Navigator.NavigateTo($"/print/report/{ux.CountryCode}/{ux.Id}/{ReportDate}");
}
private async Task GetReport(string workDate)
{
@ -65,6 +73,7 @@ public partial class CrmReportViewPage
Report = await ReportRepo.GetReport(workDate);
Items = Report.ReportItems.Where(x => x.Lines.Any()).ToList();
await Storage.SetItemAsync($"{UserInfo.Id}-{Report.ReportData.ReportDate}", Report);
Working = false;
}
}

View file

@ -85,11 +85,10 @@ public partial class OfficeReportViewPage : IDisposable
{
if (target == PTarget.Order)
{
Navigator.NavigateTo($"/print/orders/{CountryCode}/{UserId}/{ReportDate}");
Navigator.NavigateTo($"/print/orders/{CountryCode}/{UserId}/{ReportDate}?returnUrl={Navigator.Uri}");
return;
}
Navigator.NavigateTo($"/print/report/{CountryCode}/{UserId}/{ReportDate}");
Navigator.NavigateTo($"/print/report/{CountryCode}/{UserId}/{ReportDate}?returnUrl={Navigator.Uri}");
}
/// <summary>
@ -98,9 +97,10 @@ public partial class OfficeReportViewPage : IDisposable
/// <param name="workDate"></param>
private async Task FetchReport(string workDate)
{
var returnUrl = new Uri(Navigator.Uri).AbsolutePath;
if (workDate != ReportDate)
{
Navigator.NavigateTo($"/office/users/advisors/{CountryCode}/{UserId}/reports/{workDate}");
Navigator.NavigateTo($"/office/users/advisors/{CountryCode}/{UserId}/reports/{workDate}?returnUrl={returnUrl}");
return;
}

View file

@ -16,6 +16,7 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Wonky.Client.Helpers;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
@ -32,8 +33,7 @@ public partial class PrintOrdersPage
private ReportView Report { get; set; } = new();
private List<ReportItemView> Items { get; set; } = new();
private IJSObjectReference JsModule { get; set; }
private string ReturnUrl { get; set; } = "";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
@ -45,6 +45,10 @@ public partial class PrintOrdersPage
protected override async Task OnInitializedAsync()
{
var uri = new Uri(Navigator.Uri);
var query = Utils.ParseQueryString(uri.Query[1..]);
ReturnUrl = string.IsNullOrWhiteSpace(query["returnUrl"]) ? "/" : query["returnUrl"];
Report = await Storage.GetItemAsync<ReportView>($"{UserId}-{ReportDate}");
Items = Report.ReportItems;
}
@ -52,8 +56,8 @@ public partial class PrintOrdersPage
private async Task Print()
{
await JsModule.InvokeVoidAsync("printInvoke");
Navigator.NavigateTo($"/office/users/advisors/{CountryCode}/{UserId}/reports/{ReportDate}");
Navigator.NavigateTo(ReturnUrl);
}
/*

View file

@ -13,9 +13,11 @@
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using System.Runtime.CompilerServices;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Wonky.Client.Helpers;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
@ -31,10 +33,14 @@ public partial class PrintReportPage
[Inject] public ILogger<PrintReportPage> Logger { get; set; }
private ReportView Report { get; set; } = new();
private IJSObjectReference JsModule { get; set; }
private bool Printed { get; set; }
private string ReturnUrl { get; set; } = "";
protected override async Task OnInitializedAsync()
{
var uri = new Uri(Navigator.Uri);
var query = Utils.ParseQueryString(uri.Query[1..]);
ReturnUrl = string.IsNullOrWhiteSpace(query["returnUrl"]) ? "/" : query["returnUrl"];
Report = await Storage.GetItemAsync<ReportView>($"{UserId}-{ReportDate}");
}
@ -46,13 +52,12 @@ public partial class PrintReportPage
.InvokeAsync<IJSObjectReference>("import", "/scripts/print-invoke.js");
}
}
private async Task Print()
{
if(!Printed)
Printed = true;
await JsModule.InvokeVoidAsync("printInvoke");
Navigator.NavigateTo($"/office/users/advisors/{CountryCode}/{UserId}/reports/{ReportDate}");
Navigator.NavigateTo(ReturnUrl);
}
/*

View file

@ -1,7 +1,7 @@
{
"appInfo": {
"name": "Wonky Client",
"version": "0.87.1",
"version": "0.87.3",
"rc": true,
"sandBox": false,
"image": "grumpy-coder.png"