feat: audit log buyer group filter
This commit is contained in:
parent
16676b14a7
commit
fa5362401a
|
|
@ -9,9 +9,10 @@ import (
|
|||
func (h *Handler) handleAuditLog(w http.ResponseWriter, r *http.Request) {
|
||||
profile := getProfile(r.Context())
|
||||
dealID := r.URL.Query().Get("deal_id")
|
||||
buyerGroup := r.URL.Query().Get("buyer_group")
|
||||
deals := h.getDeals(profile)
|
||||
|
||||
activities := h.getActivitiesFiltered(profile.OrganizationID, dealID, 50)
|
||||
activities := h.getActivitiesFilteredBuyer(profile.OrganizationID, dealID, buyerGroup, 50)
|
||||
|
||||
// Populate deal names
|
||||
dealNames := make(map[string]string)
|
||||
|
|
@ -24,5 +25,17 @@ func (h *Handler) handleAuditLog(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
templates.AuditLogPage(profile, activities, deals, dealID).Render(r.Context(), w)
|
||||
// Get distinct buyer groups for filter
|
||||
var buyerGroups []string
|
||||
rows, _ := h.db.Query(`SELECT DISTINCT COALESCE(buyer_group, '') FROM deal_activity WHERE organization_id = ? AND COALESCE(buyer_group, '') != '' ORDER BY buyer_group`, profile.OrganizationID)
|
||||
if rows != nil {
|
||||
for rows.Next() {
|
||||
var bg string
|
||||
rows.Scan(&bg)
|
||||
buyerGroups = append(buyerGroups, bg)
|
||||
}
|
||||
rows.Close()
|
||||
}
|
||||
|
||||
templates.AuditLogPage(profile, activities, deals, dealID, buyerGroups, buyerGroup).Render(r.Context(), w)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -499,6 +499,10 @@ func (h *Handler) getActivities(orgID string, limit int) []*model.DealActivity {
|
|||
}
|
||||
|
||||
func (h *Handler) getActivitiesFiltered(orgID string, dealID string, limit int) []*model.DealActivity {
|
||||
return h.getActivitiesFilteredBuyer(orgID, dealID, "", limit)
|
||||
}
|
||||
|
||||
func (h *Handler) getActivitiesFilteredBuyer(orgID string, dealID string, buyerGroup string, limit int) []*model.DealActivity {
|
||||
query := `
|
||||
SELECT a.id, a.deal_id, a.user_id, a.activity_type, a.resource_type, a.resource_name, a.created_at, COALESCE(p.full_name, 'Unknown')
|
||||
FROM deal_activity a LEFT JOIN profiles p ON a.user_id = p.id
|
||||
|
|
@ -508,6 +512,10 @@ func (h *Handler) getActivitiesFiltered(orgID string, dealID string, limit int)
|
|||
query += " AND a.deal_id = ?"
|
||||
args = append(args, dealID)
|
||||
}
|
||||
if buyerGroup != "" {
|
||||
query += " AND a.buyer_group = ?"
|
||||
args = append(args, buyerGroup)
|
||||
}
|
||||
query += " ORDER BY a.created_at DESC LIMIT ?"
|
||||
args = append(args, limit)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package templates
|
|||
import "dealroom/internal/model"
|
||||
import "fmt"
|
||||
|
||||
templ AuditLogPage(profile *model.Profile, activities []*model.DealActivity, deals []*model.Deal, selectedDealID string) {
|
||||
templ AuditLogPage(profile *model.Profile, activities []*model.DealActivity, deals []*model.Deal, selectedDealID string, buyerGroups []string, selectedBuyerGroup string) {
|
||||
@Layout(profile, "audit") {
|
||||
<div class="space-y-5">
|
||||
<div class="flex items-center justify-between">
|
||||
|
|
@ -11,14 +11,33 @@ templ AuditLogPage(profile *model.Profile, activities []*model.DealActivity, dea
|
|||
<h1 class="text-2xl font-bold">Audit Log</h1>
|
||||
<p class="text-sm text-gray-500 mt-1">Complete activity timeline across all deal rooms.</p>
|
||||
</div>
|
||||
<div>
|
||||
<select onchange="window.location.href='/audit?deal_id='+this.value" class="px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm text-gray-100 focus:border-teal-500 focus:outline-none">
|
||||
<div class="flex items-center gap-3">
|
||||
<select id="auditDealFilter" onchange="updateAuditFilters()" class="px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm text-gray-100 focus:border-teal-500 focus:outline-none">
|
||||
<option value="">All Deals</option>
|
||||
for _, deal := range deals {
|
||||
<option value={ deal.ID } selected?={ deal.ID == selectedDealID }>{ deal.Name }</option>
|
||||
}
|
||||
</select>
|
||||
if len(buyerGroups) > 0 {
|
||||
<select id="auditBuyerFilter" onchange="updateAuditFilters()" class="px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm text-gray-100 focus:border-teal-500 focus:outline-none">
|
||||
<option value="">All Buyer Groups</option>
|
||||
for _, bg := range buyerGroups {
|
||||
<option value={ bg } selected?={ bg == selectedBuyerGroup }>{ bg }</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
</div>
|
||||
<script>
|
||||
function updateAuditFilters() {
|
||||
var d = document.getElementById('auditDealFilter').value;
|
||||
var b = document.getElementById('auditBuyerFilter');
|
||||
var bg = b ? b.value : '';
|
||||
var url = '/audit?';
|
||||
if (d) url += 'deal_id=' + d + '&';
|
||||
if (bg) url += 'buyer_group=' + bg;
|
||||
window.location.href = url;
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-900 rounded-lg border border-gray-800 p-6">
|
||||
|
|
|
|||
Loading…
Reference in New Issue