-
Notifications
You must be signed in to change notification settings - Fork 4
Copilot/add snapshot functionality #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| export interface SnapshotConnection { | ||
| srcDev: any; | ||
| src: any; | ||
| dstDev: any; | ||
| dst: any; | ||
| } | ||
|
|
||
| export interface Snapshot { | ||
| id: string; | ||
| name: string; | ||
| timestamp: number; | ||
| connections: SnapshotConnection[]; | ||
| } | ||
|
|
||
| const STORAGE_KEY = 'nmos_crosspoint_snapshots'; | ||
|
|
||
| class _SnapshotService { | ||
| saveSnapshot(name: string, connections: SnapshotConnection[]): Snapshot { | ||
| const snapshot: Snapshot = { | ||
| id: crypto.randomUUID(), | ||
| name, | ||
| timestamp: Date.now(), | ||
| connections: structuredClone(connections) | ||
| }; | ||
|
|
||
| const snapshots = this.getAllSnapshots(); | ||
| snapshots.push(snapshot); | ||
| localStorage.setItem(STORAGE_KEY, JSON.stringify(snapshots)); | ||
|
|
||
| return snapshot; | ||
| } | ||
|
|
||
| getAllSnapshots(): Snapshot[] { | ||
| try { | ||
| const data = localStorage.getItem(STORAGE_KEY); | ||
| if (data) { | ||
| return JSON.parse(data); | ||
| } | ||
| } catch (e) { | ||
| console.error('Error loading snapshots:', e); | ||
| } | ||
| return []; | ||
| } | ||
|
|
||
| getSnapshot(id: string): Snapshot | null { | ||
| const snapshots = this.getAllSnapshots(); | ||
| const filtered = snapshots.filter(s => s.id === id); | ||
| return filtered.length > 0 ? filtered[0] : null; | ||
| } | ||
|
|
||
| deleteSnapshot(id: string): void { | ||
| const snapshots = this.getAllSnapshots(); | ||
| const filtered = snapshots.filter(s => s.id !== id); | ||
| localStorage.setItem(STORAGE_KEY, JSON.stringify(filtered)); | ||
| } | ||
| } | ||
|
|
||
| const SnapshotService = new _SnapshotService(); | ||
| export default SnapshotService; | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,9 +5,10 @@ | |||||||||
| import { onDestroy, onMount } from "svelte"; | ||||||||||
| import { createEventDispatcher } from 'svelte'; | ||||||||||
|
|
||||||||||
| import { Icon, ChevronRight, VideoCamera, Microphone, CodeBracketSquare, MagnifyingGlass, SpeakerWave, Tv,Pencil, Eye, EyeSlash, Link, InformationCircle } from "svelte-hero-icons"; | ||||||||||
| import { Icon, ChevronRight, VideoCamera, Microphone, CodeBracketSquare, MagnifyingGlass, SpeakerWave, Tv,Pencil, Eye, EyeSlash, Link, InformationCircle, Camera, ArrowUturnLeft } from "svelte-hero-icons"; | ||||||||||
| import { getSearchTokens, tokenSearch } from "../lib/functions"; | ||||||||||
| import OverlayMenuService from "../lib/OverlayMenu/OverlayMenuService"; | ||||||||||
| import SnapshotService, { type Snapshot } from "../lib/SnapshotService"; | ||||||||||
|
|
||||||||||
| interface CrosspointConnect { | ||||||||||
| source:string, | ||||||||||
|
|
@@ -40,6 +41,14 @@ | |||||||||
|
|
||||||||||
| let sync:Subject<any> ; | ||||||||||
|
|
||||||||||
| // Snapshot state variables | ||||||||||
| let snapshots: Snapshot[] = []; | ||||||||||
| let snapshotName: string = ""; | ||||||||||
| let showSnapshotDialog: boolean = false; | ||||||||||
| let showRecallDialog: boolean = false; | ||||||||||
| let saveSnapshotModal: any; | ||||||||||
| let recallSnapshotModal: any; | ||||||||||
|
|
||||||||||
| let flowTypes = ["video", "audio", "data", "mqtt", "websocket", "audiochannel", "unknown"]; | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
@@ -97,6 +106,9 @@ | |||||||||
| } | ||||||||||
| }catch(e){} | ||||||||||
|
|
||||||||||
| // Load snapshots | ||||||||||
| loadSnapshots(); | ||||||||||
|
|
||||||||||
| sync = ServerConnector.sync("crosspoint"); | ||||||||||
| sync.subscribe((obj:any)=>{ | ||||||||||
| sourceState = obj; | ||||||||||
|
|
@@ -772,6 +784,122 @@ | |||||||||
| labelModal.close() | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Snapshot functions | ||||||||||
| function loadSnapshots() { | ||||||||||
| snapshots = SnapshotService.getAllSnapshots(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function openSaveSnapshotDialog() { | ||||||||||
| if (preparedConnectList.length === 0) { | ||||||||||
| ServerConnector.addFeedback({ | ||||||||||
| message: "No connections to save. Prepare connections first.", | ||||||||||
| level: "warning" | ||||||||||
| }); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| const now = new Date(); | ||||||||||
| snapshotName = `Snapshot ${now.toLocaleDateString()} ${now.toLocaleTimeString()}`; | ||||||||||
| saveSnapshotModal.showModal(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function saveCurrentSnapshot() { | ||||||||||
| if (snapshotName.trim() === "") { | ||||||||||
| ServerConnector.addFeedback({ | ||||||||||
| message: "Please enter a snapshot name", | ||||||||||
| level: "warning" | ||||||||||
| }); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| SnapshotService.saveSnapshot(snapshotName, preparedConnectList); | ||||||||||
| loadSnapshots(); | ||||||||||
| saveSnapshotModal.close(); | ||||||||||
| ServerConnector.addFeedback({ | ||||||||||
| message: `Snapshot "${snapshotName}" saved successfully`, | ||||||||||
| level: "success" | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function openRecallDialog() { | ||||||||||
| loadSnapshots(); | ||||||||||
| recallSnapshotModal.showModal(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function recallSnapshot(snapshotId: string) { | ||||||||||
| const snapshot = SnapshotService.getSnapshot(snapshotId); | ||||||||||
| if (!snapshot) { | ||||||||||
| ServerConnector.addFeedback({ | ||||||||||
| message: "Snapshot not found", | ||||||||||
| level: "error" | ||||||||||
| }); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Clear current prepared connections | ||||||||||
| preparedConnectList = []; | ||||||||||
|
|
||||||||||
| // Recall each connection from the snapshot | ||||||||||
| let recallPromises: Promise<any>[] = []; | ||||||||||
|
||||||||||
| snapshot.connections.forEach((conn) => { | ||||||||||
| let srcString = getDevcieNameString(conn.srcDev, conn.src); | ||||||||||
| let dstString = getDevcieNameString(conn.dstDev, conn.dst); | ||||||||||
|
Comment on lines
+843
to
+844
|
||||||||||
| let srcString = getDevcieNameString(conn.srcDev, conn.src); | |
| let dstString = getDevcieNameString(conn.dstDev, conn.dst); | |
| let srcString = getDeviceNameString(conn.srcDev, conn.src); | |
| let dstString = getDeviceNameString(conn.dstDev, conn.dst); |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keyCode property is deprecated. Use e.key === 'Enter' instead for better browser compatibility and adherence to modern standards.
| on:keypress={(e)=>{if(e.keyCode == 13) saveCurrentSnapshot()}} | |
| on:keypress={(e)=>{if(e.key === 'Enter') saveCurrentSnapshot()}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
anytype removes type safety. Consider defining more specific types for these connection properties based on the actual data structure used in the application.