go
This commit is contained in:
93
C4IT.API/DeepLinkBuilder.cs
Normal file
93
C4IT.API/DeepLinkBuilder.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace C4IT.API
|
||||
{
|
||||
public enum ViewType
|
||||
{
|
||||
New, // open create dialog
|
||||
Preview, // open preview
|
||||
Action, // run action/wizard
|
||||
Edit // open edit dialog
|
||||
}
|
||||
|
||||
public class DeepLinkBuilder
|
||||
{
|
||||
public string Host { get; set; }
|
||||
public string AppName { get; set; }
|
||||
|
||||
// Parameter f<>r view-options
|
||||
public bool? Embedded { get; set; }
|
||||
public Guid? DialogId { get; set; }
|
||||
public Guid? ObjectId { get; set; }
|
||||
public int? Archived { get; set; }
|
||||
public string Type { get; set; }
|
||||
public ViewType? ViewType { get; set; }
|
||||
public Guid? ActionId { get; set; }
|
||||
public Guid? ViewId { get; set; }
|
||||
|
||||
public object PresetParams { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Baut die URL basierend auf den gesetzten Eigenschaften.
|
||||
/// </summary>
|
||||
/// <returns>Die erstellte DeepLink-URL als string.</returns>
|
||||
public string BuildUrl()
|
||||
{
|
||||
var viewOptions = new Dictionary<string, object>();
|
||||
|
||||
if (Embedded.HasValue)
|
||||
viewOptions["embedded"] = Embedded.Value;
|
||||
if (DialogId.HasValue)
|
||||
viewOptions["dialogId"] = DialogId.Value;
|
||||
if (ObjectId.HasValue)
|
||||
viewOptions["objectId"] = ObjectId.Value;
|
||||
if (Archived.HasValue)
|
||||
viewOptions["archived"] = Archived.Value;
|
||||
if (!string.IsNullOrEmpty(Type))
|
||||
viewOptions["type"] = Type;
|
||||
if (ViewType.HasValue)
|
||||
viewOptions["viewType"] = ViewType.Value.ToString().ToLower();
|
||||
if (ActionId.HasValue)
|
||||
viewOptions["actionId"] = ActionId.Value;
|
||||
if (ViewId.HasValue)
|
||||
viewOptions["viewId"] = ViewId.Value;
|
||||
|
||||
string viewOptionsJson = JsonConvert.SerializeObject(viewOptions);
|
||||
string encodedViewOptions = HttpUtility.UrlEncode(viewOptionsJson);
|
||||
string url = $"{Host.TrimEnd('/')}/wm/app-{AppName}/?view-options={encodedViewOptions}";
|
||||
|
||||
if (PresetParams != null)
|
||||
{
|
||||
string presetParamsJson = JsonConvert.SerializeObject(PresetParams);
|
||||
string encodedPresetParams = HttpUtility.UrlEncode(presetParamsJson);
|
||||
url += $"&presetParams={encodedPresetParams}";
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statische Methode zur Erstellung eines DeepLinks basierend auf den angegebenen Parametern.
|
||||
/// </summary>
|
||||
/// <param name="host">Der Hostname der Anwendung.</param>
|
||||
/// <param name="appName">Der Name der Anwendung.</param>
|
||||
/// <param name="viewType">Der Typ der Ansicht.</param>
|
||||
/// <param name="type">Der Type des Objekts.</param>
|
||||
/// <returns>Die erstellte DeepLink-URL als string.</returns>
|
||||
public static string CreateDeepLink(string host, string appName, ViewType viewType, string type)
|
||||
{
|
||||
var builder = new DeepLinkBuilder
|
||||
{
|
||||
Host = host,
|
||||
AppName = appName,
|
||||
ViewType = viewType,
|
||||
Type = type,
|
||||
};
|
||||
|
||||
return builder.BuildUrl();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user