244 lines
13 KiB
C#
244 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web.Mvc;
|
|
using Kreta.BusinessLogic.Helpers;
|
|
using Kreta.BusinessLogic.Interfaces;
|
|
using Kreta.BusinessLogic.Security;
|
|
using Kreta.Enums.ManualEnums;
|
|
using Kreta.Resources;
|
|
using Kreta.Web.Areas.UgyfelSzolgalat.Models;
|
|
using Kreta.Web.Helpers;
|
|
using Kreta.Web.Models.EditorTemplates;
|
|
using Kreta.Web.Security;
|
|
|
|
namespace Kreta.Web.Areas.UgyfelSzolgalat.Controllers
|
|
{
|
|
[MvcRoleClaimsAuthorize(true)]
|
|
[MvcRolePackageAuthorize(TanevEnum.Mind, KretaClaimPackages.Adminisztrator.ClaimValue)]
|
|
public class UgyfelSzolgalatController : Controller
|
|
{
|
|
private readonly IJiraHelper JiraHelper;
|
|
|
|
public readonly Dictionary<string, RequestTypeConnectionModel> RequestTypeConections;
|
|
|
|
private const string UgyfelSzolgalat = nameof(UgyfelSzolgalat);
|
|
private const string HibaOldal = nameof(HibaOldal);
|
|
private const string BejelentesMegse = nameof(BejelentesMegse);
|
|
private const string BejelentesKuldes = nameof(BejelentesKuldes);
|
|
private const string Bejelentes = nameof(Bejelentes);
|
|
private const string DbVisszaallitas = nameof(DbVisszaallitas);
|
|
private const string UjUrlIgenyles = nameof(UjUrlIgenyles);
|
|
private const string KonferenciaJelentkezes = nameof(KonferenciaJelentkezes);
|
|
private const string Kommunikacios = nameof(Kommunikacios);
|
|
private const string kommVissza = nameof(kommVissza);
|
|
private const string ugyfelVissza = nameof(ugyfelVissza);
|
|
|
|
public UgyfelSzolgalatController(IJiraHelper jiraHelper)
|
|
{
|
|
JiraHelper = jiraHelper ?? throw new ArgumentNullException(nameof(jiraHelper));
|
|
|
|
RequestTypeConections = new Dictionary<string, RequestTypeConnectionModel>
|
|
{
|
|
{ "DbVisszaallitas", ReRequestTypeConnectionBuilder.DbVisszaallitasRequest() },
|
|
{ "UjUrlIgenyles", ReRequestTypeConnectionBuilder.UjUrlIgenylesRequest() },
|
|
{ "Egyeb", ReRequestTypeConnectionBuilder.EgyebRequest(JiraHelper.IsFileUploadEnabled) },
|
|
{ "OktatasIgenyles", ReRequestTypeConnectionBuilder.OktatasIgenylesRequest() },
|
|
{ "FejlesztesiJavaslat", ReRequestTypeConnectionBuilder.FejlesztesiJavaslatRequest(JiraHelper.IsFileUploadEnabled) },
|
|
{ "SzakmaiKerdesek", ReRequestTypeConnectionBuilder.SzakmaiKerdesekRequest(JiraHelper.IsFileUploadEnabled) },
|
|
{ "Hibajegy", ReRequestTypeConnectionBuilder.HibajegyRequest(JiraHelper.IsFileUploadEnabled) },
|
|
{ "KonferenciaJelentkezes", ReRequestTypeConnectionBuilder.KonferenciaJelentkezesRequest() },
|
|
{ "UzletiKerdes", ReRequestTypeConnectionBuilder.UzletiRequest(JiraHelper.IsFileUploadEnabled) },
|
|
{ "KretaPoszeidon", ReRequestTypeConnectionBuilder.KretaPoszeidonRequest(JiraHelper.IsFileUploadEnabled) },
|
|
{ "PenzugyiModul", ReRequestTypeConnectionBuilder.PenzugyiModulRequest() },
|
|
{ "Dkt", ReRequestTypeConnectionBuilder.DktRequest(JiraHelper.IsFileUploadEnabled) }
|
|
};
|
|
}
|
|
|
|
public ActionResult UgyfelSzolgalatPopUp()
|
|
{
|
|
var popUpModel = new PopUpModel(CreateUgyfelszolgalatModel(), UgyfelSzolgalat);
|
|
|
|
popUpModel = popUpModel.AddBtn(popUpModel, ugyfelVissza, CommonResource.Vissza, "function(){ KretaWindowHelper.destroyWindow('UgyfelSzolgalatWindow'); }");
|
|
return PartialView(Constants.General.PopupView, popUpModel);
|
|
}
|
|
|
|
public ActionResult BejelentesPopUp(int typeId, string typeKey)
|
|
{
|
|
var requestType = new RequestTypeConnectionModel();
|
|
if (!RequestTypeConections.TryGetValue(typeKey, out requestType))
|
|
{
|
|
var popupModel = new PopUpModel(null, HibaOldal);
|
|
popupModel = popupModel.AddCancelBtn(popupModel, "function(){KretaWindowHelper.destroyWindow('UgyfelSzolgalatWindow');}");
|
|
return PartialView(Constants.General.PopupView, popupModel);
|
|
}
|
|
|
|
var model = SetModel(typeId, requestType);
|
|
|
|
var popUpModel = new PopUpModel(model, requestType.View);
|
|
|
|
popUpModel = popUpModel.AddBtn(popUpModel, BejelentesMegse, UgyfelszolgalatResource.Megse, "function(){ KretaWindowHelper.destroyWindow('BejelentesWindow'); }");
|
|
popUpModel = popUpModel.AddBtn(popUpModel, BejelentesKuldes, UgyfelszolgalatResource.Kuldes, "function(){ BejelentesHelper.SendBejelentes(); }");
|
|
return PartialView(Constants.General.PopupView, popUpModel);
|
|
}
|
|
|
|
private BejelentesBaseModel SetModel(int typeId, RequestTypeConnectionModel requestType)
|
|
{
|
|
var model = new BejelentesBaseModel();
|
|
var intezmenyCo = new IntezmenyHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetIntezmenyiAdatok();
|
|
|
|
switch (requestType.View)
|
|
{
|
|
case Bejelentes:
|
|
model = new BejelentesModel(requestType.Fejlec,
|
|
typeId,
|
|
requestType.NeedUserAndBrowserInformation,
|
|
requestType.IsFileUploadEnabled,
|
|
JiraHelper.GetMaxFileSizeInBytes(),
|
|
JiraHelper.GetAllowedFileExtensionArray(),
|
|
requestType.TextBoxTitle,
|
|
requestType.TextAreaTitle,
|
|
requestType.NeedFullAddressToBejelentesCim ? ClaimData.OrganizationFullAddress : string.Empty,
|
|
intezmenyCo);
|
|
break;
|
|
|
|
case DbVisszaallitas:
|
|
model = new DbVisszaallitasModel(requestType.Fejlec, typeId, requestType.NeedUserAndBrowserInformation, requestType.IsFileUploadEnabled, intezmenyCo);
|
|
break;
|
|
|
|
case UjUrlIgenyles:
|
|
model = new UjUrlIgenyles(requestType.Fejlec, typeId, requestType.NeedUserAndBrowserInformation, requestType.IsFileUploadEnabled, intezmenyCo);
|
|
break;
|
|
|
|
case KonferenciaJelentkezes:
|
|
model = new KonferenciaJelentkezesModel(requestType.Fejlec, typeId, requestType.NeedUserAndBrowserInformation, requestType.IsFileUploadEnabled);
|
|
break;
|
|
}
|
|
return model;
|
|
}
|
|
|
|
public ActionResult KommunikaciosPopUp(string id)
|
|
{
|
|
var popUpModel = new PopUpModel(GetKommunikaciosModel(id), Kommunikacios);
|
|
popUpModel = popUpModel.AddBtn(popUpModel, kommVissza, CommonResource.Vissza, "function(){ KretaWindowHelper.destroyWindow('KommunikaciosWindow'); }");
|
|
return PartialView(Constants.General.PopupView, popUpModel);
|
|
}
|
|
|
|
private UgyfelszolgalatModel CreateUgyfelszolgalatModel()
|
|
{
|
|
var model = new UgyfelszolgalatModel
|
|
{
|
|
ServiceDeskId = JiraHelper.GetServiceDeskId(ClaimData.IntezmenyAzonosito)
|
|
};
|
|
|
|
model.StatusList.Add(new SelectListItem { Text = UgyfelszolgalatResource.Osszes, Value = " ", Selected = true });
|
|
model.StatusList.Add(new SelectListItem { Text = UgyfelszolgalatResource.Nyitott, Value = "OPEN_REQUESTS" });
|
|
model.StatusList.Add(new SelectListItem { Text = UgyfelszolgalatResource.Lezart, Value = "CLOSED_REQUESTS" });
|
|
|
|
var requestTypes = JiraHelper.GetRequestTypes(ClaimData.IntezmenyAzonosito);
|
|
|
|
foreach (var requestTypeItem in requestTypes.Values)
|
|
{
|
|
if (RequestTypeConections.TryGetValue(requestTypeItem.HelpText, out RequestTypeConnectionModel value))
|
|
{
|
|
requestTypeItem.Order = value.Order;
|
|
requestTypeItem.IsFileUploadEnabled = value.IsFileUploadEnabled;
|
|
}
|
|
}
|
|
|
|
if (requestTypes?.Values != null)
|
|
{
|
|
foreach (var item in requestTypes.Values.Where(a => a.GroupIds != null && a.GroupIds.Count > 0 && a.HelpText != "Hibajegy" && a.HelpText != "Egyeb").OrderBy(a => a.Order))
|
|
{
|
|
model.BejelentesTypusList.Add(new SelectListItem { Text = item.Name, Value = item.Id });
|
|
model.BejelentesGombsor.Add(new UgyfelszolgalatModel.BejelentesGomb { Id = item.Id, ToolTip = item.Name, Key = item.HelpText });
|
|
}
|
|
|
|
foreach (var item in requestTypes.Values.Where(a => a.GroupIds != null && a.GroupIds.Count > 0 && (a.HelpText == "Hibajegy" || a.HelpText == "Egyeb")).OrderBy(a => a.Order))
|
|
{
|
|
model.BejelentesTypusList.Add(new SelectListItem { Text = item.Name, Value = item.Id });
|
|
model.BejelentesGombsor.Add(new UgyfelszolgalatModel.BejelentesGomb { Id = item.Id, ToolTip = item.Name, Key = item.HelpText });
|
|
}
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public ActionResult RefreshCommentList(string id)
|
|
{
|
|
CommentsModel CommentList = GetCommentListReverse(id);
|
|
return PartialView("Comments", CommentList);
|
|
}
|
|
|
|
private KommunikaciosModel GetKommunikaciosModel(string id)
|
|
{
|
|
var bejelentes = JiraHelper.GetBejelentes(ClaimData.IntezmenyAzonosito, id);
|
|
|
|
if (RequestTypeConections.TryGetValue(bejelentes.RequestType.HelpText, out RequestTypeConnectionModel value))
|
|
{
|
|
bejelentes.RequestType.IsFileUploadEnabled = value.IsFileUploadEnabled;
|
|
}
|
|
else
|
|
{
|
|
bejelentes.RequestType.IsFileUploadEnabled = false;
|
|
}
|
|
|
|
CommentsModel CommentList = GetCommentListReverse(id);
|
|
var issueName = bejelentes.RequestFieldValues.FirstOrDefault(a => a.fieldId == "summary").value.ToString();
|
|
string issueDescription = null;
|
|
foreach (var bejelentesItem in bejelentes.RequestFieldValues)
|
|
{
|
|
if (bejelentesItem.fieldId == "description" && bejelentesItem.value != null)
|
|
{
|
|
issueDescription = bejelentesItem.value.ToString().Split(new[] { Kreta.Core.Constants.General.UgyfelszolgalatSpecialisElvalaszto }, StringSplitOptions.None)[0];
|
|
break;
|
|
}
|
|
}
|
|
|
|
var bejelentesModel = new KommunikaciosModel
|
|
{
|
|
Status = bejelentes.CurrentStatus.Status,
|
|
ServiceDesk = bejelentes.ServiceDesk.ProjectName,
|
|
IssueId = bejelentes.IssueId,
|
|
IssueName = issueName,
|
|
IssueDescription = issueDescription == null ? null : Regex.Replace(issueDescription, Core.Constants.RegularExpressions.ThisOrThatLineBreak, "<br />"),
|
|
TaskKey = bejelentes.IssueKey,
|
|
CommentList = CommentList,
|
|
IsFileUploadEnabled = bejelentes.RequestType.IsFileUploadEnabled,
|
|
AttachmentMaxFileSizeInBytes = JiraHelper.GetMaxFileSizeInBytes(),
|
|
AllowedFileExtensionArray = JiraHelper.GetAllowedFileExtensionArray()
|
|
};
|
|
|
|
return bejelentesModel;
|
|
}
|
|
|
|
private CommentsModel GetCommentListReverse(string id)
|
|
{
|
|
var comments = JiraHelper.GetBejelentesCommentek(ClaimData.IntezmenyAzonosito, id);
|
|
|
|
CommentsModel CommentList = new CommentsModel();
|
|
foreach (var comment in comments)
|
|
{
|
|
/*A Jira api sajnos nem ad lehetőséget a text html-é formázására jelenleg
|
|
ezt megkérdeztük a Jira szuporttól és a forumokon is.
|
|
ez egy alternativ megoldás de service usert igényelne amit nem szeretnénk*/
|
|
//var restapiClient = new RestClient("https://jira.ekreta.hu/rest/api/1.0");
|
|
//restapiClient.Authenticator = new HttpBasicAuthenticator("dezsit", "dezsitjelszava");
|
|
//var apiRequest = CreateRequest("/render", Method.POST);
|
|
//apiRequest.AddHeader("Accept", "text/html, */*; q=0.01");
|
|
//apiRequest.AddBody(new { rendererType = "atlassian-wiki-renderer", unrenderedMarkup = text, forWysiwyg = true });
|
|
//return Execute(restapiClient, apiRequest);
|
|
var formatedHTMLText = comment.Body.Replace("\n\n", "<br>");
|
|
CommentList.Add(new CommentModel
|
|
{
|
|
Id = comment.Id,
|
|
Name = comment.Author.DisplayName,
|
|
Text = formatedHTMLText,
|
|
FreandlyDate = DateTime.Parse(comment.Created.Iso8601).ToString(Core.Constants.ToStringPattern.DateTimeWithoutSecondsPattern)
|
|
});
|
|
}
|
|
return CommentList;
|
|
}
|
|
}
|
|
}
|