106 lines
3.9 KiB
C#
106 lines
3.9 KiB
C#
using Disco.Data.Repository;
|
|
using Disco.Plugins.ServiceTracker.Models;
|
|
using Disco.Plugins.ServiceTracker.Services;
|
|
using Disco.Services.Plugins;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.WebPages;
|
|
|
|
namespace Disco.Plugins.ServiceTracker.ConfigurationHandler
|
|
{
|
|
public class ServiceTrackerConfigurationHandler : PluginConfigurationHandler
|
|
{
|
|
public override PluginConfigurationHandlerGetResponse Get(DiscoDataContext Database, Controller controller)
|
|
{
|
|
return Response<ConfigurationView>();
|
|
}
|
|
|
|
public override bool Post(DiscoDataContext Database, FormCollection form, Controller controller)
|
|
{
|
|
try
|
|
{
|
|
var dataPath = System.IO.Path.Combine(
|
|
AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Plugins", "Disco.Plugins.ServiceTracker");
|
|
|
|
var dataStore = new ServiceTrackerDataStore(dataPath);
|
|
var config = dataStore.LoadConfig();
|
|
|
|
var refreshStr = form["refreshSeconds"];
|
|
int refresh;
|
|
if (int.TryParse(refreshStr, out refresh) && refresh >= 10)
|
|
config.DashboardRefreshSeconds = refresh;
|
|
|
|
config.AutoCreateTicketsForNewJobs = form["autoCreate"] == "on" || form["autoCreate"] == "true";
|
|
|
|
var defaultPriority = form["defaultPriority"];
|
|
if (!string.IsNullOrEmpty(defaultPriority))
|
|
config.DefaultPriorityId = defaultPriority;
|
|
|
|
var defaultLocation = form["defaultLocation"];
|
|
if (!string.IsNullOrEmpty(defaultLocation))
|
|
config.DefaultLocationId = defaultLocation;
|
|
|
|
var prioritiesJson = form["prioritiesJson"];
|
|
if (!string.IsNullOrEmpty(prioritiesJson))
|
|
{
|
|
try
|
|
{
|
|
var priorities = JsonConvert.DeserializeObject<System.Collections.Generic.List<PriorityLevel>>(prioritiesJson);
|
|
if (priorities != null && priorities.Count > 0)
|
|
config.Priorities = priorities;
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
var locationsJson = form["locationsJson"];
|
|
if (!string.IsNullOrEmpty(locationsJson))
|
|
{
|
|
try
|
|
{
|
|
var locations = JsonConvert.DeserializeObject<System.Collections.Generic.List<DeviceLocation>>(locationsJson);
|
|
if (locations != null && locations.Count > 0)
|
|
config.Locations = locations;
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
var statusOptionsRaw = form["statusOptions"];
|
|
if (!string.IsNullOrEmpty(statusOptionsRaw))
|
|
{
|
|
config.StatusOptions = statusOptionsRaw.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(s => s.Trim()).Where(s => s.Length > 0).ToList();
|
|
}
|
|
|
|
dataStore.SaveConfig(config);
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ConfigurationView : WebViewPage
|
|
{
|
|
public override void Execute()
|
|
{
|
|
WriteLiteral(@"
|
|
<div style='padding: 15px;'>
|
|
<h3>Service Tracker Plugin</h3>
|
|
<p>Enhanced service/support tracking with priority management, location tracking,
|
|
tile dashboard, and SLA monitoring for Disco ICT jobs.</p>
|
|
<hr />
|
|
<p>
|
|
<a href='/Plugin/Disco.Plugins.ServiceTracker/Dashboard' class='btn btn-primary btn-lg'>
|
|
<i class='fa fa-dashboard'></i> Open Service Tracker Dashboard
|
|
</a>
|
|
</p>
|
|
</div>");
|
|
}
|
|
}
|
|
}
|