|
|
|
@ -23,6 +23,7 @@ class DashboardWatcher { |
|
|
|
|
uid?: string; |
|
|
|
|
ignoreSave?: boolean; |
|
|
|
|
editing = false; |
|
|
|
|
lastEditing?: DashboardEvent; |
|
|
|
|
|
|
|
|
|
setEditingState(state: boolean) { |
|
|
|
|
const changed = (this.editing = state); |
|
|
|
@ -42,7 +43,8 @@ class DashboardWatcher { |
|
|
|
|
sessionId, |
|
|
|
|
uid: this.uid!, |
|
|
|
|
action: this.editing ? DashboardEventAction.EditingStarted : DashboardEventAction.EditingCanceled, |
|
|
|
|
message: 'user (name)', |
|
|
|
|
message: (window as any).grafanaBootData?.user?.name, |
|
|
|
|
timestamp: Date.now(), |
|
|
|
|
}; |
|
|
|
|
this.channel!.publish!(msg); |
|
|
|
|
} |
|
|
|
@ -79,6 +81,16 @@ class DashboardWatcher { |
|
|
|
|
this.ignoreSave = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getRecentEditingEvent() { |
|
|
|
|
if (this.lastEditing && this.lastEditing.timestamp) { |
|
|
|
|
const elapsed = Date.now() - this.lastEditing.timestamp; |
|
|
|
|
if (elapsed > 5000) { |
|
|
|
|
this.lastEditing = undefined; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return this.lastEditing; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
observer = { |
|
|
|
|
next: (event: LiveChannelEvent<DashboardEvent>) => { |
|
|
|
|
// Send the editing state when connection starts
|
|
|
|
@ -121,10 +133,15 @@ class DashboardWatcher { |
|
|
|
|
} |
|
|
|
|
} else if (showPopup) { |
|
|
|
|
if (action === DashboardEventAction.EditingStarted) { |
|
|
|
|
appEvents.emit(AppEvents.alertWarning, [ |
|
|
|
|
'Another session is editing this dashboard', |
|
|
|
|
event.message.message, |
|
|
|
|
]); |
|
|
|
|
const editingEvent = event.message; |
|
|
|
|
const recent = this.getRecentEditingEvent(); |
|
|
|
|
if (!recent || recent.message !== editingEvent.message) { |
|
|
|
|
appEvents.emit(AppEvents.alertWarning, [ |
|
|
|
|
'Another session is editing this dashboard', |
|
|
|
|
editingEvent.message, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
this.lastEditing = editingEvent; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|