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

[#16] reload dashboard list when renaming dashboard #163

Closed
wants to merge 1 commit into from
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
28 changes: 16 additions & 12 deletions rd_ui/app/scripts/controllers/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@
});
}

var MainCtrl = function ($scope, Dashboard, notifications) {
var MainCtrl = function ($scope, Dashboard, notifications, Events) {
$scope.dashboards = [];
$scope.reloadDashboards = function() {
$scope.currentUser = currentUser;
$scope.newDashboard = {
'name': null,
'layout': null
}

function reloadDashboards() {
Dashboard.query(function (dashboards) {
$scope.dashboards = _.sortBy(dashboards, "name");
$scope.allDashboards = _.groupBy($scope.dashboards, function(d) {
Expand All @@ -123,33 +129,31 @@
});
}

$scope.reloadDashboards();
reloadDashboards();

$scope.currentUser = currentUser;
$scope.newDashboard = {
'name': null,
'layout': null
}
$scope.$on(Events.dashboardchange, function() {
reloadDashboards();
});

$(window).click(function () {
notifications.getPermissions();
});
}

var IndexCtrl = function($scope, Dashboard) {
var IndexCtrl = function($scope, Dashboard, Events) {
$scope.$parent.pageTitle = "Home";

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

angular.module('redash.controllers', [])
.controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl])
.controller('IndexCtrl', ['$scope', 'Dashboard', IndexCtrl])
.controller('MainCtrl', ['$scope', 'Dashboard', 'notifications', MainCtrl]);
.controller('IndexCtrl', ['$scope', 'Dashboard', 'Events', IndexCtrl])
.controller('MainCtrl', ['$scope', 'Dashboard', 'notifications', 'Events', MainCtrl]);
})();
5 changes: 3 additions & 2 deletions rd_ui/app/scripts/directives/dashboard_directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

var directives = angular.module('redash.directives');

directives.directive('editDashboardForm', ['$http', '$location', '$timeout', 'Dashboard',
function($http, $location, $timeout, Dashboard) {
directives.directive('editDashboardForm', ['$http', '$location', '$timeout', 'Dashboard', 'Events',
function($http, $location, $timeout, Dashboard, Events) {
return {
restrict: 'E',
scope: {
Expand Down Expand Up @@ -89,6 +89,7 @@
$scope.dashboard = new Dashboard(response);
$scope.saveInProgress = false;
$(element).modal('hide');
$scope.$emit(Events.dashboardchange);
})
} else {
$http.post('/api/dashboards', {
Expand Down
7 changes: 7 additions & 0 deletions rd_ui/app/scripts/services/services.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
(function() {
'use strict'

function Events() {
return {
dashboardchange: 'dashboardchange'
}
}

function KeyboardShortcuts() {
this.bind = function bind(keymap) {
_.forEach(keymap, function(fn, key) {
Expand All @@ -20,5 +26,6 @@
}

angular.module('redash.services', [])
.service('Events', [Events])
.service('KeyboardShortcuts', [KeyboardShortcuts])
})();
32 changes: 17 additions & 15 deletions rd_ui/app/views/edit_dashboard.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-disabled="saveInProgress" aria-hidden="true">&times;</button>
<h4 class="modal-title">Edit: {{dashboard.name}}</h4>
</div>
<div class="modal-body">
<p>
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="dashboard.name">
</p>
<form ng-submit="saveDashboard()">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-disabled="saveInProgress" aria-hidden="true">&times;</button>
<h4 class="modal-title">Edit: {{dashboard.name}}</h4>
</div>
<div class="modal-body">
<p>
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="dashboard.name">
</p>

<div class="gridster">
<ul></ul>
<div class="gridster">
<ul></ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-disabled="saveInProgress" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" ng-disabled="saveInProgress">Save</button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-disabled="saveInProgress" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" ng-disabled="saveInProgress" ng-click="saveDashboard()">Save</button>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
Expand Down