From cb2d52968951b6adb6fb3b3955d182008ea19cb6 Mon Sep 17 00:00:00 2001 From: Michael Atwood Date: Tue, 30 Jun 2020 04:16:08 -0700 Subject: [PATCH] added in GetUrlParameters route to Module Index action --- Oqtane.Client/Modules/ModuleBase.cs | 43 ++++++++++++++++++++++++++--- Oqtane.Client/UI/SiteRouter.razor | 19 +++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Oqtane.Client/Modules/ModuleBase.cs b/Oqtane.Client/Modules/ModuleBase.cs index f36a04ae..84aa19f6 100644 --- a/Oqtane.Client/Modules/ModuleBase.cs +++ b/Oqtane.Client/Modules/ModuleBase.cs @@ -17,7 +17,7 @@ namespace Oqtane.Modules private Logger _logger; protected Logger logger => _logger ?? (_logger = new Logger(this)); - + [Inject] protected ILogService LoggingService { get; set; } @@ -30,7 +30,7 @@ namespace Oqtane.Modules [CascadingParameter] protected Module ModuleState { get; set; } - [CascadingParameter] + [CascadingParameter] protected ModuleInstance ModuleInstance { get; set; } // optional interface properties @@ -62,7 +62,7 @@ namespace Oqtane.Modules } } } - + // path method public string ModulePath() @@ -116,6 +116,38 @@ namespace Oqtane.Modules return Utilities.ContentUrl(PageState.Alias, fileid); } + public Dictionary GetUrlParameters(string parameterTemplate) + { + var urlParameters = new Dictionary(); + + var templateSegments = parameterTemplate.Split('/', StringSplitOptions.RemoveEmptyEntries); + var parameters = PageState.UrlParameters.Split('/', StringSplitOptions.RemoveEmptyEntries); + + if (parameters.Length == templateSegments.Length) + { + for (int i = 0; i < parameters.Length; i++) + { + if (parameters.Length > i) + { + if (templateSegments[i] == parameters[i]) + { + } + else if (templateSegments[i].StartsWith("[") && templateSegments[i].EndsWith("]")) + { + var key = templateSegments[i].Replace("[", ""); + key = key.Replace("]", ""); + urlParameters.TryAdd(key, parameters[i]); + } + else + { + i = parameters.Length; + } + } + } + } + return urlParameters; + } + // user feedback methods public void AddModuleMessage(string message, MessageType type) { @@ -154,12 +186,15 @@ namespace Oqtane.Modules case "add": logFunction = LogFunction.Create; break; + case "edit": logFunction = LogFunction.Update; break; + case "delete": logFunction = LogFunction.Delete; break; + default: logFunction = LogFunction.Read; break; @@ -241,4 +276,4 @@ namespace Oqtane.Modules } } } -} +} \ No newline at end of file diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index d7f8b931..75d9142c 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -209,7 +209,15 @@ { modIdPos = i + 1; actionPos = modIdPos + 1; - action = segments[actionPos]; + if (actionPos > segments.Length - 1) + { + action = Constants.DefaultAction; + } + else + { + action = segments[actionPos]; + + } } } @@ -219,7 +227,14 @@ { int.TryParse(segments[modIdPos], out result); moduleid = result; - path = path.Replace("/" + segments[modIdPos - 1] + "/" + segments[modIdPos] + "/" + segments[actionPos], ""); + if (actionPos > segments.Length - 1) + { + path = path.Replace("/" + segments[modIdPos - 1] + "/" + segments[modIdPos], ""); + } + else + { + path = path.Replace("/" + segments[modIdPos - 1] + "/" + segments[modIdPos] + "/" + segments[actionPos], ""); + } }