gaard-client 0.2.11__tar.gz → 0.2.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gaard_client-0.2.11 → gaard_client-0.2.12}/PKG-INFO +1 -1
- {gaard_client-0.2.11 → gaard_client-0.2.12}/pyproject.toml +1 -1
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/client-web/assets/main.js +350 -21
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/client-web/assets/styles.css +148 -1
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/main.py +109 -1
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client.egg-info/PKG-INFO +1 -1
- {gaard_client-0.2.11 → gaard_client-0.2.12}/tests/test_client_app.py +76 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/README.md +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/setup.cfg +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/__init__.py +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/cli.py +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/cli_commands.py +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/client-web/assets/getgaard.svg +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client/client-web/index.html +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client.egg-info/SOURCES.txt +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client.egg-info/dependency_links.txt +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client.egg-info/entry_points.txt +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client.egg-info/requires.txt +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/src/gaard_client.egg-info/top_level.txt +0 -0
- {gaard_client-0.2.11 → gaard_client-0.2.12}/tests/test_cli.py +0 -0
|
@@ -9,12 +9,14 @@ var storedMustChangePassword = localStorage.getItem("gaard_client_must_change_pa
|
|
|
9
9
|
var storedEnterpriseAccess = localStorage.getItem("gaard_client_enterprise_access") === "true";
|
|
10
10
|
var storedActiveView = localStorage.getItem("gaard_client_active_view") || "";
|
|
11
11
|
var storedConversationId = localStorage.getItem("gaard_client_active_conversation_id") || "";
|
|
12
|
+
var storedSidebarCollapsed = localStorage.getItem("gaard_client_sidebar_collapsed") === "true";
|
|
12
13
|
var state = {
|
|
13
14
|
backendUrl: configuredBackendUrl,
|
|
14
15
|
token: storedToken,
|
|
15
16
|
username: storedUsername,
|
|
16
17
|
role: storedRole,
|
|
17
18
|
enterpriseAccess: storedEnterpriseAccess,
|
|
19
|
+
sidebarCollapsed: storedSidebarCollapsed,
|
|
18
20
|
mustChangePassword: storedMustChangePassword,
|
|
19
21
|
passwordChangeError: "",
|
|
20
22
|
activeView: normalizeView(params.get("view") || storedActiveView),
|
|
@@ -51,6 +53,17 @@ var state = {
|
|
|
51
53
|
dashboardEditId: "",
|
|
52
54
|
dashboardCreatePending: false,
|
|
53
55
|
dashboardDeletePendingId: "",
|
|
56
|
+
dashboardShareOpen: false,
|
|
57
|
+
dashboardShareDashboardId: "",
|
|
58
|
+
dashboardShares: [],
|
|
59
|
+
dashboardSharesLoadedDashboardId: "",
|
|
60
|
+
dashboardSharesLoading: false,
|
|
61
|
+
dashboardSharesPending: false,
|
|
62
|
+
dashboardSharesError: "",
|
|
63
|
+
dashboardShareUsers: [],
|
|
64
|
+
dashboardShareUsersLoaded: false,
|
|
65
|
+
dashboardShareUsersLoading: false,
|
|
66
|
+
dashboardShareUserCount: 0,
|
|
54
67
|
savedMetrics: [],
|
|
55
68
|
savedMetricsLoaded: false,
|
|
56
69
|
savedMetricsResultsLoaded: false,
|
|
@@ -298,6 +311,26 @@ function renderIcon(name) {
|
|
|
298
311
|
<rect x="9" y="9" width="11" height="11" rx="2" />
|
|
299
312
|
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
|
|
300
313
|
</svg>`,
|
|
314
|
+
share: `
|
|
315
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
316
|
+
<circle cx="18" cy="5" r="3" />
|
|
317
|
+
<circle cx="6" cy="12" r="3" />
|
|
318
|
+
<circle cx="18" cy="19" r="3" />
|
|
319
|
+
<path d="m8.6 10.5 6.8-4" />
|
|
320
|
+
<path d="m8.6 13.5 6.8 4" />
|
|
321
|
+
</svg>`,
|
|
322
|
+
panelCollapse: `
|
|
323
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
324
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
325
|
+
<path d="M9 4v16" />
|
|
326
|
+
<path d="m16 9-3 3 3 3" />
|
|
327
|
+
</svg>`,
|
|
328
|
+
panelExpand: `
|
|
329
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
330
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
331
|
+
<path d="M9 4v16" />
|
|
332
|
+
<path d="m13 9 3 3-3 3" />
|
|
333
|
+
</svg>`,
|
|
301
334
|
chevronDown: `
|
|
302
335
|
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
303
336
|
<path d="m6 9 6 6 6-6" />
|
|
@@ -324,8 +357,9 @@ function renderSidebar() {
|
|
|
324
357
|
["queries", "My Queries", "Chat history"],
|
|
325
358
|
["alerts", "Alerts", "Alert definitions"]
|
|
326
359
|
];
|
|
360
|
+
const toggleTitle = state.sidebarCollapsed ? "Expand navigation" : "Collapse navigation";
|
|
327
361
|
return `
|
|
328
|
-
<aside class="sidebar" aria-label="Navigation">
|
|
362
|
+
<aside class="sidebar ${state.sidebarCollapsed ? "collapsed" : ""}" aria-label="Navigation">
|
|
329
363
|
<div class="brand">
|
|
330
364
|
<img class="brand-logo" src="/assets/getgaard.svg" alt="" />
|
|
331
365
|
<div class="brand-copy">
|
|
@@ -343,12 +377,17 @@ function renderSidebar() {
|
|
|
343
377
|
</span>
|
|
344
378
|
</button>`).join("")}
|
|
345
379
|
</nav>
|
|
346
|
-
<div class="
|
|
347
|
-
<
|
|
348
|
-
|
|
349
|
-
<
|
|
350
|
-
|
|
380
|
+
<div class="sidebar-footer">
|
|
381
|
+
<div class="data-status" role="status">
|
|
382
|
+
<span class="status-dot"></span>
|
|
383
|
+
<div>
|
|
384
|
+
<strong>Data status</strong>
|
|
385
|
+
<small>All systems operational</small>
|
|
386
|
+
</div>
|
|
351
387
|
</div>
|
|
388
|
+
<button class="sidebar-toggle-button" type="button" data-toggle-sidebar aria-label="${escapeHtml(toggleTitle)}" title="${escapeHtml(toggleTitle)}">
|
|
389
|
+
${renderIcon(state.sidebarCollapsed ? "panelExpand" : "panelCollapse")}
|
|
390
|
+
</button>
|
|
352
391
|
</div>
|
|
353
392
|
</aside>`;
|
|
354
393
|
}
|
|
@@ -448,11 +487,12 @@ function renderAnalysisHeading() {
|
|
|
448
487
|
}
|
|
449
488
|
const title = dashboard?.name || "Analysis";
|
|
450
489
|
const description = dashboard?.description || (dashboard ? "No description yet." : "Create a dashboard to organize saved query widgets.");
|
|
490
|
+
const editable = canEditDashboard(dashboard);
|
|
451
491
|
return `
|
|
452
492
|
<div class="conversation-heading analysis-heading">
|
|
453
493
|
<span>Analysis</span>
|
|
454
494
|
<div class="dashboard-title-row">
|
|
455
|
-
${dashboard ? `
|
|
495
|
+
${dashboard && editable ? `
|
|
456
496
|
<button class="dashboard-title-button" type="button" data-edit-active-dashboard aria-label="Edit dashboard details" title="Edit dashboard details">
|
|
457
497
|
${escapeHtml(title)}
|
|
458
498
|
</button>` : `<strong>${escapeHtml(title)}</strong>`}
|
|
@@ -536,13 +576,44 @@ function getActiveDashboard() {
|
|
|
536
576
|
}
|
|
537
577
|
return state.dashboards.find((item) => item.id === state.activeDashboardId) || state.dashboards[0] || null;
|
|
538
578
|
}
|
|
579
|
+
function dashboardAccessLevel(dashboard) {
|
|
580
|
+
return dashboard?.access_level || (dashboard?.is_owner === false ? "view" : "owner");
|
|
581
|
+
}
|
|
582
|
+
function canEditDashboard(dashboard = getActiveDashboard()) {
|
|
583
|
+
if (!dashboard) return false;
|
|
584
|
+
return Boolean(dashboard.can_edit ?? dashboard.is_owner ?? dashboardAccessLevel(dashboard) === "edit");
|
|
585
|
+
}
|
|
586
|
+
function canShareDashboard(dashboard = getActiveDashboard()) {
|
|
587
|
+
if (!dashboard) return false;
|
|
588
|
+
return Boolean(dashboard.can_share ?? canEditDashboard(dashboard));
|
|
589
|
+
}
|
|
590
|
+
function canDeleteDashboard(dashboard) {
|
|
591
|
+
if (!dashboard) return false;
|
|
592
|
+
return Boolean(dashboard.can_delete ?? dashboard.is_owner ?? dashboardAccessLevel(dashboard) === "owner");
|
|
593
|
+
}
|
|
594
|
+
function dashboardSharingAvailable() {
|
|
595
|
+
return Number(state.dashboardShareUserCount || 0) > 1 || state.dashboardShareUsers.length > 1;
|
|
596
|
+
}
|
|
539
597
|
function renderAnalysisView() {
|
|
540
598
|
const dashboard = getActiveDashboard();
|
|
599
|
+
const editable = canEditDashboard(dashboard);
|
|
600
|
+
const shareable = canShareDashboard(dashboard) && dashboardSharingAvailable();
|
|
541
601
|
return `
|
|
542
602
|
<section class="dashboard-view" aria-label="Dashboard Analysis">
|
|
543
603
|
<div class="dashboard-toolbar dashboard-toolbar-compact">
|
|
544
604
|
<div class="dashboard-toolbar-actions">
|
|
545
|
-
${dashboard && state.token ? `
|
|
605
|
+
${dashboard && state.token && shareable ? `
|
|
606
|
+
<button
|
|
607
|
+
class="dashboard-edit-mode-button"
|
|
608
|
+
type="button"
|
|
609
|
+
data-open-dashboard-share
|
|
610
|
+
aria-label="Share dashboard"
|
|
611
|
+
title="Share dashboard"
|
|
612
|
+
${state.dashboardSharesLoading ? "disabled" : ""}
|
|
613
|
+
>
|
|
614
|
+
${state.dashboardSharesLoading ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("share")}
|
|
615
|
+
</button>` : ""}
|
|
616
|
+
${dashboard && state.token && editable ? `
|
|
546
617
|
<button
|
|
547
618
|
class="dashboard-edit-mode-button ${state.dashboardEditMode ? "active" : ""} ${state.dashboardLayoutSaving ? "saving" : ""}"
|
|
548
619
|
type="button"
|
|
@@ -555,7 +626,7 @@ function renderAnalysisView() {
|
|
|
555
626
|
${state.dashboardLayoutSaving ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("edit")}
|
|
556
627
|
${state.dashboardLayoutSaving ? `<span>Saving...</span>` : ""}
|
|
557
628
|
</button>` : ""}
|
|
558
|
-
${dashboard && state.token && state.dashboardEditMode ? `
|
|
629
|
+
${dashboard && state.token && state.dashboardEditMode && editable ? `
|
|
559
630
|
<button class="dashboard-add-widget-button" type="button" data-open-widget-dialog aria-label="Add widget" title="Add widget">
|
|
560
631
|
${renderIcon("plus")}
|
|
561
632
|
</button>` : ""}
|
|
@@ -598,6 +669,7 @@ function renderAnalysisDashboardBody(dashboard) {
|
|
|
598
669
|
</div>`;
|
|
599
670
|
}
|
|
600
671
|
function renderDashboardWidgetGrid(dashboard) {
|
|
672
|
+
const editable = canEditDashboard(dashboard);
|
|
601
673
|
if (state.dashboardWidgetsLoading && state.dashboardWidgetsDashboardId !== dashboard.id) {
|
|
602
674
|
return renderDashboardLoadingState(
|
|
603
675
|
"Loading widgets...",
|
|
@@ -609,12 +681,12 @@ function renderDashboardWidgetGrid(dashboard) {
|
|
|
609
681
|
<div class="dashboard-empty">
|
|
610
682
|
<h2>No widgets yet.</h2>
|
|
611
683
|
<div class="dashboard-empty-copy">
|
|
612
|
-
<span
|
|
613
|
-
${state.dashboardEditMode ? `
|
|
684
|
+
<span>${editable ? "Add a saved metric to start building this dashboard." : "This shared dashboard does not have widgets yet."}</span>
|
|
685
|
+
${state.dashboardEditMode && editable ? `
|
|
614
686
|
<button class="dashboard-inline-add" type="button" data-open-widget-dialog>
|
|
615
687
|
${renderIcon("plus")}
|
|
616
688
|
<span>Add widget</span>
|
|
617
|
-
</button>` : `<p>Choose "Edit layout" to add the first widget.</p>`}
|
|
689
|
+
</button>` : editable ? `<p>Choose "Edit layout" to add the first widget.</p>` : `<p>View-only dashboards cannot be edited.</p>`}
|
|
618
690
|
</div>
|
|
619
691
|
</div>`;
|
|
620
692
|
}
|
|
@@ -710,6 +782,62 @@ function renderDashboardCreateForm(editingDashboard = null, editing = false) {
|
|
|
710
782
|
</div>
|
|
711
783
|
</form>`;
|
|
712
784
|
}
|
|
785
|
+
function renderDashboardShareDialog() {
|
|
786
|
+
const dashboard = state.dashboards.find((item) => item.id === state.dashboardShareDashboardId) || getActiveDashboard();
|
|
787
|
+
const sharesByUserId = new Map(state.dashboardShares.map((share) => [String(share.user_id), share]));
|
|
788
|
+
const users = state.dashboardShareUsers.filter((user) => String(user.user_id) !== String(dashboard?.owner_user_id || ""));
|
|
789
|
+
const loading = state.dashboardSharesLoading || state.dashboardShareUsersLoading;
|
|
790
|
+
return `
|
|
791
|
+
<div class="dashboard-dialog-overlay" role="presentation">
|
|
792
|
+
<section class="dashboard-dialog dashboard-share-dialog" role="dialog" aria-modal="true" aria-labelledby="dashboard-share-title">
|
|
793
|
+
<button class="icon-button dashboard-dialog-close" type="button" data-close-dashboard-share aria-label="Close dialog" title="Close" ${state.dashboardSharesPending ? "disabled" : ""}>
|
|
794
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
795
|
+
<path d="M18 6 6 18" />
|
|
796
|
+
<path d="m6 6 12 12" />
|
|
797
|
+
</svg>
|
|
798
|
+
</button>
|
|
799
|
+
<div class="dashboard-dialog-heading">
|
|
800
|
+
<span>Analysis</span>
|
|
801
|
+
<h2 id="dashboard-share-title">Share dashboard</h2>
|
|
802
|
+
<p>${escapeHtml(dashboard?.name || "Dashboard")}</p>
|
|
803
|
+
</div>
|
|
804
|
+
${loading ? renderDashboardLoadingState("Loading sharing settings...", "Please wait while GAARD prepares user access.") : ""}
|
|
805
|
+
${!loading && !users.length ? `
|
|
806
|
+
<div class="dashboard-widget-empty">
|
|
807
|
+
<strong>No users available.</strong>
|
|
808
|
+
<p>Create another user before sharing dashboards.</p>
|
|
809
|
+
</div>` : ""}
|
|
810
|
+
${!loading && users.length ? `
|
|
811
|
+
<form class="dashboard-share-form" data-dashboard-share-form>
|
|
812
|
+
<div class="dashboard-share-list">
|
|
813
|
+
${users.map((user) => {
|
|
814
|
+
const share = sharesByUserId.get(String(user.user_id));
|
|
815
|
+
const selectedLevel = share?.access_level || "none";
|
|
816
|
+
return `
|
|
817
|
+
<label class="dashboard-share-row">
|
|
818
|
+
<span>
|
|
819
|
+
<strong>${escapeHtml(user.name || user.username || user.user_id)}</strong>
|
|
820
|
+
<small>${escapeHtml(user.username || user.user_id)}</small>
|
|
821
|
+
</span>
|
|
822
|
+
<select data-dashboard-share-user="${escapeHtml(user.user_id)}" ${state.dashboardSharesPending ? "disabled" : ""}>
|
|
823
|
+
<option value="none" ${selectedLevel === "none" ? "selected" : ""}>No access</option>
|
|
824
|
+
<option value="view" ${selectedLevel === "view" ? "selected" : ""}>View</option>
|
|
825
|
+
<option value="edit" ${selectedLevel === "edit" ? "selected" : ""}>Edit</option>
|
|
826
|
+
</select>
|
|
827
|
+
</label>`;
|
|
828
|
+
}).join("")}
|
|
829
|
+
</div>
|
|
830
|
+
${state.dashboardSharesError ? `<div class="source-error datasource-error" role="alert">${escapeHtml(state.dashboardSharesError)}</div>` : ""}
|
|
831
|
+
<div class="dashboard-create-actions">
|
|
832
|
+
<button type="button" data-close-dashboard-share ${state.dashboardSharesPending ? "disabled" : ""}>Cancel</button>
|
|
833
|
+
<button class="primary" type="submit" ${state.dashboardSharesPending ? "disabled" : ""}>
|
|
834
|
+
${state.dashboardSharesPending ? "Saving..." : "Save sharing"}
|
|
835
|
+
</button>
|
|
836
|
+
</div>
|
|
837
|
+
</form>` : ""}
|
|
838
|
+
</section>
|
|
839
|
+
</div>`;
|
|
840
|
+
}
|
|
713
841
|
function renderDashboardWidgetDialog() {
|
|
714
842
|
const metrics = state.savedMetrics;
|
|
715
843
|
const selectedMetric = getSelectedSavedMetric();
|
|
@@ -877,18 +1005,24 @@ function renderWidgetTypePreview(type) {
|
|
|
877
1005
|
function renderDashboardMenuItem(dashboard) {
|
|
878
1006
|
const selected = dashboard.id === state.activeDashboardId;
|
|
879
1007
|
const deleting = state.dashboardDeletePendingId === dashboard.id;
|
|
1008
|
+
const sharedLabel = dashboard.shared
|
|
1009
|
+
? `${dashboardAccessLevel(dashboard) === "edit" ? "Shared edit" : "Shared view"} by ${dashboard.owner_username || "owner"}`
|
|
1010
|
+
: "";
|
|
1011
|
+
const description = sharedLabel || dashboard.description || "No description";
|
|
880
1012
|
return `
|
|
881
1013
|
<div class="dashboard-menu-item ${selected ? "active" : ""}">
|
|
882
1014
|
<button type="button" data-select-dashboard="${escapeHtml(dashboard.id)}">
|
|
883
1015
|
<strong>${escapeHtml(dashboard.name || "Untitled dashboard")}</strong>
|
|
884
|
-
<small>${escapeHtml(
|
|
1016
|
+
<small>${escapeHtml(description)}</small>
|
|
885
1017
|
</button>
|
|
1018
|
+
${canDeleteDashboard(dashboard) ? `
|
|
886
1019
|
<button class="dashboard-delete-button" type="button" data-delete-dashboard="${escapeHtml(dashboard.id)}" aria-label="Delete ${escapeHtml(dashboard.name || "dashboard")}" title="Delete dashboard" ${deleting ? "disabled" : ""}>
|
|
887
1020
|
${renderIcon("trash")}
|
|
888
|
-
</button
|
|
1021
|
+
</button>` : ""}
|
|
889
1022
|
</div>`;
|
|
890
1023
|
}
|
|
891
1024
|
function renderDashboardWidget(widget) {
|
|
1025
|
+
const editable = canEditDashboard();
|
|
892
1026
|
const layout = widget.layout || {};
|
|
893
1027
|
const content = renderDashboardWidgetContent(widget);
|
|
894
1028
|
return `
|
|
@@ -896,7 +1030,7 @@ function renderDashboardWidget(widget) {
|
|
|
896
1030
|
<article class="grid-stack-item-content dashboard-card dashboard-user-widget">
|
|
897
1031
|
<header>
|
|
898
1032
|
<h2>${escapeHtml(widget.title || widget.metric?.label || "Dashboard widget")}</h2>
|
|
899
|
-
${state.dashboardEditMode ? `
|
|
1033
|
+
${state.dashboardEditMode && editable ? `
|
|
900
1034
|
<button type="button" data-delete-dashboard-widget="${escapeHtml(widget.id)}" aria-label="Remove widget" title="Remove widget">
|
|
901
1035
|
${renderIcon("trash")}
|
|
902
1036
|
</button>` : ""}
|
|
@@ -1207,7 +1341,7 @@ function render(options = {}) {
|
|
|
1207
1341
|
if (!app) return;
|
|
1208
1342
|
const historyScroll = captureHistoryScroll();
|
|
1209
1343
|
app.innerHTML = `
|
|
1210
|
-
<main class="app-shell">
|
|
1344
|
+
<main class="app-shell ${state.sidebarCollapsed ? "sidebar-collapsed" : ""}">
|
|
1211
1345
|
${renderSidebar()}
|
|
1212
1346
|
<section class="workspace-shell" aria-label="GAARD workspace">
|
|
1213
1347
|
<header class="topbar">
|
|
@@ -1223,6 +1357,7 @@ function render(options = {}) {
|
|
|
1223
1357
|
${state.loginOpen ? renderLoginDialog() : ""}
|
|
1224
1358
|
${state.mustChangePassword ? renderPasswordChangeDialog() : ""}
|
|
1225
1359
|
${state.dashboardCreateOpen ? renderDashboardCreateDialog() : ""}
|
|
1360
|
+
${state.dashboardShareOpen ? renderDashboardShareDialog() : ""}
|
|
1226
1361
|
${state.dashboardWidgetDialogOpen ? renderDashboardWidgetDialog() : ""}
|
|
1227
1362
|
${state.saveWidgetDialogOpen ? renderSaveWidgetDialog() : ""}
|
|
1228
1363
|
${state.metricEditDialogOpen ? renderMetricEditDialog() : ""}
|
|
@@ -1230,6 +1365,7 @@ function render(options = {}) {
|
|
|
1230
1365
|
document.querySelectorAll("[data-view]").forEach((button) => {
|
|
1231
1366
|
button.addEventListener("click", changeView);
|
|
1232
1367
|
});
|
|
1368
|
+
document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", toggleSidebarCollapsed);
|
|
1233
1369
|
document.querySelectorAll("[data-open-conversation]").forEach((button) => {
|
|
1234
1370
|
button.addEventListener("click", openConversation);
|
|
1235
1371
|
});
|
|
@@ -1252,6 +1388,11 @@ function render(options = {}) {
|
|
|
1252
1388
|
button.addEventListener("click", openDashboardCreate);
|
|
1253
1389
|
});
|
|
1254
1390
|
document.querySelector("[data-edit-active-dashboard]")?.addEventListener("click", openActiveDashboardEdit);
|
|
1391
|
+
document.querySelector("[data-open-dashboard-share]")?.addEventListener("click", openDashboardShareDialog);
|
|
1392
|
+
document.querySelectorAll("[data-close-dashboard-share]").forEach((button) => {
|
|
1393
|
+
button.addEventListener("click", closeDashboardShareDialog);
|
|
1394
|
+
});
|
|
1395
|
+
document.querySelector("[data-dashboard-share-form]")?.addEventListener("submit", saveDashboardShares);
|
|
1255
1396
|
document.querySelectorAll("[data-close-dashboard-create]").forEach((button) => {
|
|
1256
1397
|
button.addEventListener("click", closeDashboardCreate);
|
|
1257
1398
|
});
|
|
@@ -1333,9 +1474,15 @@ function render(options = {}) {
|
|
|
1333
1474
|
maybeLoadConversationsForActiveView();
|
|
1334
1475
|
maybeLoadDatasourcesForActiveView();
|
|
1335
1476
|
maybeLoadDashboardsForActiveView();
|
|
1477
|
+
maybeLoadDashboardShareUsersForActiveView();
|
|
1336
1478
|
maybeLoadSavedMetricsForActiveView();
|
|
1337
1479
|
restoreHistoryScroll(historyScroll, options);
|
|
1338
1480
|
}
|
|
1481
|
+
function toggleSidebarCollapsed() {
|
|
1482
|
+
state.sidebarCollapsed = !state.sidebarCollapsed;
|
|
1483
|
+
localStorage.setItem("gaard_client_sidebar_collapsed", String(state.sidebarCollapsed));
|
|
1484
|
+
render();
|
|
1485
|
+
}
|
|
1339
1486
|
var apiErrorTimer = null;
|
|
1340
1487
|
function apiErrorMessage(error, fallback = "Request failed.") {
|
|
1341
1488
|
const raw = typeof error === "string" ? error : error?.message;
|
|
@@ -1482,6 +1629,16 @@ function maybeLoadDashboardsForActiveView() {
|
|
|
1482
1629
|
void loadDashboardWidgets(state.activeDashboardId);
|
|
1483
1630
|
}
|
|
1484
1631
|
}
|
|
1632
|
+
function maybeLoadDashboardShareUsersForActiveView() {
|
|
1633
|
+
if (
|
|
1634
|
+
state.activeView === "analysis" &&
|
|
1635
|
+
state.token &&
|
|
1636
|
+
!state.dashboardShareUsersLoaded &&
|
|
1637
|
+
!state.dashboardShareUsersLoading
|
|
1638
|
+
) {
|
|
1639
|
+
void loadDashboardShareUsers();
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1485
1642
|
function maybeLoadSavedMetricsForActiveView() {
|
|
1486
1643
|
if (state.activeView === "metrics" && state.token && !state.savedMetricsLoaded && !state.savedMetricsLoading) {
|
|
1487
1644
|
void loadSavedMetrics({ includeResult: false });
|
|
@@ -1501,6 +1658,7 @@ async function loadDashboards() {
|
|
|
1501
1658
|
state.dashboardsLoaded = false;
|
|
1502
1659
|
state.activeDashboardId = "";
|
|
1503
1660
|
state.dashboardEditMode = false;
|
|
1661
|
+
resetDashboardShareState();
|
|
1504
1662
|
return;
|
|
1505
1663
|
}
|
|
1506
1664
|
state.dashboardEditMode = false;
|
|
@@ -1516,8 +1674,12 @@ async function loadDashboards() {
|
|
|
1516
1674
|
throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
1517
1675
|
}
|
|
1518
1676
|
state.dashboards = payload.items || [];
|
|
1677
|
+
state.dashboardShareUserCount = Number(payload.share_user_count || state.dashboardShareUserCount || 0);
|
|
1519
1678
|
state.dashboardsLoaded = true;
|
|
1520
1679
|
state.activeDashboardId = payload.active_dashboard_id || payload.active_dashboard?.id || state.dashboards[0]?.id || "";
|
|
1680
|
+
if (!canEditDashboard(getActiveDashboard())) {
|
|
1681
|
+
state.dashboardEditMode = false;
|
|
1682
|
+
}
|
|
1521
1683
|
if (state.activeDashboardId) {
|
|
1522
1684
|
await loadDashboardWidgets(state.activeDashboardId, { silent: true });
|
|
1523
1685
|
}
|
|
@@ -1538,6 +1700,162 @@ function toggleDashboardMenu() {
|
|
|
1538
1700
|
void loadDashboards();
|
|
1539
1701
|
}
|
|
1540
1702
|
}
|
|
1703
|
+
function resetDashboardShareState() {
|
|
1704
|
+
state.dashboardShareOpen = false;
|
|
1705
|
+
state.dashboardShareDashboardId = "";
|
|
1706
|
+
state.dashboardShares = [];
|
|
1707
|
+
state.dashboardSharesLoadedDashboardId = "";
|
|
1708
|
+
state.dashboardSharesLoading = false;
|
|
1709
|
+
state.dashboardSharesPending = false;
|
|
1710
|
+
state.dashboardSharesError = "";
|
|
1711
|
+
state.dashboardShareUsers = [];
|
|
1712
|
+
state.dashboardShareUsersLoaded = false;
|
|
1713
|
+
state.dashboardShareUsersLoading = false;
|
|
1714
|
+
state.dashboardShareUserCount = 0;
|
|
1715
|
+
}
|
|
1716
|
+
async function loadDashboardShareUsers(options = {}) {
|
|
1717
|
+
if (!state.token) {
|
|
1718
|
+
state.dashboardShareUsers = [];
|
|
1719
|
+
state.dashboardShareUsersLoaded = false;
|
|
1720
|
+
state.dashboardShareUserCount = 0;
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
state.dashboardShareUsersLoading = true;
|
|
1724
|
+
state.dashboardSharesError = "";
|
|
1725
|
+
if (!options.silent) {
|
|
1726
|
+
render();
|
|
1727
|
+
}
|
|
1728
|
+
try {
|
|
1729
|
+
const response = await fetch(`/api/dashboard-users?backend_url=${encodeURIComponent(state.backendUrl)}`, {
|
|
1730
|
+
headers: authHeaders()
|
|
1731
|
+
});
|
|
1732
|
+
const payload = await response.json().catch(() => ({}));
|
|
1733
|
+
if (!response.ok) {
|
|
1734
|
+
throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
1735
|
+
}
|
|
1736
|
+
state.dashboardShareUsers = payload.items || [];
|
|
1737
|
+
state.dashboardShareUserCount = Number(payload.total_users || state.dashboardShareUsers.length || 0);
|
|
1738
|
+
state.dashboardShareUsersLoaded = true;
|
|
1739
|
+
} catch (error) {
|
|
1740
|
+
state.dashboardSharesError = error.message || "Could not load dashboard users.";
|
|
1741
|
+
reportApiError(error, "Could not load dashboard users.");
|
|
1742
|
+
state.dashboardShareUsersLoaded = true;
|
|
1743
|
+
} finally {
|
|
1744
|
+
state.dashboardShareUsersLoading = false;
|
|
1745
|
+
if (!options.silent) {
|
|
1746
|
+
render();
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
async function loadDashboardShares(dashboardId, options = {}) {
|
|
1751
|
+
if (!state.token || !dashboardId) {
|
|
1752
|
+
state.dashboardShares = [];
|
|
1753
|
+
state.dashboardSharesLoadedDashboardId = "";
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
state.dashboardSharesLoading = true;
|
|
1757
|
+
state.dashboardSharesError = "";
|
|
1758
|
+
if (!options.silent) {
|
|
1759
|
+
render();
|
|
1760
|
+
}
|
|
1761
|
+
try {
|
|
1762
|
+
const params = new URLSearchParams({ backend_url: state.backendUrl });
|
|
1763
|
+
const response = await fetch(`/api/dashboards/${encodeURIComponent(dashboardId)}/shares?${params.toString()}`, {
|
|
1764
|
+
headers: authHeaders()
|
|
1765
|
+
});
|
|
1766
|
+
const payload = await response.json().catch(() => ({}));
|
|
1767
|
+
if (!response.ok) {
|
|
1768
|
+
throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
1769
|
+
}
|
|
1770
|
+
state.dashboardShares = payload.items || [];
|
|
1771
|
+
state.dashboardSharesLoadedDashboardId = dashboardId;
|
|
1772
|
+
if (payload.users) {
|
|
1773
|
+
state.dashboardShareUsers = payload.users;
|
|
1774
|
+
state.dashboardShareUsersLoaded = true;
|
|
1775
|
+
}
|
|
1776
|
+
state.dashboardShareUserCount = Number(payload.total_users || state.dashboardShareUsers.length || state.dashboardShareUserCount || 0);
|
|
1777
|
+
} catch (error) {
|
|
1778
|
+
state.dashboardSharesError = error.message || "Could not load dashboard sharing.";
|
|
1779
|
+
reportApiError(error, "Could not load dashboard sharing.");
|
|
1780
|
+
} finally {
|
|
1781
|
+
state.dashboardSharesLoading = false;
|
|
1782
|
+
if (!options.silent) {
|
|
1783
|
+
render();
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
async function openDashboardShareDialog() {
|
|
1788
|
+
const dashboard = getActiveDashboard();
|
|
1789
|
+
if (!dashboard?.id || !state.token || !canShareDashboard(dashboard)) return;
|
|
1790
|
+
state.dashboardShareOpen = true;
|
|
1791
|
+
state.dashboardShareDashboardId = dashboard.id;
|
|
1792
|
+
state.dashboardSharesError = "";
|
|
1793
|
+
state.dashboardMenuOpen = false;
|
|
1794
|
+
render();
|
|
1795
|
+
const tasks = [];
|
|
1796
|
+
if (!state.dashboardShareUsersLoaded && !state.dashboardShareUsersLoading) {
|
|
1797
|
+
tasks.push(loadDashboardShareUsers({ silent: true }));
|
|
1798
|
+
}
|
|
1799
|
+
if (state.dashboardSharesLoadedDashboardId !== dashboard.id && !state.dashboardSharesLoading) {
|
|
1800
|
+
tasks.push(loadDashboardShares(dashboard.id, { silent: true }));
|
|
1801
|
+
}
|
|
1802
|
+
if (tasks.length) {
|
|
1803
|
+
await Promise.all(tasks);
|
|
1804
|
+
render();
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
function closeDashboardShareDialog() {
|
|
1808
|
+
if (state.dashboardSharesPending) return;
|
|
1809
|
+
state.dashboardShareOpen = false;
|
|
1810
|
+
state.dashboardShareDashboardId = "";
|
|
1811
|
+
state.dashboardSharesError = "";
|
|
1812
|
+
render();
|
|
1813
|
+
}
|
|
1814
|
+
async function saveDashboardShares(event) {
|
|
1815
|
+
event.preventDefault();
|
|
1816
|
+
const dashboardId = state.dashboardShareDashboardId;
|
|
1817
|
+
const dashboard = state.dashboards.find((item) => item.id === dashboardId);
|
|
1818
|
+
if (!state.token || !dashboardId || !canShareDashboard(dashboard) || state.dashboardSharesPending) return;
|
|
1819
|
+
const items = Array.from(event.currentTarget.querySelectorAll("[data-dashboard-share-user]")).reduce((shares, select) => {
|
|
1820
|
+
const accessLevel = select.value;
|
|
1821
|
+
const userId = select.dataset.dashboardShareUser || "";
|
|
1822
|
+
if (userId && ["view", "edit"].includes(accessLevel)) {
|
|
1823
|
+
shares.push({ user_id: userId, access_level: accessLevel });
|
|
1824
|
+
}
|
|
1825
|
+
return shares;
|
|
1826
|
+
}, []);
|
|
1827
|
+
state.dashboardSharesPending = true;
|
|
1828
|
+
state.dashboardSharesError = "";
|
|
1829
|
+
render();
|
|
1830
|
+
try {
|
|
1831
|
+
const response = await fetch(`/api/dashboards/${encodeURIComponent(dashboardId)}/shares`, {
|
|
1832
|
+
method: "PUT",
|
|
1833
|
+
headers: {
|
|
1834
|
+
"Content-Type": "application/json",
|
|
1835
|
+
...authHeaders()
|
|
1836
|
+
},
|
|
1837
|
+
body: JSON.stringify({
|
|
1838
|
+
items,
|
|
1839
|
+
backend_url: state.backendUrl
|
|
1840
|
+
})
|
|
1841
|
+
});
|
|
1842
|
+
const payload = await response.json().catch(() => ({}));
|
|
1843
|
+
if (!response.ok) {
|
|
1844
|
+
throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
|
|
1845
|
+
}
|
|
1846
|
+
state.dashboardShares = payload.items || [];
|
|
1847
|
+
state.dashboardSharesLoadedDashboardId = dashboardId;
|
|
1848
|
+
state.dashboardShareOpen = false;
|
|
1849
|
+
state.dashboardShareDashboardId = "";
|
|
1850
|
+
await loadDashboards();
|
|
1851
|
+
} catch (error) {
|
|
1852
|
+
state.dashboardSharesError = error.message || "Could not save dashboard sharing.";
|
|
1853
|
+
reportApiError(error, "Could not save dashboard sharing.");
|
|
1854
|
+
} finally {
|
|
1855
|
+
state.dashboardSharesPending = false;
|
|
1856
|
+
render();
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1541
1859
|
function openDashboardCreate() {
|
|
1542
1860
|
state.dashboardCreateOpen = true;
|
|
1543
1861
|
state.dashboardEditId = "";
|
|
@@ -1547,7 +1865,7 @@ function openDashboardCreate() {
|
|
|
1547
1865
|
}
|
|
1548
1866
|
function openActiveDashboardEdit() {
|
|
1549
1867
|
const dashboard = getActiveDashboard();
|
|
1550
|
-
if (!dashboard?.id || !state.token) return;
|
|
1868
|
+
if (!dashboard?.id || !state.token || !canEditDashboard(dashboard)) return;
|
|
1551
1869
|
state.dashboardCreateOpen = true;
|
|
1552
1870
|
state.dashboardEditId = dashboard.id;
|
|
1553
1871
|
state.dashboardMenuOpen = false;
|
|
@@ -1618,6 +1936,10 @@ async function createDashboard(event) {
|
|
|
1618
1936
|
event.preventDefault();
|
|
1619
1937
|
if (!state.token || state.dashboardCreatePending) return;
|
|
1620
1938
|
const editingDashboardId = state.dashboardEditId;
|
|
1939
|
+
if (editingDashboardId) {
|
|
1940
|
+
const editingDashboard = state.dashboards.find((dashboard) => dashboard.id === editingDashboardId);
|
|
1941
|
+
if (!canEditDashboard(editingDashboard)) return;
|
|
1942
|
+
}
|
|
1621
1943
|
const form = new FormData(event.currentTarget);
|
|
1622
1944
|
const name = String(form.get("name") || "").trim();
|
|
1623
1945
|
const description = String(form.get("description") || "").trim();
|
|
@@ -1683,7 +2005,7 @@ async function deleteDashboard(event) {
|
|
|
1683
2005
|
event.stopPropagation();
|
|
1684
2006
|
const dashboardId = event.currentTarget.dataset.deleteDashboard || "";
|
|
1685
2007
|
const dashboard = state.dashboards.find((item) => item.id === dashboardId);
|
|
1686
|
-
if (!dashboardId || state.dashboardDeletePendingId) return;
|
|
2008
|
+
if (!dashboardId || state.dashboardDeletePendingId || !canDeleteDashboard(dashboard)) return;
|
|
1687
2009
|
if (!window.confirm(`Delete dashboard "${dashboard?.name || "Untitled dashboard"}"?`)) {
|
|
1688
2010
|
return;
|
|
1689
2011
|
}
|
|
@@ -1960,7 +2282,7 @@ async function saveMetricLabel(event) {
|
|
|
1960
2282
|
}
|
|
1961
2283
|
}
|
|
1962
2284
|
function openDashboardWidgetDialog() {
|
|
1963
|
-
if (!state.dashboardEditMode) return;
|
|
2285
|
+
if (!state.dashboardEditMode || !canEditDashboard()) return;
|
|
1964
2286
|
if (!state.token) {
|
|
1965
2287
|
openLogin();
|
|
1966
2288
|
return;
|
|
@@ -1999,7 +2321,7 @@ function changeDashboardWidgetType(event) {
|
|
|
1999
2321
|
}
|
|
2000
2322
|
async function addDashboardWidget(event) {
|
|
2001
2323
|
event.preventDefault();
|
|
2002
|
-
if (!state.dashboardEditMode) return;
|
|
2324
|
+
if (!state.dashboardEditMode || !canEditDashboard()) return;
|
|
2003
2325
|
if (!state.token || state.dashboardWidgetPending || !state.activeDashboardId) return;
|
|
2004
2326
|
const form = new FormData(event.currentTarget);
|
|
2005
2327
|
const metricWidgetKey = String(form.get("metric_widget_key") || "").trim();
|
|
@@ -2048,7 +2370,7 @@ async function addDashboardWidget(event) {
|
|
|
2048
2370
|
}
|
|
2049
2371
|
}
|
|
2050
2372
|
async function deleteDashboardWidget(event) {
|
|
2051
|
-
if (!state.dashboardEditMode) return;
|
|
2373
|
+
if (!state.dashboardEditMode || !canEditDashboard()) return;
|
|
2052
2374
|
const widgetId = event.currentTarget.dataset.deleteDashboardWidget || "";
|
|
2053
2375
|
if (!widgetId || !state.activeDashboardId) return;
|
|
2054
2376
|
if (!window.confirm("Remove this widget from the dashboard?")) {
|
|
@@ -2074,6 +2396,7 @@ async function deleteDashboardWidget(event) {
|
|
|
2074
2396
|
}
|
|
2075
2397
|
function scheduleDashboardLayoutSave() {
|
|
2076
2398
|
if (!state.dashboardEditMode) return;
|
|
2399
|
+
if (!canEditDashboard()) return;
|
|
2077
2400
|
if (!canPersistDashboardLayout()) return;
|
|
2078
2401
|
const dashboardId = state.activeDashboardId;
|
|
2079
2402
|
if (state.dashboardLayoutSaveTimer) {
|
|
@@ -2085,6 +2408,7 @@ function scheduleDashboardLayoutSave() {
|
|
|
2085
2408
|
}
|
|
2086
2409
|
async function saveDashboardLayout(dashboardId = state.activeDashboardId) {
|
|
2087
2410
|
if (!dashboardId || dashboardId !== state.activeDashboardId || !state.token) return;
|
|
2411
|
+
if (!canEditDashboard()) return;
|
|
2088
2412
|
if (!canPersistDashboardLayout()) return;
|
|
2089
2413
|
const items = collectDashboardLayout();
|
|
2090
2414
|
if (!items.length) return;
|
|
@@ -2159,6 +2483,7 @@ async function flushPendingDashboardLayoutSave() {
|
|
|
2159
2483
|
}
|
|
2160
2484
|
async function toggleDashboardEditMode() {
|
|
2161
2485
|
if (!state.token || !getActiveDashboard()?.id || state.dashboardLayoutSaving) return;
|
|
2486
|
+
if (!canEditDashboard()) return;
|
|
2162
2487
|
if (state.dashboardEditMode) {
|
|
2163
2488
|
setDashboardLayoutSaving(true);
|
|
2164
2489
|
await flushPendingDashboardLayoutSave();
|
|
@@ -2368,6 +2693,8 @@ async function changeView(event) {
|
|
|
2368
2693
|
state.dashboardMenuOpen = false;
|
|
2369
2694
|
state.dashboardCreateOpen = false;
|
|
2370
2695
|
state.dashboardEditId = "";
|
|
2696
|
+
state.dashboardShareOpen = false;
|
|
2697
|
+
state.dashboardShareDashboardId = "";
|
|
2371
2698
|
render();
|
|
2372
2699
|
}
|
|
2373
2700
|
function openConversation(event) {
|
|
@@ -3270,6 +3597,7 @@ async function login(event) {
|
|
|
3270
3597
|
state.dashboardsLoaded = false;
|
|
3271
3598
|
state.activeDashboardId = "";
|
|
3272
3599
|
state.dashboardEditMode = false;
|
|
3600
|
+
resetDashboardShareState();
|
|
3273
3601
|
state.messages = [];
|
|
3274
3602
|
state.conversationId = "";
|
|
3275
3603
|
state.conversations = [];
|
|
@@ -3381,6 +3709,7 @@ async function logout() {
|
|
|
3381
3709
|
state.dashboardEditId = "";
|
|
3382
3710
|
state.dashboardWidgetDialogOpen = false;
|
|
3383
3711
|
state.dashboardEditMode = false;
|
|
3712
|
+
resetDashboardShareState();
|
|
3384
3713
|
state.savedMetrics = [];
|
|
3385
3714
|
state.savedMetricsLoaded = false;
|
|
3386
3715
|
state.savedMetricsResultsLoaded = false;
|
|
@@ -1399,6 +1399,10 @@ button.primary {
|
|
|
1399
1399
|
background: var(--bg);
|
|
1400
1400
|
}
|
|
1401
1401
|
|
|
1402
|
+
.app-shell.sidebar-collapsed {
|
|
1403
|
+
grid-template-columns: 78px minmax(0, 1fr);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1402
1406
|
.sidebar {
|
|
1403
1407
|
grid-template-rows: auto minmax(0, 1fr) auto;
|
|
1404
1408
|
gap: 22px;
|
|
@@ -1532,6 +1536,74 @@ button.primary {
|
|
|
1532
1536
|
font-weight: 400;
|
|
1533
1537
|
}
|
|
1534
1538
|
|
|
1539
|
+
.sidebar-footer {
|
|
1540
|
+
display: grid;
|
|
1541
|
+
gap: 14px;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
.sidebar-toggle-button {
|
|
1545
|
+
width: 100%;
|
|
1546
|
+
min-height: 38px;
|
|
1547
|
+
display: inline-grid;
|
|
1548
|
+
place-items: center;
|
|
1549
|
+
padding: 0;
|
|
1550
|
+
border: 1px solid rgba(222, 238, 250, 0.14);
|
|
1551
|
+
border-radius: 6px;
|
|
1552
|
+
background: rgba(32, 92, 145, 0.28);
|
|
1553
|
+
color: rgba(234, 244, 252, 0.86);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
.sidebar-toggle-button:hover,
|
|
1557
|
+
.sidebar-toggle-button:focus-visible {
|
|
1558
|
+
background: rgba(32, 92, 145, 0.52);
|
|
1559
|
+
color: #ffffff;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
.sidebar-toggle-button svg {
|
|
1563
|
+
width: 19px;
|
|
1564
|
+
height: 19px;
|
|
1565
|
+
fill: none;
|
|
1566
|
+
stroke: currentColor;
|
|
1567
|
+
stroke-width: 1.8;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
.sidebar.collapsed {
|
|
1571
|
+
padding: 20px 10px;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
.sidebar.collapsed .brand {
|
|
1575
|
+
justify-content: center;
|
|
1576
|
+
padding-inline: 0;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
.sidebar.collapsed .brand-copy,
|
|
1580
|
+
.sidebar.collapsed .nav-item span,
|
|
1581
|
+
.sidebar.collapsed .sources-panel,
|
|
1582
|
+
.sidebar.collapsed .data-status div {
|
|
1583
|
+
position: absolute;
|
|
1584
|
+
width: 1px;
|
|
1585
|
+
height: 1px;
|
|
1586
|
+
margin: -1px;
|
|
1587
|
+
padding: 0;
|
|
1588
|
+
overflow: hidden;
|
|
1589
|
+
clip: rect(0 0 0 0);
|
|
1590
|
+
border: 0;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
.sidebar.collapsed .nav-item {
|
|
1594
|
+
grid-template-columns: 1fr;
|
|
1595
|
+
justify-items: center;
|
|
1596
|
+
padding: 0;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
.sidebar.collapsed .nav-item::before {
|
|
1600
|
+
inset: 9px auto 9px -10px;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
.sidebar.collapsed .data-status {
|
|
1604
|
+
display: none;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1535
1607
|
.workspace-shell,
|
|
1536
1608
|
.chat-shell {
|
|
1537
1609
|
min-width: 0;
|
|
@@ -2001,6 +2073,12 @@ button.primary {
|
|
|
2001
2073
|
width: min(430px, 100%);
|
|
2002
2074
|
}
|
|
2003
2075
|
|
|
2076
|
+
.dashboard-share-dialog {
|
|
2077
|
+
width: min(560px, 100%);
|
|
2078
|
+
max-height: min(720px, calc(100vh - 48px));
|
|
2079
|
+
overflow: auto;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2004
2082
|
.dashboard-dialog-close {
|
|
2005
2083
|
position: absolute;
|
|
2006
2084
|
top: 12px;
|
|
@@ -2107,6 +2185,66 @@ button.primary {
|
|
|
2107
2185
|
gap: 14px;
|
|
2108
2186
|
}
|
|
2109
2187
|
|
|
2188
|
+
.dashboard-share-form {
|
|
2189
|
+
display: grid;
|
|
2190
|
+
gap: 14px;
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
.dashboard-share-list {
|
|
2194
|
+
display: grid;
|
|
2195
|
+
gap: 8px;
|
|
2196
|
+
max-height: min(420px, 50vh);
|
|
2197
|
+
overflow: auto;
|
|
2198
|
+
padding-right: 4px;
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
.dashboard-share-row {
|
|
2202
|
+
display: grid;
|
|
2203
|
+
grid-template-columns: minmax(0, 1fr) 124px;
|
|
2204
|
+
align-items: center;
|
|
2205
|
+
gap: 12px;
|
|
2206
|
+
padding: 11px 12px;
|
|
2207
|
+
border: 1px solid #e5ebf0;
|
|
2208
|
+
border-radius: 7px;
|
|
2209
|
+
background: #fbfcfd;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
.dashboard-share-row span {
|
|
2213
|
+
min-width: 0;
|
|
2214
|
+
display: grid;
|
|
2215
|
+
gap: 3px;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
.dashboard-share-row strong,
|
|
2219
|
+
.dashboard-share-row small {
|
|
2220
|
+
min-width: 0;
|
|
2221
|
+
overflow: hidden;
|
|
2222
|
+
text-overflow: ellipsis;
|
|
2223
|
+
white-space: nowrap;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
.dashboard-share-row strong {
|
|
2227
|
+
color: #152333;
|
|
2228
|
+
font-size: 14px;
|
|
2229
|
+
font-weight: 500;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
.dashboard-share-row small {
|
|
2233
|
+
color: #7a8793;
|
|
2234
|
+
font-size: 12px;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
.dashboard-share-row select {
|
|
2238
|
+
width: 100%;
|
|
2239
|
+
min-height: 34px;
|
|
2240
|
+
border: 1px solid #dbe4ed;
|
|
2241
|
+
border-radius: 6px;
|
|
2242
|
+
background: #ffffff;
|
|
2243
|
+
color: #111a24;
|
|
2244
|
+
font: inherit;
|
|
2245
|
+
font-size: 13px;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2110
2248
|
.dashboard-widget-form label {
|
|
2111
2249
|
display: grid;
|
|
2112
2250
|
gap: 5px;
|
|
@@ -3196,10 +3334,15 @@ button.placeholder-item.active {
|
|
|
3196
3334
|
}
|
|
3197
3335
|
|
|
3198
3336
|
@media (max-width: 580px) {
|
|
3199
|
-
.app-shell
|
|
3337
|
+
.app-shell,
|
|
3338
|
+
.app-shell.sidebar-collapsed {
|
|
3200
3339
|
grid-template-columns: 64px minmax(0, 1fr);
|
|
3201
3340
|
}
|
|
3202
3341
|
|
|
3342
|
+
.sidebar.collapsed {
|
|
3343
|
+
padding: 10px 7px;
|
|
3344
|
+
}
|
|
3345
|
+
|
|
3203
3346
|
.topbar {
|
|
3204
3347
|
min-height: 64px;
|
|
3205
3348
|
}
|
|
@@ -3221,6 +3364,10 @@ button.placeholder-item.active {
|
|
|
3221
3364
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
3222
3365
|
}
|
|
3223
3366
|
|
|
3367
|
+
.dashboard-share-row {
|
|
3368
|
+
grid-template-columns: minmax(0, 1fr);
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3224
3371
|
.chart-episodes {
|
|
3225
3372
|
grid-template-columns: 1fr;
|
|
3226
3373
|
}
|
|
@@ -20,7 +20,7 @@ DEFAULT_BACKEND_URL = "http://localhost:8000"
|
|
|
20
20
|
|
|
21
21
|
app = FastAPI(
|
|
22
22
|
title="GAARD Client",
|
|
23
|
-
version="0.2.
|
|
23
|
+
version="0.2.12",
|
|
24
24
|
description="Community client for asking governed natural-language questions.",
|
|
25
25
|
)
|
|
26
26
|
|
|
@@ -142,6 +142,16 @@ class ClientDashboardWidgetLayoutRequest(BaseModel):
|
|
|
142
142
|
backend_url: str | None = None
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
class ClientDashboardShareItem(BaseModel):
|
|
146
|
+
user_id: str = Field(min_length=1, max_length=255)
|
|
147
|
+
access_level: str = Field(pattern=r"^(view|edit)$")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class ClientDashboardShareUpdateRequest(BaseModel):
|
|
151
|
+
items: list[ClientDashboardShareItem] = Field(default_factory=list)
|
|
152
|
+
backend_url: str | None = None
|
|
153
|
+
|
|
154
|
+
|
|
145
155
|
def get_default_backend_url() -> str:
|
|
146
156
|
return os.getenv("GAARD_CLIENT_BACKEND_URL", DEFAULT_BACKEND_URL).rstrip("/")
|
|
147
157
|
|
|
@@ -734,6 +744,37 @@ async def list_dashboards(
|
|
|
734
744
|
return cast(dict[str, Any], response.json())
|
|
735
745
|
|
|
736
746
|
|
|
747
|
+
@app.get("/api/dashboard-users")
|
|
748
|
+
async def list_dashboard_users(
|
|
749
|
+
backend_url: str | None = None,
|
|
750
|
+
authorization: str | None = Header(default=None),
|
|
751
|
+
) -> dict[str, Any]:
|
|
752
|
+
backend_url = normalize_backend_url(backend_url or get_default_backend_url())
|
|
753
|
+
users_url = f"{backend_url}/api/v1/dashboards/share-users"
|
|
754
|
+
|
|
755
|
+
try:
|
|
756
|
+
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
757
|
+
response = await client.get(
|
|
758
|
+
users_url,
|
|
759
|
+
headers=backend_auth_headers(authorization),
|
|
760
|
+
)
|
|
761
|
+
except httpx.HTTPError as exc:
|
|
762
|
+
raise HTTPException(
|
|
763
|
+
status_code=502,
|
|
764
|
+
detail=f"Backend request failed: {exc}",
|
|
765
|
+
) from exc
|
|
766
|
+
|
|
767
|
+
if response.status_code >= 400:
|
|
768
|
+
raise HTTPException(
|
|
769
|
+
status_code=response.status_code,
|
|
770
|
+
detail=response.json()
|
|
771
|
+
if response.headers.get("content-type", "").startswith("application/json")
|
|
772
|
+
else response.text,
|
|
773
|
+
)
|
|
774
|
+
|
|
775
|
+
return cast(dict[str, Any], response.json())
|
|
776
|
+
|
|
777
|
+
|
|
737
778
|
@app.post("/api/dashboards")
|
|
738
779
|
async def create_dashboard(
|
|
739
780
|
request: ClientDashboardCreateRequest,
|
|
@@ -807,6 +848,73 @@ async def set_active_dashboard(
|
|
|
807
848
|
return cast(dict[str, Any], response.json())
|
|
808
849
|
|
|
809
850
|
|
|
851
|
+
@app.get("/api/dashboards/{dashboard_id}/shares")
|
|
852
|
+
async def get_dashboard_shares(
|
|
853
|
+
dashboard_id: str,
|
|
854
|
+
backend_url: str | None = None,
|
|
855
|
+
authorization: str | None = Header(default=None),
|
|
856
|
+
) -> dict[str, Any]:
|
|
857
|
+
backend_url = normalize_backend_url(backend_url or get_default_backend_url())
|
|
858
|
+
shares_url = f"{backend_url}/api/v1/dashboards/{dashboard_id}/shares"
|
|
859
|
+
|
|
860
|
+
try:
|
|
861
|
+
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
862
|
+
response = await client.get(
|
|
863
|
+
shares_url,
|
|
864
|
+
headers=backend_auth_headers(authorization),
|
|
865
|
+
)
|
|
866
|
+
except httpx.HTTPError as exc:
|
|
867
|
+
raise HTTPException(
|
|
868
|
+
status_code=502,
|
|
869
|
+
detail=f"Backend request failed: {exc}",
|
|
870
|
+
) from exc
|
|
871
|
+
|
|
872
|
+
if response.status_code >= 400:
|
|
873
|
+
raise HTTPException(
|
|
874
|
+
status_code=response.status_code,
|
|
875
|
+
detail=response.json()
|
|
876
|
+
if response.headers.get("content-type", "").startswith("application/json")
|
|
877
|
+
else response.text,
|
|
878
|
+
)
|
|
879
|
+
|
|
880
|
+
return cast(dict[str, Any], response.json())
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
@app.put("/api/dashboards/{dashboard_id}/shares")
|
|
884
|
+
async def update_dashboard_shares(
|
|
885
|
+
dashboard_id: str,
|
|
886
|
+
request: ClientDashboardShareUpdateRequest,
|
|
887
|
+
authorization: str | None = Header(default=None),
|
|
888
|
+
) -> dict[str, Any]:
|
|
889
|
+
backend_url = normalize_backend_url(request.backend_url or get_default_backend_url())
|
|
890
|
+
shares_url = f"{backend_url}/api/v1/dashboards/{dashboard_id}/shares"
|
|
891
|
+
|
|
892
|
+
try:
|
|
893
|
+
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
894
|
+
response = await client.put(
|
|
895
|
+
shares_url,
|
|
896
|
+
**backend_request_kwargs(
|
|
897
|
+
authorization,
|
|
898
|
+
{"items": [item.model_dump() for item in request.items]},
|
|
899
|
+
),
|
|
900
|
+
)
|
|
901
|
+
except httpx.HTTPError as exc:
|
|
902
|
+
raise HTTPException(
|
|
903
|
+
status_code=502,
|
|
904
|
+
detail=f"Backend request failed: {exc}",
|
|
905
|
+
) from exc
|
|
906
|
+
|
|
907
|
+
if response.status_code >= 400:
|
|
908
|
+
raise HTTPException(
|
|
909
|
+
status_code=response.status_code,
|
|
910
|
+
detail=response.json()
|
|
911
|
+
if response.headers.get("content-type", "").startswith("application/json")
|
|
912
|
+
else response.text,
|
|
913
|
+
)
|
|
914
|
+
|
|
915
|
+
return cast(dict[str, Any], response.json())
|
|
916
|
+
|
|
917
|
+
|
|
810
918
|
@app.put("/api/dashboards/{dashboard_id}")
|
|
811
919
|
async def update_dashboard(
|
|
812
920
|
dashboard_id: str,
|
|
@@ -36,8 +36,14 @@ def test_client_app_warns_when_response_uses_mock_modes() -> None:
|
|
|
36
36
|
assert "/api/dashboards" in response.text
|
|
37
37
|
assert "data-save-widget" in response.text
|
|
38
38
|
assert "data-toggle-dashboard-menu" in response.text
|
|
39
|
+
assert "data-toggle-sidebar" in response.text
|
|
40
|
+
assert "sidebar-collapsed" in response.text
|
|
39
41
|
assert "Add new dashboard" in response.text
|
|
40
42
|
assert "data-delete-dashboard" in response.text
|
|
43
|
+
assert "data-open-dashboard-share" in response.text
|
|
44
|
+
assert "Share dashboard" in response.text
|
|
45
|
+
assert "/api/dashboard-users" in response.text
|
|
46
|
+
assert "/shares" in response.text
|
|
41
47
|
assert "analysis-progress" in response.text
|
|
42
48
|
assert "analysis-log" in response.text
|
|
43
49
|
assert "analysis-reply-question" in response.text
|
|
@@ -127,6 +133,10 @@ def test_client_dashboard_edit_mode_styles() -> None:
|
|
|
127
133
|
assert "dashboard-edit-saving-spinner" in response.text
|
|
128
134
|
assert "dashboard-grid-readonly" in response.text
|
|
129
135
|
assert "ui-resizable-handle" in response.text
|
|
136
|
+
assert ".app-shell.sidebar-collapsed" in response.text
|
|
137
|
+
assert ".sidebar-toggle-button" in response.text
|
|
138
|
+
assert ".dashboard-share-dialog" in response.text
|
|
139
|
+
assert ".dashboard-share-row" in response.text
|
|
130
140
|
|
|
131
141
|
|
|
132
142
|
def test_client_dashboard_mobile_styles() -> None:
|
|
@@ -940,6 +950,72 @@ def test_client_app_proxies_dashboard_crud(monkeypatch: Any) -> None:
|
|
|
940
950
|
assert all(call["headers"] == headers for call in captured)
|
|
941
951
|
|
|
942
952
|
|
|
953
|
+
def test_client_app_proxies_dashboard_sharing(monkeypatch: Any) -> None:
|
|
954
|
+
captured: list[dict[str, object]] = []
|
|
955
|
+
|
|
956
|
+
class FakeAsyncClient:
|
|
957
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
958
|
+
pass
|
|
959
|
+
|
|
960
|
+
async def __aenter__(self) -> "FakeAsyncClient":
|
|
961
|
+
return self
|
|
962
|
+
|
|
963
|
+
async def __aexit__(self, exc_type: Any, exc: Any, traceback: Any) -> None:
|
|
964
|
+
pass
|
|
965
|
+
|
|
966
|
+
async def get(self, url: str, headers: Any = None) -> httpx.Response:
|
|
967
|
+
captured.append({"method": "GET", "url": url, "headers": headers})
|
|
968
|
+
request = httpx.Request("GET", url)
|
|
969
|
+
if url.endswith("/share-users"):
|
|
970
|
+
return httpx.Response(
|
|
971
|
+
status_code=200,
|
|
972
|
+
request=request,
|
|
973
|
+
json={"items": [{"user_id": "2", "username": "analyst"}]},
|
|
974
|
+
)
|
|
975
|
+
return httpx.Response(
|
|
976
|
+
status_code=200,
|
|
977
|
+
request=request,
|
|
978
|
+
json={"items": [{"user_id": "2", "access_level": "view"}]},
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
async def put(self, url: str, json: dict[str, Any], headers: Any = None) -> httpx.Response:
|
|
982
|
+
captured.append(
|
|
983
|
+
{"method": "PUT", "url": url, "json": json, "headers": headers}
|
|
984
|
+
)
|
|
985
|
+
request = httpx.Request("PUT", url)
|
|
986
|
+
return httpx.Response(status_code=200, request=request, json={"items": json["items"]})
|
|
987
|
+
|
|
988
|
+
monkeypatch.setattr(httpx, "AsyncClient", FakeAsyncClient)
|
|
989
|
+
client = TestClient(app)
|
|
990
|
+
headers = {"Authorization": "Bearer token"}
|
|
991
|
+
|
|
992
|
+
users_response = client.get(
|
|
993
|
+
"/api/dashboard-users?backend_url=http://backend.example/",
|
|
994
|
+
headers=headers,
|
|
995
|
+
)
|
|
996
|
+
shares_response = client.get(
|
|
997
|
+
"/api/dashboards/dash-1/shares?backend_url=http://backend.example/",
|
|
998
|
+
headers=headers,
|
|
999
|
+
)
|
|
1000
|
+
save_response = client.put(
|
|
1001
|
+
"/api/dashboards/dash-1/shares",
|
|
1002
|
+
headers=headers,
|
|
1003
|
+
json={
|
|
1004
|
+
"items": [{"user_id": "2", "access_level": "edit"}],
|
|
1005
|
+
"backend_url": "http://backend.example/",
|
|
1006
|
+
},
|
|
1007
|
+
)
|
|
1008
|
+
|
|
1009
|
+
assert users_response.status_code == 200
|
|
1010
|
+
assert shares_response.status_code == 200
|
|
1011
|
+
assert save_response.status_code == 200
|
|
1012
|
+
assert captured[0]["url"] == "http://backend.example/api/v1/dashboards/share-users"
|
|
1013
|
+
assert captured[1]["url"] == "http://backend.example/api/v1/dashboards/dash-1/shares"
|
|
1014
|
+
assert captured[2]["url"] == "http://backend.example/api/v1/dashboards/dash-1/shares"
|
|
1015
|
+
assert captured[2]["json"] == {"items": [{"user_id": "2", "access_level": "edit"}]}
|
|
1016
|
+
assert all(call["headers"] == headers for call in captured)
|
|
1017
|
+
|
|
1018
|
+
|
|
943
1019
|
def test_client_app_streams_analysis_user_question(monkeypatch: Any) -> None:
|
|
944
1020
|
captured: dict[str, Any] = {}
|
|
945
1021
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|