diff --git a/client/app/lib/list-ctrl.js b/client/app/lib/list-ctrl.js index f1151842c3..31ac14d975 100644 --- a/client/app/lib/list-ctrl.js +++ b/client/app/lib/list-ctrl.js @@ -1,9 +1,37 @@ -import { bind } from 'lodash'; +import { bind, each } from 'lodash'; import $ from 'jquery'; import { LivePaginator } from '@/lib/pagination'; +import { Query } from '@/services/query'; +import { Dashboard } from '@/services/dashboard'; +import { User } from '@/services/user'; + +export function buildListRoutes(name, routes, template) { + const listRoutes = {}; + each(routes, (route) => { + listRoutes[route.path] = { + template, + reloadOnSearch: false, + title: route.title, + resolve: { + currentPage: () => route.page, + resource: () => { + // services that are using the ListCtrl class + const listServices = { + query: Query, + dashboard: Dashboard, + user: User, + }; + return listServices[name].query.bind(listServices[name]); + }, + }, + }; + }); + return listRoutes; +} -export default class ListCtrl { - constructor($scope, $location, currentUser, clientConfig, defaultOrder = '-created_at') { +export class ListCtrl { + constructor($scope, $location, $route, currentUser, clientConfig, defaultOrder = '-created_at') { + this.title = $route.current.title; // will make it available as $ctrl.title this.searchTerm = $location.search().q || ''; this.page = parseInt($location.search().page || 1, 10); diff --git a/client/app/pages/dashboards/dashboard-list.html b/client/app/pages/dashboards/dashboard-list.html index 17ab79a49f..38950c4064 100644 --- a/client/app/pages/dashboards/dashboard-list.html +++ b/client/app/pages/dashboards/dashboard-list.html @@ -1,6 +1,5 @@
- - +
@@ -37,22 +36,22 @@
-
- +
+
+ +
+ + + +
- - - - -
diff --git a/client/app/pages/dashboards/dashboard-list.js b/client/app/pages/dashboards/dashboard-list.js index 7d18c4fb1d..f33eeac427 100644 --- a/client/app/pages/dashboards/dashboard-list.js +++ b/client/app/pages/dashboards/dashboard-list.js @@ -1,12 +1,10 @@ -import { extend } from 'lodash'; - -import ListCtrl from '@/lib/list-ctrl'; +import { buildListRoutes, ListCtrl } from '@/lib/list-ctrl'; import template from './dashboard-list.html'; import './dashboard-list.css'; class DashboardListCtrl extends ListCtrl { - constructor($scope, $location, currentUser, clientConfig, Dashboard) { - super($scope, $location, currentUser, clientConfig); + constructor($scope, $location, $route, currentUser, clientConfig, Dashboard) { + super($scope, $location, $route, currentUser, clientConfig); this.Type = Dashboard; } @@ -14,6 +12,18 @@ class DashboardListCtrl extends ListCtrl { super.processResponse(data); const rows = data.results.map(d => new this.Type(d)); this.paginator.updateRows(rows, data.count); + + if (data.count === 0) { + if (this.isInSearchMode()) { + this.emptyType = 'search'; + } else if (this.selectedTags.size > 0) { + this.emptyType = 'tags'; + } else if (this.currentPage === 'favorites') { + this.emptyType = 'favorites'; + } else { + this.emptyType = 'default'; + } + } this.showEmptyState = data.count === 0; } } @@ -23,42 +33,20 @@ export default function init(ngModule) { template, controller: DashboardListCtrl, }); - - const route = { - template: '', - reloadOnSearch: false, - }; - - return { - '/dashboards': extend( - { - title: 'Dashboards', - resolve: { - currentPage: () => 'all', - resource(Dashboard) { - 'ngInject'; - - return Dashboard.query.bind(Dashboard); - }, - }, - }, - route, - ), - '/dashboards/favorites': extend( - { - title: 'Favorite Dashboards', - resolve: { - currentPage: () => 'favorites', - resource(Dashboard) { - 'ngInject'; - - return Dashboard.favorites.bind(Dashboard); - }, - }, - }, - route, - ), - }; + const routes = [ + { + page: 'all', + title: 'All Dashboards', + path: '/dashboards', + }, + { + page: 'favorites', + title: 'Favorite Dashboards', + path: '/dashboards/favorites', + }, + ]; + + return buildListRoutes('dashboard', routes, ''); } init.init = true; diff --git a/client/app/pages/queries-list/index.js b/client/app/pages/queries-list/index.js index 120737a6ee..df188e6d0a 100644 --- a/client/app/pages/queries-list/index.js +++ b/client/app/pages/queries-list/index.js @@ -1,14 +1,13 @@ import moment from 'moment'; -import { extend } from 'lodash'; -import ListCtrl from '@/lib/list-ctrl'; +import { buildListRoutes, ListCtrl } from '@/lib/list-ctrl'; import template from './queries-list.html'; import './queries-list.css'; class QueriesListCtrl extends ListCtrl { - constructor($scope, $location, currentUser, clientConfig, Query) { - super($scope, $location, currentUser, clientConfig); + constructor($scope, $location, $route, currentUser, clientConfig, Query) { + super($scope, $location, $route, currentUser, clientConfig); this.Type = Query; this.showMyQueries = currentUser.hasPermission('create_query'); } @@ -48,71 +47,29 @@ export default function init(ngModule) { controller: QueriesListCtrl, }); - const route = { - template: '', - reloadOnSearch: false, - }; - - return { - '/queries': extend( - { - title: 'Queries', - resolve: { - currentPage: () => 'all', - resource(Query) { - 'ngInject'; - - return Query.query.bind(Query); - }, - }, - }, - route, - ), - '/queries/my': extend( - { - title: 'My Queries', - resolve: { - currentPage: () => 'my', - resource: (Query) => { - 'ngInject'; - - return Query.myQueries.bind(Query); - }, - }, - }, - route, - ), - '/queries/favorites': extend( - { - title: 'Favorite Queries', - resolve: { - currentPage: () => 'favorites', - resource: (Query) => { - 'ngInject'; - - return Query.favorites.bind(Query); - }, - }, - }, - route, - ), - '/queries/archive': extend( - { - title: 'Archived Queries', - resolve: { - currentPage: () => 'archive', - resource: (Query) => { - 'ngInject'; - - return Query.archive.bind(Query); - }, - }, - }, - route, - ), - // TODO: setup redirect? - // '/queries/search': _.extend( - }; + const routes = [ + { + page: 'all', + title: 'All Queries', + path: '/queries', + }, + { + page: 'my', + title: 'My Queries', + path: '/queries/my', + }, + { + page: 'favorites', + title: 'Favorite Queries', + path: '/queries/favorites', + }, + { + page: 'archive', + title: 'Archived Queries', + path: '/queries/archive', + }, + ]; + return buildListRoutes('query', routes, ''); } init.init = true; diff --git a/client/app/pages/queries-list/queries-list.html b/client/app/pages/queries-list/queries-list.html index 92817befda..6f39757bc1 100644 --- a/client/app/pages/queries-list/queries-list.html +++ b/client/app/pages/queries-list/queries-list.html @@ -1,10 +1,5 @@
-
-
-
-
-
-
+
diff --git a/client/app/pages/users/list.js b/client/app/pages/users/list.js index c40ca8c8f7..6dccf59ac4 100644 --- a/client/app/pages/users/list.js +++ b/client/app/pages/users/list.js @@ -1,12 +1,12 @@ -import { extend } from 'lodash'; import { policy } from '@/services/policy'; -import ListCtrl from '@/lib/list-ctrl'; +import { buildListRoutes, ListCtrl } from '@/lib/list-ctrl'; import settingsMenu from '@/services/settingsMenu'; import template from './list.html'; + class UsersListCtrl extends ListCtrl { - constructor($scope, $location, currentUser, clientConfig, User) { - super($scope, $location, currentUser, clientConfig); + constructor($scope, $location, $route, currentUser, clientConfig, User) { + super($scope, $location, $route, currentUser, clientConfig); this.policy = policy; this.enableUser = user => User.enableUser(user).then(this.update); this.disableUser = user => User.disableUser(user).then(this.update); @@ -43,41 +43,20 @@ export default function init(ngModule) { template, }); - const route = { - template: '', - reloadOnSearch: false, - }; - - return { - '/users': extend( - { - title: 'Users', - resolve: { - currentPage: () => 'all', - resource(User) { - 'ngInject'; - - return User.query.bind(User); - }, - }, - }, - route, - ), - '/users/disabled': extend( - { - resolve: { - currentPage: () => 'disabled', - resource(User) { - 'ngInject'; - - return User.query.bind(User); - }, - }, - title: 'Disabled Users', - }, - route, - ), - }; + const routes = [ + { + page: 'all', + title: 'All Users', + path: '/users', + }, + { + page: 'disabled', + title: 'Disabled Users', + path: '/users/disabled', + }, + ]; + + return buildListRoutes('user', routes, ''); } init.init = true;