mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Wip: First naive impl * Chore: fix after merge * Chore: changes after PR comments * Chore: removes unused types * Chore: adds feature toggle * Refactor: adds library panels cleanup and connect when storing dashboards * Refactor: adds feature toggle * Update pkg/services/librarypanels/librarypanels.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Refactor: adds disconnect library panels when deleting a dashboard * Chore: changes after PR comments * Tests: adds tests for LoadLibraryPanelsForDashboard * Tests: adds tests for CleanLibraryPanelsForDashboard * Tests: adds tests for ConnectLibraryPanelsForDashboard * Tests: adds tests for DisconnectLibraryPanelsForDashboard and small refactor * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/librarypanels/librarypanels_test.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Refactor: deletes all connections in one call and connects all in the same transaction * Chore: adds better comments * Chore: changes after PR comments Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package librarypanels
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// LibraryPanel is the model for library panel definitions.
|
|
type LibraryPanel struct {
|
|
ID int64 `xorm:"pk autoincr 'id'"`
|
|
OrgID int64 `xorm:"org_id"`
|
|
FolderID int64 `xorm:"folder_id"`
|
|
UID string `xorm:"uid"`
|
|
Name string
|
|
Model json.RawMessage
|
|
|
|
Created time.Time
|
|
Updated time.Time
|
|
|
|
CreatedBy int64
|
|
UpdatedBy int64
|
|
}
|
|
|
|
// libraryPanelDashboard is the model for library panel connections.
|
|
type libraryPanelDashboard struct {
|
|
ID int64 `xorm:"pk autoincr 'id'"`
|
|
LibraryPanelID int64 `xorm:"librarypanel_id"`
|
|
DashboardID int64 `xorm:"dashboard_id"`
|
|
|
|
Created time.Time
|
|
|
|
CreatedBy int64
|
|
}
|
|
|
|
var (
|
|
// errLibraryPanelAlreadyExists is an error for when the user tries to add a library panel that already exists.
|
|
errLibraryPanelAlreadyExists = errors.New("library panel with that name already exists")
|
|
// errLibraryPanelNotFound is an error for when a library panel can't be found.
|
|
errLibraryPanelNotFound = errors.New("library panel could not be found")
|
|
// errLibraryPanelDashboardNotFound is an error for when a library panel connection can't be found.
|
|
errLibraryPanelDashboardNotFound = errors.New("library panel connection could not be found")
|
|
// errLibraryPanelHeaderUIDMissing is an error for when a library panel header is missing the uid property.
|
|
errLibraryPanelHeaderUIDMissing = errors.New("library panel header is missing required property uid")
|
|
// errLibraryPanelHeaderNameMissing is an error for when a library panel header is missing the name property.
|
|
errLibraryPanelHeaderNameMissing = errors.New("library panel header is missing required property name")
|
|
)
|
|
|
|
// Commands
|
|
|
|
// createLibraryPanelCommand is the command for adding a LibraryPanel
|
|
type createLibraryPanelCommand struct {
|
|
FolderID int64 `json:"folderId"`
|
|
Name string `json:"name"`
|
|
Model json.RawMessage `json:"model"`
|
|
}
|
|
|
|
// patchLibraryPanelCommand is the command for patching a LibraryPanel
|
|
type patchLibraryPanelCommand struct {
|
|
FolderID int64 `json:"folderId"`
|
|
Name string `json:"name"`
|
|
Model json.RawMessage `json:"model"`
|
|
}
|