From e976a1e1937f552f580b98af8508aed00218c200 Mon Sep 17 00:00:00 2001 From: jessikitty Date: Tue, 5 May 2026 15:06:11 +1000 Subject: [PATCH] feat: add ConfigurationHandler with settings page --- .../ServiceTrackerConfigurationHandler.cs | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 ConfigurationHandler/ServiceTrackerConfigurationHandler.cs diff --git a/ConfigurationHandler/ServiceTrackerConfigurationHandler.cs b/ConfigurationHandler/ServiceTrackerConfigurationHandler.cs new file mode 100644 index 0000000..4b626ad --- /dev/null +++ b/ConfigurationHandler/ServiceTrackerConfigurationHandler.cs @@ -0,0 +1,135 @@ +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(); + } + + 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>(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>(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(@" +
+

Service Tracker Plugin

+

Enhanced service/support tracking with priority management, location tracking, + tile dashboard, and SLA monitoring for Disco ICT jobs.

+
+ +

Features

+
    +
  • Priority Levels — Configurable priorities with SLA timeframes (Critical=4h, High=8h, Medium=24h, etc.)
  • +
  • Device Location Tracking — Track where each device currently is (IT Office, With User, At Repairer, etc.)
  • +
  • Tile Dashboard — Visual card-based overview of all open jobs, sorted by due date or priority
  • +
  • SLA Monitoring — Automatic breach detection with visual alerts
  • +
  • Activity Notes — Add timestamped notes and updates to each ticket
  • +
  • Tech Workload — See job distribution across technicians
  • +
  • CSV Export — Export all open tickets with metadata
  • +
+ +
+

Configuration

+

Priority levels, locations, SLA timeframes, and status options can be customised by editing + the config.json file in the plugin data directory, or by posting JSON data via the configuration form.

+

Default configuration is created on install with 5 priority levels (Critical through Scheduled) and + 6 location options.

+ +
+

+ + Open Service Tracker Dashboard + +

+
"); + } + } +}