Commit db27bbb1 by Torkel Ödegaard

Merge pull request #3918 from utkarshcmu/metadata

Added metadata fields under Settings tab
parents 1bce8f66 59a384b4
...@@ -75,7 +75,7 @@ Creates a new dashboard or updates an existing dashboard. ...@@ -75,7 +75,7 @@ Creates a new dashboard or updates an existing dashboard.
JSON Body schema: 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. - **overwrite** – Set to true if you want to overwrite existing dashboard with newer version or with same dashboard title.
**Example Response**: **Example Response**:
......
...@@ -49,17 +49,13 @@ func GetDashboard(c *middleware.Context) { ...@@ -49,17 +49,13 @@ func GetDashboard(c *middleware.Context) {
dash := query.Result dash := query.Result
// Finding the last updater of the dashboard // Finding creator and last updater of the dashboard
updater := "Anonymous" updater, creator := "Anonymous", "Anonymous"
if dash.UpdatedBy != 0 { if dash.UpdatedBy > 0 {
userQuery := m.GetUserByIdQuery{Id: dash.UpdatedBy} updater = getUserLogin(dash.UpdatedBy)
userErr := bus.Dispatch(&userQuery) }
if userErr != nil { if dash.CreatedBy > 0 {
updater = "Unknown" creator = getUserLogin(dash.CreatedBy)
} else {
user := userQuery.Result
updater = user.Login
}
} }
dto := dtos.DashboardFullWithMeta{ dto := dtos.DashboardFullWithMeta{
...@@ -74,12 +70,25 @@ func GetDashboard(c *middleware.Context) { ...@@ -74,12 +70,25 @@ func GetDashboard(c *middleware.Context) {
Created: dash.Created, Created: dash.Created,
Updated: dash.Updated, Updated: dash.Updated,
UpdatedBy: updater, UpdatedBy: updater,
CreatedBy: creator,
Version: dash.Version,
}, },
} }
c.JSON(200, dto) 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) { func DeleteDashboard(c *middleware.Context) {
slug := c.Params(":slug") slug := c.Params(":slug")
...@@ -104,9 +113,9 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) { ...@@ -104,9 +113,9 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
if !c.IsSignedIn { if !c.IsSignedIn {
cmd.UpdatedBy = 0 cmd.UserId = -1
} else { } else {
cmd.UpdatedBy = c.UserId cmd.UserId = c.UserId
} }
dash := cmd.GetDashboardModel() dash := cmd.GetDashboardModel()
......
...@@ -42,6 +42,8 @@ type DashboardMeta struct { ...@@ -42,6 +42,8 @@ type DashboardMeta struct {
Created time.Time `json:"created"` Created time.Time `json:"created"`
Updated time.Time `json:"updated"` Updated time.Time `json:"updated"`
UpdatedBy string `json:"updatedBy"` UpdatedBy string `json:"updatedBy"`
CreatedBy string `json:"createdBy"`
Version int `json:"version"`
} }
type DashboardFullWithMeta struct { type DashboardFullWithMeta struct {
......
...@@ -34,6 +34,7 @@ type Dashboard struct { ...@@ -34,6 +34,7 @@ type Dashboard struct {
Updated time.Time Updated time.Time
UpdatedBy int64 UpdatedBy int64
CreatedBy int64
Title string Title string
Data map[string]interface{} Data map[string]interface{}
...@@ -91,8 +92,11 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { ...@@ -91,8 +92,11 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard {
// GetDashboardModel turns the command into the savable model // GetDashboardModel turns the command into the savable model
func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard { func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
dash := NewDashboardFromJson(cmd.Dashboard) dash := NewDashboardFromJson(cmd.Dashboard)
if dash.Data["version"] == 0 {
dash.CreatedBy = cmd.UserId
}
dash.UpdatedBy = cmd.UserId
dash.OrgId = cmd.OrgId dash.OrgId = cmd.OrgId
dash.UpdatedBy = cmd.UpdatedBy
dash.UpdateSlug() dash.UpdateSlug()
return dash return dash
} }
...@@ -114,9 +118,9 @@ func (dash *Dashboard) UpdateSlug() { ...@@ -114,9 +118,9 @@ func (dash *Dashboard) UpdateSlug() {
type SaveDashboardCommand struct { type SaveDashboardCommand struct {
Dashboard map[string]interface{} `json:"dashboard" binding:"Required"` Dashboard map[string]interface{} `json:"dashboard" binding:"Required"`
Overwrite bool `json:"overwrite"` UserId int64 `json:"userId"`
OrgId int64 `json:"-"` OrgId int64 `json:"-"`
UpdatedBy int64 `json:"-"` Overwrite bool `json:"overwrite"`
Result *Dashboard Result *Dashboard
} }
......
...@@ -97,4 +97,9 @@ func addDashboardMigration(mg *Migrator) { ...@@ -97,4 +97,9 @@ func addDashboardMigration(mg *Migrator) {
mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
Name: "updated_by", Type: DB_Int, Nullable: true, 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 @@ ...@@ -115,9 +115,9 @@
</div> </div>
<div ng-if="editor.index == 4"> <div ng-if="editor.index == 4">
<div class="editor-row"> <div class="row">
<div class="tight-form-section"> <h5>Dashboard info</h5>
<h5>Dashboard info</h5> <div class="pull-left tight-form">
<div class="tight-form"> <div class="tight-form">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 120px"> <li class="tight-form-item" style="width: 120px">
...@@ -132,21 +132,43 @@ ...@@ -132,21 +132,43 @@
<div class="tight-form"> <div class="tight-form">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 120px"> <li class="tight-form-item" style="width: 120px">
Last updated by:
</li>
<li class="tight-form-item" style="width: 180px">
{{dashboardMeta.updatedBy}}
</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: Created at:
</li> </li>
<li class="tight-form-item" style="width: 180px"> <li class="tight-form-item" style="width: 180px">
{{formatDate(dashboardMeta.created)}} {{formatDate(dashboardMeta.created)}}
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div class="tight-form last"> <div class="tight-form">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 120px"> <li class="tight-form-item" style="width: 120px">
Last updated by: Created by:
</li> </li>
<li class="tight-form-item" style="width: 180px"> <li class="tight-form-item" style="width: 180px">
{{dashboardMeta.updatedBy}} {{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> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment