Commit cacbcb9c by Torkel Ödegaard

ux: added search box to ds list page, closes #10106

parent 22aa1f7e
///<reference path="../../headers/common.d.ts" />
import coreModule from '../../core/core_module'; import coreModule from '../../core/core_module';
import {appEvents} from 'app/core/core'; import _ from 'lodash';
export class DataSourcesCtrl { export class DataSourcesCtrl {
datasources: any; datasources: any;
unfiltered: any;
navModel: any; navModel: any;
searchQuery: string;
/** @ngInject */ /** @ngInject */
constructor( constructor(
private $scope, private $scope,
private backendSrv, private backendSrv,
private datasourceSrv, private datasourceSrv,
private $location,
private navModelSrv) { private navModelSrv) {
this.navModel = this.navModelSrv.getNav('cfg', 'datasources', 0); this.navModel = this.navModelSrv.getNav('cfg', 'datasources', 0);
this.navigateToUrl = this.navigateToUrl.bind(this);
backendSrv.get('/api/datasources').then(result => { backendSrv.get('/api/datasources').then(result => {
this.datasources = result; this.datasources = result;
}); this.unfiltered = result;
appEvents.on('location-change', payload => {
this.navigateToUrl(payload.href);
}); });
} }
navigateToUrl(url) { onQueryUpdated() {
// debugger; let regex = new RegExp(this.searchQuery, 'ig');
this.$location.path(url); this.datasources = _.filter(this.unfiltered, item => {
this.$location.replace(); return regex.test(item.name) || regex.test(item.type);
});
} }
removeDataSourceConfirmed(ds) { removeDataSourceConfirmed(ds) {
......
<page-header model="ctrl.navModel"></page-header> <page-header model="ctrl.navModel"></page-header>
<div class="page-container page-body"> <div class="page-container page-body">
<div ng-if="ctrl.datasources.length"> <div ng-if="ctrl.unfiltered.length">
<div class="page-action-bar"> <div class="page-action-bar">
<div class="gf-form">
<label class="gf-form-label">Search</label>
<input type="text" class="gf-form-input width-20" ng-model="ctrl.searchQuery" ng-change="ctrl.onQueryUpdated()" give-focus="true" placeholder="Filter by name or type" />
</div>
<div class="page-action-bar__spacer"></div> <div class="page-action-bar__spacer"></div>
<a class="page-header__cta btn btn-success" href="datasources/new"> <a class="page-header__cta btn btn-success" href="datasources/new">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
Add data source Add data source
...@@ -42,7 +48,7 @@ ...@@ -42,7 +48,7 @@
</section> </section>
</div> </div>
<div ng-if="ctrl.datasources.length === 0"> <div ng-if="ctrl.unfiltered.length === 0">
<empty-list-cta model="{ <empty-list-cta model="{
title: 'There are no data sources defined yet', title: 'There are no data sources defined yet',
buttonIcon: 'gicon gicon-dashboard-new', buttonIcon: 'gicon gicon-dashboard-new',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment