Removed unwanted api, moved logic into backend
This commit is contained in:
@@ -200,7 +200,6 @@ func Register(r *macaron.Macaron) {
|
|||||||
r.Get("/home", GetHomeDashboard)
|
r.Get("/home", GetHomeDashboard)
|
||||||
r.Get("/tags", GetDashboardTags)
|
r.Get("/tags", GetDashboardTags)
|
||||||
r.Post("/import", bind(dtos.ImportDashboardCommand{}), wrap(ImportDashboard))
|
r.Post("/import", bind(dtos.ImportDashboardCommand{}), wrap(ImportDashboard))
|
||||||
r.Get("/id/:id", GetDashboardSlugById)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Dashboard snapshots
|
// Dashboard snapshots
|
||||||
|
|||||||
+22
-14
@@ -159,6 +159,28 @@ func canEditDashboard(role m.RoleType) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetHomeDashboard(c *middleware.Context) {
|
func GetHomeDashboard(c *middleware.Context) {
|
||||||
|
|
||||||
|
// Checking if there is any preference set for home dashboard
|
||||||
|
query := m.GetPreferencesQuery{UserId: c.UserId, OrgId: c.OrgId}
|
||||||
|
|
||||||
|
if err := bus.Dispatch(&query); err != nil {
|
||||||
|
c.JsonApiErr(500, "Failed to get preferences", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if query.Result.HomeDashboardId != 0 {
|
||||||
|
query := m.GetDashboardSlugByIdQuery{Id: query.Result.HomeDashboardId}
|
||||||
|
err := bus.Dispatch(&query)
|
||||||
|
if err != nil {
|
||||||
|
c.JsonApiErr(500, "Failed to get slug from database", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
slug := dtos.DashboardSlug{Slug: query.Result}
|
||||||
|
|
||||||
|
c.JSON(200, &slug)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
|
filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -204,17 +226,3 @@ func GetDashboardTags(c *middleware.Context) {
|
|||||||
|
|
||||||
c.JSON(200, query.Result)
|
c.JSON(200, query.Result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDashboardSlugById(c *middleware.Context) {
|
|
||||||
dashId := c.ParamsInt64(":id")
|
|
||||||
query := m.GetDashboardSlugByIdQuery{Id: dashId}
|
|
||||||
err := bus.Dispatch(&query)
|
|
||||||
if err != nil {
|
|
||||||
c.JsonApiErr(500, "Failed to get slug from database", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
slug := dtos.DashboardSlug{Slug: query.Result}
|
|
||||||
|
|
||||||
c.JSON(200, &slug)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,25 +7,19 @@ function (coreModule) {
|
|||||||
coreModule.default.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) {
|
coreModule.default.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) {
|
||||||
|
|
||||||
if (!$routeParams.slug) {
|
if (!$routeParams.slug) {
|
||||||
|
backendSrv.get('/api/dashboards/home').then(function(result) {
|
||||||
backendSrv.get('/api/preferences').then(function(preferences) {
|
if (result.slug == null) {
|
||||||
if (preferences !== null && preferences.homeDashboardId !== 0) {
|
var meta = result.meta;
|
||||||
backendSrv.get('/api/dashboards/id/' + preferences.homeDashboardId).then(function(dashSlug) {
|
meta.canSave = meta.canShare = meta.canStar = false;
|
||||||
$routeParams.type = 'db';
|
$scope.initDashboard(result, $scope);
|
||||||
$routeParams.slug = dashSlug.slug;
|
|
||||||
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) {
|
|
||||||
$scope.initDashboard(result, $scope);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
backendSrv.get('/api/dashboards/home').then(function(result) {
|
$routeParams.type = 'db';
|
||||||
var meta = result.meta;
|
$routeParams.slug = result.slug;
|
||||||
meta.canSave = meta.canShare = meta.canStar = false;
|
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) {
|
||||||
$scope.initDashboard(result, $scope);
|
$scope.initDashboard(result, $scope);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user