mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #3918 from utkarshcmu/metadata
Added metadata fields under Settings tab
This commit is contained in:
commit
db27bbb162
@ -75,7 +75,7 @@ Creates a new dashboard or updates an existing dashboard.
|
||||
|
||||
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.
|
||||
|
||||
**Example Response**:
|
||||
|
@ -49,17 +49,13 @@ func GetDashboard(c *middleware.Context) {
|
||||
|
||||
dash := query.Result
|
||||
|
||||
// Finding the last updater of the dashboard
|
||||
updater := "Anonymous"
|
||||
if dash.UpdatedBy != 0 {
|
||||
userQuery := m.GetUserByIdQuery{Id: dash.UpdatedBy}
|
||||
userErr := bus.Dispatch(&userQuery)
|
||||
if userErr != nil {
|
||||
updater = "Unknown"
|
||||
} else {
|
||||
user := userQuery.Result
|
||||
updater = user.Login
|
||||
}
|
||||
// Finding creator and last updater of the dashboard
|
||||
updater, creator := "Anonymous", "Anonymous"
|
||||
if dash.UpdatedBy > 0 {
|
||||
updater = getUserLogin(dash.UpdatedBy)
|
||||
}
|
||||
if dash.CreatedBy > 0 {
|
||||
creator = getUserLogin(dash.CreatedBy)
|
||||
}
|
||||
|
||||
dto := dtos.DashboardFullWithMeta{
|
||||
@ -74,12 +70,25 @@ func GetDashboard(c *middleware.Context) {
|
||||
Created: dash.Created,
|
||||
Updated: dash.Updated,
|
||||
UpdatedBy: updater,
|
||||
CreatedBy: creator,
|
||||
Version: dash.Version,
|
||||
},
|
||||
}
|
||||
|
||||
c.JSON(200, dto)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteDashboard(c *middleware.Context) {
|
||||
slug := c.Params(":slug")
|
||||
|
||||
@ -104,9 +113,9 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
|
||||
cmd.OrgId = c.OrgId
|
||||
|
||||
if !c.IsSignedIn {
|
||||
cmd.UpdatedBy = 0
|
||||
cmd.UserId = -1
|
||||
} else {
|
||||
cmd.UpdatedBy = c.UserId
|
||||
cmd.UserId = c.UserId
|
||||
}
|
||||
|
||||
dash := cmd.GetDashboardModel()
|
||||
|
@ -42,6 +42,8 @@ type DashboardMeta struct {
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
Version int `json:"version"`
|
||||
}
|
||||
|
||||
type DashboardFullWithMeta struct {
|
||||
|
@ -34,6 +34,7 @@ type Dashboard struct {
|
||||
Updated time.Time
|
||||
|
||||
UpdatedBy int64
|
||||
CreatedBy int64
|
||||
|
||||
Title string
|
||||
Data map[string]interface{}
|
||||
@ -91,8 +92,11 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard {
|
||||
// GetDashboardModel turns the command into the savable model
|
||||
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.UpdatedBy = cmd.UpdatedBy
|
||||
dash.UpdateSlug()
|
||||
return dash
|
||||
}
|
||||
@ -114,9 +118,9 @@ func (dash *Dashboard) UpdateSlug() {
|
||||
|
||||
type SaveDashboardCommand struct {
|
||||
Dashboard map[string]interface{} `json:"dashboard" binding:"Required"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
UserId int64 `json:"userId"`
|
||||
OrgId int64 `json:"-"`
|
||||
UpdatedBy int64 `json:"-"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
|
||||
Result *Dashboard
|
||||
}
|
||||
|
@ -97,4 +97,9 @@ func addDashboardMigration(mg *Migrator) {
|
||||
mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
|
||||
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,
|
||||
}))
|
||||
}
|
||||
|
@ -115,9 +115,9 @@
|
||||
</div>
|
||||
|
||||
<div ng-if="editor.index == 4">
|
||||
<div class="editor-row">
|
||||
<div class="tight-form-section">
|
||||
<h5>Dashboard info</h5>
|
||||
<div class="row">
|
||||
<h5>Dashboard info</h5>
|
||||
<div class="pull-left tight-form">
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 120px">
|
||||
@ -130,17 +130,6 @@
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 120px">
|
||||
Created at:
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 180px">
|
||||
{{formatDate(dashboardMeta.created)}}
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form last">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 120px">
|
||||
Last updated by:
|
||||
@ -150,6 +139,39 @@
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 120px">
|
||||
Created at:
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 180px">
|
||||
{{formatDate(dashboardMeta.created)}}
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 120px">
|
||||
Created by:
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 180px">
|
||||
{{dashboardMeta.createdBy}}
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 120px">
|
||||
Current version:
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 180px">
|
||||
{{dashboardMeta.version}}
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user