aktueller Stand
This commit is contained in:
85
FasdDesktopUi/Basics/Helper/TicketDeepLinkHelper.cs
Normal file
85
FasdDesktopUi/Basics/Helper/TicketDeepLinkHelper.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using C4IT.FASD.Base;
|
||||
using C4IT.Logging;
|
||||
using FasdDesktopUi.Basics;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace FasdDesktopUi.Basics.Helper
|
||||
{
|
||||
internal static class TicketDeepLinkHelper
|
||||
{
|
||||
internal static bool TryOpenTicketRelationExternally(cF4sdApiSearchResultRelation relation)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (relation == null || relation.Type != enumF4sdSearchResultClass.Ticket)
|
||||
return false;
|
||||
|
||||
var ticketConfig = cFasdCockpitConfig.Instance?.Global?.TicketConfiguration;
|
||||
if (ticketConfig == null)
|
||||
return false;
|
||||
|
||||
var isIncident = IsIncidentRelation(relation, out var activityType);
|
||||
var openExternally = isIncident
|
||||
? ticketConfig.OpenIncidentsExternally
|
||||
: ticketConfig.OpenTicketsExternally;
|
||||
|
||||
if (!openExternally)
|
||||
return false;
|
||||
|
||||
var url = BuildTicketDeepLink(relation.id, activityType);
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
return false;
|
||||
|
||||
new cBrowsers().Start("default", url);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsIncidentRelation(cF4sdApiSearchResultRelation relation, out string activityType)
|
||||
{
|
||||
activityType = null;
|
||||
|
||||
if (relation?.Infos != null && relation.Infos.TryGetValue("ActivityType", out var activityTypeValue))
|
||||
activityType = activityTypeValue;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(activityType))
|
||||
return false;
|
||||
|
||||
return activityType.IndexOf("Incident", StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
internal static string BuildTicketDeepLink(Guid ticketId, string activityType)
|
||||
{
|
||||
if (ticketId == Guid.Empty)
|
||||
return null;
|
||||
|
||||
var server = cCockpitConfiguration.Instance?.m42ServerConfiguration?.Server;
|
||||
if (string.IsNullOrWhiteSpace(server))
|
||||
return null;
|
||||
|
||||
var baseUrl = server.TrimEnd('/');
|
||||
if (!baseUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
||||
!baseUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
baseUrl = "https://" + baseUrl;
|
||||
}
|
||||
if (!baseUrl.EndsWith("/wm", StringComparison.OrdinalIgnoreCase))
|
||||
baseUrl += "/wm";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(activityType))
|
||||
return null;
|
||||
|
||||
var viewOptionsJson = $"{{\"embedded\":false,\"objectId\":\"{ticketId}\",\"type\":\"{activityType}\",\"viewType\":\"preview\",\"archived\":0}}";
|
||||
var viewOptionsEncoded = Uri.EscapeDataString(viewOptionsJson);
|
||||
|
||||
return $"{baseUrl}/app-ServiceDesk/?view-options={viewOptionsEncoded}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using C4IT.FASD.Base;
|
||||
using C4IT.Logging;
|
||||
using C4IT.MultiLanguage;
|
||||
using C4IT.MultiLanguage;
|
||||
using FasdDesktopUi.Basics.Helper;
|
||||
using FasdDesktopUi.Basics.Services.RelationService;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -60,15 +61,18 @@ namespace FasdDesktopUi.Basics.UiActions
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_selectedRelation == null)
|
||||
{
|
||||
Debug.Assert(true, "A new support case can't be opend, if we have no selected relation or seach result");
|
||||
LogEntry("A new support case can't be opend, if we have no sselected relation or seach result", LogLevels.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check, if have an active support case
|
||||
var supportCaseActive = dataProvider?.IsActive ?? false;
|
||||
if (_selectedRelation == null)
|
||||
{
|
||||
Debug.Assert(true, "A new support case can't be opend, if we have no selected relation or seach result");
|
||||
LogEntry("A new support case can't be opend, if we have no sselected relation or seach result", LogLevels.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TicketDeepLinkHelper.TryOpenTicketRelationExternally(_selectedRelation))
|
||||
return false;
|
||||
|
||||
// check, if have an active support case
|
||||
var supportCaseActive = dataProvider?.IsActive ?? false;
|
||||
|
||||
// create the search histroy entry
|
||||
var _seachHistoryEntry = new cSearchHistoryRelationEntry(Name, _selectedSearchResult, _relations, _selectedRelation, _searchUiProvider);
|
||||
|
||||
Reference in New Issue
Block a user