Merge pull request #3918 from utkarshcmu/metadata

Added metadata fields under Settings tab
This commit is contained in:
Torkel Ödegaard
2016-02-05 08:47:57 +01:00
6 changed files with 73 additions and 31 deletions
+22 -13
View File
@@ -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()
+2
View File
@@ -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 {