Commit 7023dedc by Torkel Ödegaard

feat(preferences): refactoring PR #4399

parent 9e98c86a
...@@ -175,9 +175,8 @@ func GetHomeDashboard(c *middleware.Context) { ...@@ -175,9 +175,8 @@ func GetHomeDashboard(c *middleware.Context) {
return return
} }
slug := dtos.DashboardSlug{Slug: query.Result} dashRedirect := dtos.DashboardRedirect{RedirectUri: "db/" + query.Result}
c.JSON(200, &dashRedirect)
c.JSON(200, &slug)
return return
} }
......
...@@ -57,8 +57,8 @@ type DashboardFullWithMeta struct { ...@@ -57,8 +57,8 @@ type DashboardFullWithMeta struct {
Dashboard *simplejson.Json `json:"dashboard"` Dashboard *simplejson.Json `json:"dashboard"`
} }
type DashboardSlug struct { type DashboardRedirect struct {
Slug string `json:"slug"` RedirectUri string `json:"redirectUri"`
} }
type DataSource struct { type DataSource struct {
......
...@@ -257,16 +257,22 @@ func GetDashboards(query *m.GetDashboardsQuery) error { ...@@ -257,16 +257,22 @@ func GetDashboards(query *m.GetDashboardsQuery) error {
return nil return nil
} }
type DashboardSlugDTO struct {
Slug string
}
func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error { func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error {
dashboard := m.Dashboard{Id: query.Id} var rawSql = `SELECT slug from dashboard WHERE Id=?`
has, err := x.Get(&dashboard) var slug = DashboardSlugDTO{}
query.Result = dashboard.Slug
exists, err := x.Sql(rawSql, query.Id).Get(&slug)
if err != nil { if err != nil {
return err return err
} else if has == false { } else if exists == false {
return m.ErrDashboardNotFound return m.ErrDashboardNotFound
} }
query.Result = slug.Slug
return nil return nil
} }
...@@ -4,20 +4,16 @@ define([ ...@@ -4,20 +4,16 @@ define([
function (coreModule) { function (coreModule) {
"use strict"; "use strict";
coreModule.default.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) { coreModule.default.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv, $location) {
if (!$routeParams.slug) { if (!$routeParams.slug) {
backendSrv.get('/api/dashboards/home').then(function(result) { backendSrv.get('/api/dashboards/home').then(function(homeDash) {
if (result.slug == null) { if (homeDash.redirectUri) {
var meta = result.meta; $location.path('dashboard/' + homeDash.redirectUri);
meta.canSave = meta.canShare = meta.canStar = false;
$scope.initDashboard(result, $scope);
} else { } else {
$routeParams.type = 'db'; var meta = homeDash.meta;
$routeParams.slug = result.slug; meta.canSave = meta.canShare = meta.canStar = false;
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) { $scope.initDashboard(homeDash, $scope);
$scope.initDashboard(result, $scope);
});
} }
}); });
return; return;
......
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