diff --git a/src/PowderCoating.Infrastructure/Services/AiQuoteService.cs b/src/PowderCoating.Infrastructure/Services/AiQuoteService.cs index 2de6e73..50d1759 100644 --- a/src/PowderCoating.Infrastructure/Services/AiQuoteService.cs +++ b/src/PowderCoating.Infrastructure/Services/AiQuoteService.cs @@ -619,7 +619,7 @@ Respond with the JSON object only."; CoatCount = request.CoatCount, MaterialCost = Math.Round(materialCost, 2), ConsumablesCost = Math.Round(consumablesSurcharge, 2), - EstimatedMinutes = (int)Math.Round(perItemMinutes), + EstimatedMinutes = perItemMinutes, MaterialMinMinutes = materialMinMinutes, MinFloorApplied = minFloorApplied, LaborCost = Math.Round(laborCost, 2), diff --git a/src/PowderCoating.Web/Controllers/PlatformAdminController.cs b/src/PowderCoating.Web/Controllers/PlatformAdminController.cs new file mode 100644 index 0000000..0d10dcf --- /dev/null +++ b/src/PowderCoating.Web/Controllers/PlatformAdminController.cs @@ -0,0 +1,130 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using PowderCoating.Shared.Constants; +using PowderCoating.Web.ViewModels.PlatformAdmin; + +namespace PowderCoating.Web.Controllers; + +[Authorize(Policy = AppConstants.Policies.SuperAdminOnly)] +public class PlatformAdminController : Controller +{ + private static readonly bool ShowRawLogFiles = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")); + + public IActionResult TenantsBilling() => View(BuildTenantsBillingHub()); + + public IActionResult PeopleActivity() => View(BuildPeopleActivityHub()); + + public IActionResult ContentMessaging() => View(BuildContentMessagingHub()); + + public IActionResult Observability() => View(BuildObservabilityHub()); + + public IActionResult Maintenance() => View(BuildMaintenanceHub()); + + private static PlatformAdminHubViewModel BuildTenantsBillingHub() => new() + { + Title = "Tenants & Billing", + PageIcon = "bi-building-gear", + Intro = "Manage tenant accounts, subscription health, pricing plans, and payment-system signals from one place.", + Cards = new List + { + Card("Companies", "Browse all tenant companies, create new accounts, and jump into company-level details.", "Companies", "Index", "bi-building", "Daily", "text-bg-primary-subtle border border-primary-subtle"), + Card("Company Health", "Review readiness, setup gaps, and health signals across every company.", "CompanyHealth", "Index", "bi-heart-pulse", "Review", "text-bg-success-subtle border border-success-subtle"), + Card("Subscriptions", "Manage tenant subscriptions, grace periods, expirations, and billing status.", "SubscriptionManagement", "Index", "bi-credit-card", "Daily", "text-bg-warning-subtle border border-warning-subtle"), + Card("Subscription Plans", "Adjust platform plan definitions, limits, pricing, and feature packaging.", "PlatformSubscription", "Index", "bi-layers", "Config", "text-bg-info-subtle border border-info-subtle"), + Card("Revenue Dashboard", "Track platform-level revenue, plan mix, and commercial performance over time.", "Revenue", "Index", "bi-graph-up-arrow", "Monitor", "text-bg-secondary-subtle border border-secondary-subtle"), + Card("Stripe Events", "Inspect incoming Stripe webhook activity and payment-provider events.", "StripeEvents", "Index", "bi-lightning-charge", "Advanced", "text-bg-secondary-subtle border border-secondary-subtle"), + Card("SMS Agreements", "Audit company SMS agreement status and identify accounts blocked by compliance gating.", "SmsAgreements", "Index", "bi-file-earmark-check", "Compliance", "text-bg-danger-subtle border border-danger-subtle") + } + }; + + private static PlatformAdminHubViewModel BuildPeopleActivityHub() => new() + { + Title = "People & Activity", + PageIcon = "bi-people", + Intro = "See who is using the platform, what they are doing, and which tenants are still onboarding.", + Cards = new List + { + Card("Platform Users", "Manage SuperAdmin accounts and review platform-user access details.", "PlatformUsers", "Index", "bi-people-fill", "Daily", "text-bg-primary-subtle border border-primary-subtle"), + Card("User Activity", "Review cross-tenant usage history, filters, and behavioral trends.", "UserActivity", "Index", "bi-person-lines-fill", "Review", "text-bg-success-subtle border border-success-subtle"), + Card("Online Now", "Check who is currently active in the application right now.", "UserActivity", "Online", "bi-broadcast-pin", "Live", "text-bg-success-subtle border border-success-subtle"), + Card("Onboarding Progress", "Track which companies are still working through setup and activation milestones.", "OnboardingProgress", "Index", "bi-rocket-takeoff", "Support", "text-bg-warning-subtle border border-warning-subtle"), + Card("Platform Notifications", "Review platform-level in-app notifications and operational follow-ups.", "PlatformNotifications", "Index", "bi-bell", "Monitor", "text-bg-info-subtle border border-info-subtle") + } + }; + + private static PlatformAdminHubViewModel BuildContentMessagingHub() => new() + { + Title = "Content & Messaging", + PageIcon = "bi-megaphone", + Intro = "Manage the platform-facing announcements, release communication, admin outreach, and inbound support signals.", + Cards = new List + { + Card("Announcements", "Publish or retire platform-wide announcements shown to tenant users.", "Announcements", "Index", "bi-megaphone", "Publish", "text-bg-primary-subtle border border-primary-subtle"), + Card("Dashboard Tips", "Curate the rotating tips and educational nudges shown in the product dashboard.", "DashboardTips", "Index", "bi-lightbulb", "Content", "text-bg-warning-subtle border border-warning-subtle"), + Card("Email Broadcast", "Send platform-admin broadcast emails to selected tenant companies.", "EmailBroadcast", "Index", "bi-broadcast", "Support", "text-bg-info-subtle border border-info-subtle"), + Card("Release Notes", "Publish and maintain customer-facing release notes and change summaries.", "ReleaseNotes", "Manage", "bi-journal-text", "Publish", "text-bg-success-subtle border border-success-subtle"), + Card("Contact Submissions", "Review inbound contact requests, questions, and support follow-up items.", "Contact", "Submissions", "bi-envelope", "Inbox", "text-bg-secondary-subtle border border-secondary-subtle"), + Card("Bug Reports", "Triage submitted product bugs and inspect the supporting report detail.", "BugReport", "Index", "bi-bug", "Triage", "text-bg-danger-subtle border border-danger-subtle") + } + }; + + private static PlatformAdminHubViewModel BuildObservabilityHub() + { + var cards = new List + { + Card("Audit Log", "Review the platform audit trail for sensitive actions and administrative changes.", "AuditLog", "Index", "bi-shield-check", "Investigate", "text-bg-primary-subtle border border-primary-subtle"), + Card("System Logs", "Inspect application warning and error logs from the structured logging pipeline.", "SystemLogs", "Index", "bi-database-exclamation", "Investigate", "text-bg-danger-subtle border border-danger-subtle"), + Card("System Info", "Review environment, infrastructure, and runtime diagnostics for the platform.", "SystemInfo", "Index", "bi-cpu", "Advanced", "text-bg-secondary-subtle border border-secondary-subtle"), + Card("AI Usage", "Monitor AI feature usage, cross-tenant consumption, and feature mix.", "AiUsageReport", "Index", "bi-robot", "Monitor", "text-bg-info-subtle border border-info-subtle"), + Card("Usage & Quota", "Review platform-wide usage ceilings, quota trends, and consumption pressure.", "UsageQuota", "Index", "bi-speedometer2", "Monitor", "text-bg-warning-subtle border border-warning-subtle"), + Card("Banned IPs", "Manage blocked IP addresses and platform-level abuse controls.", "BannedIps", "Index", "bi-slash-circle", "Security", "text-bg-danger-subtle border border-danger-subtle") + }; + + if (ShowRawLogFiles) + { + cards.Add(Card("Raw Log Files", "Open raw log-file views for deeper troubleshooting in environments where file logs are available.", "Diagnostics", "ViewLogs", "bi-file-text", "Advanced", "text-bg-secondary-subtle border border-secondary-subtle")); + } + + return new PlatformAdminHubViewModel + { + Title = "Observability", + PageIcon = "bi-binoculars", + Intro = "Investigate platform behavior across audit trails, system logs, AI usage, quotas, and security-oriented diagnostics.", + Cards = cards + }; + } + + private static PlatformAdminHubViewModel BuildMaintenanceHub() => new() + { + Title = "Maintenance", + PageIcon = "bi-wrench-adjustable-circle", + Intro = "Use these tools for exceptional maintenance work, migration tasks, and destructive admin operations. They are not routine day-to-day workflows.", + WarningTitle = "Use With Care", + WarningMessage = "These tools can expose bulk data, change platform state, or permanently remove records. Use them deliberately and preferably with a written reason or ticket.", + Cards = new List + { + Card("Data Export", "Export a tenant company's data set for audits, offboarding, support, or migration work.", "DataExport", "Index", "bi-file-earmark-arrow-down", "Maintenance", "text-bg-warning-subtle border border-warning-subtle"), + Card("Data Purge", "Permanently delete soft-deleted records after previewing impact and cutoff windows.", "DataPurge", "Index", "bi-trash3", "Dangerous", "text-bg-danger-subtle border border-danger-subtle"), + Card("Storage Migration", "Run one-off migration of local media files into cloud storage.", "StorageMigration", "Index", "bi-cloud-upload", "One-off", "text-bg-info-subtle border border-info-subtle"), + Card("Seed Data", "Seed or remove system and demo data for setup, QA, or controlled test scenarios.", "SeedData", "Index", "bi-database-fill-gear", "Restricted", "text-bg-danger-subtle border border-danger-subtle") + } + }; + + private static PlatformAdminLinkCardViewModel Card( + string title, + string description, + string controller, + string action, + string icon, + string badgeText, + string badgeStyle) => new() + { + Title = title, + Description = description, + Controller = controller, + Action = action, + Icon = icon, + BadgeText = badgeText, + BadgeStyle = badgeStyle + }; +} diff --git a/src/PowderCoating.Web/ViewModels/PlatformAdmin/PlatformAdminHubViewModel.cs b/src/PowderCoating.Web/ViewModels/PlatformAdmin/PlatformAdminHubViewModel.cs new file mode 100644 index 0000000..3a87f17 --- /dev/null +++ b/src/PowderCoating.Web/ViewModels/PlatformAdmin/PlatformAdminHubViewModel.cs @@ -0,0 +1,11 @@ +namespace PowderCoating.Web.ViewModels.PlatformAdmin; + +public class PlatformAdminHubViewModel +{ + public string Title { get; set; } = string.Empty; + public string PageIcon { get; set; } = string.Empty; + public string Intro { get; set; } = string.Empty; + public string? WarningTitle { get; set; } + public string? WarningMessage { get; set; } + public IReadOnlyList Cards { get; set; } = Array.Empty(); +} diff --git a/src/PowderCoating.Web/ViewModels/PlatformAdmin/PlatformAdminLinkCardViewModel.cs b/src/PowderCoating.Web/ViewModels/PlatformAdmin/PlatformAdminLinkCardViewModel.cs new file mode 100644 index 0000000..1d8b8a2 --- /dev/null +++ b/src/PowderCoating.Web/ViewModels/PlatformAdmin/PlatformAdminLinkCardViewModel.cs @@ -0,0 +1,13 @@ +namespace PowderCoating.Web.ViewModels.PlatformAdmin; + +public class PlatformAdminLinkCardViewModel +{ + public string Title { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string Controller { get; set; } = string.Empty; + public string Action { get; set; } = string.Empty; + public string Icon { get; set; } = string.Empty; + public string BadgeText { get; set; } = string.Empty; + public string BadgeStyle { get; set; } = string.Empty; + public Dictionary? RouteValues { get; set; } +} diff --git a/src/PowderCoating.Web/Views/Dashboard/SuperAdminDashboard.cshtml b/src/PowderCoating.Web/Views/Dashboard/SuperAdminDashboard.cshtml index 4046160..fcb240f 100644 --- a/src/PowderCoating.Web/Views/Dashboard/SuperAdminDashboard.cshtml +++ b/src/PowderCoating.Web/Views/Dashboard/SuperAdminDashboard.cshtml @@ -251,6 +251,21 @@ New Company + + Tenants & Billing + + + People & Activity + + + Content & Messaging + + + Observability + + + Maintenance + Platform Users @@ -263,7 +278,7 @@ @if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))) { - View Logs + Raw Logs } diff --git a/src/PowderCoating.Web/Views/PlatformAdmin/ContentMessaging.cshtml b/src/PowderCoating.Web/Views/PlatformAdmin/ContentMessaging.cshtml new file mode 100644 index 0000000..330e111 --- /dev/null +++ b/src/PowderCoating.Web/Views/PlatformAdmin/ContentMessaging.cshtml @@ -0,0 +1,9 @@ +@using PowderCoating.Web.ViewModels.PlatformAdmin +@model PlatformAdminHubViewModel + +@{ + ViewData["Title"] = Model.Title; + ViewData["PageIcon"] = Model.PageIcon; +} + +@await Html.PartialAsync("_HubCardGrid", Model) diff --git a/src/PowderCoating.Web/Views/PlatformAdmin/Maintenance.cshtml b/src/PowderCoating.Web/Views/PlatformAdmin/Maintenance.cshtml new file mode 100644 index 0000000..330e111 --- /dev/null +++ b/src/PowderCoating.Web/Views/PlatformAdmin/Maintenance.cshtml @@ -0,0 +1,9 @@ +@using PowderCoating.Web.ViewModels.PlatformAdmin +@model PlatformAdminHubViewModel + +@{ + ViewData["Title"] = Model.Title; + ViewData["PageIcon"] = Model.PageIcon; +} + +@await Html.PartialAsync("_HubCardGrid", Model) diff --git a/src/PowderCoating.Web/Views/PlatformAdmin/Observability.cshtml b/src/PowderCoating.Web/Views/PlatformAdmin/Observability.cshtml new file mode 100644 index 0000000..330e111 --- /dev/null +++ b/src/PowderCoating.Web/Views/PlatformAdmin/Observability.cshtml @@ -0,0 +1,9 @@ +@using PowderCoating.Web.ViewModels.PlatformAdmin +@model PlatformAdminHubViewModel + +@{ + ViewData["Title"] = Model.Title; + ViewData["PageIcon"] = Model.PageIcon; +} + +@await Html.PartialAsync("_HubCardGrid", Model) diff --git a/src/PowderCoating.Web/Views/PlatformAdmin/PeopleActivity.cshtml b/src/PowderCoating.Web/Views/PlatformAdmin/PeopleActivity.cshtml new file mode 100644 index 0000000..330e111 --- /dev/null +++ b/src/PowderCoating.Web/Views/PlatformAdmin/PeopleActivity.cshtml @@ -0,0 +1,9 @@ +@using PowderCoating.Web.ViewModels.PlatformAdmin +@model PlatformAdminHubViewModel + +@{ + ViewData["Title"] = Model.Title; + ViewData["PageIcon"] = Model.PageIcon; +} + +@await Html.PartialAsync("_HubCardGrid", Model) diff --git a/src/PowderCoating.Web/Views/PlatformAdmin/TenantsBilling.cshtml b/src/PowderCoating.Web/Views/PlatformAdmin/TenantsBilling.cshtml new file mode 100644 index 0000000..330e111 --- /dev/null +++ b/src/PowderCoating.Web/Views/PlatformAdmin/TenantsBilling.cshtml @@ -0,0 +1,9 @@ +@using PowderCoating.Web.ViewModels.PlatformAdmin +@model PlatformAdminHubViewModel + +@{ + ViewData["Title"] = Model.Title; + ViewData["PageIcon"] = Model.PageIcon; +} + +@await Html.PartialAsync("_HubCardGrid", Model) diff --git a/src/PowderCoating.Web/Views/PlatformAdmin/_HubCardGrid.cshtml b/src/PowderCoating.Web/Views/PlatformAdmin/_HubCardGrid.cshtml new file mode 100644 index 0000000..8fa6ef1 --- /dev/null +++ b/src/PowderCoating.Web/Views/PlatformAdmin/_HubCardGrid.cshtml @@ -0,0 +1,138 @@ +@using PowderCoating.Web.ViewModels.PlatformAdmin +@model PlatformAdminHubViewModel + +@{ + bool hasWarning = !string.IsNullOrWhiteSpace(Model.WarningTitle) || !string.IsNullOrWhiteSpace(Model.WarningMessage); +} + + + + diff --git a/src/PowderCoating.Web/Views/Shared/_Layout.cshtml b/src/PowderCoating.Web/Views/Shared/_Layout.cshtml index ee8845a..58c8fcb 100644 --- a/src/PowderCoating.Web/Views/Shared/_Layout.cshtml +++ b/src/PowderCoating.Web/Views/Shared/_Layout.cshtml @@ -1281,140 +1281,37 @@ @* Multi-tenancy: SuperAdmin Platform Management (hidden while impersonating) *@ @if (User.IsInRole("SuperAdmin") && !isImpersonating) { - - - - Companies - - - - Company Health - - - - Subscriptions - - - - Subscription Plans - - - - Revenue Dashboard - - - - Stripe Events - - - - SMS Agreements - - - - - - Announcements - - - - Dashboard Tips - - - - Email Broadcast - - - - - - Onboarding Progress - - - - Platform Users - - - - User Activity - - - Online Now - @{ var _onlineCount = OnlineUserTracker.GetActiveCount(15); } - @if (_onlineCount > 0) - { - @_onlineCount - } - - - - Notification Log - - - - - - AI Usage - - - - Usage & Quota - - - - - - Contact Submissions - - - - Bug Reports - - + + - Audit Log + Platform Overview - - - Banned IPs + + + Tenants & Billing - - - System Logs + + + People & Activity - @if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))) - { - - - Raw Log Files + + + Content & Messaging - } - - - System Info + + + Observability + + + + Maintenance - - - - Data Export - - - - Data Purge - - - - Storage Migration - + Platform Settings - - - Seed Data - Powder Catalog @@ -1423,10 +1320,6 @@ Manufacturer Lookup Patterns - - - Release Notes - } }