Просмотр исходного кода

Successfully displayed userdId in UI

utkarshcmu 10 лет назад
Родитель
Сommit
af371249f9

+ 3 - 2
pkg/api/dashboard.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"os"
 	"path"
+	"strconv"
 	"strings"
 
 	"github.com/grafana/grafana/pkg/api/dtos"
@@ -59,8 +60,7 @@ func GetDashboard(c *middleware.Context) {
 			CanEdit:   canEditDashboard(c.OrgRole),
 			Created:   dash.Created,
 			Updated:   dash.Updated,
-			CreatedBy: dash.CreatedBy,
-			UpdatedBy: dash.UpdatedBy,
+			UpdatedBy: strconv.FormatInt(dash.UpdatedBy, 10),
 		},
 	}
 
@@ -89,6 +89,7 @@ func DeleteDashboard(c *middleware.Context) {
 
 func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
 	cmd.OrgId = c.OrgId
+	cmd.UpdatedBy = c.UserId
 
 	dash := cmd.GetDashboardModel()
 	if dash.Id == 0 {

+ 3 - 7
pkg/models/dashboards.go

@@ -33,8 +33,7 @@ type Dashboard struct {
 	Created time.Time
 	Updated time.Time
 
-	CreatedBy string
-	UpdatedBy string
+	UpdatedBy int64
 
 	Title string
 	Data  map[string]interface{}
@@ -48,8 +47,6 @@ func NewDashboard(title string) *Dashboard {
 	dash.Title = title
 	dash.Created = time.Now()
 	dash.Updated = time.Now()
-	// TODO:dash.CreatedBy = "Creator"
-	// TODO:dash.UpdatedBy = "Creator"
 	dash.UpdateSlug()
 	return dash
 }
@@ -81,14 +78,11 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard {
 		if dash.Data["version"] != nil {
 			dash.Version = int(dash.Data["version"].(float64))
 			dash.Updated = time.Now()
-			// TODO:dash.UpdatedBy = "Updater"
 		}
 	} else {
 		dash.Data["version"] = 0
 		dash.Created = time.Now()
 		dash.Updated = time.Now()
-		// TODO:dash.CreatedBy = "Creator"
-		// TODO:dash.UpdatedBy = "Creator"
 	}
 
 	return dash
@@ -98,6 +92,7 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard {
 func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
 	dash := NewDashboardFromJson(cmd.Dashboard)
 	dash.OrgId = cmd.OrgId
+  dash.UpdatedBy = cmd.UpdatedBy
 	dash.UpdateSlug()
 	return dash
 }
@@ -121,6 +116,7 @@ type SaveDashboardCommand struct {
 	Dashboard map[string]interface{} `json:"dashboard" binding:"Required"`
 	Overwrite bool                   `json:"overwrite"`
 	OrgId     int64                  `json:"-"`
+  UpdatedBy int64                  `json:"-"`
 
 	Result *Dashboard
 }

+ 1 - 6
pkg/services/sqlstore/migrations/dashboard_mig.go

@@ -93,13 +93,8 @@ func addDashboardMigration(mg *Migrator) {
 		Postgres("SELECT 0;").
 		Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;"))
 
-	// 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_NVarchar, Length: 255, Nullable: false, Default: "Anonymous",
-	}))
-
 	// add column to store updater of a dashboard
 	mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{
-		Name: "updated_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous",
+		Name: "updated_by", Type: DB_Int, Nullable: true,
 	}))
 }

+ 0 - 1
pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go

@@ -54,5 +54,4 @@ func addDashboardSnapshotMigrations(mg *Migrator) {
 		Sqlite("SELECT 0 WHERE 0;").
 		Postgres("SELECT 0;").
 		Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;"))
-
 }

+ 5 - 16
public/app/features/dashboard/partials/settings.html

@@ -117,7 +117,7 @@
   <div ng-if="editor.index == 4">
     <div class="editor-row">
       <div class="tight-form-section">
-        <h5>Info</h5>
+        <h5>Dashboard info</h5>
         <div class="tight-form">
           <ul class="tight-form-list">
             <li class="tight-form-item" style="width: 120px">
@@ -129,17 +129,6 @@
           </ul>
           <div class="clearfix"></div>
         </div>
-        <div class="tight-form">
-          <ul class="tight-form-list">
-            <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 last">
           <ul class="tight-form-list">
             <li class="tight-form-item" style="width: 120px">
@@ -151,14 +140,14 @@
           </ul>
           <div class="clearfix"></div>
         </div>
-        <div class="tight-form last">
+        <div class="tight-form">
           <ul class="tight-form-list">
             <li class="tight-form-item" style="width: 120px">
-              Created by:
+              Last updated by:
             </li>
             <li class="tight-form-item" style="width: 180px">
-              {{dashboardMeta.createdBy}}
-           </li>
+              {{dashboardMeta.updatedBy}}
+            </li>
           </ul>
           <div class="clearfix"></div>
         </div>