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