mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Updated http_api docs
This commit is contained in:
parent
6a1192172d
commit
58121d89fc
@ -70,13 +70,15 @@ Creates a new dashboard or updates an existing dashboard.
|
||||
"schemaVersion": 6,
|
||||
"version": 0
|
||||
},
|
||||
"overwrite": false
|
||||
"overwrite": false,
|
||||
"userId:": 3
|
||||
}
|
||||
|
||||
JSON Body schema:
|
||||
|
||||
- **dashboard** – The complete dashboard model, id = null to create a new dashboard
|
||||
- **dashboard** – The complete dashboard model, id = null to create a new dashboard.
|
||||
- **overwrite** – Set to true if you want to overwrite existing dashboard with newer version or with same dashboard title.
|
||||
- **userId** - Set userId if you want to record who created or updated a dashboard.
|
||||
|
||||
**Example Response**:
|
||||
|
||||
|
@ -52,11 +52,11 @@ func GetDashboard(c *middleware.Context) {
|
||||
// Finding the last creator and updater of the dashboard
|
||||
updater, creator := "Anonymous", "Anonymous"
|
||||
if dash.UpdatedBy > 0 {
|
||||
updater = getUserLogin(dash.UpdatedBy)
|
||||
}
|
||||
if dash.CreatedBy > 0 {
|
||||
creator = getUserLogin(dash.CreatedBy)
|
||||
}
|
||||
updater = getUserLogin(dash.UpdatedBy)
|
||||
}
|
||||
if dash.CreatedBy > 0 {
|
||||
creator = getUserLogin(dash.CreatedBy)
|
||||
}
|
||||
|
||||
dto := dtos.DashboardFullWithMeta{
|
||||
Dashboard: dash.Data,
|
||||
@ -70,7 +70,7 @@ func GetDashboard(c *middleware.Context) {
|
||||
Created: dash.Created,
|
||||
Updated: dash.Updated,
|
||||
UpdatedBy: updater,
|
||||
CreatedBy: creator,
|
||||
CreatedBy: creator,
|
||||
},
|
||||
}
|
||||
|
||||
@ -78,14 +78,14 @@ func GetDashboard(c *middleware.Context) {
|
||||
}
|
||||
|
||||
func getUserLogin(userId int64) string {
|
||||
query := m.GetUserByIdQuery{Id: userId}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
return "Anonymous"
|
||||
} else {
|
||||
user := query.Result
|
||||
return user.Login
|
||||
}
|
||||
query := m.GetUserByIdQuery{Id: userId}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
return "Anonymous"
|
||||
} else {
|
||||
user := query.Result
|
||||
return user.Login
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteDashboard(c *middleware.Context) {
|
||||
@ -114,8 +114,8 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
|
||||
if !c.IsSignedIn {
|
||||
cmd.UserId = -1
|
||||
} else {
|
||||
cmd.UserId = c.UserId
|
||||
}
|
||||
cmd.UserId = c.UserId
|
||||
}
|
||||
|
||||
dash := cmd.GetDashboardModel()
|
||||
if dash.Id == 0 {
|
||||
|
@ -42,7 +42,7 @@ type DashboardMeta struct {
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
}
|
||||
|
||||
type DashboardFullWithMeta struct {
|
||||
|
@ -34,7 +34,7 @@ type Dashboard struct {
|
||||
Updated time.Time
|
||||
|
||||
UpdatedBy int64
|
||||
CreatedBy int64
|
||||
CreatedBy int64
|
||||
|
||||
Title string
|
||||
Data map[string]interface{}
|
||||
@ -67,7 +67,7 @@ func (dash *Dashboard) GetTags() []string {
|
||||
return b
|
||||
}
|
||||
|
||||
func NewDashboardFromJson(data map[string]interface {}) *Dashboard {
|
||||
func NewDashboardFromJson(data map[string]interface{}) *Dashboard {
|
||||
dash := &Dashboard{}
|
||||
dash.Data = data
|
||||
dash.Title = dash.Data["title"].(string)
|
||||
@ -93,10 +93,10 @@ func NewDashboardFromJson(data map[string]interface {}) *Dashboard {
|
||||
func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
|
||||
dash := NewDashboardFromJson(cmd.Dashboard)
|
||||
if dash.Data["version"] == 0 {
|
||||
dash.CreatedBy = cmd.UserId
|
||||
}
|
||||
dash.UpdatedBy = cmd.UserId
|
||||
dash.OrgId = cmd.OrgId
|
||||
dash.CreatedBy = cmd.UserId
|
||||
}
|
||||
dash.UpdatedBy = cmd.UserId
|
||||
dash.OrgId = cmd.OrgId
|
||||
dash.UpdateSlug()
|
||||
return dash
|
||||
}
|
||||
@ -118,9 +118,9 @@ func (dash *Dashboard) UpdateSlug() {
|
||||
|
||||
type SaveDashboardCommand struct {
|
||||
Dashboard map[string]interface{} `json:"dashboard" binding:"Required"`
|
||||
UserId int64 `json:"userId"`
|
||||
UserId int64 `json:"userId"`
|
||||
OrgId int64 `json:"-"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
|
||||
Result *Dashboard
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ func addDashboardMigration(mg *Migrator) {
|
||||
Name: "updated_by", Type: DB_Int, Nullable: true,
|
||||
}))
|
||||
|
||||
// add column to store creator of a dashboard
|
||||
mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
|
||||
Name: "created_by", Type: DB_Int, Nullable: true,
|
||||
}))
|
||||
// add column to store creator of a dashboard
|
||||
mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
|
||||
Name: "created_by", Type: DB_Int, Nullable: true,
|
||||
}))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user