Commit 143c0022 by Johannes Schill

Merge branch 'master' into 10190_fix_select_icon_and_firefox

parents bc7462cd b1621e1e
import coreModule from '../../core_module'; import coreModule from '../../core_module';
import {NavModel} from '../../nav_model_srv'; import {NavModel} from '../../nav_model_srv';
import appEvents from 'app/core/app_events';
export class NavbarCtrl { export class NavbarCtrl {
model: NavModel; model: NavModel;
/** @ngInject */ /** @ngInject */
constructor(private $rootScope) { constructor() {}
}
showSearch() { showSearch() {
this.$rootScope.appEvent('show-dash-search'); appEvents.emit('show-dash-search');
} }
navItemClicked(navItem, evt) { navItemClicked(navItem, evt) {
......
...@@ -57,11 +57,11 @@ ...@@ -57,11 +57,11 @@
<div class="search-filter-box"> <div class="search-filter-box">
<a href="dashboard/new" class="search-filter-box-link"> <a href="dashboard/new" class="search-filter-box-link">
<i class="gicon gicon-dashboard-new"></i> <i class="gicon gicon-dashboard-new"></i>
Dashboard New dashboard
</a> </a>
<a href="dashboards/folder/new" class="search-filter-box-link"> <a href="dashboards/folder/new" class="search-filter-box-link">
<i class="gicon gicon-folder-new"></i> <i class="gicon gicon-folder-new"></i>
Folder New folder
</a> </a>
<a class="search-filter-box-link" target="_blank" href="https://grafana.com/dashboards?utm_source=grafana_search"> <a class="search-filter-box-link" target="_blank" href="https://grafana.com/dashboards?utm_source=grafana_search">
<img src="public/img/icn-dashboard-tiny.svg" width="20" /> Find dashboards on Grafana.com <img src="public/img/icn-dashboard-tiny.svg" width="20" /> Find dashboards on Grafana.com
......
import _ from 'lodash'; import _ from 'lodash';
import coreModule from '../../core_module'; import coreModule from '../../core_module';
import { SearchSrv } from 'app/core/services/search_srv'; import { SearchSrv } from 'app/core/services/search_srv';
import appEvents from 'app/core/app_events';
export class SearchCtrl { export class SearchCtrl {
isOpen: boolean; isOpen: boolean;
...@@ -16,9 +17,9 @@ export class SearchCtrl { ...@@ -16,9 +17,9 @@ export class SearchCtrl {
initialFolderFilterTitle: string; initialFolderFilterTitle: string;
/** @ngInject */ /** @ngInject */
constructor($scope, private $location, private $timeout, private searchSrv: SearchSrv, $rootScope) { constructor($scope, private $location, private $timeout, private searchSrv: SearchSrv) {
$rootScope.onAppEvent('show-dash-search', this.openSearch.bind(this), $scope); appEvents.on('show-dash-search', this.openSearch.bind(this), $scope);
$rootScope.onAppEvent('hide-dash-search', this.closeSearch.bind(this), $scope); appEvents.on('hide-dash-search', this.closeSearch.bind(this), $scope);
this.initialFolderFilterTitle = "All"; this.initialFolderFilterTitle = "All";
} }
...@@ -74,6 +75,7 @@ export class SearchCtrl { ...@@ -74,6 +75,7 @@ export class SearchCtrl {
if (selectedDash) { if (selectedDash) {
this.$location.search({}); this.$location.search({});
this.$location.path(selectedDash.url); this.$location.path(selectedDash.url);
this.closeSearch();
} }
} else { } else {
const selectedFolder = this.results[currentItem.folderIndex]; const selectedFolder = this.results[currentItem.folderIndex];
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<span class="search-item__icon"> <span class="search-item__icon">
<i class="gicon mini gicon-dashboard-list"></i> <i class="gicon mini gicon-dashboard-list"></i>
</span> </span>
<span class="search-item__body"> <span class="search-item__body" ng-click="ctrl.onItemClick(item)">
<div class="search-item__body-title">{{::item.title}}</div> <div class="search-item__body-title">{{::item.title}}</div>
</span> </span>
<span class="search-item__tags"> <span class="search-item__tags">
......
import _ from 'lodash'; import _ from 'lodash';
import coreModule from '../../core_module'; import coreModule from '../../core_module';
import appEvents from 'app/core/app_events';
export class SearchResultsCtrl { export class SearchResultsCtrl {
results: any; results: any;
...@@ -61,6 +62,12 @@ export class SearchResultsCtrl { ...@@ -61,6 +62,12 @@ export class SearchResultsCtrl {
} }
} }
onItemClick(item) {
if (this.$location.path().indexOf(item.url) > -1) {
appEvents.emit('hide-dash-search');
}
}
selectTag(tag, evt) { selectTag(tag, evt) {
if (this.onTagSelected) { if (this.onTagSelected) {
this.onTagSelected({$tag: tag}); this.onTagSelected({$tag: tag});
......
...@@ -36,15 +36,15 @@ export class KeybindingSrv { ...@@ -36,15 +36,15 @@ export class KeybindingSrv {
} }
openSearchStarred() { openSearchStarred() {
this.$rootScope.appEvent('show-dash-search', {starred: true}); appEvents.emit('show-dash-search', {starred: true});
} }
openSearchTags() { openSearchTags() {
this.$rootScope.appEvent('show-dash-search', {tagsMode: true}); appEvents.emit('show-dash-search', {tagsMode: true});
} }
openSearch() { openSearch() {
this.$rootScope.appEvent('show-dash-search'); appEvents.emit('show-dash-search');
} }
openAlerting() { openAlerting() {
......
...@@ -6,7 +6,7 @@ describe('SearchCtrl', () => { ...@@ -6,7 +6,7 @@ describe('SearchCtrl', () => {
search: (options: any) => {}, search: (options: any) => {},
getDashboardTags: () => {} getDashboardTags: () => {}
}; };
let ctrl = new SearchCtrl({}, {}, {}, <SearchSrv>searchSrvStub, { onAppEvent: () => { } }); let ctrl = new SearchCtrl({$on: () => {}}, {}, {}, <SearchSrv>searchSrvStub);
describe('Given an empty result', () => { describe('Given an empty result', () => {
beforeEach(() => { beforeEach(() => {
......
import { SearchResultsCtrl } from '../components/search/search_results'; import { SearchResultsCtrl } from '../components/search/search_results';
import { beforeEach, afterEach } from 'test/lib/common';
import appEvents from 'app/core/app_events';
jest.mock('app/core/app_events', () => {
return {
emit: jest.fn<any>()
};
});
describe('SearchResultsCtrl', () => { describe('SearchResultsCtrl', () => {
let ctrl; let ctrl;
...@@ -94,4 +102,39 @@ describe('SearchResultsCtrl', () => { ...@@ -94,4 +102,39 @@ describe('SearchResultsCtrl', () => {
expect(folderExpanded).toBeFalsy(); expect(folderExpanded).toBeFalsy();
}); });
}); });
describe('when clicking on a link in search result', () => {
const dashPath = 'dashboard/path';
const $location = { path: () => dashPath};
const appEventsMock = appEvents as any;
describe('with the same url as current path', () => {
beforeEach(() => {
ctrl = new SearchResultsCtrl($location);
const item = { url: dashPath};
ctrl.onItemClick(item);
});
it('should close the search', () => {
expect(appEventsMock.emit.mock.calls.length).toBe(1);
expect(appEventsMock.emit.mock.calls[0][0]).toBe('hide-dash-search');
});
});
describe('with a different url than current path', () => {
beforeEach(() => {
ctrl = new SearchResultsCtrl($location);
const item = { url: 'another/path'};
ctrl.onItemClick(item);
});
it('should do nothing', () => {
expect(appEventsMock.emit.mock.calls.length).toBe(0);
});
});
afterEach(() => {
appEventsMock.emit.mockClear();
});
});
}); });
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
<i class="fa fa-save"></i> <i class="fa fa-save"></i>
</button> </button>
<button class="btn navbar-button navbar-button--snapshot-origin" ng-if="::ctrl.dashboard.snapshot.originalUrl" ng-href="{{ctrl.dashboard.snapshot.originalUrl}}" bs-tooltip="'Open original dashboard'" data-placement="bottom"> <a class="btn navbar-button navbar-button--snapshot-origin" ng-if="::ctrl.dashboard.snapshot.originalUrl" href="{{ctrl.dashboard.snapshot.originalUrl}}" bs-tooltip="'Open original dashboard'" data-placement="bottom">
<i class="fa fa-link"></i> <i class="fa fa-link"></i>
</button> </a>
<button class="btn navbar-button navbar-button--settings" ng-click="ctrl.toggleSettings()" bs-tooltip="'Settings'" data-placement="bottom" ng-show="ctrl.dashboard.meta.showSettings"> <button class="btn navbar-button navbar-button--settings" ng-click="ctrl.toggleSettings()" bs-tooltip="'Settings'" data-placement="bottom" ng-show="ctrl.dashboard.meta.showSettings">
<i class="fa fa-cog"></i> <i class="fa fa-cog"></i>
......
...@@ -11,7 +11,6 @@ export class DashNavCtrl { ...@@ -11,7 +11,6 @@ export class DashNavCtrl {
/** @ngInject */ /** @ngInject */
constructor( constructor(
private $scope, private $scope,
private $rootScope,
private dashboardSrv, private dashboardSrv,
private $location, private $location,
public playlistSrv) { public playlistSrv) {
...@@ -75,7 +74,7 @@ export class DashNavCtrl { ...@@ -75,7 +74,7 @@ export class DashNavCtrl {
} }
showSearch() { showSearch() {
this.$rootScope.appEvent('show-dash-search'); appEvents.emit('show-dash-search');
} }
addPanel() { addPanel() {
......
///<reference path="../../headers/common.d.ts" /> ///<reference path="../../headers/common.d.ts" />
import coreModule from "app/core/core_module"; import coreModule from 'app/core/core_module';
import { appEvents } from "app/core/core"; import appEvents from 'app/core/app_events';
export class TeamsCtrl { export class TeamsCtrl {
teams: any; teams: any;
......
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