Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add an unarchive dashboard button #2180

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions client/app/pages/dashboards/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h3>{{$ctrl.dashboard.name}}
<span class="zmdi zmdi-share"></span>
</button>
</span>
<div class="btn-group hidden-print" role="group" ng-show="$ctrl.dashboard.canEdit()" uib-dropdown ng-if="!$ctrl.dashboard.is_archived">
<div class="btn-group hidden-print" role="group" ng-show="$ctrl.dashboard.canEdit()" uib-dropdown>
<button class="btn btn-default btn-sm dropdown-toggle" uib-dropdown-toggle>
<span class="zmdi zmdi-more"></span>
</button>
Expand All @@ -60,8 +60,9 @@ <h3>{{$ctrl.dashboard.name}}
<li ng-if="!$ctrl.dashboard.is_archived" ng-class="{hidden: $ctrl.isGridDisabled}"><a ng-click="$ctrl.editLayout(true)">Edit Layout</a></li>
<li ng-if="!$ctrl.dashboard.is_archived"><a ng-click="$ctrl.addWidget()">Add Widget</a></li>
<li ng-if="$ctrl.showPermissionsControl"><a ng-click="$ctrl.showManagePermissionsModal()">Manage Permissions</a></li>
<li ng-if="!$ctrl.dashboard.is_draft"><a ng-click="$ctrl.togglePublished()">Unpublish Dashboard</a></li>
<li ng-if="$ctrl.dashboard.is_draft"><a ng-click="$ctrl.togglePublished()">Publish Dashboard</a></li>
<li ng-if="$ctrl.dashboard.is_archived"><a ng-click="$ctrl.unArchiveDashboard()">Unarchive Dashboard</a></li>
<li ng-if="!$ctrl.dashboard.is_archived && $ctrl.dashboard.is_draft"><a ng-click="$ctrl.togglePublished()">Publish Dashboard</a></li>
<li ng-if="!$ctrl.dashboard.is_archived && !$ctrl.dashboard.is_draft"><a ng-click="$ctrl.togglePublished()">Unpublish Dashboard</a></li>
<li ng-if="!$ctrl.dashboard.is_archived"><a ng-click="$ctrl.archiveDashboard()">Archive Dashboard</a></li>
</ul>
</div>
Expand Down
17 changes: 17 additions & 0 deletions client/app/pages/dashboards/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ function DashboardCtrl(
AlertDialog.open(title, message, confirm).then(archive);
};

this.unArchiveDashboard = () => {
Events.record('unarchive', 'dashboard', this.dashboard.id);
Dashboard.unarchive(
{
slug: this.dashboard.id,
is_archived: false,
},
() => {
this.loadDashboard();
toastr.success('Dashboard unarchived');
},
() => {
toastr.error('Dashboard could not be unarchived.');
},
);
};

this.showManagePermissionsModal = () => {
$uibModal.open({
component: 'permissionsEditor',
Expand Down
5 changes: 5 additions & 0 deletions client/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function Dashboard($resource, $http, currentUser, Widget, dashboardGridOptions)
url: 'api/dashboards/recent',
transformResponse: transform,
},
unarchive: {
method: 'POST',
transformResponse: transform,
url: 'api/dashboards/:slug/unarchive',
},
});

resource.prototype.canEdit = function canEdit() {
Expand Down
4 changes: 3 additions & 1 deletion redash/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def json_representation(data, code, headers=None):

api.add_org_resource(DashboardListResource, '/api/dashboards', endpoint='dashboards')
api.add_org_resource(RecentDashboardsResource, '/api/dashboards/recent', endpoint='recent_dashboards')
api.add_org_resource(DashboardResource, '/api/dashboards/<dashboard_slug>', endpoint='dashboard')
api.add_org_resource(DashboardResource, '/api/dashboards/<dashboard_slug>',
'/api/dashboards/<dashboard_slug>/unarchive',
endpoint='dashboard')
api.add_org_resource(PublicDashboardResource, '/api/dashboards/public/<token>', endpoint='public_dashboard')
api.add_org_resource(DashboardShareResource, '/api/dashboards/<dashboard_id>/share', endpoint='dashboard_share')

Expand Down
3 changes: 2 additions & 1 deletion redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def post(self, dashboard_slug):
require_object_modify_permission(dashboard, self.current_user)

updates = project(dashboard_properties, ('name', 'layout', 'version',
'is_draft', 'dashboard_filters_enabled'))
'is_draft', 'dashboard_filters_enabled',
'is_archived'))

# SQLAlchemy handles the case where a concurrent transaction beats us
# to the update. But we still have to make sure that we're not starting
Expand Down