Skip to content

Commit

Permalink
Merge pull request #1497 from getredash/v1fixes
Browse files Browse the repository at this point in the history
Fix #16: when updating dashboard name refresh dashboards dropdown
  • Loading branch information
arikfr authored Jan 1, 2017
2 parents 4e218b7 + e58f703 commit 703f996
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
21 changes: 5 additions & 16 deletions client/app/components/app-header/app-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,12 @@
<span class="visible-xs visible-sm"><i class="zmdi zmdi-view-dashboard"></i> <b class="caret"></b></span>
</a>
<ul class="dropdown-menu" uib-dropdown-menu>
<span ng-repeat="(name, group) in $ctrl.groupedDashboards">
<li class="dropdown-submenu">
<a href="#" ng-bind="name"></a>
<ul class="dropdown-menu">
<li ng-repeat="dashboard in group" role="presentation">
<a role="menu-item" ng-href="dashboard/{{dashboard.slug}}" ng-bind="dashboard.name"></a>
</li>
</ul>
</li>
</span>
<li ng-repeat="dashboard in $ctrl.otherDashboards">
<a role="menu-item" ng-href="dashboard/{{dashboard.slug}}" ng-bind="dashboard.name"></a>
</li>
<li class="divider"
ng-show="$ctrl.currentUser.hasPermission('create_dashboard') && ($ctrl.groupedDashboards.length > 0 || $ctrl.otherDashboards.length > 0)"></li>
<li><a ng-show="$ctrl.currentUser.hasPermission('create_dashboard')" ng-click="$ctrl.newDashboard()">New Dashboard</a></li>
<li><a href="dashboards">Dashboards</a></li>
<li class="divider" ng-if="$ctrl.dashboards | notEmpty"></li>
<li ng-repeat="dashboard in $ctrl.dashboards">
<a href="dashboard/{{dashboard.slug}}" ng-bind="dashboard.name"></a>
</li>
</ul>
</li>
<li class="dropdown" ng-show="$ctrl.showQueriesMenu" uib-dropdown>
Expand All @@ -49,7 +38,7 @@
</ul>
<form class="navbar-form navbar-left" role="search" ng-submit="$ctrl.searchQueries()">
<div class="form-group">
<input type="text" ng-model="term" class="form-control" placeholder="Search queries...">
<input type="text" ng-model="$ctrl.term" class="form-control" placeholder="Search queries...">
</div>
<button type="submit" class="btn btn-default"><span class="zmdi zmdi-search"></span></button>
</form>
Expand Down
40 changes: 16 additions & 24 deletions client/app/components/app-header/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { omit, groupBy, sortBy } from 'underscore';
import debug from 'debug';

import template from './app-header.html';
import logoUrl from '../../assets/images/redash_icon_small.png';

function controller($scope, $location, $uibModal, Auth, currentUser, Dashboard) {
this.dashboards = [];
const logger = debug('redash:appHeader');

function controller($rootScope, $location, $uibModal, Auth, currentUser, Dashboard) {
// TODO: logoUrl should come from clientconfig
this.logoUrl = logoUrl;
this.currentUser = currentUser;
this.showQueriesMenu = currentUser.hasPermission('view_query');
this.showNewQueryMenu = currentUser.hasPermission('create_query');
this.showSettingsMenu = currentUser.hasPermission('list_users');
this.currentUser = currentUser;
this.showDashboardsMenu = currentUser.hasPermission('list_dashboards');

this.reloadDashboards = () => {
logger('Reloading dashboards.');
this.dashboards = Dashboard.recent();
};

this.reloadDashboards();

$rootScope.$on('reloadDashboards', this.reloadDashboards);

this.newDashboard = () => {
$uibModal.open({
Expand All @@ -21,32 +32,13 @@ function controller($scope, $location, $uibModal, Auth, currentUser, Dashboard)
});
};

this.reloadDashboards = () => {
Dashboard.recent((dashboards) => {
this.dashboards = sortBy(dashboards, 'name');
this.allDashboards = groupBy(this.dashboards, (d) => {
const parts = d.name.split(':');
if (parts.length === 1) {
return 'Other';
}
return parts[0];
});

this.otherDashboards = this.allDashboards.Other || [];
this.groupedDashboards = omit(this.allDashboards, 'Other');
this.showDashboardsMenu = this.groupedDashboards.length > 0 || this.otherDashboards.length > 0 || currentUser.hasPermission('create_dashboard');
});
};

this.searchQueries = () => {
$location.path('/queries/search').search({ q: $scope.term });
$location.path('/queries/search').search({ q: this.term });
};

this.logout = () => {
Auth.logout();
};

this.reloadDashboards();
}

export default function (ngModule) {
Expand Down
6 changes: 3 additions & 3 deletions client/app/pages/dashboards/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as _ from 'underscore';
import template from './dashboard.html';
import shareDashboardTemplate from './share-dashboard.html';

function DashboardCtrl($routeParams, $location, $timeout, $q, $uibModal,
function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibModal,
Title, AlertDialog, Dashboard, currentUser, clientConfig, Events) {
this.isFullscreen = false;
this.refreshRate = null;
Expand Down Expand Up @@ -104,8 +104,7 @@ function DashboardCtrl($routeParams, $location, $timeout, $q, $uibModal,
const archive = () => {
Events.record('archive', 'dashboard', this.dashboard.id);
this.dashboard.$delete(() => {
// TODO:
// this.$parent.reloadDashboards();
$rootScope.$broadcast('reloadDashboards');
});
};

Expand Down Expand Up @@ -166,6 +165,7 @@ function DashboardCtrl($routeParams, $location, $timeout, $q, $uibModal,
}, (dashboard) => {
this.saveInProgress = false;
this.dashboard.version = dashboard.version;
$rootScope.$broadcast('reloadDashboards');
});
};

Expand Down
3 changes: 2 additions & 1 deletion client/app/pages/dashboards/edit-dashboard-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const EditDashboardDialog = {
dismiss: '&',
},
template,
controller($location, $http, toastr, Events, Dashboard) {
controller($rootScope, $location, $http, toastr, Events, Dashboard) {
'ngInject';

this.dashboard = this.resolve.dashboard;
Expand Down Expand Up @@ -72,6 +72,7 @@ const EditDashboardDialog = {
this.dashboard = dashboard;
this.saveInProgress = false;
this.close({ $value: this.dashboard });
$rootScope.$broadcast('reloadDashboards');
}, (error) => {
this.saveInProgress = false;
if (error.status === 403) {
Expand Down
2 changes: 1 addition & 1 deletion client/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function Dashboard($resource, $http, currentUser, Widget) {
transformResponse: transform,
},
});
resource.prototype.canEdit = () => currentUser.canEdit(this) || this.can_edit;

resource.prototype.canEdit = () => currentUser.canEdit(this) || this.can_edit;
return resource;
}

Expand Down

0 comments on commit 703f996

Please sign in to comment.