Skip to content

Commit

Permalink
Merge pull request #544 from EverythingMe/fix/archived_dashboard_in_r…
Browse files Browse the repository at this point in the history
…ecent

Fix: archived dashboards were shown in recent list (and move archive button)
  • Loading branch information
arikfr committed Sep 3, 2015
2 parents 7000547 + 795a9fe commit 8686694
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
18 changes: 0 additions & 18 deletions rd_ui/app/scripts/controllers/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,6 @@
var IndexCtrl = function ($scope, Events, Dashboard) {
Events.record(currentUser, "view", "page", "homepage");
$scope.$parent.pageTitle = "Home";

$scope.archiveDashboard = function (dashboard) {
if (confirm('Are you sure you want to delete "' + dashboard.name + '" dashboard?')) {
Events.record(currentUser, "archive", "dashboard", dashboard.id);
dashboard.$delete(function () {
$scope.$parent.reloadDashboards();
});
}
}
};

var PersonalIndexCtrl = function ($scope, Events, Dashboard, Query) {
Expand All @@ -211,15 +202,6 @@

$scope.recentQueries = Query.recent();
$scope.recentDashboards = Dashboard.recent();

$scope.archiveDashboard = function (dashboard) {
if (confirm('Are you sure you want to delete "' + dashboard.name + '" dashboard?')) {
Events.record(currentUser, "archive", "dashboard", dashboard.id);
dashboard.$delete(function () {
$scope.$parent.reloadDashboards();
});
}
}
};

angular.module('redash.controllers', [])
Expand Down
9 changes: 9 additions & 0 deletions rd_ui/app/scripts/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@
}
};

$scope.archiveDashboard = function () {
if (confirm('Are you sure you want to archive the "' + $scope.dashboard.name + '" dashboard?')) {
Events.record(currentUser, "archive", "dashboard", $scope.dashboard.id);
$scope.dashboard.$delete(function () {
$scope.$parent.reloadDashboards();
});
}
}

$scope.triggerRefresh = function() {
$scope.refreshEnabled = !$scope.refreshEnabled;

Expand Down
8 changes: 8 additions & 0 deletions rd_ui/app/styles/redash.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ li.widget:hover {
overflow-x: auto;
}

/* Support for Font-Awesome in btn-xs */

.btn-xs > .fa {
font-size: 14px;
top: 1px;
position: relative;
}

/* Because of ng-repeat we add span between the .dropdown-menu element and the li element, so we had
to add those CSS styles here. */

Expand Down
8 changes: 6 additions & 2 deletions rd_ui/app/views/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
<edit-dashboard-form dashboard="dashboard" id="edit_dashboard_dialog"></edit-dashboard-form>

<div class="container">
<p class="alert alert-warning" ng-if="dashboard.is_archived">This dashboard is archived and won't appear in the dashboards list or search results.</p>
<h2 id="dashboard_title">
{{dashboard.name}}

<span ng-if="!dashboard.is_archived">
<button type="button" class="btn btn-default btn-xs" ng-class="{active: refreshEnabled}" tooltip="Enable/Disable Auto Refresh" ng-click="triggerRefresh()"><span class="glyphicon glyphicon-refresh"></span></button>
<span ng-show="dashboard.canEdit()">
<div class="btn-group" role="group" ng-show="dashboard.canEdit()">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" href="#edit_dashboard_dialog" tooltip="Edit Dashboard (Name/Layout)"><span
class="glyphicon glyphicon-cog"></span></button>
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
href="#add_query_dialog" tooltip="Add Widget (Chart/Table)"><span class="glyphicon glyphicon-plus"></span>
</button>
</span>
<butotn class="btn btn-danger btn-xs" ng-click="archiveDashboard()" ng-if="!dashboard.is_archived" tooltip="Archive"><i class="fa fa-archive"></i></butotn>
</div>
</span>
</h2>
<filters ng-if="dashboard.dashboard_filters_enabled"></filters>
</div>
Expand Down
7 changes: 3 additions & 4 deletions rd_ui/app/views/personal.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<div class="list-group-item active">
Recent Dashboards
</div>
<div class="list-group-item" ng-repeat="dashboard in recentDashboards" >
<button type="button" class="close delete-button" aria-hidden="true" ng-show="dashboard.canEdit()" ng-click="archiveDashboard(dashboard)" tooltip="Delete Dashboard">&times;</button>
<a ng-href="/dashboard/{{dashboard.slug}}">{{dashboard.name}}</a>
</div>
<a ng-href="/dashboard/{{dashboard.slug}}" class="list-group-item" ng-repeat="dashboard in recentDashboards">
{{dashboard.name}}
</a>
</div>

<div class="list-group col-md-6">
Expand Down
2 changes: 2 additions & 0 deletions redash/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def delete(self, dashboard_slug):
dashboard.is_archived = True
dashboard.save()

return dashboard.to_dict(with_widgets=True)

api.add_resource(DashboardListAPI, '/api/dashboards', endpoint='dashboards')
api.add_resource(DashboardRecentAPI, '/api/dashboards/recent', endpoint='recent_dashboards')
api.add_resource(DashboardAPI, '/api/dashboards/<dashboard_slug>', endpoint='dashboard')
Expand Down
2 changes: 2 additions & 0 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ def to_dict(self, with_widgets=False):
'layout': layout,
'dashboard_filters_enabled': self.dashboard_filters_enabled,
'widgets': widgets_layout,
'is_archived': self.is_archived,
'updated_at': self.updated_at,
'created_at': self.created_at
}
Expand All @@ -715,6 +716,7 @@ def recent(cls, user_id=None, limit=20):
where(Event.action << ('edit', 'view')).\
where(~(Event.object_id >> None)). \
where(Event.object_type == 'dashboard'). \
where(Dashboard.is_archived == False). \
group_by(Event.object_id, Dashboard.id). \
order_by(peewee.SQL("count(0) desc"))

Expand Down

0 comments on commit 8686694

Please sign in to comment.