mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* ux: Add missing icon for login with grafana-com, fixes #10238 * fix: This fix potentially solves installations in sub directories, #10252
This commit is contained in:
parent
22643eb109
commit
e569c8ea10
@ -1,19 +1,35 @@
|
||||
import coreModule from 'app/core/core_module';
|
||||
import config from 'app/core/config';
|
||||
import appEvents from 'app/core/app_events';
|
||||
|
||||
// This service is for registering global events.
|
||||
// Good for communication react > angular and vice verse
|
||||
export class GlobalEventSrv {
|
||||
private appSubUrl;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private $location, private $timeout) {
|
||||
this.appSubUrl = config.appSubUrl;
|
||||
}
|
||||
|
||||
// Angular's $location does not like <base href...> and absolute urls
|
||||
stripBaseFromUrl (url = '') {
|
||||
const appSubUrl = this.appSubUrl;
|
||||
const stripExtraChars = appSubUrl.endsWith('/') ? 1 : 0;
|
||||
const urlWithoutBase = url.length > 0 && url.indexOf(appSubUrl) === 0 ?
|
||||
url.slice(appSubUrl.length - stripExtraChars)
|
||||
: url;
|
||||
|
||||
return urlWithoutBase;
|
||||
}
|
||||
|
||||
init() {
|
||||
appEvents.on('location-change', payload => {
|
||||
this.$timeout(() => { // A hack to use timeout when we're changing things (in this case the url) from outside of Angular.
|
||||
this.$location.path(payload.href);
|
||||
});
|
||||
const urlWithoutBase = this.stripBaseFromUrl(payload.href);
|
||||
|
||||
this.$timeout(() => { // A hack to use timeout when we're changing things (in this case the url) from outside of Angular.
|
||||
this.$location.url(urlWithoutBase);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
23
public/app/core/specs/global_event_srv.jest.ts
Normal file
23
public/app/core/specs/global_event_srv.jest.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { GlobalEventSrv } from 'app/core/services/global_event_srv';
|
||||
import { beforeEach } from 'test/lib/common';
|
||||
|
||||
jest.mock('app/core/config', () => {
|
||||
return {
|
||||
appSubUrl: '/subUrl'
|
||||
};
|
||||
});
|
||||
|
||||
describe('GlobalEventSrv', () => {
|
||||
let searchSrv;
|
||||
|
||||
beforeEach(() => {
|
||||
searchSrv = new GlobalEventSrv(null, null);
|
||||
});
|
||||
|
||||
describe('With /subUrl as appSubUrl', () => {
|
||||
it('/subUrl should be stripped', () => {
|
||||
const urlWithoutMaster = searchSrv.stripBaseFromUrl('/subUrl/grafana/');
|
||||
expect(urlWithoutMaster).toBe('/grafana/');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user