mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(preferences): refactoring PR #4399
This commit is contained in:
@@ -175,9 +175,8 @@ func GetHomeDashboard(c *middleware.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
slug := dtos.DashboardSlug{Slug: query.Result}
|
||||
|
||||
c.JSON(200, &slug)
|
||||
dashRedirect := dtos.DashboardRedirect{RedirectUri: "db/" + query.Result}
|
||||
c.JSON(200, &dashRedirect)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -57,8 +57,8 @@ type DashboardFullWithMeta struct {
|
||||
Dashboard *simplejson.Json `json:"dashboard"`
|
||||
}
|
||||
|
||||
type DashboardSlug struct {
|
||||
Slug string `json:"slug"`
|
||||
type DashboardRedirect struct {
|
||||
RedirectUri string `json:"redirectUri"`
|
||||
}
|
||||
|
||||
type DataSource struct {
|
||||
|
@@ -257,16 +257,22 @@ func GetDashboards(query *m.GetDashboardsQuery) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type DashboardSlugDTO struct {
|
||||
Slug string
|
||||
}
|
||||
|
||||
func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error {
|
||||
dashboard := m.Dashboard{Id: query.Id}
|
||||
has, err := x.Get(&dashboard)
|
||||
query.Result = dashboard.Slug
|
||||
var rawSql = `SELECT slug from dashboard WHERE Id=?`
|
||||
var slug = DashboardSlugDTO{}
|
||||
|
||||
exists, err := x.Sql(rawSql, query.Id).Get(&slug)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has == false {
|
||||
} else if exists == false {
|
||||
return m.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
query.Result = slug.Slug
|
||||
return nil
|
||||
}
|
||||
|
@@ -4,20 +4,16 @@ define([
|
||||
function (coreModule) {
|
||||
"use strict";
|
||||
|
||||
coreModule.default.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) {
|
||||
coreModule.default.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv, $location) {
|
||||
|
||||
if (!$routeParams.slug) {
|
||||
backendSrv.get('/api/dashboards/home').then(function(result) {
|
||||
if (result.slug == null) {
|
||||
var meta = result.meta;
|
||||
meta.canSave = meta.canShare = meta.canStar = false;
|
||||
$scope.initDashboard(result, $scope);
|
||||
backendSrv.get('/api/dashboards/home').then(function(homeDash) {
|
||||
if (homeDash.redirectUri) {
|
||||
$location.path('dashboard/' + homeDash.redirectUri);
|
||||
} else {
|
||||
$routeParams.type = 'db';
|
||||
$routeParams.slug = result.slug;
|
||||
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) {
|
||||
$scope.initDashboard(result, $scope);
|
||||
});
|
||||
var meta = homeDash.meta;
|
||||
meta.canSave = meta.canShare = meta.canStar = false;
|
||||
$scope.initDashboard(homeDash, $scope);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
Reference in New Issue
Block a user