Commit 187834b1 by Torkel Ödegaard

Trying to get dashboard loading and dashboard meta flags like canSave, canStar more managable

parent 4822d027
......@@ -16,6 +16,7 @@
**Breaking changes**
- [Issue #1928](https://github.com/grafana/grafana/issues/1928). HTTP API: GET /api/dashboards/db/:slug response changed property `model` to `dashboard` to match the POST request nameing
- Backend render URL changed from `/render/dashboard/solo` `render/dashboard-solo/` (in order to have consistent dashboard url `/dashboard/:type/:slug`)
# 2.0.3 (unreleased - 2.0.x branch)
......
......@@ -53,7 +53,8 @@ func GetDashboard(c *middleware.Context) {
IsStarred: isStarred,
Slug: slug,
Type: m.DashTypeDB,
CanSave: c.OrgRole != m.ROLE_VIEWER,
CanStar: c.IsSignedIn,
CanSave: c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR,
},
}
......@@ -136,7 +137,6 @@ func GetDashboardFromJsonFile(c *middleware.Context) {
dash := dtos.DashboardFullWithMeta{Dashboard: dashboard.Data}
dash.Meta.Type = m.DashTypeJson
dash.Meta.CanSave = false
c.JSON(200, &dash)
}
......@@ -66,6 +66,7 @@ func GetDashboardSnapshot(c *middleware.Context) {
dto := dtos.DashboardFullWithMeta{
Dashboard: snapshot.Dashboard,
Meta: dtos.DashboardMeta{
Type: m.DashTypeSnapshot,
IsSnapshot: true,
Created: snapshot.Created,
Expires: snapshot.Expires,
......
......@@ -34,6 +34,7 @@ type DashboardMeta struct {
IsSnapshot bool `json:"isSnapshot,omitempty"`
Type string `json:"type,omitempty"`
CanSave bool `json:"canSave"`
CanStar bool `json:"canStar"`
Slug string `json:"slug"`
Expires time.Time `json:"expires"`
Created time.Time `json:"created"`
......
......@@ -7,6 +7,11 @@ import (
)
func StarDashboard(c *middleware.Context) {
if !c.IsSignedIn {
c.JsonApiErr(412, "You need to sign in to star dashboards", nil)
return
}
var cmd = m.StarDashboardCommand{
UserId: c.UserId,
DashboardId: c.ParamsInt64(":id"),
......
......@@ -16,9 +16,10 @@ var (
)
var (
DashTypeJson = "file"
DashTypeDB = "db"
DashTypeScript = "script"
DashTypeJson = "file"
DashTypeDB = "db"
DashTypeScript = "script"
DashTypeSnapshot = "snapshot"
)
// Dashboard model
......
......@@ -70,7 +70,7 @@ function (angular, $, config) {
};
$scope.updateTopNavPartial = function() {
if ($scope.dashboard.meta.isSnapshot) {
if ($scope.dashboard.meta.type === 'snapshot') {
$scope.topNavPartial = 'app/features/dashboard/partials/snapshotTopNav.html';
}
};
......
......@@ -19,7 +19,7 @@ function (angular, moment, _, $, kbn) {
var self = this;
this._dashboardLoadFailed = function(title) {
return {meta: {}, dashboard: {title: title}};
return {meta: {canStar: false, canDelete: false, canSave: false}, dashboard: {title: title}};
};
this.loadDashboard = function(type, slug) {
......@@ -28,9 +28,7 @@ function (angular, moment, _, $, kbn) {
}
if (type === 'snapshot') {
return backendSrv.get('/api/snapshots/' + $routeParams.slug).then(function(result) {
return result;
}, function() {
return backendSrv.get('/api/snapshots/' + $routeParams.slug).catch(function() {
return {meta:{isSnapshot: true, canSave: false, canEdit: false}, dashboard: {title: 'Snapshot not found'}};
});
}
......@@ -45,7 +43,7 @@ function (angular, moment, _, $, kbn) {
return $http({ url: url, method: "GET" })
.then(this._executeScript).then(function(result) {
return { meta: { fromScript: true, canDelete: false, canSave: false}, dashboard: result.data };
return { meta: { fromScript: true, canDelete: false, canSave: false, canStar: false}, dashboard: result.data };
}, function(err) {
console.log('Script dashboard error '+ err);
$rootScope.appEvent('alert-error', ["Script Error", "Please make sure it exists and returns a valid dashboard"]);
......
......@@ -56,9 +56,8 @@ function (angular, $, kbn, _, moment) {
meta.canShare = meta.canShare === false ? false : true;
meta.canSave = meta.canSave === false ? false : true;
meta.canEdit = meta.canEdit === false ? false : true;
meta.canStar = meta.canStar === false ? false : true;
meta.canDelete = meta.canDelete === false ? false : true;
meta.canEdit = meta.canEdit === false ? false : true;
if (!this.editable) {
meta.canEdit = false;
......
......@@ -15,7 +15,6 @@
<i class="fa fa-caret-down"></i>
</a>
</div>
</div>
<ul class="nav pull-left top-nav-dash-actions">
......@@ -27,7 +26,7 @@
<li ng-show="dashboardMeta.canShare">
<a class="pointer" ng-click="shareDashboard()" bs-tooltip="'Share dashboard'" data-placement="bottom"><i class="fa fa-share-square-o"></i></a>
</li>
<li ng-show="dashboardMeta.canSave && contextSrv.isEditor">
<li ng-show="dashboardMeta.canSave">
<a ng-click="saveDashboard()" bs-tooltip="'Save dashboard'" data-placement="bottom"><i class="fa fa-save"></i></a>
</li>
<li class="dropdown">
......@@ -39,7 +38,7 @@
<li><a class="pointer" ng-click="exportDashboard();">Export</a></li>
<li><a class="pointer" ng-click="editJson();">View JSON</a></li>
<li ng-if="contextSrv.isEditor"><a class="pointer" ng-click="saveDashboardAs();">Save As...</a></li>
<li ng-if="dashboardMeta.canDelete"><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li>
<li ng-if="dashboardMeta.canSave"><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li>
</ul>
</li>
</ul>
......
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