Files
disco-service-tracker-plugin/ConfigurationHandler/ServiceTrackerConfigurationHandler.cs
T

136 lines
5.6 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 = GetPluginDataDirectory(
controller.HttpContext.Application["Disco.Plugins.ServiceTracker"] as Plugin
?? new ServiceTrackerPlugin());
if (string.IsNullOrEmpty(dataPath))
{
dataPath = System.IO.Path.Combine(
AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Plugins", "Disco.Plugins.ServiceTracker");
}
var dataStore = new ServiceTrackerDataStore(dataPath);
var config = dataStore.LoadConfig();
// Update simple settings
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;
// Parse priorities JSON if provided
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 { /* keep existing */ }
}
// Parse locations JSON if provided
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 { /* keep existing */ }
}
// Parse status options
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 />
<h4>Features</h4>
<ul>
<li><strong>Priority Levels</strong> &mdash; Configurable priorities with SLA timeframes (Critical=4h, High=8h, Medium=24h, etc.)</li>
<li><strong>Device Location Tracking</strong> &mdash; Track where each device currently is (IT Office, With User, At Repairer, etc.)</li>
<li><strong>Tile Dashboard</strong> &mdash; Visual card-based overview of all open jobs, sorted by due date or priority</li>
<li><strong>SLA Monitoring</strong> &mdash; Automatic breach detection with visual alerts</li>
<li><strong>Activity Notes</strong> &mdash; Add timestamped notes and updates to each ticket</li>
<li><strong>Tech Workload</strong> &mdash; See job distribution across technicians</li>
<li><strong>CSV Export</strong> &mdash; Export all open tickets with metadata</li>
</ul>
<hr />
<h4>Configuration</h4>
<p>Priority levels, locations, SLA timeframes, and status options can be customised by editing
the <code>config.json</code> file in the plugin data directory, or by posting JSON data via the configuration form.</p>
<p>Default configuration is created on install with 5 priority levels (Critical through Scheduled) and
6 location options.</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>");
}
}
}