Browse Source

Added createdBy in metadata ui and dashboard table

utkarshcmu 10 years ago
parent
commit
753fd164d7

+ 1 - 0
pkg/api/dtos/models.go

@@ -42,6 +42,7 @@ type DashboardMeta struct {
 	Created    time.Time `json:"created"`
 	Updated    time.Time `json:"updated"`
 	UpdatedBy  string    `json:"updatedBy"`
+  CreatedBy  string    `json:"createdBy"`
 }
 
 type DashboardFullWithMeta struct {

+ 9 - 5
pkg/models/dashboards.go

@@ -34,6 +34,7 @@ type Dashboard struct {
 	Updated time.Time
 
 	UpdatedBy int64
+  CreatedBy int64
 
 	Title string
 	Data  map[string]interface{}
@@ -66,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)
@@ -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)
-	dash.OrgId = cmd.OrgId
-	dash.UpdatedBy = cmd.UpdatedBy
+	if dash.Data["version"] == 0 {
+    dash.CreatedBy = cmd.UserId
+  }
+  dash.UpdatedBy = cmd.UserId
+  dash.OrgId = cmd.OrgId
 	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
 }

+ 5 - 0
pkg/services/sqlstore/migrations/dashboard_mig.go

@@ -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,
+  }))
 }

+ 11 - 0
public/app/features/dashboard/partials/settings.html

@@ -151,6 +151,17 @@
           </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>
     </div>
   </div>