diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 6b19224f934..610f29e70aa 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -29,6 +29,7 @@ type Dashboard struct { Id int64 Slug string OrgId int64 + GnetId int64 Version int Created time.Time @@ -77,6 +78,10 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard { dash.Updated = time.Now() } + if gnetId, err := dash.Data.Get("gnetId").Float64(); err == nil { + dash.GnetId = int64(gnetId) + } + return dash } diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index a4a8629b331..536b153c6c9 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -102,4 +102,9 @@ func addDashboardMigration(mg *Migrator) { mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ Name: "created_by", Type: DB_Int, Nullable: true, })) + + // add column to store gnetId + mg.AddMigration("Add column gnetId in dashboard", NewAddColumnMigration(dashboardV2, &Column{ + Name: "gnet_id", Type: DB_BigInt, Nullable: true, + })) } diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index ef540927cc0..0a3c1b95f95 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -39,6 +39,7 @@ function (angular, $, _, moment) { this.schemaVersion = data.schemaVersion || 0; this.version = data.version || 0; this.links = data.links || []; + this.gnetId = data.gnetId || null; this._updateSchema(data); this._initMeta(meta); } diff --git a/public/app/features/dashboard/import/dash_import.ts b/public/app/features/dashboard/import/dash_import.ts index 7a3e5b3ae3d..be4ae744eca 100644 --- a/public/app/features/dashboard/import/dash_import.ts +++ b/public/app/features/dashboard/import/dash_import.ts @@ -147,10 +147,11 @@ export class DashImportCtrl { return this.backendSrv.get('api/gnet/dashboards/' + dashboardId).then(res => { this.gnetInfo = res; // store reference to grafana.net - res.json.gnetId = dashboardId; + res.json.gnetId = res.id; this.onUpload(res.json); }).catch(err => { - this.gnetError = err.message || err; + err.isHandled = true; + this.gnetError = err.data.message || err; }); }